forked from jserv/amacc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntest.py
executable file
·52 lines (39 loc) · 1.48 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
#!/usr/bin/env python
# encoding: utf-8
import unittest
import subprocess as sp
import os
import sys
qemuCmd = "qemu-arm -L /usr/arm-linux-gnueabihf".split()
amacc = "./amacc"
gcc = "arm-linux-gnueabihf-gcc"
amaccdir = "amaccelf"
gccdir = "gccelf"
class TestAmacc(unittest.TestCase):
pass
def testGenerator(f):
def test(self):
print("verify file: %s" % (f))
# amaccexe = os.path.join(amaccdir, os.path.splitext(os.path.basename(f))[0])
gccexe = os.path.join(gccdir, os.path.splitext(os.path.basename(f))[0])
gccparams = [gcc, "-o", gccexe, f]
sp.check_call(gccparams)
amaccout = sp.Popen(qemuCmd + [amacc, f, "2"], stdout=sp.PIPE).communicate()[0]
gccout = sp.Popen(qemuCmd + [gccexe, "2"], stdout=sp.PIPE).communicate()[0]
self.maxDiff = None
self.assertEqual(amaccout.decode("utf-8"), gccout.decode("utf-8"))
return test
if __name__ == '__main__':
if not os.access(amaccdir, os.F_OK):
os.mkdir(amaccdir)
if not os.access(gccdir, os.F_OK):
os.mkdir(gccdir)
namePattern = ""
if len(sys.argv) > 1:
namePattern = sys.argv[1]
for dirpath, _, filenames in os.walk("tests"):
for f in filter(lambda name: namePattern in name, filenames):
testfile = os.path.abspath(os.path.join(dirpath, f))
test_func = testGenerator(testfile)
setattr(TestAmacc, 'test_%s' % (os.path.splitext(f)[0]), test_func)
unittest.main(argv=[sys.argv[0]])