fetch.py 5.1 KB

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