1 /*
2 * Copyright (C) 2023 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 #include "src/traced/probes/statsd_client/common.h"
18
19 #include "perfetto/tracing/core/data_source_config.h"
20 #include "test/gtest_and_gmock.h"
21
22 #include "protos/perfetto/config/statsd/statsd_tracing_config.gen.h"
23 #include "protos/third_party/statsd/shell_config.pbzero.h"
24
25 using ::perfetto::protos::gen::StatsdTracingConfig;
26 using ::perfetto::protos::pbzero::StatsdShellSubscription;
27 using ::perfetto::protos::pbzero::StatsdSimpleAtomMatcher;
28
29 namespace perfetto {
30 namespace {
31
TEST(StatsdDataSourceCommonTest,EmptyConfig)32 TEST(StatsdDataSourceCommonTest, EmptyConfig) {
33 DataSourceConfig cfg{};
34 std::string s = CreateStatsdShellConfig(cfg);
35 EXPECT_EQ(s, "");
36 }
37
TEST(StatsdDataSourceCommonTest,PushOneAtom)38 TEST(StatsdDataSourceCommonTest, PushOneAtom) {
39 StatsdTracingConfig cfg;
40 cfg.add_raw_push_atom_id(42);
41
42 DataSourceConfig ds_cfg;
43 ds_cfg.set_statsd_tracing_config_raw(cfg.SerializeAsString());
44
45 std::string s = CreateStatsdShellConfig(ds_cfg);
46 StatsdShellSubscription::Decoder subscription(s);
47
48 EXPECT_TRUE(subscription.has_pushed());
49 EXPECT_EQ(StatsdSimpleAtomMatcher::Decoder(*subscription.pushed()).atom_id(),
50 42);
51 }
52
53 } // namespace
54 } // namespace perfetto
55