-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathruntest.py
executable file
·113 lines (102 loc) · 3.88 KB
/
runtest.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import time
import signal
import sys
import subprocess
from preparetest import TestParpare
from public import ReadPublicinfo
from testsetup import TestSetup
from parameter import ParameterAnalysis
from subprocess import call, PIPE, Popen
class RunTest(TestSetup, ParameterAnalysis):
@staticmethod
def pacagemanger(self, *args):
'''
Check test tool based on
'''
for arg in args:
try:
retcode = call('which %s' % arg, shell=True)
if retcode == 0:
return arg
break
except OSError:
pass
@staticmethod
def packageinstall(defectlist):
packagetool = RunTest.pacagemanger('dnf', 'yum', 'apt-get')
for defect in defectlist:
call('%s -y install %s' % (packagetool, defect), shell=True)
@staticmethod
def _depend(*args):
defectlist = []
for arg in args:
testcmd = Popen('which %s' % arg, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
testcmd.wait()
exitcode = testcmd.poll()
if exitcode != 0:
defectlist.append(arg)
if len(defectlist) > 0:
RunTest.packageinstall(defectlist)
@staticmethod
def _pretesttool(testitem, tooltar, testtool, homepath):
setup = TestSetup()
url = u"%s"%testtool["address"]
print url
tarfilepath = setup.testtooldownload(url, tooltar, homepath)
testbindir = setup.decompressfile(tarfilepath, testitem, homepath)
return testbindir
@staticmethod
def _dotest(executable, cmd, runtimes):
homedir = os.getcwd()
for root, dirs, files in os.walk(homedir):
if executable in files:
executable = os.path.join(root, executable)
break
cmds = [executable, cmd]
finalcmd = os.path.join(' ', ' '.join(cmds))
print finalcmd
for runonce in range(int(runtimes)):
test = Popen(finalcmd, stdout=PIPE, stderr=PIPE, shell=True, preexec_fn=RunTest.restore_signals)
stdout, stderr = test.communicate()
print stdout, stderr
@staticmethod
def _runtest(executable, cmd, runtimes):
homedir = os.getcwd()
for root, dirs, files in os.walk(homedir):
if executable in files:
executable = os.path.join(root, executable)
break
cmds = [executable, cmd]
finalcmd = os.path.join(' ', ' '.join(cmds))
print finalcmd
for runonce in range(int(runtimes)):
try:
retcode = call(finalcmd, shell=True)
if retcode < 0:
print >> sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError as e:
print >>sys.stderr, "Execution failed:", e
@staticmethod
def restore_signals():
signals = ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ')
for sig in signals:
if hasattr(signal, sig):
signal.signal(getattr(signal, sig), signal.SIG_DFL)
#call("./Run -c 4 -i 100 context1", shell=True, preexec_fn=restore_signals)
@staticmethod
def _test(executable, cmd, runtimes):
homedir = os.getcwd()
for root, dirs, files in os.walk(homedir):
if executable in files:
executable = os.path.join(root, executable)
break
cmds = [executable, cmd]
finalcmd = os.path.join(' ', ' '.join(cmds))
print finalcmd
for runonce in range(int(runtimes)):
returncode = subprocess.call(finalcmd, shell=True, preexec_fn=RunTest.restore_signals)
#RunTest._pretesttool('Testsetup_sample.xml', 'Test_parameter.xml', 'Perf_cpu')