02_Memory.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python2
  2. import os, sys, mmap
  3. from regression import Regression
  4. loader = os.environ['PAL_LOADER']
  5. try:
  6. sgx = os.environ['SGX_RUN']
  7. except KeyError:
  8. sgx = 0
  9. regression = Regression(loader, "Memory")
  10. regression.add_check(name="Memory Allocation",
  11. check=lambda res: "Memory Allocation OK" in res[0].log)
  12. regression.add_check(name="Memory Allocation with Address",
  13. check=lambda res: "Memory Allocation with Address OK" in res[0].log)
  14. # SGX1 does not support unmapping a page or changing its permission after
  15. # enclave init. Therefore the memory protection and deallocation tests will
  16. # fail. By utilizing SGX2 it's possibile to fix this.
  17. regression.add_check(name="Memory Protection", ignore_failure = sgx,
  18. check=lambda res: "Memory Allocation Protection (RW) OK" in res[0].log and
  19. "Memory Protection (R) OK" in res[0].log)
  20. regression.add_check(name="Memory Deallocation", ignore_failure = sgx,
  21. check=lambda res: "Memory Deallocation OK" in res[0].log)
  22. def check_quota(res):
  23. for line in res[0].log:
  24. if line.startswith("Total Memory:"):
  25. return line != "Total Memory: 0"
  26. return False
  27. regression.add_check(name="Get Memory Total Quota", check=check_quota)
  28. regression.add_check(name="Get Memory Available Quota",
  29. check=lambda res: "Get Memory Available Quota OK" in res[0].log)
  30. rv = regression.run_checks()
  31. if rv: sys.exit(rv)