aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bentham <matthew.bentham@arm.com>2019-02-27 11:51:40 +0000
committerderek.lamberti <derek.lamberti@arm.com>2019-02-27 13:00:49 +0000
commitdbfb8549d4aa80115a7049b3e94788fb7a474d9b (patch)
treeaf3ff46755e6c23907acc4ed0351d80536d7b533
parentb2845655b7814470c2a52cd7d0bee01031615bfc (diff)
downloadarmnn-dbfb8549d4aa80115a7049b3e94788fb7a474d9b.tar.gz
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 <matthew.bentham@arm.com>
-rw-r--r--src/armnn/test/ProfilerTests.cpp28
1 files 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<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
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)