Audio HAL VTS: Improve ASSERT of Result and Return
Previously tests on Result and Return were using ASSERT_NO_FATAL_FAILURE
and helper methods.
This leaded to complex error messages were the error did not pointed to
the helper methods instead of the ASSERT_RESULT call.
Additionally SCOPE_TRACE messages are repeated
for each ASSERT_NO_FATAL_FAILURE level.
Use ::testing::AssertionResult to improve drastically the error messages.
Test: vts-tradefed run vts --module VtsHalAudioV2_0Target
Test: call/play music/record/video...
Bug: 36311550
Change-Id: If705502546606d678df3f1966b0cd9f3ef8c2529
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
index 46a2f78..447ceaa 100644
--- a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
+++ b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
@@ -318,7 +318,7 @@
protected:
bool areAudioPatchesSupported() {
auto result = device->supportsAudioPatches();
- EXPECT_TRUE(result.isOk());
+ EXPECT_IS_OK(result);
return result;
}
};
@@ -494,10 +494,10 @@
doc::test("Check that the hal can receive the screen state");
for (bool turnedOn : {false, true, true, false, false}) {
auto ret = device->setScreenState(turnedOn);
- ASSERT_TRUE(ret.isOk());
+ ASSERT_IS_OK(ret);
Result result = ret;
- ASSERT_TRUE(result == Result::OK || result == Result::NOT_SUPPORTED)
- << toString(result);
+ auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED};
+ ASSERT_RESULT(okOrNotSupported, result);
}
}
@@ -715,7 +715,7 @@
template <class R>
static R extract(Return<R> ret) {
if (!ret.isOk()) {
- ADD_FAILURE();
+ EXPECT_IS_OK(ret);
return R{};
}
return ret;
@@ -819,7 +819,7 @@
// NOT_SUPPORTED
// Thus allow NONE as signaling that the call is not supported.
auto ret = stream->getDevice();
- ASSERT_TRUE(ret.isOk());
+ ASSERT_IS_OK(ret);
AudioDevice device = ret;
ASSERT_TRUE(device == expectedDevice || device == AudioDevice::NONE)
<< "Expected: " << ::testing::PrintToString(expectedDevice)
@@ -891,7 +891,7 @@
stream->setHwAvSync(666)))
TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail",
- ASSERT_TRUE(device->getHwAvSync().isOk()))
+ ASSERT_IS_OK(device->getHwAvSync()));
static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys,
vector<Result> expectedResults) {
@@ -1048,7 +1048,7 @@
static void testOptionalUnitaryGain(
std::function<Return<Result>(float)> setGain, string debugName) {
auto result = setGain(1);
- ASSERT_TRUE(result.isOk());
+ ASSERT_IS_OK(result);
if (result == Result::NOT_SUPPORTED) {
doc::partialTest(debugName + " is not supported");
return;
@@ -1098,7 +1098,7 @@
doc::test(
"The number of frames lost on a never started stream should be 0");
auto ret = stream->getInputFramesLost();
- ASSERT_TRUE(ret.isOk());
+ ASSERT_IS_OK(ret);
uint32_t framesLost{ret};
ASSERT_EQ(0U, framesLost);
}
@@ -1120,7 +1120,7 @@
TEST_P(OutputStreamTest, getLatency) {
doc::test("Make sure latency is over 0");
auto result = stream->getLatency();
- ASSERT_TRUE(result.isOk());
+ ASSERT_IS_OK(result);
ASSERT_GT(result, 0U);
}
@@ -1166,7 +1166,7 @@
Capability(IStreamOut* stream) {
EXPECT_OK(stream->supportsPauseAndResume(returnIn(pause, resume)));
auto ret = stream->supportsDrain();
- EXPECT_TRUE(ret.isOk());
+ EXPECT_IS_OK(ret);
if (ret.isOk()) {
drain = ret;
}
@@ -1301,7 +1301,7 @@
TEST_P(OutputStreamTest, FlushStop) {
doc::test("If supported, a stream should always succeed to flush");
auto ret = stream->flush();
- ASSERT_TRUE(ret.isOk());
+ ASSERT_IS_OK(ret);
if (ret == Result::NOT_SUPPORTED) {
doc::partialTest("Flush is not supported");
return;