00_Bootstrap.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 = False
  9. def manifest_file(file):
  10. if 'SGX_RUN' in os.environ and os.environ['SGX_RUN'] == '1':
  11. return file + '.manifest.sgx'
  12. else:
  13. return file + '.manifest'
  14. # Running Bootstrap
  15. regression = Regression(loader, "Bootstrap")
  16. regression.add_check(name="Basic Bootstrapping",
  17. check=lambda res: "User Program Started" in res[0].log)
  18. regression.add_check(name="Control Block: Executable Name",
  19. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  20. regression.add_check(name="One Argument Given",
  21. check=lambda res: "# of Arguments: 1" in res[0].log and \
  22. "argv[0] = file:Bootstrap" in res[0].log)
  23. regression.add_check(name="Five Arguments Given",
  24. args = ['a', 'b', 'c', 'd'],
  25. check=lambda res: "# of Arguments: 5" in res[0].log and \
  26. "argv[1] = a" in res[0].log and "argv[2] = b" in res[0].log and \
  27. "argv[3] = c" in res[0].log and "argv[4] = d" in res[0].log)
  28. regression.add_check(name="Control Block: Debug Stream (Inline)",
  29. check=lambda res: "Written to Debug Stream" in res[0].out)
  30. regression.add_check(name="Control Block: Page Size",
  31. check=lambda res: ("Page Size: %d" % (mmap.PAGESIZE)) in res[0].log)
  32. regression.add_check(name="Control Block: Allocation Alignment",
  33. check=lambda res: ("Allocation Alignment: %d" % (mmap.ALLOCATIONGRANULARITY)) in res[0].log)
  34. regression.add_check(name="Control Block: Executable Range",
  35. check=lambda res: "Executable Range OK" in res[0].log)
  36. rv = regression.run_checks()
  37. if rv: sys.exit(rv)
  38. # Running ..Bootstrap
  39. regression = Regression(loader, "..Bootstrap")
  40. regression.add_check(name="Dotdot handled properly",
  41. check=lambda res: "User Program Started" in res[0].log)
  42. rv = regression.run_checks()
  43. if rv: sys.exit(rv)
  44. # Running Bootstrap2
  45. regression = Regression(loader, "Bootstrap2")
  46. regression.add_check(name="Control Block: Manifest as Executable Name",
  47. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap2") in res[0].log)
  48. rv = regression.run_checks()
  49. if rv: sys.exit(rv)
  50. # Running Bootstrap3
  51. regression = Regression(loader, "Bootstrap3")
  52. regression.add_check(name="Preload Libraries",
  53. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  54. "Binary 2 Preloaded" in res[0].log)
  55. regression.add_check(name="Preload Libraries Linking",
  56. check=lambda res: "Preloaded Function 1 Called" in res[0].log and
  57. "Preloaded Function 2 Called" in res[0].log)
  58. rv = regression.run_checks()
  59. if rv: sys.exit(rv)
  60. # Running Bootstrap4
  61. regression = Regression(loader, manifest_file("Bootstrap4"))
  62. regression.add_check(name="Control Block: Manifest as Argument",
  63. check=lambda res: any([line.startswith("Loaded Manifest: file:" + manifest_file("Bootstrap4")) for line in res[0].log]))
  64. regression.add_check(name="Control Block: Executable as in Manifest",
  65. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  66. rv = regression.run_checks()
  67. if rv: sys.exit(rv)
  68. # Running Bootstrap4.manifest
  69. regression = Regression(executable = "./" + manifest_file("Bootstrap4"))
  70. regression.add_check(name="Control Block: Manifest as Argument (Load by Shebang)",
  71. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap4") in res[0].log)
  72. regression.add_check(name="Control Block: Executable as in Manifest (Load by Shebang)",
  73. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  74. regression.add_check(name="Arguments: loader.execname in Manifest",
  75. check=lambda res: "argv[0] = Bootstrap" in res[0].log)
  76. rv = regression.run_checks()
  77. if rv: sys.exit(rv)
  78. # Running Bootstrap5.manifest
  79. regression = Regression(loader, manifest_file("Bootstrap5"))
  80. regression.add_check(name="Bootstrap without Executable but Preload Libraries",
  81. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  82. "Binary 2 Preloaded" in res[0].log)
  83. rv = regression.run_checks()
  84. if rv: sys.exit(rv)
  85. # Running Bootstrap6.manifest - SGX-specific test
  86. if sgx:
  87. regression = Regression(loader, manifest_file("Bootstrap6"), timeout = 100000)
  88. regression.add_check(name="8GB Enclave Creation (SGX Only)",
  89. check=lambda res: "Loaded Manifest: file:Bootstrap6.manifest.sgx" in res[0].log and
  90. "Executable Range OK" in res[0].log)
  91. rv = regression.run_checks()
  92. if rv: sys.exit(rv)