Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 1 | // 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 | |
| 21 | namespace pw { |
| 22 | namespace metric { |
| 23 | |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 24 | // Create two global metrics; make sure they show up. |
| 25 | PW_METRIC_GLOBAL(stat_x, "stat_x", 123u); |
| 26 | PW_METRIC_GLOBAL(stat_y, "stat_y", 123u); |
| 27 | |
| 28 | TEST(Global, Metrics) { |
| 29 | Metric::Dump(global_metrics); |
Wyatt Hepler | 63afc00 | 2021-02-08 13:20:26 -0800 | [diff] [blame] | 30 | EXPECT_EQ(global_metrics.size(), 2u); |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // Create three global metric groups; make sure they show up. |
| 34 | // Also, register some sub-metrics in the global groups. |
| 35 | PW_METRIC_GROUP_GLOBAL(gyro_metrics, "gyro"); |
| 36 | PW_METRIC(gyro_metrics, max_velocity, "max_velocity", 5.0f); |
| 37 | |
| 38 | PW_METRIC_GROUP_GLOBAL(comms_metrics, "comms"); |
| 39 | PW_METRIC(comms_metrics, packet_drops, "packet_drops", 10u); |
| 40 | PW_METRIC(comms_metrics, bandwidth, "bandwidth", 230.3f); |
| 41 | |
| 42 | PW_METRIC_GROUP_GLOBAL(power_metrics, "power"); |
| 43 | PW_METRIC(power_metrics, voltage, "voltage", 3.33f); |
| 44 | PW_METRIC(power_metrics, battery_cycles, "battery_cycles", 550u); |
| 45 | PW_METRIC(power_metrics, current_ma, "current_ma", 35.2f); |
| 46 | |
| 47 | TEST(Global, Groups) { |
| 48 | Group::Dump(global_groups); |
Wyatt Hepler | 63afc00 | 2021-02-08 13:20:26 -0800 | [diff] [blame] | 49 | EXPECT_EQ(global_groups.size(), 4u); |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 50 | |
Wyatt Hepler | 63afc00 | 2021-02-08 13:20:26 -0800 | [diff] [blame] | 51 | EXPECT_EQ(gyro_metrics.metrics().size(), 1u); |
| 52 | EXPECT_EQ(comms_metrics.metrics().size(), 2u); |
| 53 | EXPECT_EQ(power_metrics.metrics().size(), 3u); |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } // namespace metric |
| 57 | } // namespace pw |
Paul Mathieu | 990fab9 | 2020-08-31 17:55:44 +0200 | [diff] [blame] | 58 | |
| 59 | // this is a compilation test to make sure metrics can be defined outside of |
| 60 | // ::pw::metric |
| 61 | PW_METRIC_GROUP_GLOBAL(global_group, "global group"); |