aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2021-08-05 15:01:07 +0100
committerNikhil Raj Arm <nikhil.raj@arm.com>2021-08-05 17:44:39 +0000
commit95e9efc28ce70a8cda93e722f5ce90ebc96bdd95 (patch)
treea386f0984280f15b782eaa84af4709d9a870b755
parent2b9fe3aecb14938257537460d20e01e33cb03e5c (diff)
downloadarmnn-95e9efc28ce70a8cda93e722f5ce90ebc96bdd95.tar.gz
IVGCVSW-6258 'Unittest failures'
* Fixed unit test failures happening on threads. Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I2a6048f75ece4a9f4c2116306838ff55385aabe7
-rw-r--r--src/armnn/test/ProfilerTests.cpp19
-rw-r--r--src/profiling/test/ProfilingGuidTest.cpp33
-rw-r--r--src/profiling/test/ProfilingTests.cpp51
3 files changed, 54 insertions, 49 deletions
diff --git a/src/armnn/test/ProfilerTests.cpp b/src/armnn/test/ProfilerTests.cpp
index 8fd97179f1..b23ac1ccc3 100644
--- a/src/armnn/test/ProfilerTests.cpp
+++ b/src/armnn/test/ProfilerTests.cpp
@@ -7,6 +7,7 @@
#include <doctest/doctest.h>
+#include <algorithm>
#include <thread>
#include <Profiling.hpp>
@@ -90,15 +91,17 @@ TEST_CASE("RegisterUnregisterProfilerSingleThread")
TEST_CASE("RegisterUnregisterProfilerMultipleThreads")
{
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();
+ std::vector<std::thread> threads;
+ for (unsigned int i = 0; i < 3; ++i)
+ {
+ threads.push_back(std::thread([&res, i]() { RegisterUnregisterProfilerSingleThreadImpl(res[i]); }));
+ }
+ std::for_each(threads.begin(), threads.end(), [](std::thread& theThread)
+ {
+ theThread.join();
+ });
- for (int i = 0 ; i < 3 ; i++)
+ for (int i = 0 ; i < 3 ; ++i)
{
CHECK(res[i]);
}
diff --git a/src/profiling/test/ProfilingGuidTest.cpp b/src/profiling/test/ProfilingGuidTest.cpp
index caec210150..30cfae82ca 100644
--- a/src/profiling/test/ProfilingGuidTest.cpp
+++ b/src/profiling/test/ProfilingGuidTest.cpp
@@ -7,6 +7,8 @@
#include <common/include/LabelsAndEventClasses.hpp>
+#include <algorithm>
+#include <functional>
#include <set>
#include <doctest/doctest.h>
#include <fmt/format.h>
@@ -133,25 +135,26 @@ TEST_CASE("DynamicGuidGeneratorTest")
}
}
+void GenerateProfilingGUID(ProfilingGuidGenerator& guidGenerator)
+{
+ for (int i = 0; i < 1000; ++i)
+ {
+ guidGenerator.NextGuid();
+ }
+}
+
TEST_CASE("ProfilingGuidThreadTest")
{
ProfilingGuidGenerator profilingGuidGenerator;
-
- auto guidGenerator = [&profilingGuidGenerator]()
+ std::vector<std::thread> threads;
+ for (unsigned int i = 0; i < 3; ++i)
{
- for (int i = 0; i < 1000; ++i)
- {
- profilingGuidGenerator.NextGuid();
- }
- };
-
- std::thread t1(guidGenerator);
- std::thread t2(guidGenerator);
- std::thread t3(guidGenerator);
-
- t1.join();
- t2.join();
- t3.join();
+ threads.push_back(std::thread(GenerateProfilingGUID, std::ref(profilingGuidGenerator)));
+ }
+ std::for_each(threads.begin(), threads.end(), [](std::thread& theThread)
+ {
+ theThread.join();
+ });
uint64_t guid = profilingGuidGenerator.NextGuid();
CHECK(guid == 3000u);
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index e0629b3913..5e9a5e7e8d 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -42,6 +42,7 @@
#include <doctest/doctest.h>
+#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iostream>
@@ -534,17 +535,15 @@ TEST_CASE("CheckProfilingStateMachine")
ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
- std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
- std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
- std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
- std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
- std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
-
- thread1.join();
- thread2.join();
- thread3.join();
- thread4.join();
- thread5.join();
+ std::vector<std::thread> threads;
+ for (unsigned int i = 0; i < 5; ++i)
+ {
+ threads.push_back(std::thread(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)));
+ }
+ std::for_each(threads.begin(), threads.end(), [](std::thread& theThread)
+ {
+ theThread.join();
+ });
CHECK((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
}
@@ -703,36 +702,36 @@ TEST_CASE("CheckProfilingServiceCounterValues")
std::vector<std::thread> writers;
CHECK(!counters.empty());
+ uint16_t inferencesRun = armnn::profiling::INFERENCES_RUN;
// Test GetAbsoluteCounterValue
for (int i = 0; i < 4; ++i)
{
// Increment and decrement the INFERENCES_RUN counter 250 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 250; ++i)
{
- profilingService.IncrementCounterValue(INFERENCES_RUN);
+ profilingService.IncrementCounterValue(inferencesRun);
}
}));
// Add 10 to the INFERENCES_RUN counter 200 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 200; ++i)
{
- profilingService.AddCounterValue(INFERENCES_RUN, 10);
+ profilingService.AddCounterValue(inferencesRun, 10);
}
}));
// Subtract 5 from the INFERENCES_RUN counter 200 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 200; ++i)
{
- profilingService.SubtractCounterValue(INFERENCES_RUN, 5);
+ profilingService.SubtractCounterValue(inferencesRun, 5);
}
}));
}
-
std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
uint32_t absoluteCounterValue = 0;
@@ -749,38 +748,38 @@ TEST_CASE("CheckProfilingServiceCounterValues")
writers.clear();
uint32_t deltaCounterValue = 0;
//Start a reading thread to randomly read the INFERENCES_RUN counter value
- std::thread reader([&profilingService](uint32_t& deltaCounterValue)
+ std::thread reader([&profilingService, inferencesRun](uint32_t& deltaCounterValue)
{
for (int i = 0; i < 300; ++i)
{
- deltaCounterValue += profilingService.GetDeltaCounterValue(INFERENCES_RUN);
+ deltaCounterValue += profilingService.GetDeltaCounterValue(inferencesRun);
}
}, std::ref(deltaCounterValue));
for (int i = 0; i < 4; ++i)
{
// Increment and decrement the INFERENCES_RUN counter 250 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 250; ++i)
{
- profilingService.IncrementCounterValue(INFERENCES_RUN);
+ profilingService.IncrementCounterValue(inferencesRun);
}
}));
// Add 10 to the INFERENCES_RUN counter 200 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 200; ++i)
{
- profilingService.AddCounterValue(INFERENCES_RUN, 10);
+ profilingService.AddCounterValue(inferencesRun, 10);
}
}));
// Subtract 5 from the INFERENCES_RUN counter 200 times
- writers.push_back(std::thread([&profilingService]()
+ writers.push_back(std::thread([&profilingService, inferencesRun]()
{
for (int i = 0; i < 200; ++i)
{
- profilingService.SubtractCounterValue(INFERENCES_RUN, 5);
+ profilingService.SubtractCounterValue(inferencesRun, 5);
}
}));
}