trusty: metrics: Drain events before each test
Also add tighter checks to make sure we didn't drop events. Bug: 240617890 Test: libtrusty_metrics_test Change-Id: I0029d91ad0ff67eb97913b2316efca627b118616
This commit is contained in:
parent
45545c68d1
commit
4b38ffab15
1 changed files with 18 additions and 0 deletions
|
@ -61,6 +61,18 @@ class TrustyMetricsTest : public TrustyMetrics, public ::testing::Test {
|
|||
virtual void SetUp() override {
|
||||
auto ret = Open();
|
||||
ASSERT_TRUE(ret.ok()) << ret.error();
|
||||
|
||||
/* Drain events (if any) and reset state */
|
||||
DrainEvents();
|
||||
crashed_app_.clear();
|
||||
event_drop_count_ = 0;
|
||||
}
|
||||
|
||||
void DrainEvents() {
|
||||
while (WaitForEvent(1000 /* 1 second timeout */).ok()) {
|
||||
auto ret = HandleEvent();
|
||||
ASSERT_TRUE(ret.ok()) << ret.error();
|
||||
}
|
||||
}
|
||||
|
||||
void WaitForAndHandleEvent() {
|
||||
|
@ -79,6 +91,9 @@ TEST_F(TrustyMetricsTest, Crash) {
|
|||
TriggerCrash();
|
||||
WaitForAndHandleEvent();
|
||||
|
||||
/* Check that no event was dropped. */
|
||||
ASSERT_EQ(event_drop_count_, 0);
|
||||
|
||||
/* Check that correct TA crashed. */
|
||||
ASSERT_EQ(crashed_app_, "36f5b435-5bd3-4526-8b76-200e3a7e79f3:crasher");
|
||||
}
|
||||
|
@ -110,6 +125,9 @@ TEST_F(TrustyMetricsTest, PollSet) {
|
|||
auto ret = HandleEvent();
|
||||
ASSERT_TRUE(ret.ok()) << ret.error();
|
||||
|
||||
/* Check that no event was dropped. */
|
||||
ASSERT_EQ(event_drop_count_, 0);
|
||||
|
||||
/* Check that correct TA crashed. */
|
||||
ASSERT_EQ(crashed_app_, "36f5b435-5bd3-4526-8b76-200e3a7e79f3:crasher");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue