05_Reference_Monitor.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python
  2. import os, sys, mmap
  3. from regression import Regression
  4. loader = os.environ['PAL_SEC']
  5. if not os.path.exists(loader):
  6. print "Reference monitor mode is not available on this platform"
  7. exit(0)
  8. # Running Bootstrap
  9. regression = Regression(loader, "Bootstrap")
  10. regression.add_check(name="Basic Bootstrapping",
  11. check=lambda res: "User Program Started" in res[0].log)
  12. regression.add_check(name="Control Block: Executable Name",
  13. check=lambda res: "Loaded Executable: file:Bootstrap" in res[0].log)
  14. regression.add_check(name="Control Block: Default Manifest",
  15. check=lambda res: "Loaded Manifest: file:manifest" 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[0] = file:Bootstrap" in res[0].log and \
  23. "argv[1] = a" in res[0].log and "argv[2] = b" in res[0].log and \
  24. "argv[3] = c" in res[0].log and "argv[4] = d" in res[0].log)
  25. regression.add_check(name="Control Block: Debug Stream (Inline)",
  26. check=lambda res: "Written to Debug Stream" in res[0].out)
  27. regression.add_check(name="Control Block: Page Size",
  28. check=lambda res: ("Page Size: %d" % (mmap.PAGESIZE)) in res[0].log)
  29. regression.add_check(name="Control Block: Allocation Alignment",
  30. check=lambda res: ("Allocation Alignment: %d" % (mmap.ALLOCATIONGRANULARITY)) in res[0].log)
  31. regression.add_check(name="Control Block: Executable Range",
  32. check=lambda res: "Executable Range OK" in res[0].log)
  33. regression.run_checks()
  34. # Running Bootstrap3
  35. regression = Regression(loader, "Bootstrap3")
  36. regression.add_check(name="Preload Libraries",
  37. check=lambda res: "Binary 1 Preloaded" in res[0].log and
  38. "Binary 2 Preloaded" in res[0].log)
  39. regression.add_check(name="Preload Libraries Linking",
  40. check=lambda res: "Preloaded Function 1 Called" in res[0].log and
  41. "Preloaded Function 2 Called" in res[0].log)
  42. regression.run_checks()