02_Memory.py 1.4 KB

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