ltp.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # LTP 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 LtpParser
  14. class LtpTestBase(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, 'ltp_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['ltpresult.rawlogs'] = {'log': ""}
  35. @classmethod
  36. def ltp_finishup(cls):
  37. cls.extras['ltpresult.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 LtpTest(LtpTestBase):
  45. ltp_groups = ["math", "syscalls", "dio", "io", "mm", "ipc", "sched", "nptl", "pty", "containers", "controllers", "filecaps", "cap_bounds", "fcntl-locktests", "connectors","timers", "commands", "net.ipv6_lib", "input","fs_perms_simple"]
  46. ltp_fs = ["fs", "fsx", "fs_bind", "fs_ext4"]
  47. # skip kernel cpuhotplug
  48. ltp_kernel = ["power_management_tests", "hyperthreading ", "kernel_misc", "hugetlb"]
  49. ltp_groups += ltp_fs
  50. def runltp(self, ltp_group):
  51. cmd = '/opt/ltp/runltp -f %s -p -q -r /opt/ltp -l /opt/ltp/results/%s -I 1 -d /opt/ltp' % (ltp_group, ltp_group)
  52. starttime = time.time()
  53. (status, output) = self.target.run(cmd)
  54. endtime = time.time()
  55. with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f:
  56. f.write(output)
  57. self.extras['ltpresult.rawlogs']['log'] = self.extras['ltpresult.rawlogs']['log'] + output
  58. # copy nice log from DUT
  59. dst = os.path.join(self.ltptest_log_dir, "%s" % ltp_group )
  60. remote_src = "/opt/ltp/results/%s" % ltp_group
  61. (status, output) = self.target.copyFrom(remote_src, dst)
  62. msg = 'File could not be copied. Output: %s' % output
  63. self.assertEqual(status, 0, msg=msg)
  64. parser = LtpParser()
  65. results, sections = parser.parse(dst)
  66. runtime = int(endtime-starttime)
  67. sections['duration'] = runtime
  68. self.sections[ltp_group] = sections
  69. failed_tests = {}
  70. for test in results:
  71. result = results[test]
  72. testname = ("ltpresult." + ltp_group + "." + test)
  73. self.extras[testname] = {'status': result}
  74. if result == 'FAILED':
  75. failed_tests[ltp_group] = test
  76. if failed_tests:
  77. self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
  78. # LTP runtime tests
  79. @OETestDepends(['ssh.SSHTest.test_ssh'])
  80. @OEHasPackage(["ltp"])
  81. def test_ltp_help(self):
  82. (status, output) = self.target.run('/opt/ltp/runltp --help')
  83. msg = 'Failed to get ltp help. Output: %s' % output
  84. self.assertEqual(status, 0, msg=msg)
  85. @OETestDepends(['ltp.LtpTest.test_ltp_help'])
  86. def test_ltp_groups(self):
  87. for ltp_group in self.ltp_groups:
  88. self.runltp(ltp_group)
  89. @OETestDepends(['ltp.LtpTest.test_ltp_groups'])
  90. def test_ltp_runltp_cve(self):
  91. self.runltp("cve")