fetch.py 5.2 KB

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