From 3201eea0565ce2bb0418d1936fec71bdeb14c084 Mon Sep 17 00:00:00 2001 From: Keith Davis Date: Thu, 24 Oct 2019 17:30:41 +0100 Subject: IVGCVSW-3444 File Only Profiling Connection * Add FileOnlyProfilingConnection Decorator * Fix bug where Conn Ack not automatically sent back * Modify GatordMock to use the Counter Directory class. * Promote DirectoryCaptureCommandHandler from GatordMock into ArmNN. * Remove MockUtils as it's contents were moved or deleted. * Rewrite GatordMockTests to use Counter Directory class. * Flush streams in ProfilingConnectionDumpToFileDecorator::Close. Signed-off-by: Keith Davis Signed-off-by: Colm Donelan Change-Id: I77b2aedece24150dd31691b577f3b5d81b2e226f --- .../test/FileOnlyProfilingDecoratorTests.cpp | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/profiling/test/FileOnlyProfilingDecoratorTests.cpp (limited to 'src/profiling/test/FileOnlyProfilingDecoratorTests.cpp') diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp new file mode 100644 index 0000000000..7f927bdeee --- /dev/null +++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp @@ -0,0 +1,111 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "../FileOnlyProfilingConnection.hpp" +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if defined(__ANDROID__) +#define ARMNN_PROFILING_CONNECTION_TEST_DUMP_DIR "/data/local/tmp" +#else +#define ARMNN_PROFILING_CONNECTION_TEST_DUMP_DIR "/tmp" +#endif + +using namespace armnn::profiling; +using namespace armnn; + +using namespace std::chrono_literals; + +BOOST_AUTO_TEST_SUITE(FileOnlyProfilingDecoratorTests) + +BOOST_AUTO_TEST_CASE(DumpOutgoingValidFileEndToEnd) +{ + // Create a temporary file name. + boost::filesystem::path tempPath = boost::filesystem::temp_directory_path(); + boost::filesystem::path tempFile = boost::filesystem::unique_path(); + tempPath = tempPath / tempFile; + armnn::Runtime::CreationOptions::ExternalProfilingOptions options; + options.m_EnableProfiling = true; + options.m_FileOnly = true; + options.m_IncomingCaptureFile = ""; + options.m_OutgoingCaptureFile = tempPath.c_str(); + options.m_CapturePeriod = 100; + + // Enable the profiling service + ProfilingService& profilingService = ProfilingService::Instance(); + profilingService.ResetExternalProfilingOptions(options, true); + // Bring the profiling service to the "WaitingForAck" state + profilingService.Update(); + profilingService.Update(); + + u_int32_t timeout = 2000; + u_int32_t sleepTime = 50; + u_int32_t timeSlept = 0; + + // Give the profiling service sending thread time start executing and send the stream metadata. + while (profilingService.GetCurrentState() != ProfilingState::WaitingForAck) + { + if (timeSlept >= timeout) + { + BOOST_FAIL("Timeout: Profiling service did not switch to WaitingForAck state"); + } + std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + timeSlept += sleepTime; + } + + profilingService.Update(); + + timeSlept = 0; + + while (profilingService.GetCurrentState() != profiling::ProfilingState::Active) + { + if (timeSlept >= timeout) + { + BOOST_FAIL("Timeout: Profiling service did not switch to Active state"); + } + std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + timeSlept += sleepTime; + } + + // Minimum test here is to check that the file was created. + BOOST_CHECK(boost::filesystem::exists(tempPath.c_str()) == true); + + // Increment a counter. + BOOST_CHECK(profilingService.IsCounterRegistered(0) == true); + profilingService.IncrementCounterValue(0); + BOOST_CHECK(profilingService.GetCounterValue(0) > 0); + + // At this point the profiling service is active and we've activated all the counters. Waiting a collection + // period should be enough to have some data in the file. + + // Wait for 1 collection period plus a bit of overhead.. + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + + // In order to flush the files we need to gracefully close the profiling service. + options.m_EnableProfiling = false; + profilingService.ResetExternalProfilingOptions(options, true); + // Wait a short time to allow the threads to clean themselves up. + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + // The output file size should be greater than 0. + struct stat statusBuffer; + BOOST_CHECK(stat(tempPath.c_str(), &statusBuffer) == 0); + BOOST_CHECK(statusBuffer.st_size > 0); + + // Delete the tmp file. + BOOST_CHECK(remove(tempPath.c_str()) == 0); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1