Fix remaining instrumentation tests.
Bug: 69958777
Test: VTS, Instrumentation
Change-Id: I98956ea4b1d2953b9159fb7d53ce61e57f80a90f
diff --git a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
index 8d9d622..feb62c6 100644
--- a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
+++ b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
@@ -15,6 +15,8 @@
*/
#define LOG_TAG "BcRadio.vts"
+#define LOG_NDEBUG 0
+#define EGMOCK_VERBOSE 1
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h>
@@ -113,7 +115,15 @@
std::cout << "[ SKIPPED ] " << msg << std::endl;
}
+MATCHER_P(InfoHasId, id,
+ std::string(negation ? "does not contain" : "contains") + " " + toString(id)) {
+ auto ids = utils::getAllIds(arg.selector, utils::getType(id));
+ return ids.end() != find(ids.begin(), ids.end(), id.value);
+}
+
TunerCallbackMock::TunerCallbackMock() {
+ EXPECT_TIMEOUT_CALL(*this, onCurrentProgramInfoChanged, _).Times(AnyNumber());
+
// we expect the antenna is connected through the whole test
EXPECT_CALL(*this, onAntennaStateChange(false)).Times(0);
}
@@ -362,9 +372,19 @@
uint64_t freq = 100100; // 100.1 FM
auto sel = make_selector_amfm(freq);
+ /* TODO(b/69958777): there is a race condition between tune() and onCurrentProgramInfoChanged
+ * callback setting infoCb, because egmock cannot distinguish calls with different matchers
+ * (there is one here and one in callback constructor).
+ *
+ * This sleep workaround will fix default implementation, but the real HW tests will still be
+ * flaky. We probably need to implement egmock alternative based on actions.
+ */
+ std::this_thread::sleep_for(100ms);
+
// try tuning
ProgramInfo infoCb = {};
- EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _)
+ EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged,
+ InfoHasId(utils::make_identifier(IdentifierType::AMFM_FREQUENCY, freq)))
.Times(AnyNumber())
.WillOnce(DoAll(SaveArg<0>(&infoCb), testing::Return(ByMove(Void()))));
auto result = mSession->tune(sel);
@@ -379,6 +399,8 @@
EXPECT_EQ(Result::OK, result);
EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+ ALOGD("current program info: %s", toString(infoCb).c_str());
+
// it should tune exactly to what was requested
auto freqs = utils::getAllIds(infoCb.selector, IdentifierType::AMFM_FREQUENCY);
EXPECT_NE(freqs.end(), find(freqs.begin(), freqs.end(), freq));
@@ -442,6 +464,9 @@
TEST_F(BroadcastRadioHalTest, Scan) {
ASSERT_TRUE(openSession());
+ // TODO(b/69958777): see FmTune workaround
+ std::this_thread::sleep_for(100ms);
+
EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _);
auto result = mSession->scan(true /* up */, true /* skip subchannel */);
EXPECT_EQ(Result::OK, result);
@@ -464,9 +489,15 @@
TEST_F(BroadcastRadioHalTest, Step) {
ASSERT_TRUE(openSession());
+ // TODO(b/69958777): see FmTune workaround
+ std::this_thread::sleep_for(100ms);
+
EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _).Times(AnyNumber());
auto result = mSession->step(true /* up */);
- if (result == Result::NOT_SUPPORTED) return;
+ if (result == Result::NOT_SUPPORTED) {
+ printSkipped("step not supported");
+ return;
+ }
EXPECT_EQ(Result::OK, result);
EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);