Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twister: Add support for required snippets #61111

Merged
merged 4 commits into from
Sep 6, 2023

Conversation

nordicjm
Copy link
Collaborator

@nordicjm nordicjm commented Aug 3, 2023

Adds support for twister to require using snippets on tests

@nordicjm
Copy link
Collaborator Author

nordicjm commented Aug 3, 2023

@JordanYates Is this sort of what you were asking for? I don't see much use for it with the cdc-acm-console snippet given that it raises a warning for each invocation and twister instantly fails on that

@nordicjm
Copy link
Collaborator Author

@JordanYates ping

Copy link
Collaborator

@JordanYates JordanYates left a comment

Choose a reason for hiding this comment

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

Generally it looks good. What do you mean by failing instantly on cdc-acm-console?
We would probably also need an additional twister arg to add snippet roots as well.

scripts/pylib/twister/twisterlib/testplan.py Outdated Show resolved Hide resolved
@nordicjm
Copy link
Collaborator Author

Generally it looks good. What do you mean by failing instantly on cdc-acm-console?

It emits a build warning when USB CDC is enabled and logging is also enabled from https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/usb/device/class/cdc_acm.c#L63 and this will fail by default in twister

@nordicjm nordicjm force-pushed the twistersnippets branch 5 times, most recently from d9dc6c8 to a273402 Compare August 18, 2023 11:09
@nordicjm nordicjm marked this pull request as ready for review August 18, 2023 11:10
@zephyrbot zephyrbot added area: West West utility area: Twister Twister labels Aug 18, 2023
@nordicjm nordicjm force-pushed the twistersnippets branch 2 times, most recently from 56da98d to fb24b48 Compare August 18, 2023 11:34
@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Aug 18, 2023
hakehuang
hakehuang previously approved these changes Aug 24, 2023
hakehuang
hakehuang previously approved these changes Aug 25, 2023
@@ -160,6 +160,10 @@ Build system and infrastructure

* Added support for CodeChecker

* Twister now supports ``required_snippets`` in testsuite .yml files, this can
be used to include a snippet when a test is ran (and exclude any boards from
Copy link
Member

Choose a reason for hiding this comment

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

... when a test is run

Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

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

Do we have someone using this feature in the tree? Would be great to have some tests using this.

@nordicjm
Copy link
Collaborator Author

Do we have someone using this feature in the tree? Would be great to have some tests using this.

Not in tree other than the twister test cases no, the problem is that the only snippet in tree is the USB CDC console one which emits a build warning for a lot of boards because it reduces the USB log level, and when ran in twister that fails the build immediately

Copy link
Member

@PerMac PerMac left a comment

Choose a reason for hiding this comment

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

A minor request for logging level. The other comment is a general question, as I'd like to understand the logic there. When I added cdc-acm-console to hello_world sample it seemed to work as I got extra OUTPUT: uart connected to pseudotty: /dev/pts/4 in the output.

scripts/pylib/twister/twisterlib/testplan.py Show resolved Hide resolved
Comment on lines 838 to 839
if len(found_snippets[this_snippet].appends) > 0:
continue
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain these lines? I think I don't follow. While debugging I see that cdc-acm-console has len(found_snippets[this_snippet].appends) = 2 hence continuing, i.e. ignoring the rest of the logic, where it is decided if a matching board was found

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This checks if it is a global snippet i.e. applies to all boards, or if it only applies to some boards, see https://docs.zephyrproject.org/latest/build/snippets/writing.html#by-name for an example

Copy link
Contributor

@mbolivar-ampere mbolivar-ampere left a comment

Choose a reason for hiding this comment

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

Looks like a good feature and no objections to the idea. One minor naming suggestion, nonblocking.

@@ -238,6 +238,22 @@ def process_snippets(args: argparse.Namespace) -> Snippets:

return snippets

def process_snippets_inter(requested_snippets, snippet_roots) -> Snippets:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better named find_snippets_in_roots or something like that. I had a hard time guessing what process_snippets_inter meant when I first saw it earlier in the patch.

@nashif
Copy link
Member

nashif commented Aug 28, 2023

Not in tree other than the twister test cases no, the problem is that the only snippet in tree is the USB CDC console one which emits a build warning for a lot of boards because it reduces the USB log level, and when ran in twister that fails the build immediately

ok, who is using this feature then and how? I am trying to understand the usecase here and this and it would help if we have a user in-tree beside the unit test.

@nordicjm
Copy link
Collaborator Author

nordicjm commented Aug 29, 2023

Not in tree other than the twister test cases no, the problem is that the only snippet in tree is the USB CDC console one which emits a build warning for a lot of boards because it reduces the USB log level, and when ran in twister that fails the build immediately

ok, who is using this feature then and how? I am trying to understand the usecase here and this and it would help if we have a user in-tree beside the unit test.

It was a feature requested by @JordanYates from the original implementation PR. Currently there cannot be an in-tree usage of this because there is only one in tree snippet, but as time passes and more snippets are added, then it would be a good fit for having usage by tests/samples in tree.

@PerMac
Copy link
Member

PerMac commented Aug 29, 2023

I realized you forgot to add "required_snippets" to the schema for a common section. Adding this entry in common causes

ERROR   - /home/maciej/zephyrproject/zephyr/samples/hello_world: can't load (skipping): SchemaError(msg='Schema validation failed:
 - Key 'required_snippets' was not defined. Path: '/sample'.')

@nashif
Copy link
Member

nashif commented Aug 29, 2023

Currently there cannot be an in-tree usage of this because there is only one in tree snippet, but as time passes and more snippets are added, then it would be a good fit for having usage by tests/samples in tree.

maybe it is time to add more snippets, software only, i.e. something that can be used as an example without dependency on hardware, I just added

commit 3f3374bbb96a2a84984905e7f934385400801bd4 (HEAD -> twistersnippets)
Author: Anas Nashif <anas.nashif@intel.com>
Date:   Tue Aug 29 12:03:29 2023 +0000

    debug snippet

    Signed-off-by: Anas Nashif <anas.nashif@intel.com>

diff --git a/snippets/debug/debug.conf b/snippets/debug/debug.conf
new file mode 100644
index 0000000000..53c5adaac3
--- /dev/null
+++ b/snippets/debug/debug.conf
@@ -0,0 +1,5 @@
+CONFIG_DEBUG=y
+CONFIG_THREAD_NAME=y
+CONFIG_THREAD_ANALYZER=y
+CONFIG_THREAD_ANALYZER_AUTO=y
+CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
diff --git a/snippets/debug/snippet.yml b/snippets/debug/snippet.yml
new file mode 100644
index 0000000000..9c6d9e78a0
--- /dev/null
+++ b/snippets/debug/snippet.yml
@@ -0,0 +1,3 @@
+name: debug
+append:
+  EXTRA_CONF_FILE: debug.conf

and used this with you PR, and it works fine.

Adds support for twister to require using snippets on tests

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds 2 tests which check required_snippet functionality works.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds a note that twister now supports applying snippets

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds information on the new required_snippets feature

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
@@ -145,6 +145,11 @@ mapping:
matching: "all"
sequence:
- type: str
"required_snippets":
Copy link
Member

Choose a reason for hiding this comment

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

might it be just snippets ? or are there other types of snippets possible e.g. 'optional'. If so, then shouldn't it be snippets_required to follow the naming convention here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "required" part is to make it clear that the test will only run with them. I don't envisage having support for optional snippets, they will either be required and applied or not available and test will not run

Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

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

still do not see of example usage in zephyr, but thats fine, I can add this as a followup.

@carlescufi carlescufi merged commit e6d5b3f into zephyrproject-rtos:main Sep 6, 2023
32 checks passed
@nordicjm nordicjm deleted the twistersnippets branch December 12, 2023 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Documentation area: Twister Twister area: West West utility Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants