Fix failures on long CRAM test scripts with internal commands that can consume stdin - #48
Open
nmerinov wants to merge 1 commit into
Open
Fix failures on long CRAM test scripts with internal commands that can consume stdin#48nmerinov wants to merge 1 commit into
nmerinov wants to merge 1 commit into
Conversation
Some of applications could consume data from stdin, when stdin is not empty. As the result, when we trying to pass shell script through stdin of shell process some data can be processed by such consumers instead of desired shell process. In order to solve this provide the following changes: * cram/_process.py: Add new named "script" argument for the "execute()" function. Users can pass arguments either as "script" or as "stdin". The "stdin" capability preserved to run "patch" utility from "cram/_cli.py". * cram/_test.py: Run tests through "script" option instead of "stdin". This change required to make sure that internal test commands can't steal data targeted for shell process. * tests/debug.t: Replace test option from "-s" to "-x", because now test commands passed through file, not through stdin. * tests/consume-stdin.py: Test utility that can steal data from stdin if it available. * tests/stdin-consumers-in-test.t: Create trivial test which contains more than 8KB of commands, to be sure that shell will not read all of them from stdin at once. On each command run the "consume-stdin.py" script in order to steal remainging data from stdin before shell will read them for own execution. Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com> Reported-by: Petr Štetiar <petr.stetiar@prplfoundation.org>
kynan
suggested changes
Aug 9, 2026
Comment on lines
+1
to
+2
|
|
||
| et up cram alias and example tests: |
| @@ -0,0 +1,100 @@ | |||
| Exercise cram script with determenistic output that consumes extra stdin if any after each command | |||
There was a problem hiding this comment.
Suggested change
| Exercise cram script with determenistic output that consumes extra stdin if any after each command | |
| Exercise cram script with deterministic output that consumes extra stdin if any after each command |
There was a problem hiding this comment.
Why so many test case? What's the benefit?
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.
During work on CRAM-based testsuite in prplFoundation we observed the issue that CRAM tests where text for the commands longer than 8KB can fail with error messages like the following:
+ /bin/sh: 72: Syntax error: Unterminated quoted string (no-eol)After investigation we found that failures related to the commands that can try to read from
stdinif there are any data available instdin. You can find minimal example in the providedtests/stdin-consumers-in-test.t.With current CRAM implementation this test fails with the following error:
Root cause of the issue
Currently CRAM execute all tests in the following manner:
/bin/shprocess and send all commands to it's stdin.stdin.Suggested solution
In order to solve the issue with such commands we suggest to send commands to shell through shell script instead of piping it to stdin.
This made with new arguments
cram._process.execute()function. Newexecute()implementation can get eitherscript=b'commands'argument for test fromcram/_test.py, orstdin=b'patch text'argument for usage fromcram/_cli.py.