Skip to content
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

[BUG] testrunner matching local echo #10952

Merged

Conversation

cladmi
Copy link
Contributor

@cladmi cladmi commented Feb 5, 2019

Contribution description

When local echo is enabled, pexpect will also match on send lines to the
node. So could think a node is echoing when it is only seeing the sent
message.
The sent messages are still written to logfile but now only once.

This may show issues with our current tests implementation that expected
this behavior.

Testing procedure

I included a test commit to show the fixed issue.
Sending a string to hello-world and matching on the same string works in master even if the nodes does not echo anything.

When running the test commit alone, it will fail with a RuntimeError to show the erroneous behavior.
With the disable local echo fix, the test passes.

# both with native and a board to show it is not a `pyterm` issue

BOARD=native make -C examples/hello-world flash test
BOARD=samr21-xpro make -C examples/hello-world flash test

EDIT: it can now be tested with #11094 alone.

I will retry all our test suite on this:

  • native after running dist/tools/tapsetup/tapsetup
    • Only have the same error as in master
      • tests/gnrc_ipv6_ext No root permission
      • tests/gnrc_rpl_srh No root permission
  • samr21-xpro
    • Only have the same error as in master
      • tests/gnrc_ipv6_ext No root permission
      • tests/gnrc_rpl_srh No root permission
      • tests/pkg_fatfs_vfs It needs a special initial configuration

Issues/PRs references

Found while implementing #10949 based on testrunner handling.

Depends on #11064
Depends on #11086 Silencing codacy for assert
Handling make term without local echo.

@cladmi cladmi added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: tests Area: tests and testing framework CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Feb 5, 2019
@cladmi cladmi requested review from miri64 and aabadie February 5, 2019 15:10
@cladmi cladmi changed the title Pr/bug/testrunner/matching local echo [BUG] testrunner matching local echo Feb 5, 2019
@cladmi cladmi requested a review from MrKevinWeiss February 5, 2019 15:15
cladmi added a commit to cladmi/RIOT that referenced this pull request Feb 5, 2019
Include fix for RIOT-OS#10952

Disable local echo otherwise pexpect matches sent characters.

child.sendline("the test should not match this")
try:
child.expect_exact("the test should not match this")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct way to do this pexpect style would be

Suggested change
child.expect_exact("the test should not match this")
res child.expect([pexpect.TIMEOUT, "the test should not match this"])
if res == 0:
raise RuntimeError("There should have been a timeout on the match,"
" and not match on stdin")

See e.g. this of pexpect's own examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just a throwaway commit anyway but I take the suggestion for other uses.
I think it would still require expect_exact here to have the same behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the test with expect_exact([pexpect.TIMEOUT, msg]) for #10949 in commit cladmi@f386f39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that my computer finished testing samr21-xpro I updated the first commit and force-pushed to do this.

@cladmi cladmi force-pushed the pr/bug/testrunner/matching_local_echo branch from 1786c11 to 2558efd Compare February 5, 2019 16:22
@cladmi
Copy link
Contributor Author

cladmi commented Feb 5, 2019

This did not introduce regression in our testsuite according to running ./dist/tools/compile_and_test_for_board/compile_and_test_for_board.py for native and samr21-xpro.

Unrelated: I somehow noticed that pexpect.EOF exception should not be handled as test failure but more as test setup failure so as an error. It could return a different return value to be handled differently.

@cladmi
Copy link
Contributor Author

cladmi commented Feb 5, 2019

The codacy error can be ignored as it is the goal to have an assert here and also, it is in a throwaway commit anyway.

@MrKevinWeiss
Copy link
Contributor

Test results on native

main(): This is RIOT! (Version: 2019.04-devel-120-g2558e-tstxxx/10952)
Hello World!
You are running RIOT on a(n) native board.
This board features a(n) native MCU.
the test should not match this

Test results on nucleo-f103rb

2019-02-06 13:59:43,756 - INFO # �main(): This is RIOT! (Version: 2019.04-devel-120-g2558e-tstxxx/10952)
2019-02-06 13:59:43,758 - INFO # Hello World!
the test should not match this
2019-02-06 13:59:43,762 - INFO # You are running RIOT on a(n) nucleo-f103rb board.
2019-02-06 13:59:43,765 - INFO # This board features a(n) stm32f1 MCU.

I suppose seeing the message on native is expected?

@jcarrano
Copy link
Contributor

jcarrano commented Feb 8, 2019

I think that the test should not be removed. It is an important sanity check for the test runner.

@miri64
Copy link
Member

miri64 commented Feb 8, 2019

I think that the test should not be removed. It is an important sanity check for the test runner.

I think so as well. Also, it finally starts introducing test-scripts for the examples, which I dearly miss ;-).

@cladmi
Copy link
Contributor Author

cladmi commented Feb 11, 2019

@MrKevinWeiss We see the message on both boards, it is displayed before on nucleo-f103rb. And yes it is expected as all messages sent are saved to the logfile.

A test for this is important, but I would not put it in examples/hello-world.
Here it is not really testing hello-world just using one of its property to test something else.

I found about it while testing the riotnode wrapping #10949
(Currently is only a rewrite as a class on the pexpect initialization).
And have a dedicated library only test using a fake node over there:

cladmi@f386f39

Would that be enough or do you prefer to also have a board test for this too ?

One issue I see for tests with a real board is that it may require multiple firmwares for testing everything. But it could make sense to have a few directories in test/ to handle these integration tests too.

With all this, should I add dedicated test to this PR instead of the throwaway commit ?

cladmi added a commit to cladmi/RIOT that referenced this pull request Feb 19, 2019
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
@cladmi
Copy link
Contributor Author

cladmi commented Feb 20, 2019

I just tested with picocom and the test fails as picocom does a local echo itself:

RIOT_TERMINAL=picocom BOARD=samr21-xpro make --no-print-directory -C examples/hello-world test
picocom --nolock --imap lfcrlf --echo --baud "115200" "/dev/ttyACM0"
picocom v2.2

port is        : /dev/ttyACM0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : yes
noinit is      : no
noreset is     : no
nolock is      : yes
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : lfcrlf,
omap is        : 
emap is        : crcrlf,delbs,

Type [C-a] [C-h] to see available commands

Terminal ready
main(): This is RIOT! (Version: 2019.04-devel-120-g2558e-pr/bmain(): This is RIOT! (Version: 2019.04-devel-120-g2558e-pr/bug/testrunner/matching_local_echo)
Hello World!
the test should not match this
You are running RIOT on a(n) samr21-xpro board.
This board features a(n) samd21 MCU.
the test should not match this

Traceback (most recent call last):
  File "/home/harter/work/git/RIOT/examples/hello-world/tests/01-run.py", line 20, in <module>
    sys.exit(run(testfunc))
  File "/home/harter/work/git/RIOT/dist/pythonlibs/testrunner/__init__.py", line 57, in run
    testfunc(child)
  File "/home/harter/work/git/RIOT/examples/hello-world/tests/01-run.py", line 16, in testfunc
    assert res == 0, "There should have been a timeout and not match stdin"
AssertionError: There should have been a timeout and not match stdin
/home/harter/work/git/RIOT/examples/hello-world/../../Makefile.include:568: recipe for target 'test' failed
make: *** [test] Error 1

So having a dedicated test could be good.

@MrKevinWeiss
Copy link
Contributor

One issue I see for tests with a real board is that it may require multiple firmwares for testing everything. But it could make sense to have a few directories in test/ to handle these integration tests too.

I think a test should be in the test/ folder. What do you mean by multiple firmwares? I agree that there would need to be multiple environments (RIOT_TERMINAL=) per test firmware.
Can that be written into the 01-run.py somehow or should it the different terms be tested on a higher level (eg. calling compile_and_test_for_board.py with RIOT_TERMINAL=)?

@cladmi
Copy link
Contributor Author

cladmi commented Feb 21, 2019

One issue I see for tests with a real board is that it may require multiple firmwares for testing everything. But it could make sense to have a few directories in test/ to handle these integration tests too.

I think a test should be in the test/ folder. What do you mean by multiple firmwares? I agree that there would need to be multiple environments (RIOT_TERMINAL=) per test firmware.
Can that be written into the 01-run.py somehow or should it the different terms be tested on a higher level (eg. calling compile_and_test_for_board.py with RIOT_TERMINAL=)?

For multiple firmwares I was thinking about testing both a non echo case, a shell, a case where the nodes starts and flood and everything that could be needed for testing. But this would be more high level tests than the issue here.

I will write a simple one at least for this.

Running with different terminals can come in a second step.
It would be more a "Run it with your board and setup and see how it works and if it can be used for testing".

@MrKevinWeiss
Copy link
Contributor

Ahh, got it! Thanks!

@RIOT-OS RIOT-OS deleted a comment Feb 21, 2019
@cladmi cladmi force-pushed the pr/bug/testrunner/matching_local_echo branch 3 times, most recently from 3e85734 to b992353 Compare February 21, 2019 17:04
@RIOT-OS RIOT-OS deleted a comment Feb 26, 2019
@cladmi cladmi force-pushed the pr/bug/testrunner/matching_local_echo branch from 414a315 to d17b130 Compare February 28, 2019 15:06
@RIOT-OS RIOT-OS deleted a comment Mar 1, 2019
@cladmi cladmi force-pushed the pr/bug/testrunner/matching_local_echo branch from 364574d to c43c7a0 Compare March 1, 2019 11:28
@RIOT-OS RIOT-OS deleted a comment Mar 1, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Mar 4, 2019

As there is issue currently with make term, I will split this pull request in two. I will keep the fix here as having echo=False is already better and move the test to another pull request until the main issue is fixed.

When local echo is enabled, pexpect will also match on send lines to the
node. So could think a node is echoing when it is only seeing the sent
message.
The sent messages are still written to `logfile` but now only once.

This may show issues with our current tests implementation that expected
this behavior.
@cladmi cladmi force-pushed the pr/bug/testrunner/matching_local_echo branch from c43c7a0 to 731dcfc Compare March 4, 2019 12:27
@cladmi cladmi added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Mar 4, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Mar 4, 2019

The test has been split out to #11094 until the main issue is fixed. It includes this pull request fix.
It can be tested from that pull request with an include HACK for picocom to make it work on murdock.

Copy link
Contributor

@jcarrano jcarrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nobody has anything more to say I'll merge this.

@cladmi
Copy link
Contributor Author

cladmi commented Mar 13, 2019

I can still re-add the test on local echo from #11094 now that murdock does not fail because of it.

@jcarrano jcarrano merged commit 999ef3b into RIOT-OS:master Mar 13, 2019
@cladmi cladmi deleted the pr/bug/testrunner/matching_local_echo branch March 13, 2019 15:24
cladmi added a commit to cladmi/RIOT that referenced this pull request Mar 13, 2019
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
cladmi added a commit to cladmi/RIOT that referenced this pull request Mar 23, 2019
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
cladmi added a commit to cladmi/RIOT that referenced this pull request Mar 23, 2019
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
@danpetry danpetry added this to the Release 2019.04 milestone Mar 26, 2019
fjmolinas pushed a commit to fjmolinas/RIOT that referenced this pull request Jan 16, 2020
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
fjmolinas pushed a commit to fjmolinas/RIOT that referenced this pull request Mar 4, 2020
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
leandrolanzieri pushed a commit to leandrolanzieri/RIOT that referenced this pull request Mar 6, 2020
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
leandrolanzieri pushed a commit to leandrolanzieri/RIOT that referenced this pull request Mar 6, 2020
The abstraction is a basic class to replicate behavior that was in
`testrunner.

Implementation was sometime directly taken from `testrunner` without
being technically justified to keep backward compatibility. This is
described in `TODO.rst` and dedicated implementation.

This also adds a test `node` implementation with a Makefile.
It is currently an easy to use node as no output is lost and reset
correctly resets.

TODO maybe put this as a comment in the file!!
When pexpect 'close' a 'ptyprocess' it starts by 'SIGHUP'.
It is not handled by default to call 'atexit'.
To not do a specific handling for 'SIGHUP' just forward all signals to
the child. This wrapper should not do any specific things anyway.

TODO Split the 'safe_term_close' to utils with a test not using Make
term and so directly only wanting 'sigkill'
This should allow merging it before and using it in testrunner

TODO settle the `env` handling.
Get feedback on what to do here.

Disable local echo otherwise pexpect matches sent characters.

REMOVE ME: Include fix for RIOT-OS#10952
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants