fetch.py 4.4 KB

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