1 // Copyright (C) 2017 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
17 #include "src/condition/ConditionTracker.h"
18 #include "src/matchers/LogMatchingTracker.h"
19 #include "src/metrics/CountMetricProducer.h"
20 #include "src/metrics/GaugeMetricProducer.h"
21 #include "src/metrics/MetricProducer.h"
22 #include "src/metrics/ValueMetricProducer.h"
23 #include "src/metrics/metrics_manager_util.h"
24 #include "statsd_test_util.h"
25 
26 #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
27 
28 #include <stdio.h>
29 #include <set>
30 #include <unordered_map>
31 #include <vector>
32 
33 using namespace android::os::statsd;
34 using android::sp;
35 using std::set;
36 using std::unordered_map;
37 using std::vector;
38 using android::os::statsd::Predicate;
39 
40 #ifdef __ANDROID__
41 
42 const ConfigKey kConfigKey(0, 12345);
43 
44 const long timeBaseSec = 1000;
45 
buildGoodConfig()46 StatsdConfig buildGoodConfig() {
47     StatsdConfig config;
48     config.set_id(12345);
49 
50     AtomMatcher* eventMatcher = config.add_atom_matcher();
51     eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
52 
53     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
54     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
55     simpleAtomMatcher->add_field_value_matcher()->set_field(
56             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
57     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
58             2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
59 
60     eventMatcher = config.add_atom_matcher();
61     eventMatcher->set_id(StringToId("SCREEN_IS_OFF"));
62 
63     simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
64     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
65     simpleAtomMatcher->add_field_value_matcher()->set_field(
66             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
67     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
68             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/);
69 
70     eventMatcher = config.add_atom_matcher();
71     eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
72 
73     AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
74     combination->set_operation(LogicalOperation::OR);
75     combination->add_matcher(StringToId("SCREEN_IS_ON"));
76     combination->add_matcher(StringToId("SCREEN_IS_OFF"));
77 
78     CountMetric* metric = config.add_count_metric();
79     metric->set_id(3);
80     metric->set_what(StringToId("SCREEN_IS_ON"));
81     metric->set_bucket(ONE_MINUTE);
82     metric->mutable_dimensions_in_what()->set_field(2 /*SCREEN_STATE_CHANGE*/);
83     metric->mutable_dimensions_in_what()->add_child()->set_field(1);
84 
85     config.add_no_report_metric(3);
86 
87     auto alert = config.add_alert();
88     alert->set_id(3);
89     alert->set_metric_id(3);
90     alert->set_num_buckets(10);
91     alert->set_refractory_period_secs(100);
92     alert->set_trigger_if_sum_gt(100);
93     return config;
94 }
95 
buildCircleMatchers()96 StatsdConfig buildCircleMatchers() {
97     StatsdConfig config;
98     config.set_id(12345);
99 
100     AtomMatcher* eventMatcher = config.add_atom_matcher();
101     eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
102 
103     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
104     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
105     simpleAtomMatcher->add_field_value_matcher()->set_field(
106             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
107     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
108             2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
109 
110     eventMatcher = config.add_atom_matcher();
111     eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
112 
113     AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
114     combination->set_operation(LogicalOperation::OR);
115     combination->add_matcher(StringToId("SCREEN_IS_ON"));
116     // Circle dependency
117     combination->add_matcher(StringToId("SCREEN_ON_OR_OFF"));
118 
119     return config;
120 }
121 
buildAlertWithUnknownMetric()122 StatsdConfig buildAlertWithUnknownMetric() {
123     StatsdConfig config;
124     config.set_id(12345);
125 
126     AtomMatcher* eventMatcher = config.add_atom_matcher();
127     eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
128 
129     CountMetric* metric = config.add_count_metric();
130     metric->set_id(3);
131     metric->set_what(StringToId("SCREEN_IS_ON"));
132     metric->set_bucket(ONE_MINUTE);
133     metric->mutable_dimensions_in_what()->set_field(2 /*SCREEN_STATE_CHANGE*/);
134     metric->mutable_dimensions_in_what()->add_child()->set_field(1);
135 
136     auto alert = config.add_alert();
137     alert->set_id(3);
138     alert->set_metric_id(2);
139     alert->set_num_buckets(10);
140     alert->set_refractory_period_secs(100);
141     alert->set_trigger_if_sum_gt(100);
142     return config;
143 }
144 
buildMissingMatchers()145 StatsdConfig buildMissingMatchers() {
146     StatsdConfig config;
147     config.set_id(12345);
148 
149     AtomMatcher* eventMatcher = config.add_atom_matcher();
150     eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
151 
152     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
153     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
154     simpleAtomMatcher->add_field_value_matcher()->set_field(
155             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
156     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
157             2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
158 
159     eventMatcher = config.add_atom_matcher();
160     eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
161 
162     AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
163     combination->set_operation(LogicalOperation::OR);
164     combination->add_matcher(StringToId("SCREEN_IS_ON"));
165     // undefined matcher
166     combination->add_matcher(StringToId("ABC"));
167 
168     return config;
169 }
170 
buildMissingPredicate()171 StatsdConfig buildMissingPredicate() {
172     StatsdConfig config;
173     config.set_id(12345);
174 
175     CountMetric* metric = config.add_count_metric();
176     metric->set_id(3);
177     metric->set_what(StringToId("SCREEN_EVENT"));
178     metric->set_bucket(ONE_MINUTE);
179     metric->set_condition(StringToId("SOME_CONDITION"));
180 
181     AtomMatcher* eventMatcher = config.add_atom_matcher();
182     eventMatcher->set_id(StringToId("SCREEN_EVENT"));
183 
184     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
185     simpleAtomMatcher->set_atom_id(2);
186 
187     return config;
188 }
189 
buildDimensionMetricsWithMultiTags()190 StatsdConfig buildDimensionMetricsWithMultiTags() {
191     StatsdConfig config;
192     config.set_id(12345);
193 
194     AtomMatcher* eventMatcher = config.add_atom_matcher();
195     eventMatcher->set_id(StringToId("BATTERY_VERY_LOW"));
196     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
197     simpleAtomMatcher->set_atom_id(2);
198 
199     eventMatcher = config.add_atom_matcher();
200     eventMatcher->set_id(StringToId("BATTERY_VERY_VERY_LOW"));
201     simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
202     simpleAtomMatcher->set_atom_id(3);
203 
204     eventMatcher = config.add_atom_matcher();
205     eventMatcher->set_id(StringToId("BATTERY_LOW"));
206 
207     AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
208     combination->set_operation(LogicalOperation::OR);
209     combination->add_matcher(StringToId("BATTERY_VERY_LOW"));
210     combination->add_matcher(StringToId("BATTERY_VERY_VERY_LOW"));
211 
212     // Count process state changes, slice by uid, while SCREEN_IS_OFF
213     CountMetric* metric = config.add_count_metric();
214     metric->set_id(3);
215     metric->set_what(StringToId("BATTERY_LOW"));
216     metric->set_bucket(ONE_MINUTE);
217     // This case is interesting. We want to dimension across two atoms.
218     metric->mutable_dimensions_in_what()->add_child()->set_field(1);
219 
220     auto alert = config.add_alert();
221     alert->set_id(103);
222     alert->set_metric_id(3);
223     alert->set_num_buckets(10);
224     alert->set_refractory_period_secs(100);
225     alert->set_trigger_if_sum_gt(100);
226     return config;
227 }
228 
buildCirclePredicates()229 StatsdConfig buildCirclePredicates() {
230     StatsdConfig config;
231     config.set_id(12345);
232 
233     AtomMatcher* eventMatcher = config.add_atom_matcher();
234     eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
235 
236     SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
237     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
238     simpleAtomMatcher->add_field_value_matcher()->set_field(
239             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
240     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
241             2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
242 
243     eventMatcher = config.add_atom_matcher();
244     eventMatcher->set_id(StringToId("SCREEN_IS_OFF"));
245 
246     simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
247     simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
248     simpleAtomMatcher->add_field_value_matcher()->set_field(
249             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/);
250     simpleAtomMatcher->mutable_field_value_matcher(0)->set_eq_int(
251             1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/);
252 
253     auto condition = config.add_predicate();
254     condition->set_id(StringToId("SCREEN_IS_ON"));
255     SimplePredicate* simplePredicate = condition->mutable_simple_predicate();
256     simplePredicate->set_start(StringToId("SCREEN_IS_ON"));
257     simplePredicate->set_stop(StringToId("SCREEN_IS_OFF"));
258 
259     condition = config.add_predicate();
260     condition->set_id(StringToId("SCREEN_IS_EITHER_ON_OFF"));
261 
262     Predicate_Combination* combination = condition->mutable_combination();
263     combination->set_operation(LogicalOperation::OR);
264     combination->add_predicate(StringToId("SCREEN_IS_ON"));
265     combination->add_predicate(StringToId("SCREEN_IS_EITHER_ON_OFF"));
266 
267     return config;
268 }
269 
TEST(MetricsManagerTest,TestGoodConfig)270 TEST(MetricsManagerTest, TestGoodConfig) {
271     UidMap uidMap;
272     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
273     sp<AlarmMonitor> anomalyAlarmMonitor;
274     sp<AlarmMonitor> periodicAlarmMonitor;
275     StatsdConfig config = buildGoodConfig();
276     set<int> allTagIds;
277     vector<sp<LogMatchingTracker>> allAtomMatchers;
278     vector<sp<ConditionTracker>> allConditionTrackers;
279     vector<sp<MetricProducer>> allMetricProducers;
280     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
281     std::vector<sp<AlarmTracker>> allAlarmTrackers;
282     unordered_map<int, std::vector<int>> conditionToMetricMap;
283     unordered_map<int, std::vector<int>> trackerToMetricMap;
284     unordered_map<int, std::vector<int>> trackerToConditionMap;
285     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
286     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
287     vector<int> metricsWithActivation;
288     std::set<int64_t> noReportMetricIds;
289 
290     EXPECT_TRUE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
291                                  periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
292                                  allAtomMatchers, allConditionTrackers, allMetricProducers,
293                                  allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
294                                  trackerToMetricMap, trackerToConditionMap,
295                                  activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
296                                  metricsWithActivation, noReportMetricIds));
297     EXPECT_EQ(1u, allMetricProducers.size());
298     EXPECT_EQ(1u, allAnomalyTrackers.size());
299     EXPECT_EQ(1u, noReportMetricIds.size());
300 }
301 
TEST(MetricsManagerTest,TestDimensionMetricsWithMultiTags)302 TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) {
303     UidMap uidMap;
304     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
305     sp<AlarmMonitor> anomalyAlarmMonitor;
306     sp<AlarmMonitor> periodicAlarmMonitor;
307     StatsdConfig config = buildDimensionMetricsWithMultiTags();
308     set<int> allTagIds;
309     vector<sp<LogMatchingTracker>> allAtomMatchers;
310     vector<sp<ConditionTracker>> allConditionTrackers;
311     vector<sp<MetricProducer>> allMetricProducers;
312     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
313     std::vector<sp<AlarmTracker>> allAlarmTrackers;
314     unordered_map<int, std::vector<int>> conditionToMetricMap;
315     unordered_map<int, std::vector<int>> trackerToMetricMap;
316     unordered_map<int, std::vector<int>> trackerToConditionMap;
317     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
318     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
319     vector<int> metricsWithActivation;
320     std::set<int64_t> noReportMetricIds;
321 
322     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
323                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
324                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
325                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
326                                   trackerToMetricMap, trackerToConditionMap,
327                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
328                                   metricsWithActivation, noReportMetricIds));
329 }
330 
TEST(MetricsManagerTest,TestCircleLogMatcherDependency)331 TEST(MetricsManagerTest, TestCircleLogMatcherDependency) {
332     UidMap uidMap;
333     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
334     sp<AlarmMonitor> anomalyAlarmMonitor;
335     sp<AlarmMonitor> periodicAlarmMonitor;
336     StatsdConfig config = buildCircleMatchers();
337     set<int> allTagIds;
338     vector<sp<LogMatchingTracker>> allAtomMatchers;
339     vector<sp<ConditionTracker>> allConditionTrackers;
340     vector<sp<MetricProducer>> allMetricProducers;
341     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
342     std::vector<sp<AlarmTracker>> allAlarmTrackers;
343     unordered_map<int, std::vector<int>> conditionToMetricMap;
344     unordered_map<int, std::vector<int>> trackerToMetricMap;
345     unordered_map<int, std::vector<int>> trackerToConditionMap;
346     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
347     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
348     vector<int> metricsWithActivation;
349     std::set<int64_t> noReportMetricIds;
350 
351     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
352                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
353                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
354                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
355                                   trackerToMetricMap, trackerToConditionMap,
356                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
357                                   metricsWithActivation, noReportMetricIds));
358 }
359 
TEST(MetricsManagerTest,TestMissingMatchers)360 TEST(MetricsManagerTest, TestMissingMatchers) {
361     UidMap uidMap;
362     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
363     sp<AlarmMonitor> anomalyAlarmMonitor;
364     sp<AlarmMonitor> periodicAlarmMonitor;
365     StatsdConfig config = buildMissingMatchers();
366     set<int> allTagIds;
367     vector<sp<LogMatchingTracker>> allAtomMatchers;
368     vector<sp<ConditionTracker>> allConditionTrackers;
369     vector<sp<MetricProducer>> allMetricProducers;
370     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
371     std::vector<sp<AlarmTracker>> allAlarmTrackers;
372     unordered_map<int, std::vector<int>> conditionToMetricMap;
373     unordered_map<int, std::vector<int>> trackerToMetricMap;
374     unordered_map<int, std::vector<int>> trackerToConditionMap;
375     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
376     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
377     vector<int> metricsWithActivation;
378     std::set<int64_t> noReportMetricIds;
379     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
380                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
381                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
382                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
383                                   trackerToMetricMap, trackerToConditionMap,
384                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
385                                   metricsWithActivation, noReportMetricIds));
386 }
387 
TEST(MetricsManagerTest,TestMissingPredicate)388 TEST(MetricsManagerTest, TestMissingPredicate) {
389     UidMap uidMap;
390     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
391     sp<AlarmMonitor> anomalyAlarmMonitor;
392     sp<AlarmMonitor> periodicAlarmMonitor;
393     StatsdConfig config = buildMissingPredicate();
394     set<int> allTagIds;
395     vector<sp<LogMatchingTracker>> allAtomMatchers;
396     vector<sp<ConditionTracker>> allConditionTrackers;
397     vector<sp<MetricProducer>> allMetricProducers;
398     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
399     std::vector<sp<AlarmTracker>> allAlarmTrackers;
400     unordered_map<int, std::vector<int>> conditionToMetricMap;
401     unordered_map<int, std::vector<int>> trackerToMetricMap;
402     unordered_map<int, std::vector<int>> trackerToConditionMap;
403     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
404     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
405     vector<int> metricsWithActivation;
406     std::set<int64_t> noReportMetricIds;
407     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
408                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
409                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
410                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
411                                   trackerToMetricMap, trackerToConditionMap,
412                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
413                                   metricsWithActivation, noReportMetricIds));
414 }
415 
TEST(MetricsManagerTest,TestCirclePredicateDependency)416 TEST(MetricsManagerTest, TestCirclePredicateDependency) {
417     UidMap uidMap;
418     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
419     sp<AlarmMonitor> anomalyAlarmMonitor;
420     sp<AlarmMonitor> periodicAlarmMonitor;
421     StatsdConfig config = buildCirclePredicates();
422     set<int> allTagIds;
423     vector<sp<LogMatchingTracker>> allAtomMatchers;
424     vector<sp<ConditionTracker>> allConditionTrackers;
425     vector<sp<MetricProducer>> allMetricProducers;
426     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
427     std::vector<sp<AlarmTracker>> allAlarmTrackers;
428     unordered_map<int, std::vector<int>> conditionToMetricMap;
429     unordered_map<int, std::vector<int>> trackerToMetricMap;
430     unordered_map<int, std::vector<int>> trackerToConditionMap;
431     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
432     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
433     vector<int> metricsWithActivation;
434     std::set<int64_t> noReportMetricIds;
435 
436     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
437                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
438                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
439                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
440                                   trackerToMetricMap, trackerToConditionMap,
441                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
442                                   metricsWithActivation, noReportMetricIds));
443 }
444 
TEST(MetricsManagerTest,testAlertWithUnknownMetric)445 TEST(MetricsManagerTest, testAlertWithUnknownMetric) {
446     UidMap uidMap;
447     sp<StatsPullerManager> pullerManager = new StatsPullerManager();
448     sp<AlarmMonitor> anomalyAlarmMonitor;
449     sp<AlarmMonitor> periodicAlarmMonitor;
450     StatsdConfig config = buildAlertWithUnknownMetric();
451     set<int> allTagIds;
452     vector<sp<LogMatchingTracker>> allAtomMatchers;
453     vector<sp<ConditionTracker>> allConditionTrackers;
454     vector<sp<MetricProducer>> allMetricProducers;
455     std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
456     std::vector<sp<AlarmTracker>> allAlarmTrackers;
457     unordered_map<int, std::vector<int>> conditionToMetricMap;
458     unordered_map<int, std::vector<int>> trackerToMetricMap;
459     unordered_map<int, std::vector<int>> trackerToConditionMap;
460     unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
461     unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
462     vector<int> metricsWithActivation;
463     std::set<int64_t> noReportMetricIds;
464 
465     EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
466                                   periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
467                                   allAtomMatchers, allConditionTrackers, allMetricProducers,
468                                   allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
469                                   trackerToMetricMap, trackerToConditionMap,
470                                   activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
471                                   metricsWithActivation, noReportMetricIds));
472 }
473 
474 #else
475 GTEST_LOG_(INFO) << "This test does nothing.\n";
476 #endif
477