Rahix / tbot

Automation/Testing tool for Embedded Linux Development
https://tbot.tools
GNU General Public License v3.0
84 stars 21 forks source link

Unable to retrieve the value of crc32 command in uboot with exec0. #111

Open Adnan-Elhammoudi opened 7 months ago

Adnan-Elhammoudi commented 7 months ago

Hi!

This assertion is failing because exec0 does not return the complete result, even though stdout does! Could you please advise me on how to ensure that the entire result is returned?

            .
            .
            pattern = re.compile(r'=(\w+)')
            fileaddr =  pattern.findall(ub.env("fileaddr"))
            filesize =  pattern.findall(ub.env("filesize"))
            output = ub.exec0("crc32", f"{fileaddr[0]}" ,f"{filesize[0]}")
>           assert expected_crc in output
E           AssertionError: assert 'b2aff8d0' in '\ncrc32 for 80280000 ... 8028004b ='
│   ├─[device-u-boot] crc32 80280000 4c
│   │    ## 
│   │    ## crc32 for 80280000 ... 8028004b ==> b2aff8d0
Rahix commented 7 months ago

Hi,

yeah I have seen this exact problem in the past but never managed to build a proper solution for it... So what's happening is that the => inside the output of crc32 looks exactly like a U-Boot prompt to tbot. And that confuses the console parsing code...

I think a workaround that may help for the time being is to temporarily change the prompt matcher like this:

with ub.ch.with_prompt('\n=> '):
    ub.exec0("crc32", ...)

If this doesn't work, you could implement the one command by hand:

cmd = self.escape("crc32", f"{fileaddr[0]}" ,f"{filesize[0]}")
with tbot.log_event.command(self.name, cmd) as ev:
    self.ch.sendline(cmd + ";echo crcdone", read_back=True)
    with self.ch.with_stream(ev, show_prompt=False):
        out = self.ch.expect("crcdone")
        self.ch.sendline("true")
        self.ch.read_until_prompt()
    ev.data["stdout"] = out
output = out

Let me know how it goes...

Adnan-Elhammoudi commented 7 months ago

The workaround code snippet works for me!

with ub.ch.with_prompt('\n=> '):
    ub.exec0("crc32", ...)

Thank you!