1 /*
2 * Copyright (c) 2024 Mustafa Abdullah Kus, Sparse Technology
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8
9 #include <zephyr/net/prometheus/histogram.h>
10
11 PROMETHEUS_HISTOGRAM_DEFINE(test_histogram_m, "Test histogram",
12 ({ .key = "test", .value = "histogram" }), NULL);
13
14 /**
15 * @brief Test prometheus_histogram_observe
16 *
17 * @details The test shall observe the histogram value by 1 and check if the
18 * value is incremented correctly.
19 *
20 * @details The test shall observe the histogram value by 2 and check if the
21 * value is incremented correctly.
22 */
ZTEST(test_histogram,test_histogram_observe)23 ZTEST(test_histogram, test_histogram_observe)
24 {
25 int ret;
26
27 zassert_equal(test_histogram_m.sum, 0, "Histogram value is not 0");
28
29 ret = prometheus_histogram_observe(&test_histogram_m, 1);
30 zassert_ok(ret, "Error observing histogram");
31
32 zassert_equal(test_histogram_m.sum, 1.0, "Histogram value is not 1");
33
34 ret = prometheus_histogram_observe(&test_histogram_m, 2);
35 zassert_ok(ret, "Error observing histogram");
36
37 zassert_equal(test_histogram_m.sum, 3.0, "Histogram value is not 2");
38 }
39
40 ZTEST_SUITE(test_histogram, NULL, NULL, NULL, NULL, NULL);
41