blob: d918c79d9f3ce33d55d9e82c3131a6b41d3f3c6a [file] [log] [blame]
Keir Mierle45fa7852020-08-10 21:09:54 -07001// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#include "pw_metric/global.h"
16
17#include "gtest/gtest.h"
18#include "pw_log/log.h"
19#include "pw_metric/metric.h"
20
21namespace pw {
22namespace metric {
23
Keir Mierle45fa7852020-08-10 21:09:54 -070024// Create two global metrics; make sure they show up.
25PW_METRIC_GLOBAL(stat_x, "stat_x", 123u);
26PW_METRIC_GLOBAL(stat_y, "stat_y", 123u);
27
28TEST(Global, Metrics) {
29 Metric::Dump(global_metrics);
Wyatt Hepler63afc002021-02-08 13:20:26 -080030 EXPECT_EQ(global_metrics.size(), 2u);
Keir Mierle45fa7852020-08-10 21:09:54 -070031}
32
33// Create three global metric groups; make sure they show up.
34// Also, register some sub-metrics in the global groups.
35PW_METRIC_GROUP_GLOBAL(gyro_metrics, "gyro");
36PW_METRIC(gyro_metrics, max_velocity, "max_velocity", 5.0f);
37
38PW_METRIC_GROUP_GLOBAL(comms_metrics, "comms");
39PW_METRIC(comms_metrics, packet_drops, "packet_drops", 10u);
40PW_METRIC(comms_metrics, bandwidth, "bandwidth", 230.3f);
41
42PW_METRIC_GROUP_GLOBAL(power_metrics, "power");
43PW_METRIC(power_metrics, voltage, "voltage", 3.33f);
44PW_METRIC(power_metrics, battery_cycles, "battery_cycles", 550u);
45PW_METRIC(power_metrics, current_ma, "current_ma", 35.2f);
46
47TEST(Global, Groups) {
48 Group::Dump(global_groups);
Wyatt Hepler63afc002021-02-08 13:20:26 -080049 EXPECT_EQ(global_groups.size(), 4u);
Keir Mierle45fa7852020-08-10 21:09:54 -070050
Wyatt Hepler63afc002021-02-08 13:20:26 -080051 EXPECT_EQ(gyro_metrics.metrics().size(), 1u);
52 EXPECT_EQ(comms_metrics.metrics().size(), 2u);
53 EXPECT_EQ(power_metrics.metrics().size(), 3u);
Keir Mierle45fa7852020-08-10 21:09:54 -070054}
55
56} // namespace metric
57} // namespace pw
Paul Mathieu990fab92020-08-31 17:55:44 +020058
59// this is a compilation test to make sure metrics can be defined outside of
60// ::pw::metric
61PW_METRIC_GROUP_GLOBAL(global_group, "global group");