Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 1 | # |
| 2 | # Test the acc compiler |
| 3 | |
| 4 | import unittest |
| 5 | import subprocess |
| 6 | import os |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 7 | import sets |
| 8 | |
| 9 | gArmInitialized = False |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 10 | |
| 11 | def compile(args): |
| 12 | proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
| 13 | result = proc.communicate() |
| 14 | return result |
| 15 | |
| 16 | def runCmd(args): |
| 17 | proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 18 | result = proc.communicate() |
| 19 | return result[0].strip() |
| 20 | |
| 21 | def which(item): |
| 22 | return runCmd(["which", item]) |
| 23 | |
| 24 | def fileType(item): |
| 25 | return runCmd(["file", item]) |
| 26 | |
| 27 | def outputCanRun(): |
| 28 | ft = fileType(which("acc")) |
| 29 | return ft.find("ELF 32-bit LSB executable, Intel 80386") >= 0 |
| 30 | |
| 31 | def adb(args): |
| 32 | return runCmd(["adb"] + args) |
| 33 | |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 34 | def setupArm(): |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 35 | global gArmInitialized |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 36 | if gArmInitialized: |
| 37 | return |
| 38 | print "Setting up arm" |
| 39 | adb(["remount"]) |
| 40 | adb(["shell", "rm", "/system/bin/acc"]) |
| 41 | adb(["shell", "mkdir", "/system/bin/accdata"]) |
| 42 | adb(["shell", "mkdir", "/system/bin/accdata/data"]) |
| 43 | # Clear out old data TODO: handle recursion |
| 44 | adb(["shell", "rm", "/system/bin/accdata/data/*"]) |
| 45 | # Copy over data |
| 46 | for root, dirs, files in os.walk("data"): |
| 47 | for d in dirs: |
| 48 | adb(["shell", "mkdir", os.path.join(root, d)]) |
| 49 | for f in files: |
| 50 | adb(["push", os.path.join(root, f), os.path.join("/system/bin/accdata", root, f)]) |
| 51 | # Copy over compiler |
| 52 | adb(["sync"]) |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 53 | gArmInitialized = True |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 54 | |
| 55 | def compileArm(args): |
| 56 | setupArm() |
| 57 | proc = subprocess.Popen(["adb", "shell", "/system/bin/acc"] + args, stdout=subprocess.PIPE) |
| 58 | result = proc.communicate() |
| 59 | return result[0].replace("\r","") |
| 60 | |
| 61 | def compare(a, b): |
| 62 | if a != b: |
Jack Palevich | 40600de | 2009-07-01 15:32:35 -0700 | [diff] [blame] | 63 | firstDiff = firstDifference(a, b) |
Jack Palevich | bab8064 | 2009-07-09 13:54:54 -0700 | [diff] [blame] | 64 | print "Strings differ at character %d. Common: %s. Difference '%s' != '%s'" % ( |
| 65 | firstDiff, a[0:firstDiff], safeAccess(a, firstDiff), safeAccess(b, firstDiff)) |
Jack Palevich | 40600de | 2009-07-01 15:32:35 -0700 | [diff] [blame] | 66 | |
| 67 | def safeAccess(s, i): |
| 68 | if 0 <= i < len(s): |
| 69 | return s[i] |
| 70 | else: |
| 71 | return '?' |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 72 | |
| 73 | def firstDifference(a, b): |
| 74 | commonLen = min(len(a), len(b)) |
| 75 | for i in xrange(0, commonLen): |
| 76 | if a[i] != b[i]: |
| 77 | return i |
| 78 | return commonLen |
| 79 | |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 80 | # a1 and a2 are the expected stdout and stderr. |
| 81 | # b1 and b2 are the actual stdout and stderr. |
| 82 | # Compare the two, sets. Allow any individual line |
| 83 | # to appear in either stdout or stderr. This is because |
| 84 | # the way we obtain output on the ARM combines both |
| 85 | # streams into one sequence. |
| 86 | |
| 87 | def compareOuput(a1,a2,b1,b2): |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 88 | while True: |
| 89 | totalLen = len(a1) + len(a2) + len(b1) + len(b2) |
| 90 | a1, b1 = matchCommon(a1, b1) |
| 91 | a1, b2 = matchCommon(a1, b2) |
| 92 | a2, b1 = matchCommon(a2, b1) |
| 93 | a2, b2 = matchCommon(a2, b2) |
| 94 | newTotalLen = len(a1) + len(a2) + len(b1) + len(b2) |
| 95 | if newTotalLen == 0: |
| 96 | return True |
| 97 | if newTotalLen == totalLen: |
| 98 | print "Failed at %d %d %d %d" % (len(a1), len(a2), len(b1), len(b2)) |
| 99 | print "a1", a1 |
| 100 | print "a2", a2 |
| 101 | print "b1", b1 |
| 102 | print "b2", b2 |
| 103 | return False |
| 104 | |
| 105 | def matchCommon(a, b): |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 106 | """Remove common items from the beginning of a and b, |
| 107 | return just the tails that are different.""" |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 108 | while len(a) > 0 and len(b) > 0 and a[0] == b[0]: |
| 109 | a = a[1:] |
| 110 | b = b[1:] |
| 111 | return a, b |
| 112 | |
| 113 | def rewritePaths(args): |
| 114 | return [rewritePath(x) for x in args] |
| 115 | |
| 116 | def rewritePath(p): |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 117 | """Take a path that's correct on the x86 and convert to a path |
| 118 | that's correct on ARM.""" |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 119 | if p.startswith("data/"): |
| 120 | p = "/system/bin/accdata/" + p |
| 121 | return p |
| 122 | |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 123 | class TestACC(unittest.TestCase): |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 124 | |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 125 | def checkResult(self, out, err, stdErrResult, stdOutResult=""): |
| 126 | a1 = out.splitlines() |
| 127 | a2 = err.splitlines() |
| 128 | b2 = stdErrResult.splitlines() |
| 129 | b1 = stdOutResult.splitlines() |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 130 | self.assertEqual(True, compareOuput(a1,a2,b1,b2)) |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 131 | |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 132 | def compileCheck(self, args, stdErrResult, stdOutResult="", |
| 133 | targets=['arm', 'x86']): |
| 134 | targetSet = sets.ImmutableSet(targets) |
Jack Palevich | 9f51a26 | 2009-07-29 16:22:26 -0700 | [diff] [blame] | 135 | if False and 'x86' in targetSet: |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 136 | out, err = compile(args) |
| 137 | self.checkResult(out, err, stdErrResult, stdOutResult) |
| 138 | if 'arm' in targetSet: |
| 139 | out = compileArm(rewritePaths(args)) |
| 140 | self.checkResult(out, "", stdErrResult, stdOutResult) |
| 141 | |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 142 | def compileCheckArm(self, args, result): |
| 143 | self.assertEqual(compileArm(args), result) |
| 144 | |
| 145 | def testCompileReturnVal(self): |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 146 | self.compileCheck(["data/returnval-ansi.c"], "") |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 147 | |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 148 | def testCompileOTCCANSII(self): |
| 149 | self.compileCheck(["data/otcc-ansi.c"], "", "", ['x86']) |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 150 | |
| 151 | def testRunReturnVal(self): |
| 152 | self.compileCheck(["-R", "data/returnval-ansi.c"], |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 153 | "Executing compiled code:\nresult: 42\n") |
Jack Palevich | 40600de | 2009-07-01 15:32:35 -0700 | [diff] [blame] | 154 | |
Jack Palevich | bab8064 | 2009-07-09 13:54:54 -0700 | [diff] [blame] | 155 | def testStringLiteralConcatenation(self): |
Jack Palevich | 40600de | 2009-07-01 15:32:35 -0700 | [diff] [blame] | 156 | self.compileCheck(["-R", "data/testStringConcat.c"], |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 157 | "Executing compiled code:\nresult: 13\n", "Hello, world\n") |
Jack Palevich | 40600de | 2009-07-01 15:32:35 -0700 | [diff] [blame] | 158 | |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 159 | def testRunOTCCANSI(self): |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 160 | self.compileCheck(["-R", "data/otcc-ansi.c", "data/returnval.c"], |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 161 | "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n", "", |
| 162 | ['x86']) |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 163 | |
| 164 | def testRunOTCCANSI2(self): |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 165 | self.compileCheck(["-R", "data/otcc-ansi.c", "data/otcc.c", "data/returnval.c"], |
Jack Palevich | 59178c0 | 2009-07-13 14:15:18 -0700 | [diff] [blame] | 166 | "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']) |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 167 | |
| 168 | def testRunConstants(self): |
| 169 | self.compileCheck(["-R", "data/constants.c"], |
| 170 | "Executing compiled code:\nresult: 12\n", |
| 171 | "0 = 0\n010 = 8\n0x10 = 16\n'\\a' = 7\n'\\b' = 8\n'\\f' = 12\n'\\n' = 10\n'\\r' = 13\n'\\t' = 9\n'\\v' = 11\n'\\\\' = 92\n'\\'' = 39\n" + |
| 172 | "'\\\"' = 34\n'\\?' = 63\n'\\0' = 0\n'\\1' = 1\n'\\12' = 10\n'\\123' = 83\n'\\x0' = 0\n'\\x1' = 1\n'\\x12' = 18\n'\\x123' = 291\n'\\x1f' = 31\n'\\x1F' = 31\n") |
| 173 | |
Jack Palevich | bab8064 | 2009-07-09 13:54:54 -0700 | [diff] [blame] | 174 | def testRunFloat(self): |
| 175 | self.compileCheck(["-R", "data/float.c"], |
| 176 | "Executing compiled code:\nresult: 0\n", |
Jack Palevich | 2aaf21f | 2009-07-15 16:16:37 -0700 | [diff] [blame] | 177 | """Constants: 0 0 0 0.01 0.01 0.1 10 10 0.1 |
| 178 | int: 1 float: 2.2 double: 3.3 |
| 179 | ftoi(1.4f)=1 |
| 180 | dtoi(2.4)=2 |
| 181 | itof(3)=3 |
| 182 | itod(4)=4 |
| 183 | globals: 1 2 3 4 |
| 184 | args: 1 2 3 4 |
| 185 | locals: 1 2 3 4 |
| 186 | cast rval: 2 4 |
| 187 | cast lval: 1.1 2 3.3 4 |
| 188 | """) |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 189 | |
Jack Palevich | bab8064 | 2009-07-09 13:54:54 -0700 | [diff] [blame] | 190 | def testRunFlops(self): |
| 191 | self.compileCheck(["-R", "data/flops.c"], |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 192 | """Executing compiled code: |
| 193 | result: 0""", |
| 194 | """-1.1 = -1.1 |
| 195 | !1.2 = 0 |
| 196 | !0 = 1 |
| 197 | double op double: |
| 198 | 1 + 2 = 3 |
| 199 | 1 - 2 = -1 |
| 200 | 1 * 2 = 2 |
| 201 | 1 / 2 = 0.5 |
| 202 | float op float: |
| 203 | 1 + 2 = 3 |
| 204 | 1 - 2 = -1 |
| 205 | 1 * 2 = 2 |
| 206 | 1 / 2 = 0.5 |
| 207 | double op float: |
| 208 | 1 + 2 = 3 |
| 209 | 1 - 2 = -1 |
| 210 | 1 * 2 = 2 |
| 211 | 1 / 2 = 0.5 |
| 212 | double op int: |
| 213 | 1 + 2 = 3 |
| 214 | 1 - 2 = -1 |
| 215 | 1 * 2 = 2 |
| 216 | 1 / 2 = 0.5 |
| 217 | int op double: |
| 218 | 1 + 2 = 3 |
| 219 | 1 - 2 = -1 |
| 220 | 1 * 2 = 2 |
| 221 | 1 / 2 = 0.5 |
| 222 | double op double: |
| 223 | 1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1 |
| 224 | 1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0 |
| 225 | 2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1 |
| 226 | double op float: |
| 227 | 1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1 |
| 228 | 1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0 |
| 229 | 2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1 |
| 230 | float op float: |
| 231 | 1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1 |
| 232 | 1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0 |
| 233 | 2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1 |
| 234 | int op double: |
| 235 | 1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1 |
| 236 | 1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0 |
| 237 | 2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1 |
| 238 | double op int: |
| 239 | 1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1 |
| 240 | 1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0 |
| 241 | 2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1 |
| 242 | branching: 1 0 1 |
Jack Palevich | fd3db48 | 2009-07-14 19:39:36 -0700 | [diff] [blame] | 243 | testpassi: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 244 | testpassf: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 245 | testpassd: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 246 | testpassi: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 247 | testpassf: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 248 | testpassd: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 249 | testpassi: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 250 | testpassf: 1 2 3 4 5 6 7 8 9 10 11 12 |
| 251 | testpassd: 1 2 3 4 5 6 7 8 9 10 11 12 |
Jack Palevich | 45431bc | 2009-07-13 15:57:26 -0700 | [diff] [blame] | 252 | testpassidf: 1 2 3 |
| 253 | """) |
| 254 | def testCasts(self): |
| 255 | self.compileCheck(["-R", "data/casts.c"], |
| 256 | """Executing compiled code: |
| 257 | result: 0""", """Reading from a pointer: 3 3 |
| 258 | Writing to a pointer: 4 |
| 259 | Testing casts: 3 3 4.5 4 |
| 260 | Testing reading (int*): 4 |
| 261 | Testing writing (int*): 8 9 |
| 262 | Testing reading (char*): 0x78 0x56 0x34 0x12 |
| 263 | Testing writing (char*): 0x87654321 |
| 264 | f(10) |
| 265 | Function pointer result: 70 |
| 266 | Testing read/write (float*): 8.8 9.9 |
| 267 | Testing read/write (double*): 8.8 9.9 |
| 268 | """) |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 269 | |
Jack Palevich | 25c0cca | 2009-07-13 16:56:28 -0700 | [diff] [blame] | 270 | def testChar(self): |
| 271 | self.compileCheck(["-R", "data/char.c"], """Executing compiled code: |
| 272 | result: 0""", """a = 99, b = 41 |
| 273 | ga = 100, gb = 44""") |
| 274 | |
Jack Palevich | a8f427f | 2009-07-13 18:40:08 -0700 | [diff] [blame] | 275 | def testPointerArithmetic(self): |
| 276 | self.compileCheck(["-R", "data/pointers.c"], """Executing compiled code: |
| 277 | result: 0""", """Pointer difference: 1 4 |
| 278 | Pointer addition: 2 |
| 279 | Pointer comparison to zero: 0 0 1 |
| 280 | Pointer comparison: 1 0 0 0 1 |
| 281 | """) |
Jack Palevich | 37c54bd | 2009-07-14 18:35:36 -0700 | [diff] [blame] | 282 | def testRollo3(self): |
| 283 | self.compileCheck(["-R", "data/rollo3.c"], """Executing compiled code: |
| 284 | result: 10""", """""") |
| 285 | |
Jack Palevich | 8148c5b | 2009-07-16 18:24:47 -0700 | [diff] [blame] | 286 | def testFloatDouble(self): |
| 287 | self.compileCheck(["-R", "data/floatdouble.c"], """Executing compiled code: |
| 288 | result: 0""", """0.002 0.1 10""") |
Jack Palevich | a8f427f | 2009-07-13 18:40:08 -0700 | [diff] [blame] | 289 | |
Jack Palevich | ddf7c9c | 2009-07-29 10:28:18 -0700 | [diff] [blame] | 290 | def testIncDec(self): |
| 291 | self.compileCheck(["-R", "data/inc.c"], """Executing compiled code: |
| 292 | 0 |
| 293 | 1 |
| 294 | 2 |
| 295 | 1 |
Jack Palevich | aaac928 | 2009-07-31 14:34:34 -0700 | [diff] [blame] | 296 | 1 |
| 297 | 2 |
| 298 | 1 |
| 299 | 0 |
Jack Palevich | ddf7c9c | 2009-07-29 10:28:18 -0700 | [diff] [blame] | 300 | result: 0 |
| 301 | ""","""""") |
| 302 | |
Jack Palevich | 89baa20 | 2009-07-23 11:45:15 -0700 | [diff] [blame] | 303 | def testIops(self): |
| 304 | self.compileCheck(["-R", "data/iops.c"], """Executing compiled code: |
| 305 | result: 0""", """Literals: 1 -1 |
| 306 | ++ |
| 307 | 0 |
| 308 | 1 |
| 309 | 2 |
| 310 | 3 |
| 311 | 4 |
| 312 | 5 |
| 313 | 6 |
| 314 | 7 |
| 315 | 8 |
| 316 | 9 |
| 317 | -- |
| 318 | 10 |
| 319 | 9 |
| 320 | 8 |
| 321 | 7 |
| 322 | 6 |
| 323 | 5 |
| 324 | 4 |
| 325 | 3 |
| 326 | 2 |
| 327 | 1 |
| 328 | 0 |
| 329 | """) |
Jack Palevich | 25c0cca | 2009-07-13 16:56:28 -0700 | [diff] [blame] | 330 | |
Jack Palevich | beb4fe9 | 2009-07-31 11:27:29 -0700 | [diff] [blame] | 331 | def testFilm(self): |
Jack Palevich | 8f361fa | 2009-07-30 16:19:43 -0700 | [diff] [blame] | 332 | self.compileCheck(["-R", "data/film.c"], """Executing compiled code: |
| 333 | result: 0""", """testing... |
| 334 | Total bad: 0 |
| 335 | """) |
Jack Palevich | beb4fe9 | 2009-07-31 11:27:29 -0700 | [diff] [blame] | 336 | |
| 337 | def testpointers2(self): |
| 338 | self.compileCheck(["-R", "data/pointers2.c"], """Executing compiled code: |
| 339 | result: 0""", """a = 0, *pa = 0 |
| 340 | a = 2, *pa = 2 |
| 341 | a = 0, *pa = 0 **ppa = 0 |
| 342 | a = 2, *pa = 2 **ppa = 2 |
| 343 | a = 0, *pa = 0 **ppa = 0 |
| 344 | a = 2, *pa = 2 **ppa = 2 |
| 345 | """) |
| 346 | |
Jack Palevich | 0c01774 | 2009-07-31 12:00:39 -0700 | [diff] [blame] | 347 | def testassignmentop(self): |
| 348 | self.compileCheck(["-R", "data/assignmentop.c"], """Executing compiled code: |
| 349 | result: 0""", """2 *= 5 10 |
| 350 | 20 /= 5 4 |
| 351 | 17 %= 5 2 |
| 352 | 17 += 5 22 |
| 353 | 17 -= 5 12 |
| 354 | 17<<= 1 34 |
| 355 | 17>>= 1 8 |
| 356 | 17&= 1 1 |
| 357 | 17^= 1 16 |
| 358 | 16|= 1 17 |
Jack Palevich | 9613899 | 2009-07-31 15:58:19 -0700 | [diff] [blame] | 359 | *f() = *f() + 10; |
| 360 | f() |
| 361 | f() |
| 362 | a = 10 |
| 363 | *f() += 10; |
| 364 | f() |
| 365 | a = 10 |
Jack Palevich | 0c01774 | 2009-07-31 12:00:39 -0700 | [diff] [blame] | 366 | """) |
| 367 | |
Jack Palevich | 43aaee3 | 2009-07-31 14:01:37 -0700 | [diff] [blame] | 368 | def testcomma(self): |
| 369 | self.compileCheck(["-R", "data/comma.c"], """Executing compiled code: |
| 370 | result: 0""", """statement: 10 |
| 371 | if: a = 0 |
| 372 | while: b = 11 |
| 373 | for: b = 22 |
| 374 | return: 30 |
| 375 | arg: 12 |
| 376 | """) |
| 377 | |
Jack Palevich | 47cbea9 | 2009-07-31 15:25:53 -0700 | [diff] [blame] | 378 | def testBrackets(self): |
| 379 | self.compileCheck(["-R", "data/brackets.c"], """Executing compiled code: |
| 380 | Errors: 0 |
| 381 | 2D Errors: 0 |
| 382 | result: 0 |
| 383 | ""","""""") |
| 384 | |
Jack Palevich | c9b8ffc | 2009-08-03 14:42:57 -0700 | [diff] [blame] | 385 | def testShort(self): |
| 386 | self.compileCheck(["-R", "data/short.c"], """Executing compiled code: |
| 387 | result: -2 |
| 388 | ""","""""") |
| 389 | |
Jack Palevich | 609c994 | 2009-06-25 11:49:43 -0700 | [diff] [blame] | 390 | if __name__ == '__main__': |
| 391 | if not outputCanRun(): |
| 392 | print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable." |
| 393 | unittest.main() |
| 394 | |