00_Bootstrap.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. def check_cpu_info(res):
  37. cpu_num = cpu_model = cpu_family = cpu_stepping = 0
  38. cpu_vendor = cpu_brand = cpu_flags = None
  39. f = open("/proc/cpuinfo", "r")
  40. for line in f:
  41. line = line.strip()
  42. pos = line.find(":")
  43. if pos == -1:
  44. continue
  45. key = line[:pos].strip()
  46. val = line[pos+1:].strip()
  47. if key == "processor": cpu_num += 1
  48. if key == "vendor_id": cpu_vendor = val
  49. if key == "cpu family": cpu_family = int(val)
  50. if key == "model": cpu_model = int(val)
  51. if key == "model name": cpu_brand = val
  52. if key == "stepping": cpu_stepping = int(val)
  53. if key == "flags":
  54. cpu_flags = []
  55. for flag in val.split(" "):
  56. if flag in ["fpu", "vme", "de", "pse", "tsc", "msr", "pae",
  57. "mce", "cx8", "apic", "sep", "mtrr", "pge", "mca",
  58. "cmov", "pat", "pse36", "pn", "clflush", "dts", "acpi",
  59. "mmx", "fxsr", "sse", "sse2", "ss", "ht", "tm",
  60. "ia64", "pbe"]:
  61. cpu_flags.append(flag)
  62. cpu_flags = " ".join(cpu_flags)
  63. return ("CPU num: %d" % cpu_num) in res[0].log and \
  64. ("CPU vendor: %s" % cpu_vendor) in res[0].log and \
  65. ("CPU brand: %s" % cpu_brand) in res[0].log and \
  66. ("CPU family: %d" % cpu_family) in res[0].log and \
  67. ("CPU model: %d" % cpu_model) in res[0].log and \
  68. ("CPU stepping: %d" % cpu_stepping) in res[0].log and \
  69. ("CPU flags: %s" % cpu_flags) in res[0].log
  70. regression.add_check(name="Control Block: CPU Info",
  71. check=check_cpu_info)
  72. rv = regression.run_checks()
  73. if rv: sys.exit(rv)
  74. # Running ..Bootstrap
  75. regression = Regression(loader, "..Bootstrap")
  76. regression.add_check(name="Dotdot handled properly",
  77. check=lambda res: "User Program Started" in res[0].log)
  78. rv = regression.run_checks()
  79. if rv: sys.exit(rv)
  80. # Running Bootstrap2
  81. regression = Regression(loader, "Bootstrap2")
  82. regression.add_check(name="Control Block: Manifest as Executable Name",
  83. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap2") in res[0].log)
  84. rv = regression.run_checks()
  85. if rv: sys.exit(rv)
  86. # Running Bootstrap3
  87. regression = Regression(loader, "Bootstrap3")
  88. regression.add_check(name="Preload Libraries",
  89. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  90. "Binary 2 Preloaded" in res[0].log)
  91. regression.add_check(name="Preload Libraries Linking",
  92. check=lambda res: "Preloaded Function 1 Called" in res[0].log and
  93. "Preloaded Function 2 Called" in res[0].log)
  94. rv = regression.run_checks()
  95. if rv: sys.exit(rv)
  96. # Running Bootstrap4
  97. regression = Regression(loader, manifest_file("Bootstrap4"))
  98. regression.add_check(name="Control Block: Manifest as Argument",
  99. check=lambda res: any([line.startswith("Loaded Manifest: file:" + manifest_file("Bootstrap4")) for line in res[0].log]))
  100. regression.add_check(name="Control Block: Executable as in Manifest",
  101. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  102. rv = regression.run_checks()
  103. if rv: sys.exit(rv)
  104. # Running Bootstrap4.manifest
  105. regression = Regression(executable = "./" + manifest_file("Bootstrap4"))
  106. regression.add_check(name="Control Block: Manifest as Argument (Load by Shebang)",
  107. check=lambda res: "Loaded Manifest: file:" + manifest_file("Bootstrap4") in res[0].log)
  108. regression.add_check(name="Control Block: Executable as in Manifest (Load by Shebang)",
  109. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  110. regression.add_check(name="Arguments: loader.execname in Manifest",
  111. check=lambda res: "argv[0] = Bootstrap" in res[0].log)
  112. rv = regression.run_checks()
  113. if rv: sys.exit(rv)
  114. # Running Bootstrap5.manifest
  115. regression = Regression(loader, manifest_file("Bootstrap5"))
  116. regression.add_check(name="Bootstrap without Executable but Preload Libraries",
  117. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  118. "Binary 2 Preloaded" in res[0].log)
  119. rv = regression.run_checks()
  120. if rv: sys.exit(rv)
  121. # Running Bootstrap6.manifest - SGX-specific test
  122. if sgx:
  123. regression = Regression(loader, manifest_file("Bootstrap6"), timeout = 100000)
  124. regression.add_check(name="8GB Enclave Creation (SGX Only)",
  125. check=lambda res: "Loaded Manifest: file:Bootstrap6.manifest.sgx" in res[0].log and
  126. "Executable Range OK" in res[0].log)
  127. rv = regression.run_checks()
  128. if rv: sys.exit(rv)
  129. # Running Bootstrap7.manifest
  130. regression = Regression(loader, manifest_file("Bootstrap7"))
  131. regression.add_check(name="Load Large Number of Items in Manifest",
  132. check=lambda res: "key1000=na" in res[0].log and
  133. "key1=na" in res[0].log)
  134. rv = regression.run_checks()
  135. if rv: sys.exit(rv)