FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/tests/dnn-layer-mathunary.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 75 97 77.3%
Functions: 3 3 100.0%
Branches: 46 68 67.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2020
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <math.h>
24 #include "libavfilter/dnn/dnn_backend_native_layer_mathunary.h"
25 #include "libavutil/avassert.h"
26
27 #define EPS 0.00001
28
29 153 static float get_expected(float f, DNNMathUnaryOperation op)
30 {
31
17/18
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 9 times.
✓ Branch 12 taken 9 times.
✓ Branch 13 taken 9 times.
✓ Branch 14 taken 9 times.
✓ Branch 15 taken 9 times.
✓ Branch 16 taken 9 times.
✗ Branch 17 not taken.
153 switch (op)
32 {
33 9 case DMUO_ABS:
34 9 return (f >= 0) ? f : -f;
35 9 case DMUO_SIN:
36 9 return sin(f);
37 9 case DMUO_COS:
38 9 return cos(f);
39 9 case DMUO_TAN:
40 9 return tan(f);
41 9 case DMUO_ASIN:
42 9 return asin(f);
43 9 case DMUO_ACOS:
44 9 return acos(f);
45 9 case DMUO_ATAN:
46 9 return atan(f);
47 9 case DMUO_SINH:
48 9 return sinh(f);
49 9 case DMUO_COSH:
50 9 return cosh(f);
51 9 case DMUO_TANH:
52 9 return tanh(f);
53 9 case DMUO_ASINH:
54 9 return asinh(f);
55 9 case DMUO_ACOSH:
56 9 return acosh(f);
57 9 case DMUO_ATANH:
58 9 return atanh(f);
59 9 case DMUO_CEIL:
60 9 return ceil(f);
61 9 case DMUO_FLOOR:
62 9 return floor(f);
63 9 case DMUO_ROUND:
64 9 return round(f);
65 9 case DMUO_EXP:
66 9 return exp(f);
67 default:
68 av_assert0(!"not supported yet");
69 return 0.f;
70 }
71 }
72
73 17 static int test(DNNMathUnaryOperation op)
74 {
75 DnnLayerMathUnaryParams params;
76 DnnOperand operands[2];
77 int32_t input_indexes[1];
78 17 float input[1*1*3*3] = {
79 0.1, 0.5, 0.75, -3, 2.5, 2, -2.1, 7.8, 100};
80 float *output;
81
82 17 params.un_op = op;
83
84 17 operands[0].data = input;
85 17 operands[0].dims[0] = 1;
86 17 operands[0].dims[1] = 1;
87 17 operands[0].dims[2] = 3;
88 17 operands[0].dims[3] = 3;
89 17 operands[1].data = NULL;
90
91 17 input_indexes[0] = 0;
92 17 ff_dnn_execute_layer_math_unary(operands, input_indexes, 1, &params, NULL);
93
94 17 output = operands[1].data;
95
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 17 times.
170 for (int i = 0; i < sizeof(input) / sizeof(float); ++i) {
96 153 float expected_output = get_expected(input[i], op);
97 153 int output_nan = isnan(output[i]);
98 153 int expected_nan = isnan(expected_output);
99
6/8
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 130 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 23 times.
✓ Branch 7 taken 130 times.
153 if ((!output_nan && !expected_nan && fabs(output[i] - expected_output) > EPS) ||
100
4/6
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 130 times.
153 (output_nan && !expected_nan) || (!output_nan && expected_nan)) {
101 printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
102 av_freep(&output);
103 return 1;
104 }
105 }
106
107 17 av_freep(&output);
108 17 return 0;
109 }
110
111 1 int main(int agrc, char **argv)
112 {
113
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ABS))
114 return 1;
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_SIN))
116 return 1;
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_COS))
118 return 1;
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_TAN))
120 return 1;
121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ASIN))
122 return 1;
123
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ACOS))
124 return 1;
125
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ATAN))
126 return 1;
127
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_SINH))
128 return 1;
129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_COSH))
130 return 1;
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_TANH))
132 return 1;
133
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ASINH))
134 return 1;
135
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ACOSH))
136 return 1;
137
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ATANH))
138 return 1;
139
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_CEIL))
140 return 1;
141
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_FLOOR))
142 return 1;
143
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_ROUND))
144 return 1;
145
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (test(DMUO_EXP))
146 return 1;
147 1 return 0;
148 }
149