-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitycheck
executable file
·177 lines (143 loc) · 5 KB
/
sanitycheck
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
# -*- use system default python -*-
from __future__ import print_function
from fnmatch import fnmatch
from Version import Version
from util import capture
import os, sys, re
import getopt
#get files in the target parth
def files_in_tree(path,pattern):
fileA = []
wd = os.getcwd()
if (not os.path.isdir(path)):
return fileA
os.chdir(path)
path = os.getcwd()
os.chdir(wd)
for root, dirs, files in os.walk(path):
for name in files:
fn = os.path.join(root, name)
if (fnmatch(fn,pattern)):
fileA.append(fn)
return fileA
def import_class(cl):
(module, classname) = cl.rsplit(".")
m = __import__(module, globals(), locals(), [classname])
return getattr(m, classname)
testNamePat = re.compile(r'(\d+)_([^.]*)')
#main function
def main():
########################################################################
# Generate Name and Version.
########################################################################
vstr = Version().name()
replace_str = ''
# my_version=vstr
pkg_dir, exec_name = os.path.split(os.path.abspath(sys.argv[0]))
if (os.path.isdir(os.path.join(pkg_dir,".git"))):
describe = capture ("git describe").replace('\n','')
if (describe.find("command not found") == -1):
replace_str = '(' + describe + ')'
vstr = vstr.replace("@git@",replace_str)
#Please remember to update the version
vstr="1.1"
my_version=vstr
########################################################################
# Parse command line arguments
########################################################################
help_message="Sanitytool by TACC HPC\n\
[-h,--help] Help information\n\
[-s,--silent] Silent mode.\n\
[-v,--verbose] Verbose mode (default)."
# print(Help_message)
try:
opts, args = getopt.getopt(sys.argv[1:], "hsv", ["help", "silent","verbose"])
except getopt.GetoptError:
print("Invalid option.\nTry 'sanitycheck --help' for more information.")
sys.exit()
# No extra output if silend mode is on
silent_flag=False
for o, a in opts:
if o in ("-h", "--help"):
print("Sanitytool Version: ",vstr)
print(help_message)
sys.exit()
if o in ("-v", "--verbose"):
silent_flag=False
if o in ("-s", "--silent"):
silent_flag=True
########################################################################
# Find the tests in the test directory:
########################################################################
# (1) Find test directory base on location of this file:
pkg_dir, exec_name = os.path.split(os.path.abspath(sys.argv[0]))
test_dir = os.path.join(pkg_dir, "tests")
# (2) Find all *.py file in test directory
testFnA = files_in_tree(test_dir, "*.py")
testFnA.sort()
# (3) Build all test and place in "testA"
dirT = {}
testA = []
for fn in testFnA:
dir_name, bareFn = os.path.split(fn)
# Make sure that all tests directory are in appended to python internal
# path
if ( not (dir_name in dirT)):
dirT[dir_name] = True
sys.path.append(dir_name)
# Use the name of the file to build the test:
# All tests are named XYZ_ClassName.py
# For example: 001_SSH_Perm.py. The seq number is 001 and the
# class name in the file is named "SSH_Perm". It is important that
# Test programs follow this naming scheme.
m = testNamePat.search(bareFn)
if (m):
seq = m.group(1)
num = int(seq)
class_name = m.group(2)
s = m.group(0) + "." + class_name
my_class = import_class(s)
testA.append({'num' : num,
'fn' : bareFn,
'class_name' : class_name,
'test' : my_class(),
}
)
if not silent_flag:
print("Sanitytool Version: ",my_version)
print("")
#########################################################################
# Run Tests
#########################################################################
errorCount = 0
numTests = len(testA)
for entry in testA:
if silent_flag:
pass
else:
print("%3d: %s" %(entry['num'], entry['test'].description()))
result = entry['test'].execute()
if (not result):
print("\tFailed")
errorCount += 1
entry['test'].error()
entry['test'].help()
else:
if silent_flag:
pass
else:
print("\tPassed\n")
#########################################################################
# Summarize Results
#########################################################################
if not silent_flag:
if (errorCount > 0):
print ( "-------------------------------\n",
" %d/%d tests failed " % (errorCount, numTests),
"\n-------------------------------\n" )
else:
print ( "----------------------------\n",
" All tests passed"
"\n----------------------------\n")
if ( __name__ == '__main__'): main()