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