Loading cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -373,7 +373,7 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) { EXPECT_TRUE(conditionTracker.getChangedToFalseDimensions(allConditions)->empty()); EXPECT_TRUE(conditionTracker.getChangedToFalseDimensions(allConditions)->empty()); LogEvent event4(/*uid=*/-1, /*pid=*/-1); 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.clear(); matcherState.push_back(MatchingState::kNotMatched); matcherState.push_back(MatchingState::kNotMatched); matcherState.push_back(MatchingState::kMatched); matcherState.push_back(MatchingState::kMatched); Loading cmds/statsd/tests/log_event/LogEventQueue_test.cpp +24 −5 Original line number Original line Diff line number Diff line Loading @@ -16,9 +16,11 @@ #include <gmock/gmock.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <gtest/gtest.h> #include <stdio.h> #include <thread> #include <thread> #include <stdio.h> #include "stats_event.h" namespace android { namespace android { namespace os { namespace os { Loading @@ -29,6 +31,25 @@ using namespace testing; using std::unique_ptr; 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__ #ifdef __ANDROID__ TEST(LogEventQueue_test, TestGoodConsumer) { TEST(LogEventQueue_test, TestGoodConsumer) { LogEventQueue queue(50); LogEventQueue queue(50); Loading @@ -36,8 +57,7 @@ TEST(LogEventQueue_test, TestGoodConsumer) { std::thread writer([&queue, timeBaseNs] { std::thread writer([&queue, timeBaseNs] { for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) { int64_t oldestEventNs; int64_t oldestEventNs; bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); &oldestEventNs); EXPECT_TRUE(success); EXPECT_TRUE(success); std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } Loading @@ -63,8 +83,7 @@ TEST(LogEventQueue_test, TestSlowConsumer) { int failure_count = 0; int failure_count = 0; int64_t oldestEventNs; int64_t oldestEventNs; for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) { bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); &oldestEventNs); if (!success) failure_count++; if (!success) failure_count++; std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } Loading Loading
cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -373,7 +373,7 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) { EXPECT_TRUE(conditionTracker.getChangedToFalseDimensions(allConditions)->empty()); EXPECT_TRUE(conditionTracker.getChangedToFalseDimensions(allConditions)->empty()); LogEvent event4(/*uid=*/-1, /*pid=*/-1); 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.clear(); matcherState.push_back(MatchingState::kNotMatched); matcherState.push_back(MatchingState::kNotMatched); matcherState.push_back(MatchingState::kMatched); matcherState.push_back(MatchingState::kMatched); Loading
cmds/statsd/tests/log_event/LogEventQueue_test.cpp +24 −5 Original line number Original line Diff line number Diff line Loading @@ -16,9 +16,11 @@ #include <gmock/gmock.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <gtest/gtest.h> #include <stdio.h> #include <thread> #include <thread> #include <stdio.h> #include "stats_event.h" namespace android { namespace android { namespace os { namespace os { Loading @@ -29,6 +31,25 @@ using namespace testing; using std::unique_ptr; 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__ #ifdef __ANDROID__ TEST(LogEventQueue_test, TestGoodConsumer) { TEST(LogEventQueue_test, TestGoodConsumer) { LogEventQueue queue(50); LogEventQueue queue(50); Loading @@ -36,8 +57,7 @@ TEST(LogEventQueue_test, TestGoodConsumer) { std::thread writer([&queue, timeBaseNs] { std::thread writer([&queue, timeBaseNs] { for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) { int64_t oldestEventNs; int64_t oldestEventNs; bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); &oldestEventNs); EXPECT_TRUE(success); EXPECT_TRUE(success); std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } Loading @@ -63,8 +83,7 @@ TEST(LogEventQueue_test, TestSlowConsumer) { int failure_count = 0; int failure_count = 0; int64_t oldestEventNs; int64_t oldestEventNs; for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) { bool success = queue.push(std::make_unique<LogEvent>(10, timeBaseNs + i * 1000), bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs); &oldestEventNs); if (!success) failure_count++; if (!success) failure_count++; std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } Loading