-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_test
executable file
·152 lines (114 loc) · 3.5 KB
/
run_test
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
#!/usr/bin/python
import os
import shutil
from subprocess import call
import filecmp
import sys
##############################
# Define data files
##############################
eegFiles = { 'raw' : './tests/data/original.eeg.raw',
'ad-ext' : './tests/data/original.eeg'}
posFiles = { 'raw' : './tests/data/original.pos.raw',
'ad-ext' : './tests/data/original.pos',
'pos-ext' : './tests/data/original.p'}
spkFiles = { 'raw' : './tests/data/original.tt.raw',
'ad-ext' : './tests/data/original.tt'}
ttFiles = {'tt' : './tests/data/original2.tt',
'parm' : './tests/data/original2.pxyabw',
'cb' : './tests/data/original2.cb',
'ave' : './tests/data/original2.ave'}
tmpDir = '/tmp/mwltemp/'
cmdLog = 'test.log'
global nFail, nPass
nFail = 0
nPass = 0
def runTests():
mkTmpDir()
testExtractEEG()
testExtractPos1()
testExtractPos2()
testExtractTet()
testSpikeParms()
testSpikeAve()
rmTmpDir()
report()
def testExtractEEG():
print 'ADEXTRACT EEG...',
outFile = tmpDir + 'test.eeg';
cmd = './build/bin/adextract -eslen80 ' + eegFiles['raw'] + ' -c' + ' -o ' + outFile
executeTest(cmd, eegFiles['ad-ext'], outFile)
def testExtractPos1():
print 'ADEXTRACT POS...',
outFile = tmpDir + 'test.pos'
cmd = './build/bin/adextract ' + posFiles['raw'] + ' -p -o ' + outFile
executeTest(cmd, posFiles['ad-ext'], outFile);
def testExtractPos2():
print 'POSEXTRACT POS...',
outFile = tmpDir + 'test.p';
cmd = './build/bin/posextract ' + posFiles['ad-ext'] + ' -o ' + outFile
executeTest(cmd, posFiles['pos-ext'], outFile)
def testExtractTet():
print 'ADEXTRACT TET...',
outFile = tmpDir + 'test.tt'
cmd = './build/bin/adextract -eslen80 ' + spkFiles['raw'] + ' -t -probe 0 -o ' + outFile
executeTest(cmd, spkFiles['ad-ext'], outFile)
def testSpikeParms():
print 'SPIKEPARMS TET...',
outFile = tmpDir + 'test.pxyabw'
cmd = './build/bin/spikeparms2 ' + ttFiles['tt'] + ' -tetrode -parms t_px,t_py,t_pa,t_pb,time -o ' + outFile
executeTest(cmd, ttFiles['parm'], outFile)
def testSpikeAve():
print 'SPIKEAVGE TET..',
outFile = tmpDir + 'test.ave'
cmd = './build/bin/spikeavg ' + ttFiles['tt'] + ' -if ' + ttFiles['cb'] + ' > ' + outFile
executeTest(cmd, ttFiles['ave'], outFile)
def executeTest(cmd, orig, new):
with open('/dev/null', "w") as fnull:
result = call(cmd, shell=True, stdout = fnull, stderr = fnull)
ex = os.path.isfile(new)
if not ex:
failTest()
print result, cmd
return;
sz = os.stat(new).st_size;
if sz == 0:
failTest()
print result, cmd
return;
if areSameFile(orig, new):
passTest()
else:
failTest()
print result, cmd
return
def areSameFile(orig, new):
out = [tmpDir + os.path.basename(orig) + '.tmp', tmpDir + os.path.basename(new) + '.tmp']
cmd = [ "sed '1,/%%ENDHEADER/ d' " + orig + ' > ' + out[0],
"sed '1,/%%ENDHEADER/ d' " + new + ' > ' + out[1] ]
call([cmd[0]], shell=True)
call([cmd[1]], shell=True)
return filecmp.cmp(out[0], out[1])
def mkTmpDir():
if not os.path.isdir(tmpDir):
os.makedirs(tmpDir)
def rmTmpDir():
if os.path.isdir(tmpDir):
shutil.rmtree(tmpDir)
def passTest():
print '\033[92m' + '\tPASSED!' + '\033[0m'
global nPass
nPass+=1
def failTest():
print '\033[91m' + '\tFAILED!' + '\033[0m'
global nFail
nFail+=1
def report():
if nPass==0:
print ' \033[91mALL TESTS FAILED! \033[0m'
elif nFail==0:
print ' \033[92mALL TESTS PASSED! \033[0m'
else:
print ' \033[92mPASSED:' + str(nPass) + ' \033[91mFAILED:' + str(nFail) + '\033[0m'
if __name__ =='__main__':
runTests()