00_Bootstrap.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/python
  2. import os, sys, mmap
  3. from regression import Regression
  4. loader = '../src/pal'
  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 Bootstrap2
  34. regression = Regression(loader, "Bootstrap2")
  35. regression.add_check(name="Control Block: Manifest as Executable Name",
  36. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap2") in res[0].log)
  37. regression.run_checks()
  38. # Running Bootstrap3
  39. regression = Regression(loader, "Bootstrap3")
  40. regression.add_check(name="Preload Libraries",
  41. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  42. "Binary 2 Preloaded" in res[0].log)
  43. regression.add_check(name="Preload Libraries Linking",
  44. check=lambda res: "Preloaded Function 1 Called" in res[0].log and
  45. "Preloaded Function 2 Called" in res[0].log)
  46. regression.run_checks()
  47. # Running Bootstrap4
  48. regression = Regression(loader, manifest_file("Bootstrap4"))
  49. regression.add_check(name="Control Block: Manifest as Argument",
  50. check=lambda res: any([line.startswith("Loaded Manifest: file:" + manifest_file("Bootstrap4")) for line in res[0].log]))
  51. regression.add_check(name="Control Block: Executable as in Manifest",
  52. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  53. regression.run_checks()
  54. # Running Bootstrap4.manifest
  55. regression = Regression(executable = "./" + manifest_file("Bootstrap4"))
  56. regression.add_check(name="Control Block: Manifest as Argument (Load by Shebang)",
  57. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap4") in res[0].log)
  58. regression.add_check(name="Control Block: Executable as in Manifest (Load by Shebang)",
  59. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  60. regression.add_check(name="Arguments: loader.execname in Manifest",
  61. check=lambda res: "argv[0] = Bootstrap" in res[0].log)
  62. regression.run_checks()
  63. # Running Bootstrap5.manifest
  64. regression = Regression(loader, manifest_file("Bootstrap5"))
  65. regression.add_check(name="Bootstrap without Executable but Preload Libraries",
  66. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  67. "Binary 2 Preloaded" in res[0].log)
  68. regression.run_checks()