Fix test-driver output parsing crash on Ubuntu#87
Merged
picnoir merged 1 commit intonumtide:mainfrom Feb 19, 2025
Merged
Conversation
When running tests on Ubuntu VMs, the `test-driver` can crash if the
executed command calls `sudo` and writes to `stderr`. For example:
```python
vm.execute("sudo bash -c \"echo 'Created foo → bar.\n' >&2 && echo 'foo' \"")
```
`sudo` spawns a new TTY for `stderr` on Ubuntu that gets read by the
`test-driver`'s output parsing. However, the `test-driver` only expects
base64-encoded `stdout` and fails when `stderr` data is read.
- Normal command (note `stderr` usees `/dev/ttyS0`)
```
> bash -c 'echo $$; ls -l /proc/$$/fd'
lr-x------ 1 root root 64 Feb 18 06:10 0 -> /dev/hvc0
l-wx------ 1 root root 64 Feb 18 06:10 1 -> pipe:[20942]
l-wx------ 1 root root 64 Feb 18 06:10 2 -> /dev/ttyS0
lr-x------ 1 root root 64 Feb 18 06:10 3 -> /proc/664/fd
```
- Using `sudo` (note `stderr` uses `/dev/pts/0`)
```
> sudo bash -c 'echo $$; ls -l /proc/$$/fd
lrwx------ 1 root root 64 Feb 18 06:10 0 -> /dev/pts/0
l-wx------ 1 root root 64 Feb 18 06:10 1 -> pipe:[20943]
lrwx------ 1 root root 64 Feb 18 06:10 2 -> /dev/pts/0
lr-x------ 1 root root 64 Feb 18 06:10 3 -> /proc/670/fd
```
Because `stderr` is now read along with the `stdout`, the
`test-driver`'s base64 decoding code crashes on unexpected data:
- [encoding step](https://github.com/NixOS/nixpkgs/blob/8a24fbd0f3b4f47f01c897a95b1b65d6a5576c01/nixos/lib/test-driver/src/test_driver/machine.py#L578),
- [receiving the data](https://github.com/NixOS/nixpkgs/blob/8a24fbd0f3b4f47f01c897a95b1b65d6a5576c01/nixos/lib/test-driver/src/test_driver/machine.py#L515),
- [decoding step](https://github.com/NixOS/nixpkgs/blob/8a24fbd0f3b4f47f01c897a95b1b65d6a5576c01/nixos/lib/test-driver/src/test_driver/machine.py#L588).
A minimal reproducible example is provided in
[am-on/nix-test-driver-ubuntu-bug](https://github.com/am-on/nix-test-driver-ubuntu-bug).
Related issues:
- numtide#84
- numtide#5
Contributor
Author
|
There's a PR that could fix the issue on the test-driver side - NixOS/nixpkgs#382260 but it has a downside of hiding the Any opinions on which side should the issue be fixed? |
picnoir
approved these changes
Feb 19, 2025
Member
picnoir
left a comment
There was a problem hiding this comment.
Thanks!
I think this is an improvement over the previous behavior.
Let's merge that as it is and improve upon it if we need to.
Member
Forgot to respond about that. Ideally, we'd fix that upstream I think. We'll revert this PR if you manage to fix that upstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When running tests on Ubuntu VMs, the
test-drivercan crash if the executed command callssudoand writes tostderr. For example:sudospawns a new TTY forstderron Ubuntu that gets read by thetest-driver's output parsing. However, thetest-driveronly expects base64-encodedstdoutand fails whenstderrdata is read.stderrusees/dev/ttyS0)sudo(notestderruses/dev/pts/0)Because
stderris now read along with thestdout, thetest-driver's base64 decoding code crashes on unexpected data:A minimal reproducible example is provided in
am-on/nix-test-driver-ubuntu-bug.
Related issues:
(Worked on this during Thaiger sprint: Thaigersprint/thaigersprint-2025#1)