04_Ipc.py 3.2 KB

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