forked from avocado-framework/avocado-misc-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltp.py
90 lines (78 loc) · 3.6 KB
/
ltp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2016 IBM
# Author: Santhosh G <[email protected]>
#
# Based on code by Martin Bligh <[email protected]>
# copyright 2006 Google, Inc.
# https://github.com/autotest/autotest-client-tests/tree/master/ltp
from avocado import Test
from avocado import main
from avocado.utils import build
from avocado.utils import process, archive
import os
from avocado.utils.software_manager import SoftwareManager
class ltp(Test):
"""
LTP (Linux Test Project) testsuite
:param script: Which ltp script to run (default is "runltplite.sh", which
implies all LTP tests. You can use "runltp" + args to
specify subset of tests).
:param args: Extra arguments (default "", with "runltp" you can use
"-f $test")
"""
def setUp(self):
sm = SoftwareManager()
deps = ['gcc', 'make', 'automake', 'autoconf']
for package in deps:
if not sm.check_installed(package) and not sm.install(package):
self.error(package + ' is needed for the test to be run')
url = "https://github.com/linux-test-project/ltp/archive/master.zip"
tarball = self.fetch_asset("ltp-master.zip", locations=[url])
archive.extract(tarball, self.srcdir)
ltp_dir = os.path.join(self.srcdir, "ltp-master")
os.chdir(ltp_dir)
build.make(ltp_dir, extra_args='autotools')
ltpbin_dir = os.path.join(ltp_dir, 'bin')
os.mkdir(ltpbin_dir)
process.system('./configure --prefix=%s' % ltpbin_dir)
build.make(ltp_dir)
build.make(ltp_dir, extra_args='install')
def test(self):
script = self.params.get('script', default='runltplite.sh')
args = self.params.get('args', default='')
if script == 'runltp':
logfile = os.path.join(self.logdir, 'ltp.log')
failcmdfile = os.path.join(self.logdir, 'failcmdfile')
skipfile = os.path.join(self.datadir, 'skipfile')
args += (" -q -p -l %s -C %s -d %s -S %s"
% (logfile, failcmdfile, self.srcdir, skipfile))
ltpbin_dir = os.path.join(self.srcdir, "ltp-master", 'bin')
cmd = os.path.join(ltpbin_dir, script) + ' ' + args
result = process.run(cmd, ignore_status=True)
# Walk the stdout and try detect failed tests from lines like these:
# aio01 5 TPASS : Test 5: 10 reads and writes in 0.000022 sec
# vhangup02 1 TFAIL : vhangup02.c:88: vhangup() failed, errno:1
# and check for fail_statuses The first part contain test name
fail_statuses = ['TFAIL', 'TBROK', 'TWARN']
split_lines = (line.split(None, 3)
for line in result.stdout.splitlines())
failed_tests = [items[0] for items in split_lines
if len(items) == 4 and items[2] in fail_statuses]
if failed_tests:
self.fail("LTP tests failed: %s" % ", ".join(failed_tests))
elif result.exit_status != 0:
self.fail("No test failures detected, but LTP finished with %s"
% (result.exit_status))
if __name__ == "__main__":
main()