00_Bootstrap.py 4.1 KB

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