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 Cpputest #74372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vChavezB
Copy link
Contributor

@vChavezB vChavezB commented Jun 16, 2024

Similar to gTest, CppuTest is a CPP framework for unit tests. This commit adds support to detect Cpputest console output when verbose mode is enabled (-v).

I am open for any feedback. My main use case was some unit tests that were written with Cpputest that I needed to port to Zephyr and integrate with twister.

@MaureenHelm
Copy link
Member

@vChavezB please take a look at the failed checks

@vChavezB
Copy link
Contributor Author

vChavezB commented Aug 8, 2024

Thanks for the feedback, I must have missed it.

@zephyrbot zephyrbot added the area: Testsuite Testsuite label Aug 8, 2024
@vChavezB vChavezB force-pushed the twister_cpputest branch 2 times, most recently from d526801 to 0ddcc40 Compare August 8, 2024 21:42
@hakehuang
Copy link
Collaborator

would be possible to a test application for this?

Comment on lines 468 to 492
not wish to update them to zTest. If using ``cpputest`` be sure to pass the
verbose argument ``-v`` to `CommandLineTestRunner::RunAllTests`.
Copy link
Member

Choose a reason for hiding this comment

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

Why the need for "-v"? I don't see it in the code. Also, it shouldn't be the case. Level of output verbosity mustn't affect a test result.

Copy link
Contributor Author

@vChavezB vChavezB Aug 9, 2024

Choose a reason for hiding this comment

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

The verbose argument must be applied to your CPPUtest application. Correct me if I am wrong but if you do not add the verbose option, you do not get information about which test cases have passed. Instead you will only get a dot for each test that has passed (e.g. ....) and at the end something such as OK (2 tests, 2 ran, 94 checks, 0 ignored, 0 filtered out, 2 ms).

Without verbose

..
OK (2 tests, 2 ran, 94 checks, 0 ignored, 0 filtered out, 2 ms)

With verbose

TEST(MyGroup, test1)
TEST(MyGroup, test2)
 OK (2 tests, 2 ran, 94 checks, 0 ignored, 0 filtered out, 2 ms)

@vChavezB
Copy link
Contributor Author

vChavezB commented Aug 9, 2024

would be possible to a test application for this?

I made a sample here

https://github.com/vChavezB/zephyr_cpputest_sample

git clone https://github.com/vChavezB/zephyr_cpputest_sample
wes init -l zephyr_cpputest_sample
west update -o=--depth=1 -n
./zephyr/scripts/twister -vvv -T zephyr_cpputest_sample

@hakehuang
Copy link
Collaborator

would be possible to a test application for this?

I made a sample here

https://github.com/vChavezB/zephyr_cpputest_sample

git clone https://github.com/vChavezB/zephyr_cpputest_sample
wes init -l zephyr_cpputest_sample
west update -o=--depth=1 -n
./zephyr/scripts/twister -vvv -T zephyr_cpputest_sample

I would support you to move this test into tests/cpputest

@vChavezB
Copy link
Contributor Author

vChavezB commented Nov 8, 2024

These are the test cases that are identified by twister:

INFO    - 1/1 native_sim/native/64      tests/cpputest/base/base.my_test_group             PASSED (native 0.005s)
INFO    -                                    base.my_test_group                                                          NONE
INFO    -                                    base.my_test_group.my_test_group.test_1                                     PASSED

The one marked as NONE is actually the test suite group I defined in the yaml.

The only test case that I defined in the sample code is (test_1 , see here)

TEST(my_test_group, test_1) {

}

However, it seems that twister uses the name base.my_test_group.

tests:
  base.my_test_group:
    platform_allow:
      - native_sim/native/64
    harness: "cpputest"

This is implemented here:

@vChavezB
Copy link
Contributor Author

vChavezB commented Nov 9, 2024

I have opened an issue (#81176) with the error that you mentioned. This is related to how test cases are parsed for other frameworks that are not ztest.

@vChavezB vChavezB force-pushed the twister_cpputest branch 5 times, most recently from 772ca25 to f734679 Compare November 9, 2024 14:20
@vChavezB
Copy link
Contributor Author

vChavezB commented Nov 9, 2024

I have made a temporal solution to allow that my CPPUTest harness class deletes the fake testcase at start, but I would prefer that issue #81176 is solved.

Copy link

github-actions bot commented Jan 9, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jan 9, 2025
@hakehuang hakehuang removed the Stale label Jan 9, 2025
@kartben kartben modified the milestones: v4.1.0, v4.2.0 Feb 17, 2025
@vChavezB vChavezB closed this Mar 4, 2025
@vChavezB vChavezB reopened this Mar 4, 2025
@vChavezB vChavezB force-pushed the twister_cpputest branch 4 times, most recently from 303e4e1 to d4ecb01 Compare March 4, 2025 12:16
Similar to gTest, CppuTest is a CPP framework for unit tests.
This commit adds support based on the console output of
a cpputest test suite application.

Signed-off-by: Victor Chavez <vchavezb@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants