run-tests-exp.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 uos as os
  10. tests = [
  11. "basics", "micropython", "float", "import", "io",
  12. " misc", "unicode", "extmod", "unix"
  13. ]
  14. if sys.platform == 'win32':
  15. MICROPYTHON = "micropython.exe"
  16. else:
  17. MICROPYTHON = "micropython"
  18. def should_skip(test):
  19. if test.startswith("native"):
  20. return True
  21. if test.startswith("viper"):
  22. return True
  23. test_count = 0
  24. passed_count = 0
  25. skip_count = 0
  26. for suite in tests:
  27. #print("Running in: %s" % suite)
  28. if sys.platform == 'win32':
  29. # dir /b prints only contained filenames, one on a line
  30. # http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx
  31. r = os.system("dir /b %s/*.py >tests.lst" % suite)
  32. else:
  33. r = os.system("ls %s/*.py | xargs -n1 basename >tests.lst" % suite)
  34. assert r == 0
  35. with open("tests.lst") as f:
  36. testcases = f.readlines()
  37. testcases = [l[:-1] for l in testcases]
  38. assert testcases, "No tests found in dir '%s', which is implausible" % suite
  39. #print(testcases)
  40. for t in testcases:
  41. if t == "native_check.py":
  42. continue
  43. qtest = "%s/%s" % (suite, t)
  44. if should_skip(t):
  45. print("skip " + qtest)
  46. skip_count += 1
  47. continue
  48. exp = None
  49. try:
  50. f = open(qtest + ".exp")
  51. exp = f.read()
  52. f.close()
  53. except OSError:
  54. pass
  55. if exp is not None:
  56. #print("run " + qtest)
  57. r = os.system(MICROPYTHON + " %s >.tst.out" % qtest)
  58. if r == 0:
  59. f = open(".tst.out")
  60. out = f.read()
  61. f.close()
  62. else:
  63. out = "CRASH"
  64. if out == "SKIP\n":
  65. print("skip " + qtest)
  66. skip_count += 1
  67. else:
  68. if out == exp:
  69. print("pass " + qtest)
  70. passed_count += 1
  71. else:
  72. print("FAIL " + qtest)
  73. test_count += 1
  74. else:
  75. skip_count += 1
  76. print("%s tests performed" % test_count)
  77. print("%s tests passed" % passed_count)
  78. if test_count != passed_count:
  79. print("%s tests failed" % (test_count - passed_count))
  80. if skip_count:
  81. print("%s tests skipped" % skip_count)