FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/tree.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 34 52 65.4%
Functions: 3 4 75.0%
Branches: 15 28 53.6%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/tree.c"
20
21 #include <stdint.h>
22
23 #include "libavutil/common.h"
24 #include "libavutil/lfg.h"
25 #include "libavutil/log.h"
26 #include "libavutil/mem.h"
27
28 92932756 static int check(AVTreeNode *t)
29 {
30
2/2
✓ Branch 0 taken 46461378 times.
✓ Branch 1 taken 46471378 times.
92932756 if (t) {
31 46461378 int left = check(t->child[0]);
32 46461378 int right = check(t->child[1]);
33
34
2/4
✓ Branch 0 taken 46461378 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 46461378 times.
46461378 if (left > 999 || right > 999)
35 return 1000;
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46461378 times.
46461378 if (right - left != t->state)
37 return 1000;
38
2/4
✓ Branch 0 taken 46461378 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 46461378 times.
46461378 if (t->state > 1 || t->state < -1)
39 return 1000;
40 46461378 return FFMAX(left, right) + 1;
41 }
42 46471378 return 0;
43 }
44
45 static void print(AVTreeNode *t, int depth)
46 {
47 int i;
48 for (i = 0; i < depth * 4; i++)
49 av_log(NULL, AV_LOG_ERROR, " ");
50 if (t) {
51 av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem);
52 print(t->child[0], depth + 1);
53 print(t->child[1], depth + 1);
54 } else
55 av_log(NULL, AV_LOG_ERROR, "NULL\n");
56 }
57
58 360426 static int cmp(const void *a, const void *b)
59 {
60 360426 return (const uint8_t *) a - (const uint8_t *) b;
61 }
62
63 1 int main(int argc, char **argv)
64 {
65 int i;
66 void *k;
67 1 AVTreeNode *root = NULL, *node = NULL;
68 AVLFG prng;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 int log_level = argc <= 1 ? AV_LOG_INFO : atoi(argv[1]);
70
71 1 av_log_set_level(log_level);
72
73 1 av_lfg_init(&prng, 1);
74
75
2/2
✓ Branch 0 taken 10000 times.
✓ Branch 1 taken 1 times.
10001 for (i = 0; i < 10000; i++) {
76 10000 intptr_t j = av_lfg_get(&prng) % 86294;
77
78
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10000 times.
10000 if (check(root) > 999) {
79 av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
80 print(root, 0);
81 return 1;
82 }
83 10000 av_log(NULL, AV_LOG_DEBUG, "inserting %4d\n", (int)j);
84
85
2/2
✓ Branch 0 taken 9513 times.
✓ Branch 1 taken 487 times.
10000 if (!node)
86 9513 node = av_tree_node_alloc();
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10000 times.
10000 if (!node) {
88 av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n");
89 return 1;
90 }
91 10000 av_tree_insert(&root, (void *)(j + 1), cmp, &node);
92
93 10000 j = av_lfg_get(&prng) % 86294;
94 {
95 10000 AVTreeNode *node2 = NULL;
96 10000 av_log(NULL, AV_LOG_DEBUG, "removing %4d\n", (int)j);
97 10000 av_tree_insert(&root, (void *)(j + 1), cmp, &node2);
98 10000 k = av_tree_find(root, (void *)(j + 1), cmp, NULL);
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10000 times.
10000 if (k)
100 av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i);
101 10000 av_free(node2);
102 }
103 }
104 1 av_free(node);
105
106 1 av_tree_destroy(root);
107
108 1 return 0;
109 }
110