fetch.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import subprocess
  2. import csv
  3. import os
  4. import threading
  5. import time
  6. import signal
  7. import tempfile
  8. class RunCmd(threading.Thread):
  9. def __init__(self, cmd, timeout, test):
  10. threading.Thread.__init__(self)
  11. self.cmd = cmd
  12. self.timeout = int(timeout)*100
  13. self.output = ""
  14. self.test = test
  15. self.test_subtest = test
  16. def run(self):
  17. name = tempfile.NamedTemporaryFile(mode='w+b')
  18. self.p = subprocess.Popen(self.cmd, shell=True, stdout=name, stderr=subprocess.STDOUT, preexec_fn=os.setsid, close_fds=True)
  19. self.curtime = time.time()
  20. self.endtime = self.curtime + self.timeout
  21. needed_times = self.timeout
  22. sleep_time = 0
  23. finish = False
  24. while sleep_time < self.timeout:
  25. if self.p.poll() is not None:
  26. finish = True
  27. break
  28. sleep_time += 1
  29. time.sleep(.01)
  30. if not finish and self.p.poll() is None:
  31. timed_out = True
  32. print CRED + "[Hanged ] " + self.test_subtest + CEND
  33. current_hanged[self.test_subtest] = 1
  34. os.killpg(os.getpgid(self.p.pid), signal.SIGKILL)
  35. del self.p
  36. if (finish):
  37. name.seek(0)
  38. for output in name.readlines():
  39. toks = output.split()
  40. if len(toks)<2 or (toks[0] != self.test and self.test != "memcmp01" and self.test != "memcpy01"):
  41. continue
  42. test_subtest = self.test + "," + toks[1]
  43. self.test_subtest = test_subtest
  44. if "TINFO" in output or test_subtest in current_passed or test_subtest in current_failed or self.test in current_hanged or test_subtest in current_blocked:
  45. continue
  46. if output:
  47. output = output.strip()
  48. print >>f1, output
  49. if "TFAIL" in output:
  50. print >>failed_tests_fh, test_subtest
  51. print CRED + "[Fail ] " + test_subtest + CEND
  52. current_failed[test_subtest] = 1
  53. elif "TPASS" in output:
  54. print >>passed_tests_fh, test_subtest
  55. print CGREEN + "[Pass ] " + test_subtest + CEND
  56. current_passed[test_subtest] = 1
  57. elif "TCONF" in output or "TBROK" in output or "error" in output:
  58. print >>broken_tests_fh, test_subtest
  59. print "[Broken ] " + test_subtest #Syscall not implemented or test preparation failed
  60. current_blocked[test_subtest] = 1
  61. #else:
  62. # print "[Broken ] " + self.test #Syscall not implemented or test preparation failed
  63. def Run(self):
  64. self.start()
  65. self.join()
  66. CRED = '\033[91m'
  67. CGREEN = '\033[92m'
  68. CEND = '\033[0m'
  69. DEFAULT_TIMEOUT = 20
  70. resultfile = "run_output"
  71. stablePass = "PASSED"
  72. timeouts = "TIMEOUTS"
  73. failed_tests_file = "Failed.csv"
  74. passed_tests_file = "Passed.csv"
  75. broken_tests_file = "Broken.csv"
  76. f1 = open(resultfile, 'w')
  77. failed_tests_fh = open(failed_tests_file, 'w', 0)
  78. passed_tests_fh = open(passed_tests_file, 'w', 0)
  79. broken_tests_fh = open(broken_tests_file, 'w', 0)
  80. failed_tests_fh.write("Test,Subtest number,Status\n")
  81. passed_tests_fh.write("Test,Subtest number\n")
  82. broken_tests_fh.write("Test,Subtest number,Status\n")
  83. current_passed = dict()
  84. current_failed = dict()
  85. current_blocked = dict()
  86. current_hanged = dict()
  87. timeouts_dict = dict()
  88. with open(timeouts, 'rb') as csvfile:
  89. test_timeout = csv.reader(csvfile)
  90. test_timeout.next()
  91. for row in test_timeout:
  92. test = row[0]
  93. timeout = row[1]
  94. timeouts_dict[test] = timeout
  95. os.chdir("opt/ltp/testcases/bin")
  96. with open('../../../../syscalls.graphene') as testcases:
  97. for line in testcases:
  98. tokens = line.split( )
  99. test = tokens[1]
  100. if test=="seq":
  101. test = tokens[6] #splice02
  102. try:
  103. timeout = timeouts_dict[test]
  104. except KeyError:
  105. timeout = DEFAULT_TIMEOUT
  106. RunCmd([line], timeout, test).Run()
  107. time.sleep(.1)
  108. os.chdir("../../../..")
  109. stable_passed = dict()
  110. with open(stablePass, 'rb') as csvfile:
  111. test_subtest = csv.reader(csvfile)
  112. test_subtest.next()
  113. for row in test_subtest:
  114. tst = row[0] + "," + row[1]
  115. stable_passed[tst] = 1
  116. print "\n\nRESULT [Difference] :\n---------------------\n"
  117. for test in stable_passed:
  118. if not test in current_passed:
  119. print CRED + "Test '" + test + "' did not pass in the current run!!" + CEND
  120. for test in current_passed:
  121. if not test in stable_passed:
  122. print CGREEN + "Test '" + test + "' passed in the current run!!" + CEND
  123. print "\n"