Skip to content

Comments

Redesign Testing and Add BMI Unit Tests#151

Open
robertbartel wants to merge 29 commits intoNOAA-OWP:masterfrom
robertbartel:i/organized_unit_tests/main
Open

Redesign Testing and Add BMI Unit Tests#151
robertbartel wants to merge 29 commits intoNOAA-OWP:masterfrom
robertbartel:i/organized_unit_tests/main

Conversation

@robertbartel
Copy link

Redesign automated testing for the project to use CMake and CTest, rather than ad hoc test script. Also, add several, more focused unit tests for BMI functions. Also add some helper testing utils and documentation.

Additions

  • Helper test fixture struct and functions specific to BMI unit testing (test/bmi_test_utils.*)
  • General helper test functions (test/general_test_utils.*)
  • Unit test code for all BMI functions, parameterized via one single executable and main function (test/test_bmi_model.c)

Removals

  • UNITTEST option and related parts of CMake config
  • Removed old test script; tests now run through CTest

Changes

  • Renamed old testing file to better reflect what it is (a combination test, rather than true unit test)
  • Some modifications to whitespace in CMakeLists.txt for easier reading
  • Defined test executable and test in CMakeLists.txt for aforementioned combined test file
  • Defined test executable and tests in CMakeLists.txt for BMI unit tests, based on same example config as previously existing test
  • Updated testing readme to reflect these changes, in particular how to now build, run, and add tests
  • Modified GitHub Actions config to run all currently available tests

Testing

  1. All tests built, run, and passed on local dev machine

Todos

  • Eventually, additional test case examples are needed
    • Especially true for get_var_nbytes; see TODOs and notes on Rootzone-based AET and soil_moisture_profile
  • Tests still needed for non-BMI functions
  • More comprehensive automated (non-unit) tests needed to further strengthen functional and scientific quality

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

@robertbartel
Copy link
Author

Regarding the current linker error, I never encountered this on MacOS with clang, but I was able to reproduce it on another Linux system. After making the last change in the CMake config for the linker, I no longer see the problem in my Linux system (😃), but it's still happening in the Action Runner (😕) .

I'm not 100% sure at this point if something is cached, if there is some subtle difference in the Runner compared to my Linux system, or if I'm just missing something else. The idea a subtle difference seems less likely when we we are talking about involves a standard C math library, but I'm not sure.

Any thoughts @hellkite500 or @aaraney?



if (NOT NGEN)
target_link_libraries(${exe_name} PRIVATE m)
Copy link
Contributor

Choose a reason for hiding this comment

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

@robertbartel this may be the problem in the runner tests -- try linking the math lib even if NGEN is set and see if that works?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed that fixed it, but I don't understand why. I get the need for the math lib, but not why what I was doing before wasn't sufficient (given that it did correct the issue in some cases).

But unless that's clear to someone already, we can save answer that question for another time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Different compiler versions and platforms may have libm implicitly linked for all kinds of different reasons... My best guess is just slightly different toolchain versions.

Creating helper test function (with naive implementation) for getting
arbitrary values for BMI input variables to use for setting module
inputs, with parameters for (in the future) allowing different values
depending on the example test case and current time of the module.
Add func to set arbitrary values for BMI inputs ahead of a call to
update() advancing the module.
Adding for remaining grid functions and for time functions.
- Add start time and time step size values as defined macros
- Adjust function(s) for setting values prior to update to support
  direct control over what values are set
Adding tests for BMI functions that are not fully implemented and only
have a shell implementation that returns BMI_FAILURE, to ensure this is
what is returned (so that if implementations are ever added, these tests
fail and let someone know proper tests need to be added).
Fixing test by having function properly account for case (which applies
to the current test example config) when module does not fully use the
"soil_moisture_profile" variable, and thus nbytes can/should be skipped
for it.
Renaming previously existing test file to better reflect what it is, as
it is more of a comprehensive test of BMI functionality than a file with
true unit tests.
Update CMake/CTest config with executable and tests for running the
previously existing (though since renamed) combined test file testing
all BMI functionality within the single test routine.
Removing, since now those tests should be built in the normal ngen
build.
@robertbartel robertbartel force-pushed the i/organized_unit_tests/main branch from f8f3f21 to 7d6d4d5 Compare February 12, 2026 19:43
@robertbartel
Copy link
Author

Pinging on this again, as I still think it's a worthy change. I'll also tag @christophertubbs and @donaldwj in case they want to look at it. We might want/need to expand and strengthen testing ahead of incorporating some of the NGWPC contributions, and I think this would lay a good foundation for that.

@robertbartel
Copy link
Author

Looks like I also need to add the -DCMAKE_POLICY_VERSION_MINIMUM=3.5 flag in the runners. I'll do that shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants