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

UI testing #67

Merged
merged 12 commits into from
Apr 10, 2023
Merged

UI testing #67

merged 12 commits into from
Apr 10, 2023

Conversation

martinling
Copy link
Member

@martinling martinling commented Mar 17, 2023

This PR adds new test infrastructure for recording and replaying UI interactions, along with a couple of test cases.

UI interactions are recorded through normal usage of the UI, by running with the record-ui-test feature, which writes out an actions.json file describing all actions the user took, and an output.txt file containing all information displayed by the UI as a result.

A test case is created by adding a test name to tests/ui/tests.txt and creating a directory tests/ui/<name>, containing the actions.json and the expected output named as reference.txt. When the tests are run, the actions are replayed into the UI, and a new output.txt file is generated and compared to reference.txt.

To the extent I found practical, the replay test exercises all the same UI code as normal operation, including full use of the GTK toolkit, but without actually displaying a window. This raised a couple of side issues:

  • On Linux, there must be a valid X DISPLAY setting present to use GTK, so CI is modified to run the tests with an Xvfb server available.
  • On MacOS, GTK must run from the main thread. This constraint is incompatible with the standard Cargo test harness, which runs all tests in spawned threads, even if told to limit to one thread.
    • The replay test is therefore implemented as a separate test, test_replay, which does not use the standard harness.
    • Since test_replay is a separate program, this required moving most of Packetry into a library crate.
    • However, this means that the library target is always built without cfg(test) set, so blocks in the UI code that are required by test_replay have to be feature gated instead.
    • For this reason, the UI replay test must be included explicitly with cargo test --features=test-ui-replay.

Some changes are also made to the existing decoder tests:

  • The list of tests is read from tests/tests.txt, rather than listing the tests directory.
  • Sequences of identical items are deduplicated, with a single copy and a count included in the output.

This PR is part of the planned sequence documented in #54. The next PR will add interleaving support to the tree view. The tests in this PR will be used to verify that the UI behaves correctly after the changes.

@martinling martinling mentioned this pull request Mar 17, 2023
7 tasks
@mossmann mossmann requested a review from miek April 6, 2023 16:42
Copy link
Member

@miek miek left a comment

Choose a reason for hiding this comment

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

This all looks great to me!

One slight issue I'm seeing is that it breaks normal running of cargo test (without the test-ui-replay feature) because it doesn't pull in itertools. Adding itertools to dev-dependencies without optional = true fixed that for me.

@martinling
Copy link
Member Author

Oh, nice catch. I think that crept in due to some reordering; later in the #54 sequence itertools becomes a regular dependency so cargo test starts working again. Let me figure out which commits to tweak and I'll fix it.

This avoids problems when inactive tests are left around by other
branches, and makes it possible to add subdirectories in 'tests' without
confusing the existing test code.
This is needed for tests using GTK to work on Linux.
This occurs when combining record-ui-test with step-decoder.
All the statements declaring submodules are now in lib.rs, which
defines a packetry crate, used by main.rs. The UI code is moved to
ui.rs, which is exposed to main.rs as part of the packetry crate.

The UI replay test is now a separate standalone program, test_replay.rs.
This is declared as a custom test in Cargo.toml, one not using the
standard cargo harness. It must be enabled specifically when testing:

    cargo test --features=test-ui-replay

This solves the problem of not being able to run that test on macOS,
which requires GTK to be initialized and used only from the main thread.

The CI workflow is amended to test with the test-ui-replay feature
enabled, and to build the release binary without features enabled. All
current features are for debug and test purposes only.
@martinling
Copy link
Member Author

Fixed!

@miek
Copy link
Member

miek commented Apr 10, 2023

Thanks!

@miek miek merged commit 5dddf3f into greatscottgadgets:main Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants