04_Ipc.py 3.3 KB

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