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

Migrate test suite to GoogleTest framework #119

Merged

Conversation

davidtrevelyan
Copy link
Contributor

@davidtrevelyan davidtrevelyan commented Nov 27, 2023

This PR does the following:

  • Introduces GoogleTest as the testing framework for RTNeural
  • Introduces two test targets: rtneural_test_unit and rtneural_test_functional
    • Unit tests contain a small new example demonstrating unit testing patterns for Activation layers
    • Functional tests are simply the old test header files, moved to the new target. Some old assertions have been simplified to make use of test assertions built into GoogleMock, and there have been a couple of very minor clarifying refactors in the test code. No new functional tests have been added.
  • Adds a new README file in the tests folder, explaining how to build and run the tests (or a subset of them!)
  • Updates test implementations to use #include <RTNeural/RTNeural.h>, to match the intended client code inclusion pattern

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1e7b570) 95.64% compared to head (5ddbdee) 95.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #119      +/-   ##
==========================================
- Coverage   95.64%   95.59%   -0.05%     
==========================================
  Files          58       58              
  Lines        3860     3794      -66     
==========================================
- Hits         3692     3627      -65     
+ Misses        168      167       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@jatinchowdhury18 jatinchowdhury18 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! The changes look good overall, I just had a couple of notes.

  • For the RTNeural header, I think using #include <RTNeural/RTNeural.h> in both the tests and client code is the way to go.
  • I think there's some kind of linker error happening with gmock on MSVC. I think this can be fixed by adding this to our test targets:
set_property(TARGET foo PROPERTY
  MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

macro(rtneural_setup_testing)
include(CTest)
enable_testing()
add_custom_target(rtneural_test COMMAND ctest -C ${Configuration} --output-on-failure)
Copy link
Owner

Choose a reason for hiding this comment

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

Nice!

option(RTNEURAL_TEST_REPORTS "Output test reports to XML files" OFF)

macro(rtneural_setup_testing)
include(CTest)
Copy link
Owner

Choose a reason for hiding this comment

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

I was under the impression that CTest has to be included from the "top level" CMake script. But maybe this is okay because it's in a macro? (I've never used CMake macro's before)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe you're correct on both counts :)

A macro in CMake is somewhat analogous to a C preprocessor macro - after the arguments are substituted into the body, it's as if the implementation of the macro is just copy/pasted into the call site. This particular macro has no arguments, so it's pretty much just a straight copy/paste of the macro body! The result is as you suspect - CTest is indeed included at the top level CMake script here 👍

Comment on lines +5 to +6
1. unit tests, and
2. functional tests.
Copy link
Owner

Choose a reason for hiding this comment

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

This is great! I wonder if it might make sense to further split up the function tests into "layer" tests and "model" tests... at the moment we only have one model test, but I'm hoping to add more. Anyway, that's a change we can make later if we want to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glad you like it! On splitting the functional tests into tests for layers vs models, I'm not sure. I'd be happy to jump on a call to chat about it with you at some point, if you like! I would consider whether the layer tests are simple enough to be written as unit tests - they're usually simpler, easier to reason about, and less brittle. But every project has different needs and challenges, so there's no one-size-fits-all :)

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, that's a good point. I'd like to do a bit of hacking myself just to get a sense of what might work, but yeah, no rush or anything, just putting some thoughts out there.

..
./
Copy link
Owner

Choose a reason for hiding this comment

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

I think I would prefer to leave the include path as #include <RTNeural/RTNeural.h>, just to avoid having a breaking change for end-users, and then we could update the tests to use that include path also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure - sounds great. Totally agree on avoiding a breaking change. I'll update the tests and revert the include path!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one's done, and I've updated the PR description to match!

@davidtrevelyan
Copy link
Contributor Author

Thanks for the PR! The changes look good overall, I just had a couple of notes.

  • For the RTNeural header, I think using #include <RTNeural/RTNeural.h> in both the tests and client code is the way to go.
  • I think there's some kind of linker error happening with gmock on MSVC. I think this can be fixed by adding this to our test targets:
set_property(TARGET foo PROPERTY
  MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

No problem - thanks for the review!

  • Regarding the include directories and include style, I've reverted the target property and have updated the tests to use the new style, and
  • regarding the gmock linker error - oops! Missed that one. I think the solution to this is in the GoogleTest README, so I'll try that first. If it doesn't work, let's try doing it manually as you suggest?

@jatinchowdhury18
Copy link
Owner

Awesome, thanks for the update! Yeah, trying the CMake option provided by GoogleTest sounds good.

I think there's also a different include path thing happening in some of the examples, but otherwise we should be good to go :)

@jatinchowdhury18
Copy link
Owner

Awesome, I'm happy to merge whenever you're ready, the only last thing would be to add yourself to the contributor's list if you'd like to.

@davidtrevelyan
Copy link
Contributor Author

Nice one, thanks for the excellent review @jatinchowdhury18! I've updated the contributors list now and I'm ready for it to be merged too, assuming the CI passes 😁

@jatinchowdhury18 jatinchowdhury18 merged commit 6a2b7b8 into jatinchowdhury18:main Nov 28, 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.

3 participants