summaryrefslogtreecommitdiff
path: root/tst/test-android.py
blob: 86ccc9bc03ad96408a68f8c8b40621c4668ce74f (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/python
#
# Test C code on Android

import os
import subprocess
import sys

testFiles = [
  "8q",
  "array",
  "fields",
  "hello",
  "incr",
  "init",
  "limits",
  "sort",
  "struct",
  "switch",
  "testmod"
]

slow = [
  "nsievebits"
]

problems = [
  "cf", # floating point
  "cq", # floating point
  "cvt", # floating point
  "front", # This is a test of the front end, it's supposed to fail in a variety of ways.
  "paranoia", # inline asm
  "spill", # floating point
  "stdarg", # preprocessor issues
  "wf1", #requires input on stdin
  "yacc", # requires a working stdin
  ""
]

onDeviceTestDir = "/system/bin/"

def adbGetState():
  return subprocess.Popen(["adb", "get-state"], stdout=subprocess.PIPE).communicate()[0].strip()

def adbRemount():
  return subprocess.Popen(["adb", "remount"], stdout=subprocess.PIPE).communicate()[0].strip()

def compile(f):
  srcPath = f + ".c"
  outPath = f
  return subprocess.Popen(["lcc", f + ".c", "-o", f],
    stdout=subprocess.PIPE).communicate()[0].strip()

def transferToAndroid(f):
  transferText = subprocess.Popen(["adb", "push", f, onDeviceTestDir + f],
    stdout=subprocess.PIPE).communicate()[0].strip()
    
def normalizeOutput(str):
  return str.replace("\r","")

def run(f):
  return normalizeOutput(subprocess.Popen(["adb", "shell", onDeviceTestDir + f],
    stdout=subprocess.PIPE).communicate()[0])
    
def timeRun(f):
  return normalizeOutput(subprocess.Popen(["time", "adb", "shell", onDeviceTestDir + f],
    stdout=subprocess.PIPE).communicate()[0])

def compareResult(f, output):
  expected = ""
  expectedPath = f + ".expected"
  if os.path.exists(expectedPath):
    expectedFile = open(f + ".expected", "r")
    expected = expectedFile.read()
    expectedFile.close()
    expected = expected.strip()
  output = output.strip()
  if expected == output:
     print timeRun(f)
     return True
  print "results differed. Expected:"
  print expected
  print "Actual:"
  print output
  return False

def test(testFile):
  print "testing: " + testFile
  compile(testFile)
  transferToAndroid(testFile)
  os.remove(testFile)
  output = run(testFile)
  return compareResult(testFile, output)

def doTests():
  failCount = 0
  for testFile in testFiles:
    if not test(testFile):
        failCount += 1
  print "Total tests:    ", len(testFiles)
  print "Total failures: ", failCount

def checkForDevice():
  if adbGetState() != "device":
      print "We do not appear to be connected to a device."
      sys.exit(1)

def main():
  checkForDevice()
  print adbRemount()
  doTests()

main()