system/corennnnn
リビジョン | 59178c0a3d03294bd37a7e1ece1c6e0ef1570d90 (tree) |
---|---|
日時 | 2009-07-14 06:15:18 |
作者 | Jack Palevich <jackpal@goog...> |
コミッター | Jack Palevich |
Run tests on both ARM and x86
@@ -4,6 +4,9 @@ | ||
4 | 4 | import unittest |
5 | 5 | import subprocess |
6 | 6 | import os |
7 | +import sets | |
8 | + | |
9 | +gArmInitialized = False | |
7 | 10 | |
8 | 11 | def compile(args): |
9 | 12 | proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
@@ -28,9 +31,8 @@ def outputCanRun(): | ||
28 | 31 | def adb(args): |
29 | 32 | return runCmd(["adb"] + args) |
30 | 33 | |
31 | -gArmInitialized = False | |
32 | - | |
33 | 34 | def setupArm(): |
35 | + global gArmInitialized | |
34 | 36 | if gArmInitialized: |
35 | 37 | return |
36 | 38 | print "Setting up arm" |
@@ -48,7 +50,7 @@ def setupArm(): | ||
48 | 50 | adb(["push", os.path.join(root, f), os.path.join("/system/bin/accdata", root, f)]) |
49 | 51 | # Copy over compiler |
50 | 52 | adb(["sync"]) |
51 | - gArmInitialied = True | |
53 | + gArmInitialized = True | |
52 | 54 | |
53 | 55 | def compileArm(args): |
54 | 56 | setupArm() |
@@ -75,23 +77,72 @@ def firstDifference(a, b): | ||
75 | 77 | return i |
76 | 78 | return commonLen |
77 | 79 | |
80 | +def compareSet(a1,a2,b1,b2): | |
81 | + while True: | |
82 | + totalLen = len(a1) + len(a2) + len(b1) + len(b2) | |
83 | + a1, b1 = matchCommon(a1, b1) | |
84 | + a1, b2 = matchCommon(a1, b2) | |
85 | + a2, b1 = matchCommon(a2, b1) | |
86 | + a2, b2 = matchCommon(a2, b2) | |
87 | + newTotalLen = len(a1) + len(a2) + len(b1) + len(b2) | |
88 | + if newTotalLen == 0: | |
89 | + return True | |
90 | + if newTotalLen == totalLen: | |
91 | + print "Failed at %d %d %d %d" % (len(a1), len(a2), len(b1), len(b2)) | |
92 | + print "a1", a1 | |
93 | + print "a2", a2 | |
94 | + print "b1", b1 | |
95 | + print "b2", b2 | |
96 | + return False | |
97 | + | |
98 | +def matchCommon(a, b): | |
99 | + while len(a) > 0 and len(b) > 0 and a[0] == b[0]: | |
100 | + a = a[1:] | |
101 | + b = b[1:] | |
102 | + return a, b | |
103 | + | |
104 | +def rewritePaths(args): | |
105 | + return [rewritePath(x) for x in args] | |
106 | + | |
107 | +def rewritePath(p): | |
108 | + if p.startswith("data/"): | |
109 | + p = "/system/bin/accdata/" + p | |
110 | + return p | |
111 | + | |
78 | 112 | class TestACC(unittest.TestCase): |
79 | 113 | |
80 | - def compileCheck(self, args, stdErrResult, stdOutResult=""): | |
114 | + def compileCheckOld(self, args, stdErrResult, stdOutResult=""): | |
81 | 115 | out, err = compile(args) |
82 | 116 | compare(out, stdOutResult) |
83 | 117 | compare(err, stdErrResult) |
84 | 118 | self.assertEqual(out, stdOutResult) |
85 | 119 | self.assertEqual(err, stdErrResult) |
86 | 120 | |
121 | + def checkResult(self, out, err, stdErrResult, stdOutResult=""): | |
122 | + a1 = out.splitlines() | |
123 | + a2 = err.splitlines() | |
124 | + b2 = stdErrResult.splitlines() | |
125 | + b1 = stdOutResult.splitlines() | |
126 | + self.assertEqual(True, compareSet(a1,a2,b1,b2)) | |
127 | + | |
128 | + def compileCheck(self, args, stdErrResult, stdOutResult="", | |
129 | + targets=['arm', 'x86']): | |
130 | + targetSet = sets.ImmutableSet(targets) | |
131 | + if 'x86' in targetSet: | |
132 | + out, err = compile(args) | |
133 | + self.checkResult(out, err, stdErrResult, stdOutResult) | |
134 | + if 'arm' in targetSet: | |
135 | + out = compileArm(rewritePaths(args)) | |
136 | + self.checkResult(out, "", stdErrResult, stdOutResult) | |
137 | + | |
87 | 138 | def compileCheckArm(self, args, result): |
88 | 139 | self.assertEqual(compileArm(args), result) |
89 | 140 | |
90 | 141 | def testCompileReturnVal(self): |
91 | 142 | self.compileCheck(["data/returnval-ansi.c"], "") |
92 | 143 | |
93 | - def testCompileReturnVal(self): | |
94 | - self.compileCheck(["data/otcc-ansi.c"], "") | |
144 | + def testCompileOTCCANSII(self): | |
145 | + self.compileCheck(["data/otcc-ansi.c"], "", "", ['x86']) | |
95 | 146 | |
96 | 147 | def testRunReturnVal(self): |
97 | 148 | self.compileCheck(["-R", "data/returnval-ansi.c"], |
@@ -103,11 +154,12 @@ class TestACC(unittest.TestCase): | ||
103 | 154 | |
104 | 155 | def testRunOTCCANSI(self): |
105 | 156 | self.compileCheck(["-R", "data/otcc-ansi.c", "data/returnval.c"], |
106 | - "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n") | |
157 | + "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n", "", | |
158 | + ['x86']) | |
107 | 159 | |
108 | 160 | def testRunOTCCANSI2(self): |
109 | 161 | self.compileCheck(["-R", "data/otcc-ansi.c", "data/otcc.c", "data/returnval.c"], |
110 | - "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\notcc.c: about to execute compiled code.\natcc-ansi.c: result: 42\nresult: 42\n") | |
162 | + "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\notcc.c: about to execute compiled code.\natcc-ansi.c: result: 42\nresult: 42\n", "",['x86']) | |
111 | 163 | |
112 | 164 | def testRunConstants(self): |
113 | 165 | self.compileCheck(["-R", "data/constants.c"], |
@@ -178,7 +230,7 @@ class TestACC(unittest.TestCase): | ||
178 | 230 | "testpassidf: 1 2 3\n" |
179 | 231 | ) |
180 | 232 | |
181 | - def testArmRunReturnVal(self): | |
233 | + def oldtestArmRunReturnVal(self): | |
182 | 234 | self.compileCheckArm(["-R", "/system/bin/accdata/data/returnval-ansi.c"], |
183 | 235 | "Executing compiled code:\nresult: 42\n") |
184 | 236 |