GCC Code Coverage Report


Directory: ./
File: tests/unit/04_core/mngo_metrics_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 75 75 100.0%
Functions: 2 2 100.0%
Branches: 23 40 57.5%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2026 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #include <assert.h>
21 #include <float.h>
22 #include <unistd.h>
23 #include <stdbool.h>
24
25 #include "mngo/mngo_metrics.h"
26
27 15 static inline bool compare_float_eq(float a, float b) {
28 15 float residual_ab = a - b;
29 15 float residual_ba = b - a;
30
31
2/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
15 return residual_ab <= FLT_EPSILON && residual_ba <= FLT_EPSILON;
32 }
33
34 1 int main(int argc, char *argv[]) {
35 // Easy test on push
36 {
37 mngo_metrics_history_t history;
38 1 mngo_metrics__history_init(&history);
39
40 1 mngo_talp_metrics_t metric_00 = (const mngo_talp_metrics_t) {
41 .self_mpi_parallel_efficiency = 0.1010101010,
42 .shared_mpi_parallel_efficiency = 0.2020202020,
43 .global_mpi_parallel_efficiency = 0.3030303030,
44 };
45 1 mngo_metrics__history_push(&history, &metric_00);
46
47 mngo_reduced_metric_t reduced_00;
48 1 mngo_metrics__history_tendency(&history, &reduced_00);
49
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.self_mpi_parallel_efficiency,reduced_00.self_pe));
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.shared_mpi_parallel_efficiency,reduced_00.shared_pe));
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.global_mpi_parallel_efficiency,reduced_00.global_pe));
52
53 1 mngo_metrics__history_fini(&history);
54 }
55
56 // Easy test on emplace
57 {
58 mngo_metrics_history_t history;
59 1 mngo_metrics__history_init(&history);
60
61 1 mngo_talp_metrics_t *metric_00 = mngo_metrics__history_emplace(&history);
62 1 metric_00->self_mpi_parallel_efficiency = 0.1010101010;
63 1 metric_00->shared_mpi_parallel_efficiency = 0.2020202020;
64 1 metric_00->global_mpi_parallel_efficiency = 0.3030303030;
65
66 mngo_reduced_metric_t reduced_00;
67 1 mngo_metrics__history_tendency(&history, &reduced_00);
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00->self_mpi_parallel_efficiency, reduced_00.self_pe));
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00->shared_mpi_parallel_efficiency, reduced_00.shared_pe));
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00->global_mpi_parallel_efficiency, reduced_00.global_pe));
71
72 1 mngo_metrics__history_fini(&history);
73 }
74
75 // Check multiple entries
76 {
77 mngo_metrics_history_t history;
78 1 mngo_metrics__history_init(&history);
79
80
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
513 for (int i = 0; i < MNGO_HISTORY_WINDOW * 2; i++) {
81 512 mngo_talp_metrics_t *metric_00 = mngo_metrics__history_emplace(&history);
82 512 metric_00->self_mpi_parallel_efficiency = 0.1010101010;
83 512 metric_00->shared_mpi_parallel_efficiency = 0.2020202020;
84 512 metric_00->global_mpi_parallel_efficiency = 0.3030303030;
85 }
86
87 1 mngo_talp_metrics_t metric_00 = (const mngo_talp_metrics_t) {
88 .self_mpi_parallel_efficiency = 0.1010101010,
89 .shared_mpi_parallel_efficiency = 0.2020202020,
90 .global_mpi_parallel_efficiency = 0.3030303030,
91 };
92
93 mngo_reduced_metric_t reduced_00;
94 1 mngo_metrics__history_tendency(&history, &reduced_00);
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.self_mpi_parallel_efficiency, reduced_00.self_pe));
96
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.shared_mpi_parallel_efficiency, reduced_00.shared_pe));
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.global_mpi_parallel_efficiency, reduced_00.global_pe));
98
99 1 mngo_metrics__history_fini(&history);
100 }
101
102 // Check multiple entries and replace everything
103 {
104 mngo_metrics_history_t history;
105 1 mngo_metrics__history_init(&history);
106
107
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 1 times.
257 for (int i = 0; i < MNGO_HISTORY_WINDOW; i++) {
108 256 mngo_talp_metrics_t *metric_00 = mngo_metrics__history_emplace(&history);
109 256 metric_00->self_mpi_parallel_efficiency = 0.9341234320;
110 256 metric_00->shared_mpi_parallel_efficiency = 0.2342549324;
111 256 metric_00->global_mpi_parallel_efficiency = 0.3141235321;
112 }
113
114
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 1 times.
257 for (int i = 0; i < MNGO_HISTORY_WINDOW; i++) {
115 256 mngo_talp_metrics_t *metric_00 = mngo_metrics__history_emplace(&history);
116 256 metric_00->self_mpi_parallel_efficiency = 0.1010101010;
117 256 metric_00->shared_mpi_parallel_efficiency = 0.2020202020;
118 256 metric_00->global_mpi_parallel_efficiency = 0.3030303030;
119 }
120
121 1 mngo_talp_metrics_t metric_00 = (const mngo_talp_metrics_t) {
122 .self_mpi_parallel_efficiency = 0.1010101010,
123 .shared_mpi_parallel_efficiency = 0.2020202020,
124 .global_mpi_parallel_efficiency = 0.3030303030,
125 };
126
127 mngo_reduced_metric_t reduced_00;
128 1 mngo_metrics__history_tendency(&history, &reduced_00);
129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.self_mpi_parallel_efficiency, reduced_00.self_pe));
130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.shared_mpi_parallel_efficiency, reduced_00.shared_pe));
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(metric_00.global_mpi_parallel_efficiency, reduced_00.global_pe));
132
133 1 mngo_metrics__history_fini(&history);
134 }
135
136 // Check weigted average
137 // - the oldests weights 1
138 // - and the yourngest wieghts #entries
139 {
140 mngo_metrics_history_t history;
141 1 mngo_metrics__history_init(&history);
142
143 1 mngo_talp_metrics_t *metric_00 = mngo_metrics__history_emplace(&history);
144 1 metric_00->self_mpi_parallel_efficiency = 0.5;
145 1 metric_00->shared_mpi_parallel_efficiency = 0.4;
146 1 metric_00->global_mpi_parallel_efficiency = 0.3;
147
148 1 mngo_talp_metrics_t *metric_01 = mngo_metrics__history_emplace(&history);
149 1 metric_01->self_mpi_parallel_efficiency = 0.4;
150 1 metric_01->shared_mpi_parallel_efficiency = 0.3;
151 1 metric_01->global_mpi_parallel_efficiency = 0.2;
152
153 1 mngo_talp_metrics_t *metric_02 = mngo_metrics__history_emplace(&history);
154 1 metric_02->self_mpi_parallel_efficiency = 0.3;
155 1 metric_02->shared_mpi_parallel_efficiency = 0.2;
156 1 metric_02->global_mpi_parallel_efficiency = 0.1;
157
158 1 mngo_talp_metrics_t *metric_03 = mngo_metrics__history_emplace(&history);
159 1 metric_03->self_mpi_parallel_efficiency = 0.2;
160 1 metric_03->shared_mpi_parallel_efficiency = 0.1;
161 1 metric_03->global_mpi_parallel_efficiency = 0.0;
162
163 1 mngo_reduced_metric_t expected = (const mngo_reduced_metric_t) {
164 .self_pe = 0.3,
165 .shared_pe = 0.2,
166 .global_pe = 0.1,
167 };
168
169 mngo_reduced_metric_t reduced_00;
170 1 mngo_metrics__history_tendency(&history, &reduced_00);
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(expected.self_pe, reduced_00.self_pe));
172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(expected.shared_pe, reduced_00.shared_pe));
173
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(compare_float_eq(expected.global_pe, reduced_00.global_pe));
174
175 1 mngo_metrics__history_fini(&history);
176 }
177
178 }
179