diff options
author | Michael Butler <butlermichael@google.com> | 2020-04-28 18:05:15 -0700 |
---|---|---|
committer | Michael Butler <butlermichael@google.com> | 2020-04-29 21:45:46 -0700 |
commit | 8f6469fb5225d8fb91255ea7e676544e6e699767 (patch) | |
tree | a44e46004fd30bc77af0ab5b0125e6fda3598b10 /nn/runtime | |
parent | d62e2398c3497375fdaf2d554aa479d18d30f7b6 (diff) | |
download | ml-8f6469fb5225d8fb91255ea7e676544e6e699767.tar.gz |
Fix NNAPI TimingTests
This CL fixes the ordering of sequences in the test. Specifically:
1) Causes the spin-loop in waitForExecutionToBegin to spin while the
execution has not yet started
2) Adds dummyExecution() to the driver implementations of FAIL_LAUNCH
3) Skips getDurationWhileRunning for all DriverKind::CPU test cases
Further, this CL adds dummyExecution() to
TestPreparedModelLatest::executeFenced to ensure the call to
executeFenced will not complete until after the test has called
getDuration. This brings executeFenced in line with the other execution
methods which call dummyExecution().
Finally, this CL has the following two minor changes:
1) code that was previously running from a detached thread in
executeFenced now instead runs synchronously
2) a for-loop that iterated by constant reference now instead iterates
by constant value
Fixes: 155215099
Test: mma
Test: NeuralNetworksTest_static --gtest_filter=Fenced/TimingTest*
Change-Id: I69a7448367ce8353791c9462d144122b6c913802
Diffstat (limited to 'nn/runtime')
-rw-r--r-- | nn/runtime/test/TestIntrospectionControl.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/nn/runtime/test/TestIntrospectionControl.cpp b/nn/runtime/test/TestIntrospectionControl.cpp index b33e06a69..913e6ed15 100644 --- a/nn/runtime/test/TestIntrospectionControl.cpp +++ b/nn/runtime/test/TestIntrospectionControl.cpp @@ -361,7 +361,7 @@ std::ostream& operator<<(std::ostream& os, Success success) { {Success::PASS_FENCED_DRIVER_BIT, "FENCED_DRIVER"}, }; bool gotOutput = false; - for (const auto b : bits) { + for (const auto& b : bits) { if (hasBit(success, b.first)) { if (gotOutput) { os << '|'; @@ -430,6 +430,7 @@ class TestPreparedModelLatest : public SamplePreparedModel { }).detach(); return V1_0::ErrorStatus::NONE; case Success::FAIL_LAUNCH: + dummyExecution(); callback->notify(V1_0::ErrorStatus::GENERAL_FAILURE); return V1_0::ErrorStatus::GENERAL_FAILURE; case Success::FAIL_WAIT: @@ -459,6 +460,7 @@ class TestPreparedModelLatest : public SamplePreparedModel { }).detach(); return V1_0::ErrorStatus::NONE; case Success::FAIL_LAUNCH: + dummyExecution(); callback->notify(V1_0::ErrorStatus::GENERAL_FAILURE); return V1_0::ErrorStatus::GENERAL_FAILURE; case Success::FAIL_WAIT: @@ -497,9 +499,9 @@ class TestPreparedModelLatest : public SamplePreparedModel { // runtime may call it even for asynchronous execution, so we // need to tolerate Success::FAIL_WAIT here, not just // Success::FAIL_LAUNCH. - dummyExecution(); FALLTHROUGH_INTENDED; case Success::FAIL_LAUNCH: + dummyExecution(); cb(V1_0::ErrorStatus::GENERAL_FAILURE, {}, kBadTiming); return Void(); default: @@ -540,6 +542,7 @@ class TestPreparedModelLatest : public SamplePreparedModel { const OptionalTimeoutDuration&, executeFenced_cb callback) override { EXPECT_EQ(measure, MeasureTiming::YES); if (hasBit(mSuccess, Success::PASS_BIT)) { + dummyExecution(); const auto expectedTiming = getExpectedTiming(mSuccess, true); sp<SampleFencedExecutionCallback> fencedExecutionCallback = new SampleFencedExecutionCallback(expectedTiming.first, expectedTiming.second, @@ -548,19 +551,16 @@ class TestPreparedModelLatest : public SamplePreparedModel { return Void(); } switch (mSuccess) { + case Success::FAIL_WAIT: + // Due to the limitation of the SampleDriver, + // FAIL_WAIT behaves the same as FAIL_LAUNCH. + // If the SampleDriver is updated to return real + // sync fences, this must be updated. + FALLTHROUGH_INTENDED; case Success::FAIL_LAUNCH: + dummyExecution(); callback(V1_3::ErrorStatus::GENERAL_FAILURE, hidl_handle(nullptr), nullptr); return Void(); - case Success::FAIL_WAIT: - std::thread([callback] { - dummyExecution(); - // Due to the limitation of the SampleDriver, - // FAIL_WAIT behaves the same as FAIL_LAUNCH. - // If the SampleDriver is updated to return real - // sync fences, this must be updated. - callback(V1_3::ErrorStatus::GENERAL_FAILURE, hidl_handle(nullptr), nullptr); - }).detach(); - return Void(); default: ADD_FAILURE() << "Unexpected Success kind"; return Void(); @@ -579,7 +579,7 @@ class TestPreparedModelLatest : public SamplePreparedModel { // - // thread B: pauseExecutions(false); static void waitForExecutionToBegin() { CHECK(mPauseExecutions.load()); - while (mExecutionsInFlight.load()) { + while (mExecutionsInFlight.load() == 0) { } } @@ -875,7 +875,7 @@ TEST_P(TimingTest, Test) { isPass ? ANEURALNETWORKS_NO_ERROR : ANEURALNETWORKS_BAD_STATE; const auto getDurationWhileRunning = [this] { - if (kDriverKind == DriverKind::CPU && kSuccess == Success::FAIL_LAUNCH) { + if (kDriverKind == DriverKind::CPU) { // Testing DriverKind::CPU would require modifying the CPU execution // path to control execution completion, similarly to how this test // case does with TestPreparedModel::dummyExecution(). This does not |