labgrid-project / labgrid

Embedded systems control library for development, testing and installation
https://labgrid.readthedocs.io/
Other
329 stars 174 forks source link

How can we clean the pexpect buffer? #1228

Open ElenaGrigore opened 1 year ago

ElenaGrigore commented 1 year ago

I have the following sequence which fails:

  1. one negative test which:

    • powers on the board
    • activates UbootDriver
    • run some uboot commands which are supposed to break the boot
    • start the boot - and try to activate shell driver which is supposed to timeout and fail (in this case the test is pass)
  2. one test to boot from nfs/tftp

    • power cycle the board
    • activate UbootDriver - now my test is failing here because from the previous test it remains in buffer an uboot prompt (=>) and then _await_prompt returns index 0 (that it have found the prompt) while it should enter the index 1 case in order to send the interrupt line so it stops in uboot prompt

How can I cleanup the environment after test 1 (deactivating drivers serial, uboot, shell doesn't work) ?

Emantor commented 3 months ago

I looked at this recently, to clear the pexpect buffer you can simply expect anyting:

serial = target.get("SerialDriver")
serial.expect(r'.+')

This will clear the expect buffer. The problem is that this is timing based, which means that you'll want to wait until the problematic sequences have appeared on the console, and than clean the buffer. So the solution is to probably run the expect in a loop for a certain (target specific) time.