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

Auto-discover unit tests #10922

Merged
merged 5 commits into from
Feb 5, 2025
Merged

Auto-discover unit tests #10922

merged 5 commits into from
Feb 5, 2025

Conversation

Myoldmopar
Copy link
Member

TL;DR: I found a bunch of unit tests were being missed in ctest.exe runs, so I improved the test discovery.

While debugging and poking around, I realized that ctest wasn't picking up all the unit tests, Quick background:

  • Our unit tests are built on Google Test Framework, which provides macros like TEST and TEST_F to declare tests
  • Anything we build with the Google macros are automatically added to our unit test binary, energyplus_tests.exe
  • However, you can't run the tests in parallel from this binary, so we (@kbenne) added a way to include each unit test as an entry in our ctest test management.
  • This was done by parsing the unit test code itself and creating a list of matching TEST and TEST_F declarations that we then massage into ctest using the add_test function.

This has worked great for many years, but now some advanced things have trickled in, like parameterized unit tests. These use different Google Test macros, like TEST_P. These work great when you run energyplus_tests.exe, but they were not being picked up by our code that massages these into ctest add_test calls. So if you run ctest like I do, you miss out on running those unit tests.

Thanks to @kbenne for pointing out that there is a more modern way of doing this that doesn't rely on parsing the code. Just call gtest_discover_tests and point it to the built binary. It will programmatically grab all the unit tests declared so that we never miss any at all!

This was really great, but it also changed the way the test output is emitted, and it forces reporting any disabled tests. Decent CI detects those and reports them to us, which I saw as an opportunity to go in and fix the failing tests. Or at least touch base with them. I ultimately fixed a few, and then commented a few back out since they weren't running anyway. At some point if someone wants to push on them further to get them running, that's great, but I'm not taking more time now.

As of now, develop sees 2926 tests, but this branch sees 2951. So a gain of 25 tests that were being missed by CI !!

@Myoldmopar Myoldmopar added the DoNotPublish Includes changes that shouldn't be reported in the changelog label Feb 5, 2025
@Myoldmopar Myoldmopar self-assigned this Feb 5, 2025
Copy link

github-actions bot commented Feb 5, 2025

⚠️ Regressions detected on macos-14 for commit e499e2e

Regression Summary
  • Table Big Diffs: 236
  • Table Small Diffs: 2

Copy link
Member Author

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

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

Walkthrough done. If CI is all happy, this should be good to merge in and get those tests running.

DISCOVERY_TIMEOUT 30
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced that block of "manual" source code parsing with just a call to let gtest discover the tests and add them to ctest. Excellence.

// surfShade.blind.slatAngInterpFac);
// surfShade.effGlassEmi = Interp(constrSh.effGlassEmi[surfShade.blind.slatAngIdxLo],
// constrSh.effGlassEmi[surfShade.blind.slatAngIdxHi],
// surfShade.blind.slatAngInterpFac);
Copy link
Member Author

Choose a reason for hiding this comment

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

The comment explains it, but basically, on my Apple Silicon, in a release build, this was throwing a segfault because the array indices were still -1 here. I just moved them to where they were assigned before the Material refactor, and it's all happy locally. We'll see how CI likes it.

surfShade.blind.slatAngInterpFac);
surfShade.effGlassEmi = Interp(construction.effGlassEmi[surfShade.blind.slatAngIdxLo],
construction.effGlassEmi[surfShade.blind.slatAngIdxHi],
surfShade.blind.slatAngInterpFac);
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved these back here, where they were before the Material refactor. Let's see.

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a test here that was disabled, and hadn't been run in a long time. (DISABLED_AirLoopNumTest) Since ctest is more aggressively reporting out disabled tests, I commented it out. Happy to get it back in if someone wants to spend time investigating the failure.

main.cc)

set(test_dependencies energypluslib)
set(test_dependencies energypluslib energyplusapi)
Copy link
Member Author

Choose a reason for hiding this comment

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

I got rid of the separate energyplusapi_tests build. Just build the unit tests into a single test executable that depends on the lib and the api both being built. These are not optional things in the EnergyPlus build, so it should be fine for every platform, dev, machine, etc. (Famous last words)

@@ -94,13 +94,16 @@ TEST_F(EnergyPlusFixture, TestTrendVariable)
EXPECT_DOUBLE_EQ(0.0, pluginManager.getTrendVariableValue(*state, trendVarIndex, 3));
}

TEST_F(EnergyPlusFixture, DISABLED_MultiplePluginVariableObjects)
TEST_F(EnergyPlusFixture, MultiplePluginVariableObjects)
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is a bit invalid nowadays. I left what I felt was reasonable.

@@ -1908,7 +1908,7 @@ TEST_F(EnergyPlusFixture, InitAirLoops_1AirLoop2Zones3ADU)
EXPECT_EQ(state->dataZoneEquip->ZoneEquipConfig(2).InletNodeAirLoopNum(1), 1);
}

TEST_F(EnergyPlusFixture, DISABLED_AirLoop_ReturnFan_MinFlow)
TEST_F(EnergyPlusFixture, AirLoop_ReturnFan_MinFlow)
Copy link
Member Author

Choose a reason for hiding this comment

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

Enabled this and it's good to go!

@@ -405,7 +405,7 @@ TEST_F(SizingAnalysisObjectsTest, PlantCoincidentAnalyObjTest)
EXPECT_TRUE(TestAnalysisObj.anotherIterationDesired);
}

TEST_F(SizingAnalysisObjectsTest, DISABLED_LoggingSubStep4stepPerHour)
TEST_F(SizingAnalysisObjectsTest, LoggingSubStep4stepPerHour)
Copy link
Member Author

Choose a reason for hiding this comment

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

Enabled this and it's good to go!

// life DISABLE_d anyway, so this is a net improvement.
if (std::getenv("CI")) {
return;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing as numThreads here. There's something super odd about the CI image that causes this to fail. I do not understand. I'm happy to let it run on everyone's personal machines regularly and not worry about this on CI.

@@ -66,7 +66,7 @@

using namespace EnergyPlus;

TEST_F(EnergyPlusFixture, DISABLED_WCEClear)
TEST_F(EnergyPlusFixture, WCEClear)
Copy link
Member Author

Choose a reason for hiding this comment

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

Enabled 3 tests here and they seem good to go!

@Myoldmopar
Copy link
Member Author

All clean woo!!! OK, this is going in. Thanks to @kbenne for the discovery tip. If anyone notices any weirdness, obviously let me know. And if anyone wants to poke around at any of the tests I commented, that would be great. They haven't been running in various amounts of time, so they may need significant attention to get running again.

@Myoldmopar Myoldmopar merged commit 0898934 into develop Feb 5, 2025
9 checks passed
@Myoldmopar Myoldmopar deleted the TryDiscoverTests branch February 5, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DoNotPublish Includes changes that shouldn't be reported in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants