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

Allow running tests from anywhere and support EXTRA_MODULES #2725

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

urob
Copy link
Contributor

@urob urob commented Dec 19, 2024

This includes a few tweaks to run-tests.sh

  • Properly deal with paths so the the script can be run from any working directory
  • Add environment variables to set non-standard ZMK_SRC_DIR and ZMK_BUILD_DIR paths
  • Add option to specify ZMK_EXTRA_MODULES
  • Path arguments can be either absolute paths or relative to the current working directory. This applies to:
    • location of script (e.g., app/run-tests.sh or /workspace/zmk/app/run-tests.sh)
    • test path (e.g., app/tests/gresc or /workspace/zmk/app/tests/gresc, or even gresc if we are in .../tests)
    • values of ZMK_SRC_DIR, ZMK_BUILD_DIR and ZMK_EXTRA_MODULES

Being able to run tests from anywhere in the workspace is mostly a quality-of-life improvement. The real application is to test modules without having to re-invent the wheel.

For instance, suppose the working directory is the root of a workspace with the following structure:

.
├── build
├── some-module
│   ├── tests
│   └── ...
├── zmk
└── ...

Then one could run the module tests as follows:

# use absolute paths if planning to change working directory
export ZMK_SRC_DIR=zmk/app            # or $(realpath zmk/app)
export ZMK_BUILD_DIR=build            # or $(realpath build)
export ZMK_EXTRA_MODULES=some-module  # or $(realpath some-module)
./zmk/app/run-tests some-module

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.

@urob urob requested a review from a team as a code owner December 19, 2024 07:23
Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Thanks! Since this didn't opt to run tests, can you please add this file to the paths in .github/workflows/test.yml file so it'll run tests, and run them next time we have a PR to change this file?

TIA!

@petejohanson petejohanson self-assigned this Dec 20, 2024
@petejohanson petejohanson added enhancement New feature or request core Core functionality/behavior of ZMK tests labels Dec 20, 2024
@urob
Copy link
Contributor Author

urob commented Dec 20, 2024

Done! I tested backward-compatibility locally but was wondering why the GHA suite didn't run.

You might want to manually check that ZMK_TESTS_AUTO_ACCEPT still works for you. Again I checked on my end for all combinations of working directory and env variables - but better to be safe.

@petejohanson
Copy link
Contributor

Done! I tested backward-compatibility locally but was wondering why the GHA suite didn't run.

You might want to manually check that ZMK_TESTS_AUTO_ACCEPT still works for you. Again I checked on my end for all combinations of working directory and env variables - but better to be safe.

Still working fine. I added some garbage to the test snaphshot, then ran the follow sequence:

root@dfc4a8330d84:/workspaces/zmk# cd app
root@dfc4a8330d84:/workspaces/zmk/app# west test tests/none/normal/
Running none/normal:
--- tests/none/normal/keycode_events.snapshot   2024-12-20 20:08:05.441573176 +0000
+++ ./build/tests/none/normal/keycode_events.log        2024-12-20 20:08:28.920557449 +0000
@@ -1 +0,0 @@
-arst
\ No newline at end of file
FAILED: none/normal

FAILED: none/normal
root@dfc4a8330d84:/workspaces/zmk/app# ZMK_TESTS_AUTO_ACCEPT=y west test tests/none/normal/
Running none/normal:
--- tests/none/normal/keycode_events.snapshot   2024-12-20 20:08:05.441573176 +0000
+++ ./build/tests/none/normal/keycode_events.log        2024-12-20 20:08:51.317542444 +0000
@@ -1 +0,0 @@
-arst
\ No newline at end of file
Auto-accepting failure for none/normal
PASS: none/normal

PASS: none/normal
root@dfc4a8330d84:/workspaces/zmk/app# west test tests/none/normal/
Running none/normal:
PASS: none/normal

PASS: none/normal
root@dfc4a8330d84:/workspaces/zmk/app# 

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Thanks!

@petejohanson petejohanson merged commit 3f6841c into zmkfirmware:main Dec 20, 2024
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK enhancement New feature or request tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants