02_Thread.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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, "Thread")
  6. regression.add_check(name="Thread Creation",
  7. check=lambda res: "Child Thread Created" in res[0].log and
  8. "Run in Child Thread: Hello World" in res[0].log)
  9. regression.add_check(name="Multiple Threads Run in Parallel",
  10. check=lambda res: "Threads Run in Parallel OK" in res[0].log)
  11. regression.add_check(name="Set Thread Private Segment Register",
  12. check=lambda res: "Private Message (FS Segment) 1: Hello World 1" in res[0].log and
  13. "Private Message (FS Segment) 2: Hello World 2" in res[0].log)
  14. regression.add_check(name="Thread Exit",
  15. check=lambda res: "Child Thread Exited" in res[0].log)
  16. rv = regression.run_checks()
  17. if rv: sys.exit(rv)
  18. regression = Regression(loader, "Thread2")
  19. regression.add_check(name="Thread Cleanup: Exit by return.",
  20. check=lambda res: "Thread 2 ok." in res[0].log)
  21. # The 2 following tests are currently broken on SGX because TCS slots are not
  22. # reused yet (needed because of thread limit), see issue #517.
  23. regression.add_check(name="Thread Cleanup: Exit by DkThreadExit.",
  24. check=lambda res: "Thread 3 ok." in res[0].log and
  25. "Exiting thread 3 failed." not in res[0].log,
  26. ignore_failure=sgx)
  27. regression.add_check(name="Thread Cleanup: Can still start threads.",
  28. check=lambda res: "Thread 4 ok." in res[0].log,
  29. ignore_failure=sgx)
  30. rv = regression.run_checks()
  31. if rv: sys.exit(rv)