summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2023-05-12 21:41:43 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-05-12 21:41:43 +0000
commit4cf663e85f9ac5fe3cdc7ef12512417bfb783954 (patch)
treec7c8cef482366fc14594efb7e3f50a9e0b229fe2
parentaf60d736ce035fbdfbec9f8390e1957fca314fb5 (diff)
parent9d5b953ecd6ce98532a32a4912a42ced2eeaaa01 (diff)
downloadStatsD-4cf663e85f9ac5fe3cdc7ef12512417bfb783954.tar.gz
Merge "Remove dependency on full protobuf lib in libstatspull_test" into udc-dev
-rw-r--r--lib/libstatsgtestmatchers/Android.bp54
-rw-r--r--lib/libstatsgtestmatchers/include/gtest_matchers.h (renamed from statsd/tests/gtest_matchers.h)4
-rw-r--r--lib/libstatspull/Android.bp10
-rw-r--r--lib/libstatspull/tests/stats_subscription_test.cpp20
-rw-r--r--statsd/Android.bp10
-rw-r--r--statsd/tests/shell/ShellSubscriber_test.cpp2
6 files changed, 81 insertions, 19 deletions
diff --git a/lib/libstatsgtestmatchers/Android.bp b/lib/libstatsgtestmatchers/Android.bp
new file mode 100644
index 00000000..6b5801f9
--- /dev/null
+++ b/lib/libstatsgtestmatchers/Android.bp
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+// ==========================================================
+// Native library for custom GoogleTest matchers
+// ==========================================================
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_test_library {
+ name: "libstatsgtestmatchers",
+ srcs: [
+ ":libstats_log_protos",
+ ":libstats_subscription_protos",
+ ],
+ export_include_dirs: ["include"],
+ proto: {
+ type: "lite",
+ include_dirs: [
+ "external/protobuf/src",
+ ],
+ static: true,
+ },
+ static_libs: [
+ "libgmock",
+ "libplatformprotos",
+ "libprotobuf-cpp-lite",
+ ],
+ shared: {
+ enabled: false,
+ },
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ visibility: [
+ "//packages/modules/StatsD/lib/libstatspull",
+ "//packages/modules/StatsD/statsd",
+ ],
+}
diff --git a/statsd/tests/gtest_matchers.h b/lib/libstatsgtestmatchers/include/gtest_matchers.h
index d55ef61c..084346dd 100644
--- a/statsd/tests/gtest_matchers.h
+++ b/lib/libstatsgtestmatchers/include/gtest_matchers.h
@@ -21,8 +21,8 @@
#include "frameworks/proto_logging/stats/atoms.pb.h"
#include "frameworks/proto_logging/stats/attribution_node.pb.h"
-#include "src/shell/shell_data.pb.h"
-#include "src/stats_log.pb.h"
+#include "packages/modules/StatsD/statsd/src/shell/shell_data.pb.h"
+#include "packages/modules/StatsD/statsd/src/stats_log.pb.h"
namespace android {
namespace os {
diff --git a/lib/libstatspull/Android.bp b/lib/libstatspull/Android.bp
index 12b36b77..77e3e374 100644
--- a/lib/libstatspull/Android.bp
+++ b/lib/libstatspull/Android.bp
@@ -112,20 +112,22 @@ cc_library_static {
cc_test {
name: "libstatspull_test",
srcs: [
+ ":libprotobuf-internal-descriptor-proto",
+ ":libstats_log_protos",
":libstats_subscription_protos",
"tests/pull_atom_metadata_test.cpp",
"tests/stats_subscription_test.cpp",
],
proto: {
- type: "full",
+ type: "lite",
include_dirs: [
"external/protobuf/src",
],
+ static: true,
},
shared_libs: [
"libstatspull",
"libstatssocket",
- "libprotobuf-cpp-full",
"libbase",
"libbinder",
"libutils",
@@ -133,8 +135,10 @@ cc_test {
],
static_libs: [
"libgmock",
+ "libstatsgtestmatchers",
"libstatslog_statsdtest",
- "libplatformprotos-test",
+ "libplatformprotos",
+ "libprotobuf-cpp-lite",
],
test_suites: [
"general-tests",
diff --git a/lib/libstatspull/tests/stats_subscription_test.cpp b/lib/libstatspull/tests/stats_subscription_test.cpp
index 4455e329..eb99de58 100644
--- a/lib/libstatspull/tests/stats_subscription_test.cpp
+++ b/lib/libstatspull/tests/stats_subscription_test.cpp
@@ -16,8 +16,8 @@
#include <binder/ProcessState.h>
#include <gmock/gmock.h>
-#include <google/protobuf/util/message_differencer.h>
#include <gtest/gtest.h>
+#include <gtest_matchers.h>
#include <stats_subscription.h>
#include <stdint.h>
#include <utils/Looper.h>
@@ -47,18 +47,12 @@ using android::os::statsd::util::SCREEN_BRIGHTNESS_CHANGED;
using android::os::statsd::util::stats_write;
using android::os::statsd::util::TEST_ATOM_REPORTED;
using android::os::statsd::util::TEST_ATOM_REPORTED__REPEATED_ENUM_FIELD__OFF;
-using google::protobuf::util::MessageDifferencer;
using std::string;
using std::vector;
using std::this_thread::sleep_for;
namespace {
-// Checks equality on explicitly set values.
-MATCHER_P(ProtoEq, otherArg, "") {
- return MessageDifferencer::Equals(arg, otherArg);
-}
-
class SubscriptionTest : public Test {
public:
SubscriptionTest() : looper(Looper::prepare(/*opts=*/0)) {
@@ -194,7 +188,7 @@ TEST_F(SubscriptionTest, TestSubscription) {
// Verify atom 1.
Atom expectedAtom;
expectedAtom.mutable_screen_brightness_changed()->set_level(100);
- EXPECT_THAT(actualShellData.atom(0), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(0), EqAtom(expectedAtom));
// Verify atom 2.
expectedAtom.Clear();
@@ -221,11 +215,11 @@ TEST_F(SubscriptionTest, TestSubscription) {
&repeatedBool[0] + 2};
*testAtomReported->mutable_repeated_enum_field() = {repeatedEnums.begin(),
repeatedEnums.end()};
- EXPECT_THAT(actualShellData.atom(1), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(1), EqAtom(expectedAtom));
// Verify atom 3.
testAtomReported->set_int_field(2);
- EXPECT_THAT(actualShellData.atom(2), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(2), EqAtom(expectedAtom));
// Log another ScreenBrightnessChanged atom. No callback should occur.
stats_write(SCREEN_BRIGHTNESS_CHANGED, 99);
@@ -252,7 +246,7 @@ TEST_F(SubscriptionTest, TestSubscription) {
// Verify atom 1.
expectedAtom.Clear();
expectedAtom.mutable_screen_brightness_changed()->set_level(99);
- EXPECT_THAT(actualShellData.atom(0), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(0), EqAtom(expectedAtom));
// Log another ScreenBrightnessChanged atom. No callback should occur.
stats_write(SCREEN_BRIGHTNESS_CHANGED, 98);
@@ -279,7 +273,7 @@ TEST_F(SubscriptionTest, TestSubscription) {
// Verify atom 1.
expectedAtom.Clear();
expectedAtom.mutable_screen_brightness_changed()->set_level(98);
- EXPECT_THAT(actualShellData.atom(0), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(0), EqAtom(expectedAtom));
// Log another ScreenBrightnessChanged atom. No callback should occur.
stats_write(SCREEN_BRIGHTNESS_CHANGED, 97);
@@ -307,7 +301,7 @@ TEST_F(SubscriptionTest, TestSubscription) {
// Verify atom 1.
expectedAtom.Clear();
expectedAtom.mutable_screen_brightness_changed()->set_level(97);
- EXPECT_THAT(actualShellData.atom(0), ProtoEq(expectedAtom));
+ EXPECT_THAT(actualShellData.atom(0), EqAtom(expectedAtom));
} else {
GTEST_SKIP();
}
diff --git a/statsd/Android.bp b/statsd/Android.bp
index 1dcffac8..9dbf9fb3 100644
--- a/statsd/Android.bp
+++ b/statsd/Android.bp
@@ -392,6 +392,7 @@ cc_test {
static_libs: [
"libgmock",
+ "libstatsgtestmatchers",
"libplatformprotos",
"libstatslog_statsdtest",
"libstatssocket_private",
@@ -533,6 +534,15 @@ filegroup {
srcs: ["src/statsd_config.proto"],
}
+// Filegroup for statsd report protos.
+filegroup {
+ name: "libstats_log_protos",
+ srcs: [
+ "src/stats_log.proto",
+ "src/guardrail/invalid_config_reason_enum.proto",
+ ],
+}
+
// Filegroup for all statsd protos
filegroup {
name: "statsd_internal_protos",
diff --git a/statsd/tests/shell/ShellSubscriber_test.cpp b/statsd/tests/shell/ShellSubscriber_test.cpp
index ebdd32ce..43a2a1b2 100644
--- a/statsd/tests/shell/ShellSubscriber_test.cpp
+++ b/statsd/tests/shell/ShellSubscriber_test.cpp
@@ -23,11 +23,11 @@
#include <vector>
#include "frameworks/proto_logging/stats/atoms.pb.h"
+#include "gtest_matchers.h"
#include "src/shell/shell_config.pb.h"
#include "src/shell/shell_data.pb.h"
#include "stats_event.h"
#include "statslog_statsdtest.h"
-#include "tests/gtest_matchers.h"
#include "tests/metrics/metrics_test_helper.h"
#include "tests/statsd_test_util.h"