fetch.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. reported = False
  38. name.seek(0)
  39. for output in name.readlines():
  40. toks = output.split()
  41. if len(toks)<2 or (toks[0] != self.test and self.test != "memcmp01" and self.test != "memcpy01"):
  42. continue
  43. test_subtest = self.test + "," + toks[1]
  44. self.test_subtest = test_subtest
  45. 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_broken:
  46. continue
  47. if output:
  48. output = output.strip()
  49. print >>f1, output
  50. if "TFAIL" in output:
  51. print >>failed_tests_fh, test_subtest
  52. print CRED + "[Fail ] " + test_subtest + CEND
  53. current_failed[test_subtest] = 1
  54. reported = True
  55. elif "TPASS" in output:
  56. print >>passed_tests_fh, test_subtest
  57. print CGREEN + "[Pass ] " + test_subtest + CEND
  58. current_passed[test_subtest] = 1
  59. reported = True
  60. elif "TCONF" in output or "TBROK" in output or "error" in output:
  61. print >>broken_tests_fh, test_subtest
  62. print "[Broken ] " + test_subtest #Syscall not implemented or test preparation failed
  63. current_broken[test_subtest] = 1
  64. reported = True
  65. #else:
  66. # print "[Broken ] " + self.test #Syscall not implemented or test preparation failed
  67. if (not reported):
  68. print >>broken_tests_fh, self.test
  69. print CRED + "[Broken ] " + self.test + CEND
  70. current_broken[self.test] = 1
  71. def Run(self):
  72. self.start()
  73. self.join()
  74. CRED = '\033[91m'
  75. CGREEN = '\033[92m'
  76. CEND = '\033[0m'
  77. DEFAULT_TIMEOUT = 20
  78. resultfile = "run_output"
  79. stablePass = "PASSED"
  80. timeouts = "TIMEOUTS"
  81. failed_tests_file = "Failed.csv"
  82. passed_tests_file = "Passed.csv"
  83. broken_tests_file = "Broken.csv"
  84. f1 = open(resultfile, 'w')
  85. failed_tests_fh = open(failed_tests_file, 'w', 0)
  86. passed_tests_fh = open(passed_tests_file, 'w', 0)
  87. broken_tests_fh = open(broken_tests_file, 'w', 0)
  88. failed_tests_fh.write("Test,Subtest number,Status\n")
  89. passed_tests_fh.write("Test,Subtest number\n")
  90. broken_tests_fh.write("Test,Subtest number,Status\n")
  91. current_passed = dict()
  92. current_failed = dict()
  93. current_broken = dict()
  94. current_hanged = dict()
  95. timeouts_dict = dict()
  96. with open(timeouts, 'rb') as csvfile:
  97. test_timeout = csv.reader(csvfile)
  98. test_timeout.next()
  99. for row in test_timeout:
  100. test = row[0]
  101. timeout = row[1]
  102. timeouts_dict[test] = timeout
  103. os.chdir("opt/ltp/testcases/bin")
  104. with open('../../../../syscalls.graphene') as testcases:
  105. for line in testcases:
  106. tokens = line.split( )
  107. test = tokens[1]
  108. if test=="seq":
  109. test = tokens[6] #splice02
  110. try:
  111. timeout = timeouts_dict[test]
  112. except KeyError:
  113. timeout = DEFAULT_TIMEOUT
  114. RunCmd([line], timeout, test).Run()
  115. time.sleep(.1)
  116. os.chdir("../../../..")
  117. stable_passed = dict()
  118. with open(stablePass, 'rb') as csvfile:
  119. test_subtest = csv.reader(csvfile)
  120. test_subtest.next()
  121. for row in test_subtest:
  122. tst = row[0] + "," + row[1]
  123. stable_passed[tst] = 1
  124. print "\n\nRESULT [Difference] :\n---------------------\n"
  125. for test in stable_passed:
  126. if not test in current_passed:
  127. print CRED + "Test '" + test + "' did not pass in the current run!!" + CEND
  128. for test in current_passed:
  129. if not test in stable_passed:
  130. print CGREEN + "Test '" + test + "' passed in the current run!!" + CEND
  131. print "\n"