02_Memory.py 1.3 KB

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