-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
mpremote/tests: Rewrite test runner to run correctly under Windows. #17089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17089 +/- ##
==========================================
- Coverage 98.41% 98.38% -0.03%
==========================================
Files 171 171
Lines 22210 22240 +30
==========================================
+ Hits 21857 21881 +24
- Misses 353 359 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
Windows - Git BashSome test cases pass : ./test_eval_exec_run.sh: OK all others fail Tests fail when
Details
testrub with 'echo -n "" | sha256sum -t' fix
```
EUROPE+josverl@josverl-sb5 MINGW64 /d/mypython/micropython/tools/mpremote/tests (mpremote-testfix)
$ ./run-mpremote-tests.sh
./test_eval_exec_run.sh: OK
./test_filesystem.sh: FAIL
13,15c13,15
< cp C:/Users/josverl/AppData/Local/Temp/tmp.U2wf3UI3x1/a.py :
< cp C:/Users/josverl/AppData/Local/Temp/tmp.U2wf3UI3x1/a.py :b.py
< cp C:/Users/josverl/AppData/Local/Temp/tmp.U2wf3UI3x1/a.py :c.py
---
> cp |
@Josverl could you test the latest push? I've now majorly rewritten most of the test runner script with far more paranoid/maximalist quoting, and updated it to use a separate results directory to match the behavior of the main test suite (with a This also reduces some of the jank by inverting the way the tests are compared -- that is, instead of trying to use sed to replace instances of the temporary directory path with the string Also updated, it uses a diff compare mode that ignores carriage returns, and outputs the failure diffs at the end in unified-diff format the same way the main test suite does. I've also fixed the tests that were individually broken due to insufficient quoting, and added |
aaea140
to
c885ac3
Compare
initial results : recursive now also FAILS ./test_eval_exec_run.sh: OK common issues : I think the bash syntax: I think the diffing on errors would be better to understand when main problems in filesystem test
Details : https://gist.github.com/Josverl/32de060bfa072f19ea55ad326aca6403 🪲While debugging I found this bug 🦗 The same command works just fine in Windows powershell or even an old style command prompt. Personally I think that test are best written using a test framework, such as pytest. https://github.com/Josverl/micropython/blob/mpr/pytest/tools/mpremote/tests/test_filesystem.py |
I really need to spend some more time getting my Windows build environment working so we're not just playing telephone on this.
I'll try to see about refactoring this.
You're right that that that doesn't address all possible escaping problems, but there is one remaining issue I also just spotted even with that, in that it's actually the missing
Good catch, the other test runners also diff their
Could you run that command with
Agreed, this should also at least support
Almost definitely. There's a saying that, if you're using arrays in bash, it's time to rewrite it in a different language... and the rewrite technically does, even if just barely. As a shell tool, it makes sense to have the test case files for mpremote in shell languages, but I do think it'll be useful to rewrite the test runner in python so it can reuse and integrate with parts of the other test runners. I want to get to a working 'good' config first before refactoring further, though -- it's not just the runner that's broken, many of the actual tests are too. |
ec064be
to
e6c22b2
Compare
e6c22b2
to
c7182e4
Compare
Is this ready for another test run? |
Not really, no; just rebased this in order to more easily experiment with #12802 --- since its patch theoretically enables raw repl mode on the unix port, and might make it possible to run the mpremote tests as part of CI. |
7cf5415
to
545b256
Compare
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
05abd10
to
c18a821
Compare
@Josverl Just rewrote the test driver to use more-or-less the same test code as the main suite's I've tested it against my own boards and can confirm it works correctly on unix; and since it's now just doing exactly what the main test suite does it should be compatible with windows too. Theoretically, hopefully you can confirm this. It now also looks for and tries to run Still need to test the merge with #12802 or #16141 to confirm that the micropython socket server it sets up actually works though, and add the relevant CI jobs for it. On a separate note, does the Windows port of micropython support raw repl mode? If it's possible to add an mpremote CI job for windows that'd be pretty useful to have too, given that it's been one of the tool's main pain points. |
Thanks ,
I do not know |
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
33af3c0
to
7fa5d64
Compare
test_extensions = ("test_*.sh",) | ||
if sys.platform == "nt": | ||
test_extensions += ( | ||
"test_*.bat", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not bother with .bat, that is something from the previous century. if you insist on legendary support use .cmd, on Windows prefer .ps1 over anything older.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
Also, just added a powershell test!
Not proud of it though, but it's the only thing I could even get to work in the version of powershell I have on my machine:
#!/snap/bin/pwsh -File
iex "/usr/bin/python $Env:MPREMOTE eval 1+1"
I've no idea how to avoid that very non-portable /usr/bin/python
part; but without it, the test just complains /usr/bin/env: 'python3': No such file or directory
about the shebang in mpremote.py
. Though editing mpremote.py
to just use #!python
as its own shebang does manage to work...
""", | ||
) | ||
cmd_parser.add_argument( | ||
"-t", "--test-instance", default="unix", help="the MicroPython instance to test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the micropython executable ? ( micropython/micropython.exe)
what other values can be used / default to current platform ?
How is this used in the mpremote tests ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works almost the same way as running the test harness via run-tests.py
, with the only difference being that the value is passed through for mpremote to interpret, rather than being interpreted by the pyboard functions used in the other test runners.
i.e. run-mpremote-tests.py -t whatever
results in running each test script with the MPREMOTE
environment variable set to tools/mpremote/mpremote.py connect whatever
instead of just tools/mpremote/mpremote.py
, turning the $MPREMOTE test_command
invocations into tools/mpremote/mpremote.py connect whatever test_command
.
The value "unix"
is special, and causes the test script to instead launch a separate micropython process for each test using socat to open a pty or server socket, and then pass that pty path or socket address to mpremote instead. MPREMOTE
becomes tools/mpremote/mpremote.py connect socket://127.0.0.1:12345
or tools/mpremote/mpremote.py connect /tmp/mpremote.AAAAAAA/pty
. (The micropython binary to launch in this case is taken from the MICROPY_MICROPYTHON
environment variable --- defaulting to unix-standard if that's missing, consistent with the other test runners.)
A blank or whitespace-only value results in omitting this connect <target>
part entirely, and just include the mpremote.py
path, which IIRC is equivalent to passing auto
.
7fa5d64
to
ac7fbf1
Compare
Replacing the original bash script with a test script derived from the main suite's run-tests.py. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
ac7fbf1
to
018194d
Compare
I spend some effort to try to port a single test to windows
I wonder if this is the correct direction. |
Tbh that'd probably be fine --- mpremote is the code under test here, not really the rest of micropython; only mpremote itself needs to run within windows here. For now, test it against hardware with |
Mpflash just runs Mpremote in a sub process with some minor threading and tenacity to handle time outs and retries. Pure python, and Works reliable across platforms |
Summary
This PR rewrites the test runner script used for testing mpremote to run correctly under Windows, and adds some functionality present in the main test runner that it was previously missing.
This PR adds inheritance behavior for the
TESTS_DIR
andMPREMOTE
variables in therun-mpremote-tests.sh
test script. It adds a newRESULT_DIR
variable that can be specified to direct the runner for a path to place output.exp
and.out
files. It expands the use of the input arguments to allow specifying multiple test scripts.Among other things, this rewrite also enables multiple concurrent instances of the test runner to be run against multiple simultaneously-connected target boards, via:
Previously, the test runner had no way to override its automatic serial port selection, and concurrent instances had no way to specify different output paths to avoid clobbering each other's
.out
files.Testing
I've tested these changes manually and as part of the local automations I've been using to test #16994. I can confirm they address the configurability and concurrency issues described above.
For the moment I'm relying on @Josverl to report on whether this rewrite runs appropriately under Windows implementations of bash.
Trade-Offs and Alternatives
Some attention should probably be paid to adapting this to also run against locally-runnable ports, so that the mpremote tests can be added to automated CI/CD.