03_Process.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python2
  2. import os, sys, mmap
  3. from regression import Regression
  4. loader = os.environ['PAL_LOADER']
  5. regression = Regression(loader, "Process")
  6. def check_times(target, lines, times):
  7. count = 0
  8. for line in lines:
  9. if target == line:
  10. count += 1
  11. return count == times
  12. regression.add_check(name="Process Creation",
  13. check=lambda res: check_times("Child Process Created", res[0].log, 3))
  14. regression.add_check(name="Process Creation Arguments",
  15. check=lambda res: check_times("argv[0] = Process", res[0].log, 3) and
  16. check_times("argv[1] = Child", res[0].log, 3))
  17. regression.add_check(name="Process Channel Transmission",
  18. check=lambda res: check_times("Process Write 1 OK", res[0].log, 3) and
  19. check_times("Process Read 1: Hello World 1", res[0].log, 3) and
  20. check_times("Process Write 2 OK", res[0].log, 3) and
  21. check_times("Process Read 2: Hello World 2", res[0].log, 3))
  22. def check_broadcast_result(res):
  23. if not check_times("Warning: broadcast stream is not open. "
  24. "Do you have a multicast route configured?",
  25. res[0].log, 0):
  26. print("Could not open broadcast stream. Dou you have a multicast route configured?")
  27. return (check_times("Broadcast Write OK", res[0].log, 1) and
  28. check_times("Broadcast Read: Hello World 1", res[0].log, 3))
  29. regression.add_check(name="Multi-Process Broadcast Channel Transmission",
  30. check=check_broadcast_result)
  31. rv = regression.run_checks()
  32. if rv: sys.exit(rv)
  33. regression = Regression(loader, "Process2")
  34. regression.add_check(name="Process Creation with a Different Binary",
  35. check=lambda res: check_times("User Program Started", res[0].log, 1))
  36. rv = regression.run_checks()
  37. if rv: sys.exit(rv)
  38. regression = Regression(loader, "Process3")
  39. regression.add_check(name="Process Creation without Executable",
  40. check=lambda res: check_times("Binary 1 Preloaded", res[0].log, 2) and
  41. check_times("Binary 2 Preloaded", res[0].log, 2))
  42. rv = regression.run_checks()
  43. if rv: sys.exit(rv)