From dbfb8549d4aa80115a7049b3e94788fb7a474d9b Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Wed, 27 Feb 2019 11:51:40 +0000 Subject: IVGCVSW-2764 Strengthen test for thread-safety in Profiler Replace assert with explicit conditions so that the checks are correctly performed in release builds. Change-Id: Id69ab3cc0aa8c61021642b7250e30c255f144a3a Signed-off-by: Matthew Bentham --- src/armnn/test/ProfilerTests.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/armnn/test/ProfilerTests.cpp b/src/armnn/test/ProfilerTests.cpp index 650c13a4f4..f6688eafc9 100644 --- a/src/armnn/test/ProfilerTests.cpp +++ b/src/armnn/test/ProfilerTests.cpp @@ -30,29 +30,29 @@ size_t GetProfilerEventSequenceSize(armnn::Profiler* profiler) namespace { -void RegisterUnregisterProfilerSingleThreadImpl() +void RegisterUnregisterProfilerSingleThreadImpl(bool &res) { - // Important! Regular assertions must be used in this function for testing (rather than - // BOOST_TEST macros) otherwise multi-threading tests would randomly fail. + // Important! Don't use BOOST_TEST macros in this function as they + // seem to have problems when used in threads // Get a reference to the profiler manager. armnn::ProfilerManager& profilerManager = armnn::ProfilerManager::GetInstance(); // Check that there's no profiler registered for this thread. - assert(!profilerManager.GetProfiler()); + res = !profilerManager.GetProfiler(); // Create and register a profiler for this thread. std::unique_ptr profiler = std::make_unique(); profilerManager.RegisterProfiler(profiler.get()); // Check that on a single thread we get the same profiler we registered. - assert(profiler.get() == profilerManager.GetProfiler()); + res &= profiler.get() == profilerManager.GetProfiler(); // Destroy the profiler. profiler.reset(); // Check that the profiler has been un-registered for this thread. - assert(!profilerManager.GetProfiler()); + res &= !profilerManager.GetProfiler(); } } // namespace @@ -81,18 +81,26 @@ BOOST_AUTO_TEST_CASE(EnableDisableProfiling) BOOST_AUTO_TEST_CASE(RegisterUnregisterProfilerSingleThread) { - RegisterUnregisterProfilerSingleThreadImpl(); + bool res = false; + RegisterUnregisterProfilerSingleThreadImpl(res); + BOOST_TEST(res); } BOOST_AUTO_TEST_CASE(RegisterUnregisterProfilerMultipleThreads) { - std::thread thread1([]() { RegisterUnregisterProfilerSingleThreadImpl(); }); - std::thread thread2([]() { RegisterUnregisterProfilerSingleThreadImpl(); }); - std::thread thread3([]() { RegisterUnregisterProfilerSingleThreadImpl(); }); + bool res[3] = {false, false, false}; + std::thread thread1([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[0]); }); + std::thread thread2([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[1]); }); + std::thread thread3([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[2]); }); thread1.join(); thread2.join(); thread3.join(); + + for (int i = 0 ; i < 3 ; i++) + { + BOOST_TEST(res[i]); + } } BOOST_AUTO_TEST_CASE(ProfilingMacros) -- cgit v1.2.1