|
| 1 | +# |
| 2 | +# This is minimal MicroPython variant of run-tests script, which uses |
| 3 | +# .exp files as generated by run-tests --write-exp. It is useful to run |
| 4 | +# testsuite on systems which have neither CPython3 nor unix shell. |
| 5 | +# This script is intended to be run by the same interpreter executable |
| 6 | +# which is to be tested, so should use minimal language functionality. |
| 7 | +# |
| 8 | +import sys |
| 9 | +import _os as os |
| 10 | + |
| 11 | + |
| 12 | +tests = [ |
| 13 | + "basics", "micropython", "float", "import", "io", |
| 14 | + " misc", "unicode", "extmod", "unix" |
| 15 | +] |
| 16 | + |
| 17 | +if sys.platform == 'win32': |
| 18 | + MICROPYTHON = "micropython.exe" |
| 19 | +else: |
| 20 | + MICROPYTHON = "micropython" |
| 21 | + |
| 22 | + |
| 23 | +def should_skip(test): |
| 24 | + if test.startswith("native"): |
| 25 | + return True |
| 26 | + if test.startswith("viper"): |
| 27 | + return True |
| 28 | + |
| 29 | +test_count = 0 |
| 30 | +passed_count = 0 |
| 31 | +skip_count = 0 |
| 32 | + |
| 33 | +for suite in tests: |
| 34 | + #print("Running in: %s" % suite) |
| 35 | + if sys.platform == 'win32': |
| 36 | + # dir /b prints only contained filenames, one on a line |
| 37 | + # http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx |
| 38 | + r = os.system("dir /b %s/*.py >tests.lst" % suite) |
| 39 | + else: |
| 40 | + r = os.system("ls %s/*.py | xargs -n1 basename >tests.lst" % suite) |
| 41 | + assert r == 0 |
| 42 | + |
| 43 | + with open("tests.lst") as f: |
| 44 | + testcases = f.readlines() |
| 45 | + testcases = [l[:-1] for l in testcases] |
| 46 | + assert testcases, "No tests found in dir '%s', which is implausible" % suite |
| 47 | + #print(testcases) |
| 48 | + for t in testcases: |
| 49 | + if t == "native_check.py": |
| 50 | + continue |
| 51 | + |
| 52 | + qtest = "%s/%s" % (suite, t) |
| 53 | + |
| 54 | + if should_skip(t): |
| 55 | + print("skip " + qtest) |
| 56 | + skip_count += 1 |
| 57 | + continue |
| 58 | + |
| 59 | + exp = None |
| 60 | + try: |
| 61 | + f = open(qtest + ".exp") |
| 62 | + exp = f.read() |
| 63 | + f.close() |
| 64 | + except OSError: |
| 65 | + pass |
| 66 | + |
| 67 | + if exp is not None: |
| 68 | + #print("run " + qtest) |
| 69 | + r = os.system(MICROPYTHON + " %s >.tst.out" % qtest) |
| 70 | + if r == 0: |
| 71 | + f = open(".tst.out") |
| 72 | + out = f.read() |
| 73 | + f.close() |
| 74 | + else: |
| 75 | + out = "CRASH" |
| 76 | + |
| 77 | + if out == "SKIP\n": |
| 78 | + print("skip " + qtest) |
| 79 | + skip_count += 1 |
| 80 | + else: |
| 81 | + if out == exp: |
| 82 | + print("pass " + qtest) |
| 83 | + passed_count += 1 |
| 84 | + else: |
| 85 | + print("FAIL " + qtest) |
| 86 | + |
| 87 | + test_count += 1 |
| 88 | + else: |
| 89 | + skip_count += 1 |
| 90 | + |
| 91 | +print("%s tests performed" % test_count) |
| 92 | +print("%s tests passed" % passed_count) |
| 93 | +if test_count != passed_count: |
| 94 | + print("%s tests failed" % (test_count - passed_count)) |
| 95 | +if skip_count: |
| 96 | + print("%s tests skipped" % skip_count) |
0 commit comments