forked from elastic/ml-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x][ML] Improve program counter resets between unit tests (elastic#…
…1658) Program counters are implemented as a singleton object, which means their values spill between unit tests unless action is taken to prevent this. Often it doesn't matter, as most unit tests do not care about program counter values. Two unit test suites already reset program counters in between tests: CProgramCountersTest and CRestorePreviousStateTest. It turns out that a third test suite should have been resetting counters but wasn't: CDataFrameAnalysisInstrumentationTest. This PR rectifies that omission and also factors out the code used to reset counters into the test library which makes it easier to reuse if other suites also need the functionality in the future. Backport of elastic#1656
- Loading branch information
1 parent
fa776dd
commit c3c03aa
Showing
8 changed files
with
89 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
#ifndef INCLUDED_ml_test_CProgramCounterClearingFixture_h | ||
#define INCLUDED_ml_test_CProgramCounterClearingFixture_h | ||
|
||
#include <test/ImportExport.h> | ||
|
||
namespace ml { | ||
namespace test { | ||
|
||
//! \brief | ||
//! Test fixture that resets all program counters to zero | ||
//! between tests. | ||
//! | ||
//! DESCRIPTION:\n | ||
//! Program counters are implemented as a singleton object, | ||
//! which means their values are remembered across unit tests. | ||
//! Unit tests that care about the values of program counters | ||
//! should use this test fixture to ensure they start from a | ||
//! well known state. Otherwise test results can vary depending | ||
//! on whether a test is run alone or as part of a suite. | ||
//! | ||
//! IMPLEMENTATION DECISIONS:\n | ||
//! This functionality is required in multiple unit test suites, | ||
//! hence it's in the test library. | ||
//! | ||
class TEST_EXPORT CProgramCounterClearingFixture { | ||
public: | ||
CProgramCounterClearingFixture(); | ||
}; | ||
} | ||
} | ||
|
||
#endif // INCLUDED_ml_test_CProgramCounterClearingFixture_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
#include <test/CProgramCounterClearingFixture.h> | ||
|
||
#include <core/CProgramCounters.h> | ||
|
||
namespace ml { | ||
namespace test { | ||
|
||
CProgramCounterClearingFixture::CProgramCounterClearingFixture() { | ||
core::CProgramCounters& counters{core::CProgramCounters::instance()}; | ||
|
||
// Set all counters to 0 | ||
for (std::size_t i = 0; i < counter_t::NUM_COUNTERS; ++i) { | ||
counters.counter(i) = 0; | ||
} | ||
|
||
// Clear the cache | ||
counters.m_Cache.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters