ptest.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import unittest
  2. import pprint
  3. import datetime
  4. from oeqa.runtime.case import OERuntimeTestCase
  5. from oeqa.core.decorator.depends import OETestDepends
  6. from oeqa.core.decorator.data import skipIfNotFeature
  7. from oeqa.runtime.decorator.package import OEHasPackage
  8. from oeqa.utils.logparser import PtestParser
  9. class PtestRunnerTest(OERuntimeTestCase):
  10. @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES')
  11. @OETestDepends(['ssh.SSHTest.test_ssh'])
  12. @OEHasPackage(['ptest-runner'])
  13. @unittest.expectedFailure
  14. def test_ptestrunner(self):
  15. status, output = self.target.run('which ptest-runner', 0)
  16. if status != 0:
  17. self.skipTest("No -ptest packages are installed in the image")
  18. test_log_dir = self.td.get('TEST_LOG_DIR', '')
  19. # The TEST_LOG_DIR maybe NULL when testimage is added after
  20. # testdata.json is generated.
  21. if not test_log_dir:
  22. test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage')
  23. # Don't use self.td.get('DATETIME'), it's from testdata.json, not
  24. # up-to-date, and may cause "File exists" when re-reun.
  25. timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
  26. ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
  27. ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp)
  28. ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
  29. status, output = self.target.run('ptest-runner', 0)
  30. os.makedirs(ptest_log_dir)
  31. with open(ptest_runner_log, 'w') as f:
  32. f.write(output)
  33. # status != 0 is OK since some ptest tests may fail
  34. self.assertTrue(status != 127, msg="Cannot execute ptest-runner!")
  35. if not hasattr(self.tc, "extraresults"):
  36. self.tc.extraresults = {}
  37. extras = self.tc.extraresults
  38. extras['ptestresult.rawlogs'] = {'log': output}
  39. # Parse and save results
  40. parser = PtestParser()
  41. results, sections = parser.parse(ptest_runner_log)
  42. parser.results_as_files(ptest_log_dir)
  43. if os.path.exists(ptest_log_dir_link):
  44. # Remove the old link to create a new one
  45. os.remove(ptest_log_dir_link)
  46. os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link)
  47. extras['ptestresult.sections'] = sections
  48. trans = str.maketrans("()", "__")
  49. for section in results:
  50. for test in results[section]:
  51. result = results[section][test]
  52. testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
  53. extras[testname] = {'status': result}
  54. failed_tests = {}
  55. for section in results:
  56. failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ]
  57. if failed_testcases:
  58. failed_tests[section] = failed_testcases
  59. failmsg = ""
  60. status, output = self.target.run('dmesg | grep "Killed process"', 0)
  61. if output:
  62. failmsg = "ERROR: Processes were killed by the OOM Killer:\n%s\n" % output
  63. if failed_tests:
  64. failmsg = failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
  65. if failmsg:
  66. self.fail(failmsg)