diff options
| author | 2020-02-27 16:33:39 -0800 | |
|---|---|---|
| committer | 2020-02-27 17:00:52 -0800 | |
| commit | 2250fa1593cefd39900533eda070f82ddac017df (patch) | |
| tree | 4317eeb8bf3d48feb6b5b3df1c590f510b5d17a1 | |
| parent | 720830ee907945d24ee1fc5fa2f5bedffc8ef235 (diff) | |
Fix LogEventQueue_tests
These tests were broken by ag/10444161, which deleted a test-only
LogEvent constructor (the tests still built though because there was
another constructor that accepted the same parameter types but with much
different semantics).
Also fixes a bug in TestSlicedCondition that was introduced by one of
the later patchsets in ag/10444161.
Test: bit statsd_test:*
Bug: 149590301
Change-Id: If7de80922680c63505a4b30a1dcefdc47be13219
| -rw-r--r-- | cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp | 6 | ||||
| -rw-r--r-- | cmds/statsd/tests/log_event/LogEventQueue_test.cpp | 29 |
2 files changed, 27 insertions, 8 deletions
diff --git a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp index 8701e1790a69..4b78e305f65c 100644 --- a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp +++ b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp @@ -297,7 +297,7 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) { std::vector<int> uids = {111, 222, 333}; LogEvent event(/*uid=*/-1, /*pid=*/-1); - makeWakeLockEvent(&event, /*atomId=*/ 1, /*timestamp=*/ 0, uids, "wl1", /*acquire=*/ 1); + makeWakeLockEvent(&event, /*atomId=*/1, /*timestamp=*/0, uids, "wl1", /*acquire=*/1); // one matched start vector<MatchingState> matcherState; @@ -334,7 +334,7 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) { // another wake lock acquired by this uid LogEvent event2(/*uid=*/-1, /*pid=*/-1); - makeWakeLockEvent(&event2, /*atomId=*/ 1, /*timestamp=*/ 0, uids, "wl2", /*acquire=*/ 1); + makeWakeLockEvent(&event2, /*atomId=*/1, /*timestamp=*/0, uids, "wl2", /*acquire=*/1); matcherState.clear(); matcherState.push_back(MatchingState::kMatched); matcherState.push_back(MatchingState::kNotMatched); @@ -373,7 +373,7 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) { EXPECT_TRUE(conditionTracker.getChangedToFalseDimensions(allConditions)->empty()); LogEvent event4(/*uid=*/-1, /*pid=*/-1); - makeWakeLockEvent(&event, /*atomId=*/1, /*timestamp=*/ 0, uids, "wl2", /*acquire=*/0); + makeWakeLockEvent(&event4, /*atomId=*/1, /*timestamp=*/0, uids, "wl2", /*acquire=*/0); matcherState.clear(); matcherState.push_back(MatchingState::kNotMatched); matcherState.push_back(MatchingState::kMatched); diff --git a/cmds/statsd/tests/log_event/LogEventQueue_test.cpp b/cmds/statsd/tests/log_event/LogEventQueue_test.cpp index f27d12957f11..c4407f48d978 100644 --- a/cmds/statsd/tests/log_event/LogEventQueue_test.cpp +++ b/cmds/statsd/tests/log_event/LogEventQueue_test.cpp @@ -16,9 +16,11 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> +#include <stdio.h> + #include <thread> -#include <stdio.h> +#include "stats_event.h" namespace android { namespace os { @@ -29,6 +31,25 @@ using namespace testing; using std::unique_ptr; +namespace { + +std::unique_ptr<LogEvent> makeLogEvent(uint64_t timestampNs) { + AStatsEvent* statsEvent = AStatsEvent_obtain(); + AStatsEvent_setAtomId(statsEvent, 10); + AStatsEvent_overwriteTimestamp(statsEvent, timestampNs); + AStatsEvent_build(statsEvent); + + size_t size; + uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size); + + std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/-1, /*pid=*/-1); + logEvent->parseBuffer(buf, size); + AStatsEvent_release(statsEvent); + return logEvent; +} + +} // anonymous namespace + #ifdef __ANDROID__ TEST(LogEventQueue_test, TestGoodConsumer) { LogEventQueue queue(50); @@ -36,8 +57,7 @@ TEST(LogEventQueue_test, TestGoodConsumer) { std::thread writer([&queue, timeBaseNs] { for (int i = 0; i < 100; i++) { int64_t oldestEventNs; - bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), - &oldestEventNs); + bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); EXPECT_TRUE(success); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } @@ -63,8 +83,7 @@ TEST(LogEventQueue_test, TestSlowConsumer) { int failure_count = 0; int64_t oldestEventNs; for (int i = 0; i < 100; i++) { - bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), - &oldestEventNs); + bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); if (!success) failure_count++; std::this_thread::sleep_for(std::chrono::milliseconds(1)); } |