Skip to content

Commit 771ea7b

Browse files
committed
reset timer results before each test
1 parent 5d201c4 commit 771ea7b

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 externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.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 test/fixture.h test/options.h test/redirect.h
670+
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.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 externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.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
@@ -1832,3 +1832,8 @@ void CppCheck::removeCtuInfoFiles(const std::map<std::string, std::size_t> &file
18321832
}
18331833
}
18341834
}
1835+
1836+
void CppCheck::resetTimerResults()
1837+
{
1838+
s_timerResults.reset();
1839+
}

lib/cppcheck.h

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

144+
static void resetTimerResults();
145+
144146
private:
145147
#ifdef HAVE_RULES
146148
/** Are there "simple" rules */

lib/timer.cpp

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

94+
void TimerResults::reset()
95+
{
96+
std::lock_guard<std::mutex> l(mResultsSync);
97+
mResults.clear();
98+
}
99+
94100
Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults)
95101
: mStr(std::move(str))
96102
, mTimerResults(timerResults)

lib/timer.h

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

66+
void reset();
67+
6668
private:
6769
std::map<std::string, struct TimerResultsData> mResults;
6870
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"
@@ -93,6 +94,7 @@ bool TestFixture::prepareTest(const char testname[])
9394
mVerbose = false;
9495
mTemplateFormat.clear();
9596
mTemplateLocation.clear();
97+
CppCheck::resetTimerResults();
9698

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

0 commit comments

Comments
 (0)