04_Ipc.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/python
  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. if sgx:
  10. print "Bulk IPC not supported on SGX"
  11. exit(0)
  12. ## XXX Should really be running these tests as part of CI
  13. if not os.path.exists('/dev/gipc'):
  14. print "GIPC not loaded; skipping these tests\n"
  15. exit(0)
  16. def prepare_files(args):
  17. with open("ipc_mapping.tmp", "w") as f:
  18. f.write("Hello World")
  19. os.ftruncate(f.fileno(), mmap.PAGESIZE)
  20. regression = Regression(loader, "Ipc", prepare_files)
  21. def check_times(target, lines, times):
  22. count = 0
  23. for line in lines:
  24. if target == line:
  25. count += 1
  26. return count == times
  27. regression.add_check(name="Create and Join Physical Memory Bulk Copy Store",
  28. check=lambda res: check_times("Create Physical Memory Store OK", res[0].log, 5) and
  29. check_times("Join Physical Memory Store OK", res[0].log, 5))
  30. regression.add_check(name="Map and Commit Anonymous Physical Memory",
  31. check=lambda res: "[Test 1] Physical Memory Commit OK" in res[0].log and
  32. "[Test 1] Physical Memory Map : Hello World" in res[0].log)
  33. regression.add_check(name="Transfer Anonymous Physical Memory as Copy-on-Write",
  34. check=lambda res: "[Test 1] Sender After Commit: Hello World, Alice" in res[0].log and
  35. "[Test 1] Sender Before Map : Alice, Hello World" in res[0].log and
  36. "[Test 1] Receiver After Map : Hello World, Bob" in res[0].log and
  37. "[Test 1] Sender After Map : Alice, Hello World" in res[0].log)
  38. regression.add_check(name="Map and Commit Untouched Physical Memory",
  39. check=lambda res: "[Test 2] Physical Memory Commit OK" in res[0].log and
  40. "[Test 2] Physical Memory Map : " in res[0].log and
  41. "[Test 2] Sender After Commit: Hello World, Alice" in res[0].log and
  42. "[Test 2] Sender Before Map : Alice, Hello World" in res[0].log and
  43. "[Test 2] Receiver After Map : Hello World, Bob" in res[0].log and
  44. "[Test 2] Sender After Map : Alice, Hello World" in res[0].log)
  45. regression.add_check(name="Map and Commit File-Backed Physical Memory",
  46. check=lambda res: "[Test 3] Physical Memory Commit OK" in res[0].log and
  47. "[Test 3] Physical Memory Map : Hello World" in res[0].log and
  48. "[Test 3] Sender After Commit: Hello World" in res[0].log and
  49. "[Test 3] Receiver After Map : Hello World, Bob" in res[0].log and
  50. "[Test 3] Sender After Map : Hello World" in res[0].log)
  51. regression.add_check(name="Map and Commit File-Backed Physical Memory Beyond File Size",
  52. check=lambda res: "[Test 4] Physical Memory Commit OK" in res[0].log and
  53. "[Test 4] Physical Memory Map : Memory Fault" in res[0].log)
  54. regression.add_check(name="Map and Commit Huge Physical Memory",
  55. check=lambda res: "[Test 5] Physical Memory Commit OK" in res[0].log and
  56. "[Test 5] Physical Memory Map : Hello World" in res[0].log)
  57. rv = regression.run_checks()
  58. if rv: sys.exit(rv)