labgrid: Provide an integration with Labgrid
v6 cover labgrid: Provide an integration with Labgrid
Labgrid provides access to a hardware lab in an automated way. It is possible to boot U-Boot on boards in the lab without physically touching them. It relies on relays, USB UARTs and SD muxes, among other things.
By way of background, about 4 years ago I wrong a thing called Labman[1] which allowed my lab of about 30 devices to be operated remotely, using tbot for the console and build integration. While it worked OK and I used it for many bisects, I didn't take it any further.
It turns out that there was already an existing program, called Labgrid, which I did not know about at time (thank you Tom for telling me). It is more rounded than Labman and has a number of advantages:
- does not need udev rules, mostly
- has several existing users who rely on it
- supports multiple machines exporting their devices
It lacks a 'lab check' feature and a few other things, but these can be remedied.
On and off over the past several weeks I have been experimenting with Labgrid. I have managed to create an initial U-Boot integration (this series) by adding various features to Labgrid[2] and the U-Boot test hooks.
I hope that this might inspire others to set up boards and run tests automatically, rather than relying on infrequent, manual test. Perhaps it may even be possible to have a number of labs available.
Included in the integration are a number of simple scripts which make it easy to connect to boards and run tests:
ub-int <target>
Build and boot on a target, starting an interactive session
ub-cli <target>
Build and boot on a target, ensure U-Boot starts and provide an interactive session from there
ub-smoke <target>
Smoke test U-Boot to check that it boots to a prompt on a target
ub-bisect <target>
Bisect a git tree to locate a failure on a particular target
ub-pyt <target> <testspec>
Run U-Boot pytests on a target
Some of these help to provide the same tbot[4] workflow which I have relied on for several years, albeit much simpler versions.
The goal here is to create some sort of script which can collect patches from the mailing list, apply them and test them on a selection of boards. I suspect that script already exists, so please let me know what you suggest.
I hope you find this interesting and take a look!
[1] https://github.com/sjg20/u-boot/tree/lab6a
[2] https://github.com/labgrid-project/labgrid/pull/1411
[3] https://github.com/sjg20/uboot-test-hooks/tree/labgrid
[4] https://tbot.tools/index.html
Changes in v6:
- Rebase without an earlier patch
- Avoid doing the special shutdown unless USE_LABGRID is enabled
- Drop patch 'test: Pass stderr to stdout'
Changes in v5:
- Add a few more comments
- Comment out the debugging, which might be useful later
- Add a patch to support testing with two board-builds
Changes in v4:
- Expand the commit message
Changes in v3:
- Split out most patches into two new series and update cover letter
Changes in v2:
- Only disable echo if a terminal is detected
- Avoid running a docker image for skipped lab tests
Simon Glass (19):
test: Allow signaling that U-Boot is ready
test: Use a constant for the test timeout
test: Release board after tests complete
test: Allow connecting to a running board
test: Avoid failing skipped tests
test: Create a common function to get the config
test: Introduce the concept of a role
test: Move the receive code into a function
test: Separate out the exception handling
test: Detect dead connections
test: Tidy up remaining exceptions
test: Introduce lab mode
test: Improve handling of sending commands
test: Fix mulptiplex_log typo
test: Avoid double echo when starting up
test: Try to shut down the lab console gracefully
test: Add a section for closing the connection
test: Support testing with two board-builds
CI: Allow running tests on sjg lab
.gitlab-ci.yml | 153 +++++++++++++++++++++++++ test/py/conftest.py | 119 +++++++++++++++++--- test/py/u_boot_console_base.py | 154 ++++++++++++++++++-------- test/py/u_boot_console_exec_attach.py | 31 ++++-- test/py/u_boot_spawn.py | 124 ++++++++++++++++++--- test/test-main.c | 16 ++- 6 files changed, 506 insertions(+), 91 deletions(-)
Signature · 1 line
2.43.0
PATCH v6 1/19 test: Allow signaling that U-Boot is ready
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
---
(no changes since v1)
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
test/py/u_boot_console_base.py +5 -4
@@ -22,6 +22,7 @@ pattern_stop_autoboot_prompt = re.compile('Hit any key to stop autoboot: ') pattern_unknown_command = re.compile('Unknown command \'.*\' - try \'help\'') pattern_error_notification = re.compile('## Error: ') pattern_error_please_reset = re.compile('### ERROR ### Please RESET the board ###') +pattern_ready_prompt = re.compile('U-Boot is ready') PAT_ID = 0 PAT_RE = 1
@@ -196,15 +197,15 @@ class ConsoleBase(object): self.bad_pattern_ids[m - 1]) self.u_boot_version_string = self.p.after while True: - m = self.p.expect([self.prompt_compiled, + m = self.p.expect([self.prompt_compiled, pattern_ready_prompt, pattern_stop_autoboot_prompt] + self.bad_patterns) - if m == 0: + if m == 0 or m == 1: break - if m == 1: + if m == 2: self.p.send(' ') continue raise Exception('Bad pattern found on console: ' + - self.bad_pattern_ids[m - 2]) + self.bad_pattern_ids[m - 3]) except Exception as ex: self.log.error(str(ex))
Signature · 1 line
2.43.0
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Quoted 5 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
Signature · 1 line
Tom
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
I hope that helps explain the problem?
Regards,
Simon
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Quoted 26 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
Quoted 3 lines
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Quoted 4 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 5 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Signature · 1 line
Tom
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Hi Tom,
Quoted 28 lines · Tom Rini
Quoted 26 lines · Simon Glass
Hi Tom,
Quoted 22 lines · Tom Rini
Quoted 5 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
Quoted 6 lines
Quoted 3 lines
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
But if it wasn't causing a problem I would not have invented this annoying scheme. For several boards, by the time pytest gets to see the output it is too late to press a key and stop. Also, some boards have a different prompt which is not detected by pytest.
For example:
configs/am62x_beagleplay_a53_defconfig:CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"
Quoted 9 lines
Quoted 6 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Not at all. I tested this version of the series again with my pre-Labgrid lab and it works fine. But I do believe that the hooks that pytest has are not ideal for use with Labgrid.
Regards,
Simon
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Quoted 31 lines · Simon Glass
Hi Tom,
Quoted 28 lines · Tom Rini
Quoted 26 lines · Simon Glass
Hi Tom,
Quoted 22 lines · Tom Rini
Quoted 5 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Quoted 7 lines
Quoted 4 lines
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
Quoted 2 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Quoted 6 lines
Also, some boards
have a different prompt which is not detected by pytest.For example:
configs/am62x_beagleplay_a53_defconfig:CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"
Yeah, I had forgotten that as I turn that off along with turning on other tests via config fragment, on that platform. That really is a deficiency in our pytest version of this.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Not at all. I tested this version of the series again with my pre-Labgrid lab and it works fine. But I do believe that the hooks that pytest has are not ideal for use with Labgrid.
OK. But, why can't you make use of the labgrid functionality to pause the board? It's the state flag for labgrid-client yes? Dropping that in with my labgrid support would be just a tweak to the console script to check if the board set labgrid_strategy or something, and I think you could adapt yours to that too?
Signature · 1 line
Tom
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 32 lines · Tom Rini
Quoted 29 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
OK, but it does have the virtue of working properly on all the boards I have, rather than just a subset, without this patch.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 6 lines
Quoted 2 lines
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
OK.
Quoted 7 lines
Quoted 3 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Why / how - because the board prints its SPL banner as soon as reset is released, then waits for U-Boot proper to be sent, at which case the U-Boot banner is sent .Then labgrid disconnects from the console and runs microcom, which connects to the console over ser2net and misses some of what has already been sent.
This is actually a fundamental problem, not something we can adjust with timeouts.
Quoted 11 lines
Quoted 7 lines
Also, some boards
have a different prompt which is not detected by pytest.For example:
configs/am62x_beagleplay_a53_defconfig:CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"Yeah, I had forgotten that as I turn that off along with turning on other tests via config fragment, on that platform. That really is a deficiency in our pytest version of this.
OK
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Not at all. I tested this version of the series again with my pre-Labgrid lab and it works fine. But I do believe that the hooks that pytest has are not ideal for use with Labgrid.
Quoted 5 lines
OK. But, why can't you make use of the labgrid functionality to pause the board? It's the state flag for labgrid-client yes? Dropping that in with my labgrid support would be just a tweak to the console script to check if the board set
labgrid_strategyor something, and I think you could adapt yours to that too?
I am really not sure what to say here. I have explained the reality of the situation. I have spent hours debugging it and figuring out the root cause. There is no other tweak I can think of that will solve this problem.
Regards,
Simon
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Quoted 80 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 32 lines · Tom Rini
Quoted 29 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
OK, but it does have the virtue of working properly on all the boards I have, rather than just a subset, without this patch.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 6 lines
Quoted 2 lines
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
OK.
Quoted 7 lines
Quoted 3 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Quoted 8 lines
Why / how - because the board prints its SPL banner as soon as reset is released, then waits for U-Boot proper to be sent, at which case the U-Boot banner is sent .Then labgrid disconnects from the console and runs microcom, which connects to the console over ser2net and misses some of what has already been sent.
This is actually a fundamental problem, not something we can adjust with timeouts.
Wait, what? *Labgrid* is the thing that's the problem here with dropping the connection to the board and re-establishing it at some point?
That is the kind of detail which (a) needs to be in the commit message
(b) perhaps an issue filed (or if already exists Link:'d in the commit message) and (c) would have made it clear why we need this work-around and then I'd have been a lot happier to accept it as a work-around back on v1 or so.
Quoted 33 lines
Quoted 10 lines
Quoted 6 lines
Also, some boards
have a different prompt which is not detected by pytest.For example:
configs/am62x_beagleplay_a53_defconfig:CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"Yeah, I had forgotten that as I turn that off along with turning on other tests via config fragment, on that platform. That really is a deficiency in our pytest version of this.
OK
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Not at all. I tested this version of the series again with my pre-Labgrid lab and it works fine. But I do believe that the hooks that pytest has are not ideal for use with Labgrid.
Quoted 5 lines
OK. But, why can't you make use of the labgrid functionality to pause the board? It's the state flag for labgrid-client yes? Dropping that in with my labgrid support would be just a tweak to the console script to check if the board set
labgrid_strategyor something, and I think you could adapt yours to that too?
Quoted 4 lines
I am really not sure what to say here. I have explained the reality of the situation. I have spent hours debugging it and figuring out the root cause. There is no other tweak I can think of that will solve this problem.
Well, I hate to get on a tangent here, but I think a common thread is that after you've spent hours debugging a problem and working out a solution you then omit much of the details. I'd much rather see a much longer commit message here describing the problem, or a longer description under the "---" where you explain that labgrid uses minicom, gets things up, drops the connection and uses ser2net and so there's a chance we miss messages and so need something like this. Or, that you've been debugging on *x86_64* a bunch of EFI_LOADER things and off the shelf distributions aren't working (and ExitBootServices() is where you had a problem with Ubuntu I gather still on x86_64).
Quoted 3 lines
Regards,
Simon
Signature · 1 line
Tom
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Hi Tom,
Quoted 88 lines · Tom Rini
Quoted 86 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 32 lines · Tom Rini
Quoted 29 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
OK, but it does have the virtue of working properly on all the boards I have, rather than just a subset, without this patch.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 6 lines
Quoted 2 lines
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
OK.
Quoted 7 lines
Quoted 3 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Why / how - because the board prints its SPL banner as soon as reset is released, then waits for U-Boot proper to be sent, at which case the U-Boot banner is sent .Then labgrid disconnects from the console and runs microcom, which connects to the console over ser2net and misses some of what has already been sent.
Quoted 5 lines
Quoted 2 lines
This is actually a fundamental problem, not something we can adjust with timeouts.
Wait, what? *Labgrid* is the thing that's the problem here with dropping the connection to the board and re-establishing it at some point?
Er, yes. Somehow I must have forgotten to mention that.
I actually have a change proposed to Labgrid to adjust that, but it might take a while...in any case my change is just an option, not the default.
Quoted 6 lines
That is the kind of detail which (a) needs to be in the commit message
(b) perhaps an issue filed (or if already exists Link:'d in the commit message) and (c) would have made it clear why we need this work-around and then I'd have been a lot happier to accept it as a work-around back on v1 or so.
Well you can call it a hack, but it is a design feature of Labgrid (having an external terminal program). I don't think they will change it, but I'm hoping they will accept an 'internal' terminal as an option. No one has even looked at my patch yet, though, so far as I can see.
Quoted 39 lines
Quoted 34 lines
Quoted 11 lines
Quoted 7 lines
Also, some boards
have a different prompt which is not detected by pytest.For example:
configs/am62x_beagleplay_a53_defconfig:CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"Yeah, I had forgotten that as I turn that off along with turning on other tests via config fragment, on that platform. That really is a deficiency in our pytest version of this.
OK
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Basically, without this patch we cannot use '-s uboot' to tell the Labgrid strategy to take us to a U-Boot prompt. We must just use a raw console with no strategy, relying on pytest to do all the work.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I hope that helps explain the problem?
I think I see what you're saying, and it's based on the assumption that we'll make everyone either use labgrid?
Not at all. I tested this version of the series again with my pre-Labgrid lab and it works fine. But I do believe that the hooks that pytest has are not ideal for use with Labgrid.
Quoted 5 lines
OK. But, why can't you make use of the labgrid functionality to pause the board? It's the state flag for labgrid-client yes? Dropping that in with my labgrid support would be just a tweak to the console script to check if the board set
labgrid_strategyor something, and I think you could adapt yours to that too?Quoted 4 lines
I am really not sure what to say here. I have explained the reality of the situation. I have spent hours debugging it and figuring out the root cause. There is no other tweak I can think of that will solve this problem.
Quoted 10 lines
Well, I hate to get on a tangent here, but I think a common thread is that after you've spent hours debugging a problem and working out a solution you then omit much of the details. I'd much rather see a much longer commit message here describing the problem, or a longer description under the "---" where you explain that labgrid uses minicom, gets things up, drops the connection and uses ser2net and so there's a chance we miss messages and so need something like this. Or, that you've been debugging on *x86_64* a bunch of
EFI_LOADERthings and off the shelf distributions aren't working (andExitBootServices()is where you had a problem with Ubuntu I gather still onx86_64).
Sure, I will try to be more descriptive in future.
The problem in some cases is that I write the commits much later (weeks, months) and forget what they were for. It actually took quite a long time to get my lab running with Labgrid and for some of my responses I had to go and try things to figure out what on earth the change was for...some of them I dropped. I should have dug more into this one to really clarify the problem.
Regards,
Simon
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Quoted 94 lines · Simon Glass
Hi Tom,
Quoted 91 lines · Tom Rini
Quoted 88 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 32 lines · Tom Rini
Quoted 29 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
OK, but it does have the virtue of working properly on all the boards I have, rather than just a subset, without this patch.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 6 lines
Quoted 2 lines
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
OK.
Quoted 7 lines
Quoted 3 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Why / how - because the board prints its SPL banner as soon as reset is released, then waits for U-Boot proper to be sent, at which case the U-Boot banner is sent .Then labgrid disconnects from the console and runs microcom, which connects to the console over ser2net and misses some of what has already been sent.
This is actually a fundamental problem, not something we can adjust with timeouts.
Quoted 8 lines
Quoted 2 lines
Wait, what? *Labgrid* is the thing that's the problem here with dropping the connection to the board and re-establishing it at some point?
Er, yes. Somehow I must have forgotten to mention that.
I actually have a change proposed to Labgrid to adjust that, but it might take a while...in any case my change is just an option, not the default.
Can you please link to that specific one? Thanks.
[snip]
Quoted 11 lines
Quoted 10 lines
Well, I hate to get on a tangent here, but I think a common thread is that after you've spent hours debugging a problem and working out a solution you then omit much of the details. I'd much rather see a much longer commit message here describing the problem, or a longer description under the "---" where you explain that labgrid uses minicom, gets things up, drops the connection and uses ser2net and so there's a chance we miss messages and so need something like this. Or, that you've been debugging on *x86_64* a bunch of
EFI_LOADERthings and off the shelf distributions aren't working (andExitBootServices()is where you had a problem with Ubuntu I gather still onx86_64).
Quoted 8 lines
Sure, I will try to be more descriptive in future.
The problem in some cases is that I write the commits much later (weeks, months) and forget what they were for. It actually took quite a long time to get my lab running with Labgrid and for some of my responses I had to go and try things to figure out what on earth the change was for...some of them I dropped. I should have dug more into this one to really clarify the problem.
A thing I learned this year at some point was that you can pass -m to git commit multiple times and get multiple paragraphs. It won't be line wrapped correctly however. But it helps make "commit early and often" be more like "commit early and often with whatever you were thinking" easier to dump more information in to. I think something like that might help with review on your patches, which I know is a problem we all want to get resolved in a positive manner.
Signature · 1 line
Tom
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
Hi Tom,
Quoted 99 lines · Tom Rini
Quoted 97 lines · Simon Glass
Hi Tom,
Quoted 93 lines · Tom Rini
Quoted 80 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 32 lines · Tom Rini
Quoted 29 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass
When Labgrid is used, it can get U-Boot ready for running tests. It prints a message when it has done so.
Add logic to detect this message and accept it.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
Quoted 8 lines
Quoted 2 lines
test/py/u_boot_console_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)What happens is that labgrid can also be told to look for and then interrupt autoboot, just like our pytests can do, and the system is at the prompt. But this is also what it's like for a system with autoboot disabled. Do we actually need this patch to achieve the functionality you want? Doesn't that already just happen?
The point of this patch is actually to remove code in pytest, by allowing it to skip all the banner-detection stuff. It does not affect things in Labgrid, since it still needs to watch for banners, etc.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But you can't remove code from pytest, people can and will run the suite outside of labgrid.
Yes, that's right. I meant that with Labgrid the code is not used.
OK. I still think this (and I assume the related flag to tell whichever helper that was that the platform is ready to go) are too implementation specific.
OK, but it does have the virtue of working properly on all the boards I have, rather than just a subset, without this patch.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Without this patch, we have to tell Labgrid's U-Boot driver to do nothing, so that pytest does it. But that is not a good idea, since Labgrid has a lot more info about the board than pytest has. For example, look at all the SPL-banner-count stuff.
Why do you have to tell it to do nothing? The pytest suite works fine, today, if the board stops at the prompt automatically. To be clear, the labgrid yaml file I'm using with my scripts has the information to stop autoboot in it and it's not causing a problem.
Quoted 6 lines
Quoted 2 lines
But if it wasn't causing a problem I would not have invented this annoying scheme.
Well, I honestly thought it might be a remnant from development that wasn't needed once everything else was done. I do that from time to time myself.
OK.
Quoted 7 lines
Quoted 3 lines
For several boards, by the time pytest gets to see the output it is too late to press a key and stop.
Why / how? Do we perhaps need to adjust the timeout upwards, slightly? Especially in light of the changes you also did to detect a "dead" board and so we don't wait 30 minutes for a test run to fail.
Quoted 8 lines
Why / how - because the board prints its SPL banner as soon as reset is released, then waits for U-Boot proper to be sent, at which case the U-Boot banner is sent .Then labgrid disconnects from the console and runs microcom, which connects to the console over ser2net and misses some of what has already been sent.
This is actually a fundamental problem, not something we can adjust with timeouts.
Wait, what? *Labgrid* is the thing that's the problem here with dropping the connection to the board and re-establishing it at some point?
Quoted 7 lines
Quoted 5 lines
Er, yes. Somehow I must have forgotten to mention that.
I actually have a change proposed to Labgrid to adjust that, but it might take a while...in any case my change is just an option, not the default.
Can you please link to that specific one? Thanks.
Yes:
Quoted 22 lines
[snip]
Quoted 11 lines
Quoted 10 lines
Well, I hate to get on a tangent here, but I think a common thread is that after you've spent hours debugging a problem and working out a solution you then omit much of the details. I'd much rather see a much longer commit message here describing the problem, or a longer description under the "---" where you explain that labgrid uses minicom, gets things up, drops the connection and uses ser2net and so there's a chance we miss messages and so need something like this. Or, that you've been debugging on *x86_64* a bunch of
EFI_LOADERthings and off the shelf distributions aren't working (andExitBootServices()is where you had a problem with Ubuntu I gather still onx86_64).Quoted 8 lines
Sure, I will try to be more descriptive in future.
The problem in some cases is that I write the commits much later (weeks, months) and forget what they were for. It actually took quite a long time to get my lab running with Labgrid and for some of my responses I had to go and try things to figure out what on earth the change was for...some of them I dropped. I should have dug more into this one to really clarify the problem.
Quoted 7 lines
A thing I learned this year at some point was that you can pass -m to git commit multiple times and get multiple paragraphs. It won't be line wrapped correctly however. But it helps make "commit early and often" be more like "commit early and often with whatever you were thinking" easier to dump more information in to. I think something like that might help with review on your patches, which I know is a problem we all want to get resolved in a positive manner.
My workflow for larger things is that I create a load of local comments. Some of these are real, some are just wip. Then I start turning into patches once I have something finished and working. Yes I should add more details of why something didn't work.
Please let me know what can be done to get this integration in.
Regards,
Simon
Re: [PATCH v6 01/19] test: Allow signaling that U-Boot is ready
On Sat, Nov 02, 2024 at 10:32:18AM -0600, Simon Glass wrote:
[snip]
Quoted 6 lines
My workflow for larger things is that I create a load of local comments. Some of these are real, some are just wip. Then I start turning into patches once I have something finished and working. Yes I should add more details of why something didn't work.
Please let me know what can be done to get this integration in.
I think adopting a suffix to your scripts, along with seeing what ever else of the feedback that was in that long thread on v3 you can implement will help. Maybe also audit your commit messages and see if any other details about needing X in order to work around problem Y spring to mind, or concrete examples. Which is not because people don't believe you found a problem, it's because we're all a bunch of engineers and so enjoy solving a problem too and maybe have an alternative idea.
Signature · 1 line
Tom
PATCH v6 2/19 test: Use a constant for the test timeout
In reply to Simon GlassDeclare a constant rather than open-coding the same value twice.
---
(no changes since v1)
test/py/u_boot_console_base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
test/py/u_boot_console_base.py +5 -2
@@ -27,6 +27,9 @@ pattern_ready_prompt = re.compile('U-Boot is ready') PAT_ID = 0 PAT_RE = 1 +# Timeout before expecting the console to be ready (in milliseconds) +TIMEOUT_MS = 30000 + bad_pattern_defs = ( ('spl_signon', pattern_u_boot_spl_signon), ('main_signon', pattern_u_boot_main_signon),
@@ -423,7 +426,7 @@ class ConsoleBase(object): # Reset the console timeout value as some tests may change # its default value during the execution if not self.config.gdbserver: - self.p.timeout = 30000 + self.p.timeout = TIMEOUT_MS return try: self.log.start_section('Starting U-Boot')
@@ -434,7 +437,7 @@ class ConsoleBase(object): # future, possibly per-test to be optimal. This works for 'help' # on board 'seaboard'. if not self.config.gdbserver: - self.p.timeout = 30000 + self.p.timeout = TIMEOUT_MS self.p.logfile_read = self.logstream if expect_reset: loop_num = 2
Signature · 1 line
2.43.0
Re: [PATCH v6 02/19] test: Use a constant for the test timeout
Quoted 3 lines · Simon Glass
Declare a constant rather than open-coding the same value twice.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v6 3/19 test: Release board after tests complete
In reply to Simon GlassWhen a board is finished with, the lab may want to power it off, or perform some other function. Add a new script which is called when tests are complete.
---
(no changes since v1)
test/py/u_boot_console_exec_attach.py | 10 ++++++++++ 1 file changed, 10 insertions(+)
test/py/u_boot_console_exec_attach.py +10 -0
@@ -70,3 +70,13 @@ class ConsoleExecAttach(ConsoleBase): raise return s + + def close(self): + super().close() + + self.log.action('Releasing board') + args = [self.config.board_type, self.config.board_identity] + cmd = ['u-boot-test-release'] + args + runner = self.log.get_runner(cmd[0], sys.stdout) + runner.run(cmd) + runner.close()
Signature · 1 line
2.43.0
PATCH v6 4/19 test: Allow connecting to a running board
In reply to Simon GlassSometimes we know that the board is already running the right software, so provide an option to allow running of tests directly, without first resetting the board.
This saves time when re-running a test where only the Python code is changing.
---
(no changes since v1)
test/py/conftest.py | 3 +++ test/py/u_boot_console_base.py | 14 ++++++++++---- test/py/u_boot_console_exec_attach.py | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-)
test/py/conftest.py +3 -0
@@ -79,6 +79,8 @@ def pytest_addoption(parser): parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') + parser.addoption('--no-prompt-wait', default=False, action='store_true', + help="Assume that U-Boot is ready and don't wait for a prompt") def run_build(config, source_dir, build_dir, board_type, log): """run_build: Build U-Boot
@@ -238,6 +240,7 @@ def pytest_configure(config): ubconfig.board_type = board_type ubconfig.board_identity = board_identity ubconfig.gdbserver = gdbserver + ubconfig.no_prompt_wait = config.getoption('no_prompt_wait') ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb' env_vars = (
test/py/u_boot_console_base.py +10 -4
@@ -439,11 +439,17 @@ class ConsoleBase(object): if not self.config.gdbserver: self.p.timeout = TIMEOUT_MS self.p.logfile_read = self.logstream - if expect_reset: - loop_num = 2 + if self.config.no_prompt_wait: + # Send an empty command to set up the 'expect' logic. This has + # the side effect of ensuring that there was no partial command + # line entered + self.run_command(' ') else: - loop_num = 1 - self.wait_for_boot_prompt(loop_num = loop_num) + if expect_reset: + loop_num = 2 + else: + loop_num = 1 + self.wait_for_boot_prompt(loop_num = loop_num) self.at_prompt = True self.at_prompt_logevt = self.logstream.logfile.cur_evt except Exception as ex:
test/py/u_boot_console_exec_attach.py +12 -9
@@ -59,15 +59,18 @@ class ConsoleExecAttach(ConsoleBase): args = [self.config.board_type, self.config.board_identity] s = Spawn(['u-boot-test-console'] + args) - try: - self.log.action('Resetting board') - cmd = ['u-boot-test-reset'] + args - runner = self.log.get_runner(cmd[0], sys.stdout) - runner.run(cmd) - runner.close() - except: - s.close() - raise + if self.config.no_prompt_wait: + self.log.action('Connecting to board without reset') + else: + try: + self.log.action('Resetting board') + cmd = ['u-boot-test-reset'] + args + runner = self.log.get_runner(cmd[0], sys.stdout) + runner.run(cmd) + runner.close() + except: + s.close() + raise return s
Signature · 1 line
2.43.0
Re: [PATCH v6 04/19] test: Allow connecting to a running board
Quoted 22 lines · Simon Glass
Sometimes we know that the board is already running the right software, so provide an option to allow running of tests directly, without first resetting the board.
This saves time when re-running a test where only the Python code is changing.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
test/py/conftest.py | 3 +++ test/py/u_boot_console_base.py | 14 ++++++++++---- test/py/u_boot_console_exec_attach.py | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-)test/py/conftest.py +0
-0
test/py/conftest.py def pytest_addoption(parser): · line 83
Quoted 5 lines
test/py/conftest.py +2
-0@@ -79,6 +79,8 @@ def pytest_addoption(parser): parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') + parser.addoption('--no-prompt-wait', default=False, action='store_true', + help="Assume that U-Boot is ready and don't wait for a prompt")
I don't think this is the right name for what the commit message says we have? Maybe something like --use-running-system or otherwise make it clear we're using the board as it's already up and ready to go?
Signature · 1 line
Tom
Re: [PATCH v6 04/19] test: Allow connecting to a running board
Hi Tom,
Quoted 20 lines · Tom Rini
Quoted 17 lines · Simon Glass
Sometimes we know that the board is already running the right software, so provide an option to allow running of tests directly, without first resetting the board.
This saves time when re-running a test where only the Python code is changing.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
test/py/conftest.py | 3 +++ test/py/u_boot_console_base.py | 14 ++++++++++---- test/py/u_boot_console_exec_attach.py | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-)
Quoted 14 lines
test/py/conftest.py def pytest_addoption(parser): · line 83
Quoted 10 lines
test/py/conftest.py +2
-0@@ -79,6 +79,8 @@ def pytest_addoption(parser): parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') + parser.addoption('--no-prompt-wait', default=False, action='store_true', + help="Assume that U-Boot is ready and don't wait for a prompt")I don't think this is the right name for what the commit message says we have? Maybe something like --use-running-system or otherwise make it clear we're using the board as it's already up and ready to go?
OK, I can change it. The name I have chosen refers to the behaviour rather than the effect, but switching to a flag which describes the effect is fine with me.
Regards,
Simon
PATCH v6 5/19 test: Avoid failing skipped tests
In reply to Simon GlassWhen a test returns -EAGAIN this should not be considered a failure. Fix what seems to be a problem case, where the pytests see a failure when a test has merely been skipped.
We cannot squash the -EAGAIN error in ut_run_test() since the failure count is incremented by its caller, ut_run_test_live_flat()
The specific example here is on snow, where a test is compiled into the image but cannot run, so returns -EAGAIN to skip:
test/py/tests/test_ut.py sssnow # ut bdinfo bdinfo_test_eth
Test: bdinfo_test_eth: bdinfo.c
Skipping: Console recording disabled test/test-main.c:486, ut_run_test_live_flat(): 0 == ut_run_test(uts, test, test->name): Expected 0x0 (0), got 0xfffffff5 (-11) Test bdinfo_test_eth failed 1 times
Skipped: 1, Failures: 1
snow # F+u-boot-test-reset snow snow
The fix is simply to respect the return code from ut_run_test(), so do that.
---
(no changes since v4)
Changes in v4:
- Expand the commit message
test/test-main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
test/test-main.c +11 -5
@@ -486,7 +486,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,static int ut_run_test_live_flat (struct unit_test_state *uts,struct unit_test *test) { -int runs; +int runs, ret;if ((test->flags &UTF_OTHER_FDT ) && !IS_ENABLED (CONFIG_SANDBOX ))return skip_test (uts);
@@ -496,8 +496,11 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,if (CONFIG_IS_ENABLED (OF_LIVE )) {if (!(test->flags &UTF_FLAT_TREE )) { uts->of_live = true; -ut_assertok (ut_run_test (uts, test, test->name)); - runs++; + ret =ut_run_test (uts, test, test->name); +if (ret != -EAGAIN ) { +ut_assertok (ret); + runs++; + } } }
@@ -521,8 +524,11 @@ static int ut_run_test_live_flat(struct unit_test_state *uts, (!runs || ut_test_run_on_flattree(test)) && !(gd->flags & GD_FLG_FDT_CHANGED)) { uts->of_live = false; -ut_assertok (ut_run_test (uts, test, test->name)); - runs++; + ret =ut_run_test (uts, test, test->name); +if (ret != -EAGAIN ) { +ut_assertok (ret); + runs++; + } }return 0 ;
Signature · 1 line
2.43.0
PATCH v6 6/19 test: Create a common function to get the config
In reply to Simon GlassThe settings are decoded in two places. Combine them into a new function, before (in a future patch) expanding the number of items.
---
(no changes since v1)
test/py/conftest.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
test/py/conftest.py +28 -13
@@ -117,14 +117,36 @@ def run_build(config, source_dir, build_dir, board_type, log): runner.close() log.status_pass('OK') -def pytest_xdist_setupnodes(config, specs): - """Clear out any 'done' file from a previous build""" - global build_done_file - build_dir = config.getoption('build_dir') +def get_details(config): + """Obtain salient details about the board and directories to use + + Args: + config (pytest.Config): pytest configuration + + Returns: + tuple: + str: Board type (U-Boot build name) + str: Identity for the lab board + str: Build directory + str: Source directory + """ board_type = config.getoption('board_type') + board_identity = config.getoption('board_identity') + build_dir = config.getoption('build_dir') + source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) + default_build_dir = source_dir + '/build-' + board_type if not build_dir: - build_dir = source_dir + '/build-' + board_type + build_dir = default_build_dir + + return board_type, board_identity, build_dir, source_dir + +def pytest_xdist_setupnodes(config, specs): + """Clear out any 'done' file from a previous build""" + global build_done_file + + build_dir = get_details(config)[2] + build_done_file = Path(build_dir) / 'build.done' if build_done_file.exists(): os.remove(build_done_file)
@@ -163,17 +185,10 @@ def pytest_configure(config): global console global ubconfig - source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) + board_type, board_identity, build_dir, source_dir = get_details(config) - board_type = config.getoption('board_type') board_type_filename = board_type.replace('-', '_') - - board_identity = config.getoption('board_identity') board_identity_filename = board_identity.replace('-', '_') - - build_dir = config.getoption('build_dir') - if not build_dir: - build_dir = source_dir + '/build-' + board_type mkdir_p(build_dir) result_dir = config.getoption('result_dir')
Signature · 1 line
2.43.0
PATCH v6 7/19 test: Introduce the concept of a role
In reply to Simon GlassIn Labgrid there is the concept of a 'role', which is similar to the U-Boot board ID in U-Boot's pytest subsystem.
The role indicates both the target and information about the U-Boot build to use. It can also provide any amount of other configuration. The information is obtained using the 'labgrid-client query' operation.
Make use of this in tests, so that only the role is required in gitlab and other situations. The board type and other things can be queried as needed.
Use a new 'u-boot-test-getrole' script to obtain the requested information.
With this it is possible to run lab tests in gitlab with just a single 'ROLE' variable for each board.
---
(no changes since v5)
Changes in v5:
- Add a few more comments
- Comment out the debugging, which might be useful later
test/py/conftest.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-)
test/py/conftest.py +34 -4
@@ -23,6 +23,7 @@ from pathlib import Path import pytest import re from _pytest.runner import runtestprotocol +import subprocess import sys # Globals: The HTML log file, and the connection to the U-Boot console.
@@ -79,6 +80,7 @@ def pytest_addoption(parser): parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') + parser.addoption('--role', help='U-Boot board role (for Labgrid)') parser.addoption('--no-prompt-wait', default=False, action='store_true', help="Assume that U-Boot is ready and don't wait for a prompt")
@@ -130,12 +132,40 @@ def get_details(config): str: Build directory str: Source directory """ - board_type = config.getoption('board_type') - board_identity = config.getoption('board_identity') + role = config.getoption('role') + + # Get a few provided parameters build_dir = config.getoption('build_dir') + if role: + # When using a role, build_dir and build_dir_extra are normally not set, + # since they are picked up from Labgrid via the u-boot-test-getrole + # script + board_identity = role + cmd = ['u-boot-test-getrole', role, '--configure'] + env = os.environ.copy() + if build_dir: + env['U_BOOT_BUILD_DIR'] = build_dir + proc = subprocess.run(cmd, capture_output=True, encoding='utf-8', + env=env) + if proc.returncode: + raise ValueError(proc.stderr) + # For debugging + # print('conftest: lab:', proc.stdout) + vals = {} + for line in proc.stdout.splitlines(): + item, value = line.split(' ', maxsplit=1) + k = item.split(':')[-1] + vals[k] = value + # For debugging + # print('conftest: lab info:', vals) + board_type, default_build_dir, source_dir = (vals['board'], + vals['build_dir'], vals['source_dir']) + else: + board_type = config.getoption('board_type') + board_identity = config.getoption('board_identity') - source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) - default_build_dir = source_dir + '/build-' + board_type + source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) + default_build_dir = source_dir + '/build-' + board_type if not build_dir: build_dir = default_build_dir
Signature · 1 line
2.43.0
PATCH v6 8/19 test: Move the receive code into a function
In reply to Simon GlassThere is quite a bit of code to deal with receiving data from the target so move it into its own receive() function.
---
(no changes since v1)
test/py/u_boot_spawn.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
test/py/u_boot_spawn.py +27 -12
@@ -137,6 +137,32 @@ class Spawn: os.write(self.fd, data.encode(errors='replace')) + def receive(self, num_bytes): + """Receive data from the sub-process's stdin. + + Args: + num_bytes (int): Maximum number of bytes to read + + Returns: + str: The data received + + Raises: + ValueError if U-Boot died + """ + try: + c = os.read(self.fd, num_bytes).decode(errors='replace') + except OSError as err: + # With sandbox, try to detect when U-Boot exits when it + # shouldn't and explain why. This is much more friendly than + # just dying with an I/O error + if self.decode_signal and err.errno == 5: # I/O error + alive, _, info = self.checkalive() + if alive: + raise err + raise ValueError('U-Boot exited with %s' % info) + raise + return c + def expect(self, patterns): """Wait for the sub-process to emit specific data.
@@ -193,18 +219,7 @@ class Spawn: events = self.poll.poll(poll_maxwait) if not events: raise Timeout() - try: - c = os.read(self.fd, 1024).decode(errors='replace') - except OSError as err: - # With sandbox, try to detect when U-Boot exits when it - # shouldn't and explain why. This is much more friendly than - # just dying with an I/O error - if self.decode_signal and err.errno == 5: # I/O error - alive, _, info = self.checkalive() - if alive: - raise err - raise ValueError('U-Boot exited with %s' % info) - raise + c = self.receive(1024) if self.logfile_read: self.logfile_read.write(c) self.buf += c
Signature · 1 line
2.43.0
PATCH v6 9/19 test: Separate out the exception handling
In reply to Simon GlassThe tests currently catch a very board Exception in each case. This is thrown even in the event of a coding error.
We want to handle exceptions differently depending on their severity, so that we can avoid hour-long delays waiting for a board that is clearly broken.
As a first step, create some new exception types, separating out those which are simply an unexpected result from executed a command, from those which indicate some kind of hardware failure.
---
(no changes since v1)
test/py/u_boot_console_base.py | 26 ++++++++++++++------------ test/py/u_boot_spawn.py | 11 +++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-)
test/py/u_boot_console_base.py +14 -12
@@ -14,6 +14,7 @@ import pytest import re import sys import u_boot_spawn +from u_boot_spawn import BootFail, Timeout, Unexpected # Regexes for text we expect U-Boot to send to the console. pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
@@ -190,13 +191,13 @@ class ConsoleBase(object): m = self.p.expect([pattern_u_boot_spl_signon] + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on SPL console: ' + + raise BootFail('Bad pattern found on SPL console: ' + self.bad_pattern_ids[m - 1]) env_spl_banner_times -= 1 m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on console: ' + + raise BootFail('Bad pattern found on console: ' + self.bad_pattern_ids[m - 1]) self.u_boot_version_string = self.p.after while True:
@@ -207,13 +208,9 @@ class ConsoleBase(object): if m == 2: self.p.send(' ') continue - raise Exception('Bad pattern found on console: ' + + raise BootFail('Bad pattern found on console: ' + self.bad_pattern_ids[m - 3]) - except Exception as ex: - self.log.error(str(ex)) - self.cleanup_spawn() - raise finally: self.log.timestamp()
@@ -279,7 +276,7 @@ class ConsoleBase(object): m = self.p.expect([chunk] + self.bad_patterns) if m != 0: self.at_prompt = False - raise Exception('Bad pattern found on console: ' + + raise BootFail('Bad pattern found on console: ' + self.bad_pattern_ids[m - 1]) if not wait_for_prompt: return
@@ -289,14 +286,18 @@ class ConsoleBase(object): m = self.p.expect([self.prompt_compiled] + self.bad_patterns) if m != 0: self.at_prompt = False - raise Exception('Bad pattern found on console: ' + + raise BootFail('Missing prompt on console: ' + self.bad_pattern_ids[m - 1]) self.at_prompt = True self.at_prompt_logevt = self.logstream.logfile.cur_evt # Only strip \r\n; space/TAB might be significant if testing # indentation. return self.p.before.strip('\r\n') - except Exception as ex: + except Timeout as exc: + self.log.error(str(exc)) + self.cleanup_spawn() + raise + except BootFail as ex: self.log.error(str(ex)) self.cleanup_spawn() raise
@@ -355,8 +356,9 @@ class ConsoleBase(object): text = re.escape(text) m = self.p.expect([text] + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on console: ' + - self.bad_pattern_ids[m - 1]) + raise Unexpected( + "Unexpected pattern found on console (exp '{text}': " + + self.bad_pattern_ids[m - 1]) def drain_console(self): """Read from and log the U-Boot console for a short time.
test/py/u_boot_spawn.py +11 -0
@@ -16,6 +16,17 @@ import traceback class Timeout(Exception): """An exception sub-class that indicates that a timeout occurred.""" +class BootFail(Exception): + """An exception sub-class that indicates that a boot failure occurred. + + This is used when a bad pattern is seen when waiting for the boot prompt. + It is regarded as fatal, to avoid trying to boot the again and again to no + avail. + """ + +class Unexpected(Exception): + """An exception sub-class that indicates that unexpected test was seen.""" + class Spawn: """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for.
Signature · 1 line
2.43.0
PATCH v6 10/19 test: Detect dead connections
In reply to Simon GlassWhen the connection to a board dies, assume it is dead forever until some user action is taken. Skip all remaining tests. This avoids CI runs taking an hour, with hundreds of 30-second timeouts all to no avail.
---
(no changes since v1)
test/py/conftest.py | 19 +++++++++++++++++-- test/py/u_boot_spawn.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-)
test/py/conftest.py +17 -2
@@ -25,6 +25,7 @@ import re from _pytest.runner import runtestprotocol import subprocess import sys +from u_boot_spawn import BootFail, Timeout, Unexpected, handle_exception # Globals: The HTML log file, and the connection to the U-Boot console. log = None
@@ -287,6 +288,7 @@ def pytest_configure(config): ubconfig.gdbserver = gdbserver ubconfig.no_prompt_wait = config.getoption('no_prompt_wait') ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb' + ubconfig.connection_ok = True env_vars = ( 'board_type',
@@ -453,8 +455,21 @@ def u_boot_console(request): Returns: The fixture value. """ - - console.ensure_spawned() + if not ubconfig.connection_ok: + pytest.skip('Cannot get target connection') + return None + try: + console.ensure_spawned() + except OSError as err: + handle_exception(ubconfig, console, log, err, 'Lab failure', True) + except Timeout as err: + handle_exception(ubconfig, console, log, err, 'Lab timeout', True) + except BootFail as err: + handle_exception(ubconfig, console, log, err, 'Boot fail', True, + console.get_spawn_output()) + except Unexpected: + handle_exception(ubconfig, console, log, err, 'Unexpected test output', + False) return console anchors = {}
test/py/u_boot_spawn.py +38 -0
@@ -8,6 +8,7 @@ Logic to spawn a sub-process and interact with its stdio. import os import re import pty +import pytest import signal import select import time
@@ -27,6 +28,43 @@ class BootFail(Exception): class Unexpected(Exception): """An exception sub-class that indicates that unexpected test was seen.""" + +def handle_exception(ubconfig, console, log, err, name, fatal, output=''): + """Handle an exception from the console + + Exceptions can occur when there is unexpected output or due to the board + crashing or hanging. Some exceptions are likely fatal, where retrying will + just chew up time to no available. In those cases it is best to cause + further tests be skipped. + + Args: + ubconfig (ArbitraryAttributeContainer): ubconfig object + log (Logfile): Place to log errors + console (ConsoleBase): Console to clean up, if fatal + err (Exception): Exception which was thrown + name (str): Name of problem, to log + fatal (bool): True to abort all tests + output (str): Extra output to report on boot failure. This can show the + target's console output as it tried to boot + """ + msg = f'{name}: ' + if fatal: + msg += 'Marking connection bad - no other tests will run' + else: + msg += 'Assuming that lab is healthy' + print(msg) + log.error(msg) + log.error(f'Error: {err}') + + if output: + msg += f'; output {output}' + + if fatal: + ubconfig.connection_ok = False + console.cleanup_spawn() + pytest.exit(msg) + + class Spawn: """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for.
Signature · 1 line
2.43.0
PATCH v6 11/19 test: Tidy up remaining exceptions
In reply to Simon GlassUse the new handle_exception() function from ConsoleBase also.
---
(no changes since v1)
test/py/u_boot_console_base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
test/py/u_boot_console_base.py +6 -6
@@ -14,7 +14,7 @@ import pytest import re import sys import u_boot_spawn -from u_boot_spawn import BootFail, Timeout, Unexpected +from u_boot_spawn import BootFail, Timeout, Unexpected, handle_exception # Regexes for text we expect U-Boot to send to the console. pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
@@ -294,12 +294,12 @@ class ConsoleBase(object): # indentation. return self.p.before.strip('\r\n') except Timeout as exc: - self.log.error(str(exc)) - self.cleanup_spawn() + handle_exception(self.config, self, self.log, exc, 'Lab failure', + True) raise - except BootFail as ex: - self.log.error(str(ex)) - self.cleanup_spawn() + except BootFail as exc: + handle_exception(self.config, self, self.log, exc, 'Boot fail', + True, self.get_spawn_output()) raise finally: self.log.timestamp()
Signature · 1 line
2.43.0
PATCH v6 12/19 test: Introduce lab mode
In reply to Simon GlassThere is quite a bit of code in pytest to try to start up U-Boot on a board, with timeouts, expects, etc.
This is tedious to maintain and is peripheral to the test system's purpose. It seems better to put this logic in the lab itself, where is can provide such support.
With Labgrid we can use the UbootStrategy class to get the board into a useful state, however it needs to do it. Then it can report to pytest by writing a suitable string along with the U-Boot version it detected.
Add support for detecting 'lab mode' and simply assume that all is well in that case. Collect the version string when Labgrid says it is ready.
---
(no changes since v1)
test/py/u_boot_console_base.py | 68 ++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 15 deletions(-)
test/py/u_boot_console_base.py +53 -15
@@ -23,13 +23,21 @@ pattern_stop_autoboot_prompt = re.compile('Hit any key to stop autoboot: ') pattern_unknown_command = re.compile('Unknown command \'.*\' - try \'help\'') pattern_error_notification = re.compile('## Error: ') pattern_error_please_reset = re.compile('### ERROR ### Please RESET the board ###') -pattern_ready_prompt = re.compile('U-Boot is ready') +pattern_ready_prompt = re.compile('{lab ready in (.*)s: (.*)}') +pattern_lab_mode = re.compile('{lab mode.*}') PAT_ID = 0 PAT_RE = 1 # Timeout before expecting the console to be ready (in milliseconds) -TIMEOUT_MS = 30000 +TIMEOUT_MS = 30000 # Standard timeout + +# Timeout for board preparation in lab mode. This needs to be enough to build +# U-Boot, write it to the board and then boot the board. Since this process is +# under the control of another program (e.g. Labgrid), it will failure sooner +# if something goes way. So use a very long timeout here to cover all possible +# situations. +TIMEOUT_PREPARE_MS = 3 * 60 * 1000 bad_pattern_defs = ( ('spl_signon', pattern_u_boot_spl_signon),
@@ -143,6 +151,7 @@ class ConsoleBase(object): self.at_prompt = False self.at_prompt_logevt = None + self.lab_mode = False def get_spawn(self): # This is not called, ssubclass must define this.
@@ -176,40 +185,69 @@ class ConsoleBase(object): self.p.close() self.logstream.close() + def set_lab_mode(self): + """Select lab mode + + This tells us that we will get a 'lab ready' message when the board is + ready for use. We don't need to look for signon messages. + """ + self.log.info(f'test.py: Lab mode is active') + self.p.timeout = TIMEOUT_PREPARE_MS + self.lab_mode = True + def wait_for_boot_prompt(self, loop_num = 1): """Wait for the boot up until command prompt. This is for internal use only. """ try: + self.log.info('Waiting for U-Boot to be ready') bcfg = self.config.buildconfig config_spl_serial = bcfg.get('config_spl_serial', 'n') == 'y' env_spl_skipped = self.config.env.get('env__spl_skipped', False) env_spl_banner_times = self.config.env.get('env__spl_banner_times', 1) - while loop_num > 0: + while not self.lab_mode and loop_num > 0: loop_num -= 1 while config_spl_serial and not env_spl_skipped and env_spl_banner_times > 0: - m = self.p.expect([pattern_u_boot_spl_signon] + - self.bad_patterns) - if m != 0: + m = self.p.expect([pattern_u_boot_spl_signon, + pattern_lab_mode] + self.bad_patterns) + if m == 1: + self.set_lab_mode() + break + elif m != 0: raise BootFail('Bad pattern found on SPL console: ' + - self.bad_pattern_ids[m - 1]) + self.bad_pattern_ids[m - 1]) env_spl_banner_times -= 1 - m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns) - if m != 0: - raise BootFail('Bad pattern found on console: ' + - self.bad_pattern_ids[m - 1]) - self.u_boot_version_string = self.p.after + if not self.lab_mode: + m = self.p.expect([pattern_u_boot_main_signon, + pattern_lab_mode] + self.bad_patterns) + if m == 1: + self.set_lab_mode() + elif m != 0: + raise BootFail('Bad pattern found on console: ' + + self.bad_pattern_ids[m - 1]) + if not self.lab_mode: + self.u_boot_version_string = self.p.after while True: m = self.p.expect([self.prompt_compiled, pattern_ready_prompt, pattern_stop_autoboot_prompt] + self.bad_patterns) - if m == 0 or m == 1: + if m == 0: + self.log.info(f'Found ready prompt {m}') + break + elif m == 1: + m = pattern_ready_prompt.search(self.p.after) + self.u_boot_version_string = m.group(2) + self.log.info(f'Lab: Board is ready') + self.p.timeout = TIMEOUT_MS break if m == 2: + self.log.info(f'Found autoboot prompt {m}') self.p.send(' ') continue - raise BootFail('Bad pattern found on console: ' + - self.bad_pattern_ids[m - 3]) + if not self.lab_mode: + raise BootFail('Missing prompt / ready message on console: ' + + self.bad_pattern_ids[m - 3]) + self.log.info(f'U-Boot is ready') finally: self.log.timestamp()
Signature · 1 line
2.43.0
PATCH v6 13/19 test: Improve handling of sending commands
In reply to Simon GlassWe expect commands to be echoed and this should happen quite quickly, since U-Boot is sitting at the prompt waiting for a command.
Reduce the timeout for this situation. Try to produce a more useful error message when something goes wrong. Also handle the case where the connection has gone away since the last command was issued.
---
(no changes since v1)
test/py/u_boot_console_base.py | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
test/py/u_boot_console_base.py +21 -14
@@ -31,6 +31,7 @@ PAT_RE = 1 # Timeout before expecting the console to be ready (in milliseconds) TIMEOUT_MS = 30000 # Standard timeout +TIMEOUT_CMD_MS = 10000 # Command-echo timeout # Timeout for board preparation in lab mode. This needs to be enough to build # U-Boot, write it to the board and then boot the board. Since this process is
@@ -300,22 +301,28 @@ class ConsoleBase(object): try: self.at_prompt = False + if not self.p: + raise BootFail( + f"Lab failure: Connection lost when sending command '{cmd}'") + if send_nl: cmd += '\n' - while cmd: - # Limit max outstanding data, so UART FIFOs don't overflow - chunk = cmd[:self.max_fifo_fill] - cmd = cmd[self.max_fifo_fill:] - self.p.send(chunk) - if not wait_for_echo: - continue - chunk = re.escape(chunk) - chunk = chunk.replace('\\\n', '[\r\n]') - m = self.p.expect([chunk] + self.bad_patterns) - if m != 0: - self.at_prompt = False - raise BootFail('Bad pattern found on console: ' + - self.bad_pattern_ids[m - 1]) + rem = cmd # Remaining to be sent + with self.temporary_timeout(TIMEOUT_CMD_MS): + while rem: + # Limit max outstanding data, so UART FIFOs don't overflow + chunk = rem[:self.max_fifo_fill] + rem = rem[self.max_fifo_fill:] + self.p.send(chunk) + if not wait_for_echo: + continue + chunk = re.escape(chunk) + chunk = chunk.replace('\\\n', '[\r\n]') + m = self.p.expect([chunk] + self.bad_patterns) + if m != 0: + self.at_prompt = False + raise BootFail(f"Failed to get echo on console (cmd '{cmd}':rem '{rem}'): " + + self.bad_pattern_ids[m - 1]) if not wait_for_prompt: return if wait_for_reboot:
Signature · 1 line
2.43.0
PATCH v6 14/19 test: Fix mulptiplex_log typo
In reply to Simon GlassFix a typo in a comment.
---
(no changes since v1)
test/py/u_boot_console_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/py/u_boot_console_base.py +1 -1
@@ -123,7 +123,7 @@ class ConsoleBase(object): Can only usefully be called by sub-classes. Args: - log: A mulptiplex_log.Logfile object, to which the U-Boot output + log: A multiplexed_log.Logfile object, to which the U-Boot output will be logged. config: A configuration data structure, as built by conftest.py. max_fifo_fill: The maximum number of characters to send to U-Boot
Signature · 1 line
2.43.0
PATCH v6 15/19 test: Avoid double echo when starting up
In reply to Simon GlassThere is a very annoying bug at present where the terminal echos part of the first command sent to the board. This happens because the terminal is still set to echo for a period until Labgrid starts up and can change this.
Fix this by disabling echo (and other terminal features) as soon as the spawn happens.
---
Changes in v6:
- Rebase without an earlier patch
Changes in v2:
- Only disable echo if a terminal is detected
test/py/u_boot_spawn.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
test/py/u_boot_spawn.py +14 -0
@@ -11,6 +11,8 @@ import pty import pytest import signal import select +import sys +import termios import time import traceback
@@ -115,11 +117,23 @@ class Spawn: finally: os._exit(255) + old = None try: + if os.isatty(sys.stdout.fileno()): + new = termios.tcgetattr(self.fd) + old = new + new[3] = new[3] & ~(termios.ICANON | termios.ISIG) + new[3] = new[3] & ~termios.ECHO + new[6][termios.VMIN] = 0 + new[6][termios.VTIME] = 0 + termios.tcsetattr(self.fd, termios.TCSANOW, new) + self.poll = select.poll() self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL) except: + if old: + termios.tcsetattr(self.fd, termios.TCSANOW, old) self.close() raise
Signature · 1 line
2.43.0
PATCH v6 16/19 test: Try to shut down the lab console gracefully
In reply to Simon GlassSend the Labgrid quit characters to ask it to exit gracefully. This typically allows it to power off the board being used. Only do this when labgrid is being used (detected with an env var).
If that doesn't work, try the less graceful approach.
---
Changes in v6:
- Avoid doing the special shutdown unless USE_LABGRID is enabled
test/py/u_boot_spawn.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
test/py/u_boot_spawn.py +19 -3
@@ -16,6 +16,9 @@ import termios import time import traceback +# Character to send (twice) to exit the terminal +EXIT_CHAR = 0x1d # FS (Ctrl + ]) + class Timeout(Exception): """An exception sub-class that indicates that a timeout occurred."""
@@ -303,15 +306,28 @@ class Spawn: None. Returns: - Nothing. + str: Type of closure completed """ - + # For Labgrid, ask it is exit gracefully, so it can transition the board + # to the final state (like 'off') before exiting. + if os.environ.get('USE_LABGRID'): + self.send(chr(EXIT_CHAR) * 2) + + # Wait about 10 seconds for Labgrid to close and power off the board + for _ in range(100): + if not self.isalive(): + return 'normal' + time.sleep(0.1) + + # That didn't work, so try closing the PTY os.close(self.fd) for _ in range(100): if not self.isalive(): - break + return 'break' time.sleep(0.1) + return 'timeout' + def get_expect_output(self): """Return the output read by expect()
Signature · 1 line
2.43.0
PATCH v6 17/19 test: Add a section for closing the connection
In reply to Simon GlassThis can take a while and involve multiple steps (e.g. turning the board back off). Add a section for it and show the output.
---
(no changes since v1)
test/py/u_boot_console_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
test/py/u_boot_console_base.py +4 -1
@@ -183,7 +183,10 @@ class ConsoleBase(object): """ if self.p: - self.p.close() + self.log.start_section('Stopping U-Boot') + close_type = self.p.close() + self.log.info(f'Close type: {close_type}') + self.log.end_section('Stopping U-Boot') self.logstream.close() def set_lab_mode(self):
Signature · 1 line
2.43.0
PATCH v6 18/19 test: Support testing with two board-builds
In reply to Simon GlassThe Beagleplay board uses two entirely separate builds to produce an image, rather than using an SPL build for this purpose.
Handle this in test.py by adding more parameters.
---
(no changes since v5)
Changes in v5:
- Add a patch to support testing with two board-builds
test/py/conftest.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
test/py/conftest.py +31 -5
@@ -66,12 +66,16 @@ def pytest_addoption(parser): parser.addoption('--build-dir', default=None, help='U-Boot build directory (O=)') + parser.addoption('--build-dir-extra', default=None, + help='U-Boot build directory for extra build (O=)') parser.addoption('--result-dir', default=None, help='U-Boot test result/tmp directory') parser.addoption('--persistent-data-dir', default=None, help='U-Boot test persistent generated data directory') parser.addoption('--board-type', '--bd', '-B', default='sandbox', help='U-Boot board type') + parser.addoption('--board-type-extra', '--bde', default='sandbox', + help='U-Boot extra board type') parser.addoption('--board-identity', '--id', default='na', help='U-Boot board identity/instance') parser.addoption('--build', default=False, action='store_true',
@@ -129,14 +133,17 @@ def get_details(config): Returns: tuple: str: Board type (U-Boot build name) + str: Extra board type (where two U-Boot builds are needed) str: Identity for the lab board str: Build directory + str: Extra build directory (where two U-Boot builds are needed) str: Source directory """ role = config.getoption('role') # Get a few provided parameters build_dir = config.getoption('build_dir') + build_dir_extra = config.getoption('build_dir_extra') if role: # When using a role, build_dir and build_dir_extra are normally not set, # since they are picked up from Labgrid via the u-boot-test-getrole
@@ -146,6 +153,8 @@ def get_details(config): env = os.environ.copy() if build_dir: env['U_BOOT_BUILD_DIR'] = build_dir + if build_dir_extra: + env['U_BOOT_BUILD_DIR_EXTRA'] = build_dir_extra proc = subprocess.run(cmd, capture_output=True, encoding='utf-8', env=env) if proc.returncode:
@@ -159,24 +168,36 @@ def get_details(config): vals[k] = value # For debugging # print('conftest: lab info:', vals) - board_type, default_build_dir, source_dir = (vals['board'], - vals['build_dir'], vals['source_dir']) + + # Read the build directories here, in case none were provided in the + # command-line arguments + (board_type, board_type_extra, default_build_dir, + default_build_dir_extra, source_dir) = (vals['board'], + vals['board_extra'], vals['build_dir'], vals['build_dir_extra'], + vals['source_dir']) else: board_type = config.getoption('board_type') + board_type_extra = config.getoption('board_type_extra') board_identity = config.getoption('board_identity') source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) default_build_dir = source_dir + '/build-' + board_type + default_build_dir_extra = source_dir + '/build-' + board_type_extra + + # Use the provided command-line arguments if present, else fall back to if not build_dir: build_dir = default_build_dir + if not build_dir_extra: + build_dir_extra = default_build_dir_extra - return board_type, board_identity, build_dir, source_dir + return (board_type, board_type_extra, board_identity, build_dir, + build_dir_extra, source_dir) def pytest_xdist_setupnodes(config, specs): """Clear out any 'done' file from a previous build""" global build_done_file - build_dir = get_details(config)[2] + build_dir = get_details(config)[3] build_done_file = Path(build_dir) / 'build.done' if build_done_file.exists():
@@ -216,7 +237,8 @@ def pytest_configure(config): global console global ubconfig - board_type, board_identity, build_dir, source_dir = get_details(config) + (board_type, board_type_extra, board_identity, build_dir, build_dir_extra, + source_dir) = get_details(config) board_type_filename = board_type.replace('-', '_') board_identity_filename = board_identity.replace('-', '_')
@@ -281,9 +303,11 @@ def pytest_configure(config): ubconfig.test_py_dir = TEST_PY_DIR ubconfig.source_dir = source_dir ubconfig.build_dir = build_dir + ubconfig.build_dir_extra = build_dir_extra ubconfig.result_dir = result_dir ubconfig.persistent_data_dir = persistent_data_dir ubconfig.board_type = board_type + ubconfig.board_type_extra = board_type_extra ubconfig.board_identity = board_identity ubconfig.gdbserver = gdbserver ubconfig.no_prompt_wait = config.getoption('no_prompt_wait')
@@ -292,10 +316,12 @@ def pytest_configure(config): env_vars = ( 'board_type', + 'board_type_extra', 'board_identity', 'source_dir', 'test_py_dir', 'build_dir', + 'build_dir_extra', 'result_dir', 'persistent_data_dir', )
Signature · 1 line
2.43.0
PATCH v6 19/19 CI: Allow running tests on sjg lab
In reply to Simon GlassAdd a way to run tests on a real hardware lab. This is in the very early experimental stages. There are only 23 boards and 3 of those are broken! (bob, ff3399, samus). A fourth fails due to problems with the TPM tests.
To try this, assuming you have gitlab access, set SJG_LAB=1, e.g.:
git push -o ci.variable="SJG_LAB=1" dm HEAD:try
This relies on the two previous series targeted at -next as well as the bugfix series for -master
---
Changes in v6:
- Drop patch 'test: Pass stderr to stdout'
Changes in v3:
- Split out most patches into two new series and update cover letter
Changes in v2:
- Avoid running a docker image for skipped lab tests
.gitlab-ci.yml | 153 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+)
.gitlab-ci.yml +153 -0
@@ -17,6 +17,7 @@ stages: - testsuites - test.py - world build + - sjg-lab .buildman_and_testpy_template: &buildman_and_testpy_dfn stage: test.py
@@ -491,3 +492,155 @@ coreboot test.py: TEST_PY_TEST_SPEC: "not sleep" TEST_PY_ID: "--id qemu" <<: *buildman_and_testpy_dfn + +.lab_template: &lab_dfn + stage: sjg-lab + rules: + - if: $SJG_LAB == "1" + when: always + - when: manual + tags: [ 'lab' ] + script: + - if [[ -z "${SJG_LAB}" ]]; then + exit 0; + fi + # Environment: + # SRC - source tree + # OUT - output directory for builds + - export SRC="$(pwd)" + - export OUT="${SRC}/build/${BOARD}" + - export PATH=$PATH:~/bin + - export PATH=$PATH:/vid/software/devel/ubtest/u-boot-test-hooks/bin + + # Load it on the device + - ret=0 + - echo "role ${ROLE}" + - export strategy="-s uboot -e off" + # export verbose="-v" + - ${SRC}/test/py/test.py --role ${ROLE} --build-dir "${OUT}" + --capture=tee-sys -k "not bootstd"|| ret=$? + - U_BOOT_BOARD_IDENTITY="${ROLE}" u-boot-test-release || true + - if [[ $ret -ne 0 ]]; then + exit $ret; + fi + artifacts: + when: always + paths: + - "build/${BOARD}/test-log.html" + - "build/${BOARD}/multiplexed_log.css" + expire_in: 1 week + +rpi3: + variables: + ROLE: rpi3 + <<: *lab_dfn + +opi_pc: + variables: + ROLE: opi_pc + <<: *lab_dfn + +pcduino3_nano: + variables: + ROLE: pcduino3_nano + <<: *lab_dfn + +samus: + variables: + ROLE: samus + <<: *lab_dfn + +link: + variables: + ROLE: link + <<: *lab_dfn + +jerry: + variables: + ROLE: jerry + <<: *lab_dfn + +minnowmax: + variables: + ROLE: minnowmax + <<: *lab_dfn + +opi_pc2: + variables: + ROLE: opi_pc2 + <<: *lab_dfn + +bpi: + variables: + ROLE: bpi + <<: *lab_dfn + +rpi2: + variables: + ROLE: rpi2 + <<: *lab_dfn + +bob: + variables: + ROLE: bob + <<: *lab_dfn + +ff3399: + variables: + ROLE: ff3399 + <<: *lab_dfn + +coral: + variables: + ROLE: coral + <<: *lab_dfn + +rpi3z: + variables: + ROLE: rpi3z + <<: *lab_dfn + +bbb: + variables: + ROLE: bbb + <<: *lab_dfn + +kevin: + variables: + ROLE: kevin + <<: *lab_dfn + +pine64: + variables: + ROLE: pine64 + <<: *lab_dfn + +c4: + variables: + ROLE: c4 + <<: *lab_dfn + +rpi4: + variables: + ROLE: rpi4 + <<: *lab_dfn + +rpi0: + variables: + ROLE: rpi0 + <<: *lab_dfn + +snow: + variables: + ROLE: snow + <<: *lab_dfn + +pcduino3: + variables: + ROLE: pcduino3 + <<: *lab_dfn + +nyan-big: + variables: + ROLE: nyan-big + <<: *lab_dfn
Signature · 1 line
2.43.0
Quoted 48 lines · Simon Glass
Labgrid provides access to a hardware lab in an automated way. It is possible to boot U-Boot on boards in the lab without physically touching them. It relies on relays, USB UARTs and SD muxes, among other things.
By way of background, about 4 years ago I wrong a thing called Labman[1] which allowed my lab of about 30 devices to be operated remotely, using tbot for the console and build integration. While it worked OK and I used it for many bisects, I didn't take it any further.
It turns out that there was already an existing program, called Labgrid, which I did not know about at time (thank you Tom for telling me). It is more rounded than Labman and has a number of advantages:
- does not need udev rules, mostly
- has several existing users who rely on it
- supports multiple machines exporting their devicesIt lacks a 'lab check' feature and a few other things, but these can be remedied.
On and off over the past several weeks I have been experimenting with Labgrid. I have managed to create an initial U-Boot integration (this series) by adding various features to Labgrid[2] and the U-Boot test hooks.
I hope that this might inspire others to set up boards and run tests automatically, rather than relying on infrequent, manual test. Perhaps it may even be possible to have a number of labs available.
Included in the integration are a number of simple scripts which make it easy to connect to boards and run tests:
ub-int <target>
Build and boot on a target, starting an interactive sessionub-cli <target>
Build and boot on a target, ensure U-Boot starts and provide an interactive session from thereub-smoke <target>
Smoke test U-Boot to check that it boots to a prompt on a targetub-bisect <target>
Bisect a git tree to locate a failure on a particular targetub-pyt <target> <testspec>
Run U-Boot pytests on a target
Quoted 7 lines
Some of these help to provide the same tbot[4] workflow which I have relied on for several years, albeit much simpler versions.
The goal here is to create some sort of script which can collect patches from the mailing list, apply them and test them on a selection of boards. I suspect that script already exists, so please let me know what you suggest.
I still really wish you would split the labgrid parts of this series out from the pytest fixes and improvement parts. Things are largely fine outside of the labgrid part for example, which I'll probably just take after confirming it doesn't break using labgrid other ways.
Signature · 1 line
Tom
Hi Tom,
Quoted 59 lines · Tom Rini
Quoted 48 lines · Simon Glass
Labgrid provides access to a hardware lab in an automated way. It is possible to boot U-Boot on boards in the lab without physically touching them. It relies on relays, USB UARTs and SD muxes, among other things.
By way of background, about 4 years ago I wrong a thing called Labman[1] which allowed my lab of about 30 devices to be operated remotely, using tbot for the console and build integration. While it worked OK and I used it for many bisects, I didn't take it any further.
It turns out that there was already an existing program, called Labgrid, which I did not know about at time (thank you Tom for telling me). It is more rounded than Labman and has a number of advantages:
- does not need udev rules, mostly
- has several existing users who rely on it
- supports multiple machines exporting their devicesIt lacks a 'lab check' feature and a few other things, but these can be remedied.
On and off over the past several weeks I have been experimenting with Labgrid. I have managed to create an initial U-Boot integration (this series) by adding various features to Labgrid[2] and the U-Boot test hooks.
I hope that this might inspire others to set up boards and run tests automatically, rather than relying on infrequent, manual test. Perhaps it may even be possible to have a number of labs available.
Included in the integration are a number of simple scripts which make it easy to connect to boards and run tests:
ub-int <target>
Build and boot on a target, starting an interactive sessionub-cli <target>
Build and boot on a target, ensure U-Boot starts and provide an interactive session from thereub-smoke <target>
Smoke test U-Boot to check that it boots to a prompt on a targetub-bisect <target>
Bisect a git tree to locate a failure on a particular targetub-pyt <target> <testspec>
Run U-Boot pytests on a targetQuoted 7 lines
Some of these help to provide the same tbot[4] workflow which I have relied on for several years, albeit much simpler versions.
The goal here is to create some sort of script which can collect patches from the mailing list, apply them and test them on a selection of boards. I suspect that script already exists, so please let me know what you suggest.
Quoted 4 lines
I still really wish you would split the labgrid parts of this series out from the pytest fixes and improvement parts. Things are largely fine outside of the labgrid part for example, which I'll probably just take after confirming it doesn't break using labgrid other ways.
I have had a few attempts at this, but it ends up being somewhat arbitrary.
Perhaps I could split out a series with the exception-handling changes and the typo? Perhaps 'Avoid failing skipped tests' also?
Regards,
Simon
Quoted 67 lines · Simon Glass
Hi Tom,
Quoted 59 lines · Tom Rini
Quoted 48 lines · Simon Glass
Labgrid provides access to a hardware lab in an automated way. It is possible to boot U-Boot on boards in the lab without physically touching them. It relies on relays, USB UARTs and SD muxes, among other things.
By way of background, about 4 years ago I wrong a thing called Labman[1] which allowed my lab of about 30 devices to be operated remotely, using tbot for the console and build integration. While it worked OK and I used it for many bisects, I didn't take it any further.
It turns out that there was already an existing program, called Labgrid, which I did not know about at time (thank you Tom for telling me). It is more rounded than Labman and has a number of advantages:
- does not need udev rules, mostly
- has several existing users who rely on it
- supports multiple machines exporting their devicesIt lacks a 'lab check' feature and a few other things, but these can be remedied.
On and off over the past several weeks I have been experimenting with Labgrid. I have managed to create an initial U-Boot integration (this series) by adding various features to Labgrid[2] and the U-Boot test hooks.
I hope that this might inspire others to set up boards and run tests automatically, rather than relying on infrequent, manual test. Perhaps it may even be possible to have a number of labs available.
Included in the integration are a number of simple scripts which make it easy to connect to boards and run tests:
ub-int <target>
Build and boot on a target, starting an interactive sessionub-cli <target>
Build and boot on a target, ensure U-Boot starts and provide an interactive session from thereub-smoke <target>
Smoke test U-Boot to check that it boots to a prompt on a targetub-bisect <target>
Bisect a git tree to locate a failure on a particular targetub-pyt <target> <testspec>
Run U-Boot pytests on a targetQuoted 7 lines
Some of these help to provide the same tbot[4] workflow which I have relied on for several years, albeit much simpler versions.
The goal here is to create some sort of script which can collect patches from the mailing list, apply them and test them on a selection of boards. I suspect that script already exists, so please let me know what you suggest.
Quoted 4 lines
I still really wish you would split the labgrid parts of this series out from the pytest fixes and improvement parts. Things are largely fine outside of the labgrid part for example, which I'll probably just take after confirming it doesn't break using labgrid other ways.
Quoted 4 lines
I have had a few attempts at this, but it ends up being somewhat arbitrary.
Perhaps I could split out a series with the exception-handling changes and the typo? Perhaps 'Avoid failing skipped tests' also?
Well, in a previous series I said where I thought each patch went in terms of what-it-did, so yes, that sounds like one of the sets of patches I thought was unrelated to labgrid. Thanks.
Signature · 1 line
Tom