Skip to content

Commit 21250dd

Browse files
committed
reset timer results before each test
1 parent 89c33b4 commit 21250dd

6 files changed

Lines changed: 18 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h
667667
cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
668668
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp
669669

670-
test/fixture.o: test/fixture.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h test/fixture.h test/options.h test/redirect.h
670+
test/fixture.o: test/fixture.cpp lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h test/options.h test/redirect.h
671671
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp
672672

673673
test/helpers.o: test/helpers.cpp lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h

lib/cppcheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,3 +1849,8 @@ void CppCheck::removeCtuInfoFiles(const std::map<std::string, std::size_t> &file
18491849
}
18501850
}
18511851
}
1852+
1853+
void CppCheck::resetTimerResults()
1854+
{
1855+
s_timerResults.reset();
1856+
}

lib/cppcheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
145145
/** Remove *.ctu-info files */
146146
void removeCtuInfoFiles(const std::map<std::string, std::size_t>& files); // cppcheck-suppress functionConst // has side effects
147147

148+
static void resetTimerResults();
149+
148150
private:
149151
/** Are there "simple" rules */
150152
bool hasRule(const std::string &tokenlist) const;

lib/timer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ void TimerResults::addResults(const std::string& str, std::clock_t clocks)
8787
mResults[str].mNumberOfResults++;
8888
}
8989

90+
void TimerResults::reset()
91+
{
92+
std::lock_guard<std::mutex> l(mResultsSync);
93+
mResults.clear();
94+
}
95+
9096
Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults)
9197
: mStr(std::move(str))
9298
, mTimerResults(timerResults)

lib/timer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class CPPCHECKLIB TimerResults : public TimerResultsIntf {
6262
void showResults(SHOWTIME_MODES mode) const;
6363
void addResults(const std::string& str, std::clock_t clocks) override;
6464

65+
void reset();
66+
6567
private:
6668
std::map<std::string, struct TimerResultsData> mResults;
6769
mutable std::mutex mResultsSync;

test/fixture.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "fixture.h"
2020

21+
#include "cppcheck.h"
2122
#include "errortypes.h"
2223
#include "options.h"
2324
#include "redirect.h"
@@ -91,6 +92,7 @@ bool TestFixture::prepareTest(const char testname[])
9192
mVerbose = false;
9293
mTemplateFormat.clear();
9394
mTemplateLocation.clear();
95+
CppCheck::resetTimerResults();
9496

9597
// Check if tests should be executed
9698
if (testToRun.empty() || testToRun == testname) {

0 commit comments

Comments
 (0)