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