ltp_compliance.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # LTP compliance runtime
  2. #
  3. # Copyright (c) 2019 MontaVista Software, LLC
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  7. import time
  8. import datetime
  9. import pprint
  10. from oeqa.runtime.case import OERuntimeTestCase
  11. from oeqa.core.decorator.depends import OETestDepends
  12. from oeqa.runtime.decorator.package import OEHasPackage
  13. from oeqa.utils.logparser import LtpComplianceParser
  14. class LtpPosixBase(OERuntimeTestCase):
  15. @classmethod
  16. def setUpClass(cls):
  17. cls.ltp_startup()
  18. @classmethod
  19. def tearDownClass(cls):
  20. cls.ltp_finishup()
  21. @classmethod
  22. def ltp_startup(cls):
  23. cls.sections = {}
  24. cls.failmsg = ""
  25. test_log_dir = os.path.join(cls.td.get('WORKDIR', ''), 'testimage')
  26. timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
  27. cls.ltptest_log_dir_link = os.path.join(test_log_dir, 'ltpcomp_log')
  28. cls.ltptest_log_dir = '%s.%s' % (cls.ltptest_log_dir_link, timestamp)
  29. os.makedirs(cls.ltptest_log_dir)
  30. cls.tc.target.run("mkdir -p /opt/ltp/results")
  31. if not hasattr(cls.tc, "extraresults"):
  32. cls.tc.extraresults = {}
  33. cls.extras = cls.tc.extraresults
  34. cls.extras['ltpposixresult.rawlogs'] = {'log': ""}
  35. @classmethod
  36. def ltp_finishup(cls):
  37. cls.extras['ltpposixresult.sections'] = cls.sections
  38. # update symlink to ltp_log
  39. if os.path.exists(cls.ltptest_log_dir_link):
  40. os.remove(cls.ltptest_log_dir_link)
  41. os.symlink(os.path.basename(cls.ltptest_log_dir), cls.ltptest_log_dir_link)
  42. if cls.failmsg:
  43. cls.fail(cls.failmsg)
  44. class LtpPosixTest(LtpPosixBase):
  45. posix_groups = ["AIO", "MEM", "MSG", "SEM", "SIG", "THR", "TMR", "TPS"]
  46. def runltp(self, posix_group):
  47. cmd = "/opt/ltp/bin/run-posix-option-group-test.sh %s 2>@1 | tee /opt/ltp/results/%s" % (posix_group, posix_group)
  48. starttime = time.time()
  49. (status, output) = self.target.run(cmd)
  50. endtime = time.time()
  51. with open(os.path.join(self.ltptest_log_dir, "%s" % posix_group), 'w') as f:
  52. f.write(output)
  53. self.extras['ltpposixresult.rawlogs']['log'] = self.extras['ltpposixresult.rawlogs']['log'] + output
  54. parser = LtpComplianceParser()
  55. results, sections = parser.parse(os.path.join(self.ltptest_log_dir, "%s" % posix_group))
  56. runtime = int(endtime-starttime)
  57. sections['duration'] = runtime
  58. self.sections[posix_group] = sections
  59. failed_tests = {}
  60. for test in results:
  61. result = results[test]
  62. testname = ("ltpposixresult." + posix_group + "." + test)
  63. self.extras[testname] = {'status': result}
  64. if result == 'FAILED':
  65. failed_tests[posix_group] = test
  66. if failed_tests:
  67. self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
  68. # LTP Posix compliance runtime tests
  69. @OETestDepends(['ssh.SSHTest.test_ssh'])
  70. @OEHasPackage(["ltp"])
  71. def test_posix_groups(self):
  72. for posix_group in self.posix_groups:
  73. self.runltp(posix_group)