1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "VtsAidlHalStatsTest"
18
19 #include <aidl/Gtest.h>
20 #include <aidl/Vintf.h>
21
22 #include <aidl/android/frameworks/stats/IStats.h>
23 #include <android/binder_manager.h>
24 #include <android/log.h>
25
26 using aidl::android::frameworks::stats::IStats;
27 using aidl::android::frameworks::stats::VendorAtom;
28 using aidl::android::frameworks::stats::VendorAtomValue;
29
30 class StatsAidlTest : public ::testing::TestWithParam<std::string> {
31 public:
SetUp()32 virtual void SetUp() override {
33 ndk::SpAIBinder binder(AServiceManager_getService(GetParam().c_str()));
34 client = IStats::fromBinder(binder);
35 ASSERT_NE(client, nullptr);
36 }
37
TearDown()38 virtual void TearDown() override {}
39
40 std::shared_ptr<IStats> client;
41 };
42
43 // Validate IStats::reportVendorAtom.
TEST_P(StatsAidlTest,reportVendorAtom)44 TEST_P(StatsAidlTest, reportVendorAtom) {
45 std::vector<VendorAtomValue> values;
46 VendorAtomValue tmp;
47 tmp.set<VendorAtomValue::longValue>(70000);
48 values.push_back(tmp);
49 tmp.set<VendorAtomValue::intValue>(7);
50 values.push_back(tmp);
51 tmp.set<VendorAtomValue::floatValue>(8.5);
52 values.push_back(tmp);
53 tmp.set<VendorAtomValue::stringValue>("test");
54 values.push_back(tmp);
55 tmp.set<VendorAtomValue::intValue>(3);
56 values.push_back(tmp);
57 VendorAtom atom = {.reverseDomainName = "com.google.pixel", .atomId = 100001, .values = values};
58 const ndk::ScopedAStatus ret = client->reportVendorAtom(atom);
59
60 ASSERT_TRUE(ret.isOk());
61 }
62
63 // Validate IStats::reportVendorAtom - this is a negative test - the error is dumped to logcat
64 // Due to the AIDL reportVendorAtom is oneway API - the return code is not returned to the client
TEST_P(StatsAidlTest,reportVendorAtomInvalidAtomIdLow)65 TEST_P(StatsAidlTest, reportVendorAtomInvalidAtomIdLow) {
66 std::vector<VendorAtomValue> values;
67 VendorAtomValue tmp;
68 tmp.set<VendorAtomValue::longValue>(70000);
69 values.push_back(tmp);
70 tmp.set<VendorAtomValue::intValue>(7);
71 values.push_back(tmp);
72 tmp.set<VendorAtomValue::floatValue>(8.5);
73 values.push_back(tmp);
74 tmp.set<VendorAtomValue::stringValue>("test");
75 values.push_back(tmp);
76 tmp.set<VendorAtomValue::intValue>(3);
77 values.push_back(tmp);
78 VendorAtom atom = {.reverseDomainName = "com.google.pixel", .atomId = 1000, .values = values};
79 const ndk::ScopedAStatus ret = client->reportVendorAtom(atom);
80
81 ASSERT_TRUE(ret.isOk());
82 }
83
84 // Validate IStats::reportVendorAtom - this is a negative test - the error is dumped to logcat
85 // Due to the AIDL reportVendorAtom is oneway API - the return code is not returned to the client
TEST_P(StatsAidlTest,reportVendorAtomInvalidAtomIdHigh)86 TEST_P(StatsAidlTest, reportVendorAtomInvalidAtomIdHigh) {
87 std::vector<VendorAtomValue> values;
88 VendorAtomValue tmp;
89 tmp.set<VendorAtomValue::longValue>(70000);
90 values.push_back(tmp);
91 tmp.set<VendorAtomValue::intValue>(7);
92 values.push_back(tmp);
93 tmp.set<VendorAtomValue::floatValue>(8.5);
94 values.push_back(tmp);
95 tmp.set<VendorAtomValue::stringValue>("test");
96 values.push_back(tmp);
97 tmp.set<VendorAtomValue::intValue>(3);
98 values.push_back(tmp);
99 VendorAtom atom = {.reverseDomainName = "com.google.pixel", .atomId = 300001, .values = values};
100 const ndk::ScopedAStatus ret = client->reportVendorAtom(atom);
101
102 ASSERT_TRUE(ret.isOk());
103 }
104
105 // Validate IStats::reportVendorAtom - this is a negative test - the error is dumped to logcat
106 // Due to the AIDL reportVendorAtom is oneway API - the return code is not returned to the client
TEST_P(StatsAidlTest,reportVendorAtomInvalidDomainNameTooLong)107 TEST_P(StatsAidlTest, reportVendorAtomInvalidDomainNameTooLong) {
108 std::vector<VendorAtomValue> values;
109 VendorAtomValue tmp;
110 tmp.set<VendorAtomValue::longValue>(70000);
111 values.push_back(tmp);
112 tmp.set<VendorAtomValue::intValue>(7);
113 values.push_back(tmp);
114 tmp.set<VendorAtomValue::floatValue>(8.5);
115 values.push_back(tmp);
116 tmp.set<VendorAtomValue::stringValue>("test");
117 values.push_back(tmp);
118 tmp.set<VendorAtomValue::intValue>(3);
119 values.push_back(tmp);
120 VendorAtom atom = {.reverseDomainName = "com.google.pixel.SubDomainName.SubDomainName.Domain",
121 .atomId = 100001,
122 .values = values};
123 const ndk::ScopedAStatus ret = client->reportVendorAtom(atom);
124
125 ASSERT_TRUE(ret.isOk());
126 }
127
128 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(StatsAidlTest);
129 INSTANTIATE_TEST_SUITE_P(PerInstance, StatsAidlTest,
130 testing::ValuesIn(android::getAidlHalInstanceNames(IStats::descriptor)),
131 android::PrintInstanceNameToString);
132