Bug Summary

File:build-scan/src/test/test-hashmap-ordered.c
Warning:line 868, column 9
Potential memory leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test-hashmap-ordered.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I test-hashmap.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I src/test -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c src/test/test-hashmap-ordered.c
1/* GENERATED FILE */
2#define ORDERED
3/* SPDX-License-Identifier: LGPL-2.1+ */
4/***
5 Copyright © 2013 Daniel Buch
6***/
7
8#include "alloc-util.h"
9#include "env-util.h"
10#include "hashmap.h"
11#include "log.h"
12#include "string-util.h"
13#include "strv.h"
14#include "util.h"
15
16static bool_Bool arg_slow = false0;
17
18void test_ordered_hashmap_funcs(void);
19
20static void test_ordered_hashmap_replace(void) {
21 OrderedHashmap *m;
22 char *val1, *val2, *val3, *val4, *val5, *r;
23
24 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 24, __func__, "%s", __func__
) : -abs(_e); })
;
25
26 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
27
28 val1 = strdup("val1");
29 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 29, __PRETTY_FUNCTION__); } while (0)
;
30 val2 = strdup("val2");
31 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 31, __PRETTY_FUNCTION__); } while (0)
;
32 val3 = strdup("val3");
33 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 33, __PRETTY_FUNCTION__); } while (0)
;
34 val4 = strdup("val4");
35 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 35, __PRETTY_FUNCTION__); } while (0)
;
36 val5 = strdup("val5");
37 assert_se(val5)do { if ((__builtin_expect(!!(!(val5)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val5"), "src/test/test-hashmap-ordered.c"
, 37, __PRETTY_FUNCTION__); } while (0)
;
38
39 ordered_hashmap_put(m, "key 1", val1);
40 ordered_hashmap_put(m, "key 2", val2);
41 ordered_hashmap_put(m, "key 3", val3);
42 ordered_hashmap_put(m, "key 4", val4);
43
44 ordered_hashmap_replace(m, "key 3", val1);
45 r = ordered_hashmap_get(m, "key 3");
46 assert_se(streq(r, "val1"))do { if ((__builtin_expect(!!(!((strcmp((r),("val1")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val1\")"
), "src/test/test-hashmap-ordered.c", 46, __PRETTY_FUNCTION__
); } while (0)
;
47
48 ordered_hashmap_replace(m, "key 5", val5);
49 r = ordered_hashmap_get(m, "key 5");
50 assert_se(streq(r, "val5"))do { if ((__builtin_expect(!!(!((strcmp((r),("val5")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val5\")"
), "src/test/test-hashmap-ordered.c", 50, __PRETTY_FUNCTION__
); } while (0)
;
51
52 free(val1);
53 free(val2);
54 free(val3);
55 free(val4);
56 free(val5);
57 ordered_hashmap_free(m);
58}
59
60static void test_ordered_hashmap_copy(void) {
61 OrderedHashmap *m, *copy;
62 char *val1, *val2, *val3, *val4, *r;
63
64 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 64, __func__, "%s", __func__
) : -abs(_e); })
;
65
66 val1 = strdup("val1");
67 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 67, __PRETTY_FUNCTION__); } while (0)
;
68 val2 = strdup("val2");
69 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 69, __PRETTY_FUNCTION__); } while (0)
;
70 val3 = strdup("val3");
71 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 71, __PRETTY_FUNCTION__); } while (0)
;
72 val4 = strdup("val4");
73 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 73, __PRETTY_FUNCTION__); } while (0)
;
74
75 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
76
77 ordered_hashmap_put(m, "key 1", val1);
78 ordered_hashmap_put(m, "key 2", val2);
79 ordered_hashmap_put(m, "key 3", val3);
80 ordered_hashmap_put(m, "key 4", val4);
81
82 copy = ordered_hashmap_copy(m);
83
84 r = ordered_hashmap_get(copy, "key 1");
85 assert_se(streq(r, "val1"))do { if ((__builtin_expect(!!(!((strcmp((r),("val1")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val1\")"
), "src/test/test-hashmap-ordered.c", 85, __PRETTY_FUNCTION__
); } while (0)
;
86 r = ordered_hashmap_get(copy, "key 2");
87 assert_se(streq(r, "val2"))do { if ((__builtin_expect(!!(!((strcmp((r),("val2")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val2\")"
), "src/test/test-hashmap-ordered.c", 87, __PRETTY_FUNCTION__
); } while (0)
;
88 r = ordered_hashmap_get(copy, "key 3");
89 assert_se(streq(r, "val3"))do { if ((__builtin_expect(!!(!((strcmp((r),("val3")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val3\")"
), "src/test/test-hashmap-ordered.c", 89, __PRETTY_FUNCTION__
); } while (0)
;
90 r = ordered_hashmap_get(copy, "key 4");
91 assert_se(streq(r, "val4"))do { if ((__builtin_expect(!!(!((strcmp((r),("val4")) == 0)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val4\")"
), "src/test/test-hashmap-ordered.c", 91, __PRETTY_FUNCTION__
); } while (0)
;
92
93 ordered_hashmap_free_free(copy);
94 ordered_hashmap_free(m);
95}
96
97static void test_ordered_hashmap_get_strv(void) {
98 OrderedHashmap *m;
99 char **strv;
100 char *val1, *val2, *val3, *val4;
101
102 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 102, __func__, "%s", __func__
) : -abs(_e); })
;
103
104 val1 = strdup("val1");
105 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 105, __PRETTY_FUNCTION__); } while (0)
;
106 val2 = strdup("val2");
107 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 107, __PRETTY_FUNCTION__); } while (0)
;
108 val3 = strdup("val3");
109 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 109, __PRETTY_FUNCTION__); } while (0)
;
110 val4 = strdup("val4");
111 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 111, __PRETTY_FUNCTION__); } while (0)
;
112
113 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
114
115 ordered_hashmap_put(m, "key 1", val1);
116 ordered_hashmap_put(m, "key 2", val2);
117 ordered_hashmap_put(m, "key 3", val3);
118 ordered_hashmap_put(m, "key 4", val4);
119
120 strv = ordered_hashmap_get_strv(m);
121
122#ifndef ORDERED
123 strv = strv_sort(strv);
124#endif
125
126 assert_se(streq(strv[0], "val1"))do { if ((__builtin_expect(!!(!((strcmp((strv[0]),("val1")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(strv[0], \"val1\")"
), "src/test/test-hashmap-ordered.c", 126, __PRETTY_FUNCTION__
); } while (0)
;
127 assert_se(streq(strv[1], "val2"))do { if ((__builtin_expect(!!(!((strcmp((strv[1]),("val2")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(strv[1], \"val2\")"
), "src/test/test-hashmap-ordered.c", 127, __PRETTY_FUNCTION__
); } while (0)
;
128 assert_se(streq(strv[2], "val3"))do { if ((__builtin_expect(!!(!((strcmp((strv[2]),("val3")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(strv[2], \"val3\")"
), "src/test/test-hashmap-ordered.c", 128, __PRETTY_FUNCTION__
); } while (0)
;
129 assert_se(streq(strv[3], "val4"))do { if ((__builtin_expect(!!(!((strcmp((strv[3]),("val4")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(strv[3], \"val4\")"
), "src/test/test-hashmap-ordered.c", 129, __PRETTY_FUNCTION__
); } while (0)
;
130
131 strv_free(strv);
132
133 ordered_hashmap_free(m);
134}
135
136static void test_ordered_hashmap_move_one(void) {
137 OrderedHashmap *m, *n;
138 char *val1, *val2, *val3, *val4, *r;
139
140 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 140, __func__, "%s", __func__
) : -abs(_e); })
;
141
142 val1 = strdup("val1");
143 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 143, __PRETTY_FUNCTION__); } while (0)
;
144 val2 = strdup("val2");
145 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 145, __PRETTY_FUNCTION__); } while (0)
;
146 val3 = strdup("val3");
147 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 147, __PRETTY_FUNCTION__); } while (0)
;
148 val4 = strdup("val4");
149 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 149, __PRETTY_FUNCTION__); } while (0)
;
150
151 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
152 n = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
153
154 ordered_hashmap_put(m, "key 1", val1);
155 ordered_hashmap_put(m, "key 2", val2);
156 ordered_hashmap_put(m, "key 3", val3);
157 ordered_hashmap_put(m, "key 4", val4);
158
159 assert_se(ordered_hashmap_move_one(n, NULL, "key 3") == -ENOENT)do { if ((__builtin_expect(!!(!(ordered_hashmap_move_one(n, (
(void*)0), "key 3") == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_move_one(n, NULL, \"key 3\") == -ENOENT")
, "src/test/test-hashmap-ordered.c", 159, __PRETTY_FUNCTION__
); } while (0)
;
160 assert_se(ordered_hashmap_move_one(n, m, "key 5") == -ENOENT)do { if ((__builtin_expect(!!(!(ordered_hashmap_move_one(n, m
, "key 5") == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_move_one(n, m, \"key 5\") == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 160, __PRETTY_FUNCTION__); } while (0)
;
161 assert_se(ordered_hashmap_move_one(n, m, "key 3") == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_move_one(n, m
, "key 3") == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_move_one(n, m, \"key 3\") == 0"), "src/test/test-hashmap-ordered.c"
, 161, __PRETTY_FUNCTION__); } while (0)
;
162 assert_se(ordered_hashmap_move_one(n, m, "key 4") == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_move_one(n, m
, "key 4") == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_move_one(n, m, \"key 4\") == 0"), "src/test/test-hashmap-ordered.c"
, 162, __PRETTY_FUNCTION__); } while (0)
;
163
164 r = ordered_hashmap_get(n, "key 3");
165 assert_se(r && streq(r, "val3"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val3"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val3\")"
), "src/test/test-hashmap-ordered.c", 165, __PRETTY_FUNCTION__
); } while (0)
;
166 r = ordered_hashmap_get(n, "key 4");
167 assert_se(r && streq(r, "val4"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val4"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val4\")"
), "src/test/test-hashmap-ordered.c", 167, __PRETTY_FUNCTION__
); } while (0)
;
168 r = ordered_hashmap_get(m, "key 3");
169 assert_se(!r)do { if ((__builtin_expect(!!(!(!r)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!r"), "src/test/test-hashmap-ordered.c"
, 169, __PRETTY_FUNCTION__); } while (0)
;
170
171 assert_se(ordered_hashmap_move_one(n, m, "key 3") == -EEXIST)do { if ((__builtin_expect(!!(!(ordered_hashmap_move_one(n, m
, "key 3") == -17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_move_one(n, m, \"key 3\") == -EEXIST"), "src/test/test-hashmap-ordered.c"
, 171, __PRETTY_FUNCTION__); } while (0)
;
172
173 ordered_hashmap_free_free(m);
174 ordered_hashmap_free_free(n);
175}
176
177static void test_ordered_hashmap_move(void) {
178 OrderedHashmap *m, *n;
179 char *val1, *val2, *val3, *val4, *r;
180
181 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 181, __func__, "%s", __func__
) : -abs(_e); })
;
182
183 val1 = strdup("val1");
184 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 184, __PRETTY_FUNCTION__); } while (0)
;
185 val2 = strdup("val2");
186 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 186, __PRETTY_FUNCTION__); } while (0)
;
187 val3 = strdup("val3");
188 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 188, __PRETTY_FUNCTION__); } while (0)
;
189 val4 = strdup("val4");
190 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 190, __PRETTY_FUNCTION__); } while (0)
;
191
192 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
193 n = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
194
195 ordered_hashmap_put(n, "key 1", strdup(val1));
196 ordered_hashmap_put(m, "key 1", val1);
197 ordered_hashmap_put(m, "key 2", val2);
198 ordered_hashmap_put(m, "key 3", val3);
199 ordered_hashmap_put(m, "key 4", val4);
200
201 assert_se(ordered_hashmap_move(n, NULL) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_move(n, ((void
*)0)) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"ordered_hashmap_move(n, NULL) == 0"), "src/test/test-hashmap-ordered.c"
, 201, __PRETTY_FUNCTION__); } while (0)
;
202 assert_se(ordered_hashmap_move(n, m) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_move(n, m) ==
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_move(n, m) == 0"
), "src/test/test-hashmap-ordered.c", 202, __PRETTY_FUNCTION__
); } while (0)
;
203
204 assert_se(ordered_hashmap_size(m) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_size(m) == 1)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_size(m) == 1"
), "src/test/test-hashmap-ordered.c", 204, __PRETTY_FUNCTION__
); } while (0)
;
205 r = ordered_hashmap_get(m, "key 1");
206 assert_se(r && streq(r, "val1"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val1"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val1\")"
), "src/test/test-hashmap-ordered.c", 206, __PRETTY_FUNCTION__
); } while (0)
;
207
208 r = ordered_hashmap_get(n, "key 1");
209 assert_se(r && streq(r, "val1"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val1"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val1\")"
), "src/test/test-hashmap-ordered.c", 209, __PRETTY_FUNCTION__
); } while (0)
;
210 r = ordered_hashmap_get(n, "key 2");
211 assert_se(r && streq(r, "val2"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val2"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val2\")"
), "src/test/test-hashmap-ordered.c", 211, __PRETTY_FUNCTION__
); } while (0)
;
212 r = ordered_hashmap_get(n, "key 3");
213 assert_se(r && streq(r, "val3"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val3"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val3\")"
), "src/test/test-hashmap-ordered.c", 213, __PRETTY_FUNCTION__
); } while (0)
;
214 r = ordered_hashmap_get(n, "key 4");
215 assert_se(r && streq(r, "val4"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("val4"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"val4\")"
), "src/test/test-hashmap-ordered.c", 215, __PRETTY_FUNCTION__
); } while (0)
;
216
217 ordered_hashmap_free_free(m);
218 ordered_hashmap_free_free(n);
219}
220
221static void test_ordered_hashmap_update(void) {
222 OrderedHashmap *m;
223 char *val1, *val2, *r;
224
225 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 225, __func__, "%s", __func__
) : -abs(_e); })
;
226
227 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
228 val1 = strdup("old_value");
229 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 229, __PRETTY_FUNCTION__); } while (0)
;
230 val2 = strdup("new_value");
231 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 231, __PRETTY_FUNCTION__); } while (0)
;
232
233 ordered_hashmap_put(m, "key 1", val1);
234 r = ordered_hashmap_get(m, "key 1");
235 assert_se(streq(r, "old_value"))do { if ((__builtin_expect(!!(!((strcmp((r),("old_value")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"old_value\")"
), "src/test/test-hashmap-ordered.c", 235, __PRETTY_FUNCTION__
); } while (0)
;
236
237 assert_se(ordered_hashmap_update(m, "key 2", val2) == -ENOENT)do { if ((__builtin_expect(!!(!(ordered_hashmap_update(m, "key 2"
, val2) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_update(m, \"key 2\", val2) == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 237, __PRETTY_FUNCTION__); } while (0)
;
238 r = ordered_hashmap_get(m, "key 1");
239 assert_se(streq(r, "old_value"))do { if ((__builtin_expect(!!(!((strcmp((r),("old_value")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"old_value\")"
), "src/test/test-hashmap-ordered.c", 239, __PRETTY_FUNCTION__
); } while (0)
;
240
241 assert_se(ordered_hashmap_update(m, "key 1", val2) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_update(m, "key 1"
, val2) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_update(m, \"key 1\", val2) == 0"), "src/test/test-hashmap-ordered.c"
, 241, __PRETTY_FUNCTION__); } while (0)
;
242 r = ordered_hashmap_get(m, "key 1");
243 assert_se(streq(r, "new_value"))do { if ((__builtin_expect(!!(!((strcmp((r),("new_value")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"new_value\")"
), "src/test/test-hashmap-ordered.c", 243, __PRETTY_FUNCTION__
); } while (0)
;
244
245 free(val1);
246 free(val2);
247 ordered_hashmap_free(m);
248}
249
250static void test_ordered_hashmap_put(void) {
251 OrderedHashmap *m = NULL((void*)0);
252 int valid_ordered_hashmap_put;
253 void *val1 = (void*) "val 1";
254 void *val2 = (void*) "val 2";
255 _cleanup_free___attribute__((cleanup(freep))) char* key1 = NULL((void*)0);
256
257 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 257, __func__, "%s", __func__
) : -abs(_e); })
;
258
259 assert_se(ordered_hashmap_ensure_allocated(&m, &string_hash_ops) >= 0)do { if ((__builtin_expect(!!(!(internal_ordered_hashmap_ensure_allocated
(&m, &string_hash_ops ) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ordered_hashmap_ensure_allocated(&m, &string_hash_ops) >= 0"
), "src/test/test-hashmap-ordered.c", 259, __PRETTY_FUNCTION__
); } while (0)
;
260 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
260, __PRETTY_FUNCTION__); } while (0)
;
261
262 valid_ordered_hashmap_put = ordered_hashmap_put(m, "key 1", val1);
263 assert_se(valid_ordered_hashmap_put == 1)do { if ((__builtin_expect(!!(!(valid_ordered_hashmap_put == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("valid_ordered_hashmap_put == 1"
), "src/test/test-hashmap-ordered.c", 263, __PRETTY_FUNCTION__
); } while (0)
;
264 assert_se(ordered_hashmap_put(m, "key 1", val1) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, val1) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", val1) == 0"), "src/test/test-hashmap-ordered.c"
, 264, __PRETTY_FUNCTION__); } while (0)
;
265 assert_se(ordered_hashmap_put(m, "key 1", val2) == -EEXIST)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, val2) == -17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", val2) == -EEXIST"), "src/test/test-hashmap-ordered.c"
, 265, __PRETTY_FUNCTION__); } while (0)
;
266 key1 = strdup("key 1");
267 assert_se(ordered_hashmap_put(m, key1, val1) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, key1, val1
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_put(m, key1, val1) == 0"
), "src/test/test-hashmap-ordered.c", 267, __PRETTY_FUNCTION__
); } while (0)
;
268 assert_se(ordered_hashmap_put(m, key1, val2) == -EEXIST)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, key1, val2
) == -17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_put(m, key1, val2) == -EEXIST"
), "src/test/test-hashmap-ordered.c", 268, __PRETTY_FUNCTION__
); } while (0)
;
269
270 ordered_hashmap_free(m);
271}
272
273static void test_ordered_hashmap_remove(void) {
274 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
275 char *r;
276
277 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 277, __func__, "%s", __func__
) : -abs(_e); })
;
278
279 r = ordered_hashmap_remove(NULL((void*)0), "key 1");
280 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 280, __PRETTY_FUNCTION__); } while (0)
;
281
282 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
283 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
283, __PRETTY_FUNCTION__); } while (0)
;
284
285 r = ordered_hashmap_remove(m, "no such key");
286 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 286, __PRETTY_FUNCTION__); } while (0)
;
287
288 ordered_hashmap_put(m, "key 1", (void*) "val 1");
289 ordered_hashmap_put(m, "key 2", (void*) "val 2");
290
291 r = ordered_hashmap_remove(m, "key 1");
292 assert_se(streq(r, "val 1"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 1")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 1\")"
), "src/test/test-hashmap-ordered.c", 292, __PRETTY_FUNCTION__
); } while (0)
;
293
294 r = ordered_hashmap_get(m, "key 2");
295 assert_se(streq(r, "val 2"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 2")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 2\")"
), "src/test/test-hashmap-ordered.c", 295, __PRETTY_FUNCTION__
); } while (0)
;
296 assert_se(!ordered_hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, "key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, \"key 1\")"
), "src/test/test-hashmap-ordered.c", 296, __PRETTY_FUNCTION__
); } while (0)
;
297}
298
299static void test_ordered_hashmap_remove2(void) {
300 _cleanup_ordered_hashmap_free_free_free___attribute__((cleanup(ordered_hashmap_free_free_freep))) OrderedHashmap *m = NULL((void*)0);
301 char key1[] = "key 1";
302 char key2[] = "key 2";
303 char val1[] = "val 1";
304 char val2[] = "val 2";
305 void *r, *r2;
306
307 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 307, __func__, "%s", __func__
) : -abs(_e); })
;
308
309 r = ordered_hashmap_remove2(NULL((void*)0), "key 1", &r2);
310 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 310, __PRETTY_FUNCTION__); } while (0)
;
311
312 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
313 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
313, __PRETTY_FUNCTION__); } while (0)
;
314
315 r = ordered_hashmap_remove2(m, "no such key", &r2);
316 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 316, __PRETTY_FUNCTION__); } while (0)
;
317
318 ordered_hashmap_put(m, strdup(key1), strdup(val1));
319 ordered_hashmap_put(m, strdup(key2), strdup(val2));
320
321 r = ordered_hashmap_remove2(m, key1, &r2);
322 assert_se(streq(r, val1))do { if ((__builtin_expect(!!(!((strcmp((r),(val1)) == 0))),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, val1)"
), "src/test/test-hashmap-ordered.c", 322, __PRETTY_FUNCTION__
); } while (0)
;
323 assert_se(streq(r2, key1))do { if ((__builtin_expect(!!(!((strcmp((r2),(key1)) == 0))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r2, key1)"
), "src/test/test-hashmap-ordered.c", 323, __PRETTY_FUNCTION__
); } while (0)
;
324 free(r);
325 free(r2);
326
327 r = ordered_hashmap_get(m, key2);
328 assert_se(streq(r, val2))do { if ((__builtin_expect(!!(!((strcmp((r),(val2)) == 0))),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, val2)"
), "src/test/test-hashmap-ordered.c", 328, __PRETTY_FUNCTION__
); } while (0)
;
329 assert_se(!ordered_hashmap_get(m, key1))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, key1)
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, key1)"
), "src/test/test-hashmap-ordered.c", 329, __PRETTY_FUNCTION__
); } while (0)
;
330}
331
332static void test_ordered_hashmap_remove_value(void) {
333 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
334 char *r;
335
336 char val1[] = "val 1";
337 char val2[] = "val 2";
338
339 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 339, __func__, "%s", __func__
) : -abs(_e); })
;
340
341 r = ordered_hashmap_remove_value(NULL((void*)0), "key 1", val1);
342 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 342, __PRETTY_FUNCTION__); } while (0)
;
343
344 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
345 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
345, __PRETTY_FUNCTION__); } while (0)
;
346
347 r = ordered_hashmap_remove_value(m, "key 1", val1);
348 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 348, __PRETTY_FUNCTION__); } while (0)
;
349
350 ordered_hashmap_put(m, "key 1", val1);
351 ordered_hashmap_put(m, "key 2", val2);
352
353 r = ordered_hashmap_remove_value(m, "key 1", val1);
354 assert_se(streq(r, "val 1"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 1")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 1\")"
), "src/test/test-hashmap-ordered.c", 354, __PRETTY_FUNCTION__
); } while (0)
;
355
356 r = ordered_hashmap_get(m, "key 2");
357 assert_se(streq(r, "val 2"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 2")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 2\")"
), "src/test/test-hashmap-ordered.c", 357, __PRETTY_FUNCTION__
); } while (0)
;
358 assert_se(!ordered_hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, "key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, \"key 1\")"
), "src/test/test-hashmap-ordered.c", 358, __PRETTY_FUNCTION__
); } while (0)
;
359
360 r = ordered_hashmap_remove_value(m, "key 2", val1);
361 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 361, __PRETTY_FUNCTION__); } while (0)
;
362
363 r = ordered_hashmap_get(m, "key 2");
364 assert_se(streq(r, "val 2"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 2")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 2\")"
), "src/test/test-hashmap-ordered.c", 364, __PRETTY_FUNCTION__
); } while (0)
;
365 assert_se(!ordered_hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, "key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, \"key 1\")"
), "src/test/test-hashmap-ordered.c", 365, __PRETTY_FUNCTION__
); } while (0)
;
366}
367
368static void test_ordered_hashmap_remove_and_put(void) {
369 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
370 int valid;
371 char *r;
372
373 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 373, __func__, "%s", __func__
) : -abs(_e); })
;
374
375 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
376 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
376, __PRETTY_FUNCTION__); } while (0)
;
377
378 valid = ordered_hashmap_remove_and_put(m, "invalid key", "new key", NULL((void*)0));
379 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 379, __PRETTY_FUNCTION__); } while (0)
;
380
381 valid = ordered_hashmap_put(m, "key 1", (void*) (const char *) "val 1");
382 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "src/test/test-hashmap-ordered.c"
, 382, __PRETTY_FUNCTION__); } while (0)
;
383
384 valid = ordered_hashmap_remove_and_put(NULL((void*)0), "key 1", "key 2", (void*) (const char *) "val 2");
385 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 385, __PRETTY_FUNCTION__); } while (0)
;
386
387 valid = ordered_hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2");
388 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "src/test/test-hashmap-ordered.c"
, 388, __PRETTY_FUNCTION__); } while (0)
;
389
390 r = ordered_hashmap_get(m, "key 2");
391 assert_se(streq(r, "val 2"))do { if ((__builtin_expect(!!(!((strcmp((r),("val 2")) == 0))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, \"val 2\")"
), "src/test/test-hashmap-ordered.c", 391, __PRETTY_FUNCTION__
); } while (0)
;
392 assert_se(!ordered_hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, "key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, \"key 1\")"
), "src/test/test-hashmap-ordered.c", 392, __PRETTY_FUNCTION__
); } while (0)
;
393
394 valid = ordered_hashmap_put(m, "key 3", (void*) (const char *) "val 3");
395 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "src/test/test-hashmap-ordered.c"
, 395, __PRETTY_FUNCTION__); } while (0)
;
396 valid = ordered_hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2");
397 assert_se(valid == -EEXIST)do { if ((__builtin_expect(!!(!(valid == -17)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -EEXIST"), "src/test/test-hashmap-ordered.c"
, 397, __PRETTY_FUNCTION__); } while (0)
;
398}
399
400static void test_ordered_hashmap_remove_and_replace(void) {
401 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
402 int valid;
403 void *key1 = UINT_TO_PTR(1)((void *) ((uintptr_t) (1)));
404 void *key2 = UINT_TO_PTR(2)((void *) ((uintptr_t) (2)));
405 void *key3 = UINT_TO_PTR(3)((void *) ((uintptr_t) (3)));
406 void *r;
407 int i, j;
408
409 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 409, __func__, "%s", __func__
) : -abs(_e); })
;
410
411 m = ordered_hashmap_new(&trivial_hash_ops)internal_ordered_hashmap_new(&trivial_hash_ops );
412 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
412, __PRETTY_FUNCTION__); } while (0)
;
413
414 valid = ordered_hashmap_remove_and_replace(m, key1, key2, NULL((void*)0));
415 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 415, __PRETTY_FUNCTION__); } while (0)
;
416
417 valid = ordered_hashmap_put(m, key1, key1);
418 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "src/test/test-hashmap-ordered.c"
, 418, __PRETTY_FUNCTION__); } while (0)
;
419
420 valid = ordered_hashmap_remove_and_replace(NULL((void*)0), key1, key2, key2);
421 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "src/test/test-hashmap-ordered.c"
, 421, __PRETTY_FUNCTION__); } while (0)
;
422
423 valid = ordered_hashmap_remove_and_replace(m, key1, key2, key2);
424 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "src/test/test-hashmap-ordered.c"
, 424, __PRETTY_FUNCTION__); } while (0)
;
425
426 r = ordered_hashmap_get(m, key2);
427 assert_se(r == key2)do { if ((__builtin_expect(!!(!(r == key2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == key2"), "src/test/test-hashmap-ordered.c"
, 427, __PRETTY_FUNCTION__); } while (0)
;
428 assert_se(!ordered_hashmap_get(m, key1))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, key1)
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, key1)"
), "src/test/test-hashmap-ordered.c", 428, __PRETTY_FUNCTION__
); } while (0)
;
429
430 valid = ordered_hashmap_put(m, key3, key3);
431 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "src/test/test-hashmap-ordered.c"
, 431, __PRETTY_FUNCTION__); } while (0)
;
432 valid = ordered_hashmap_remove_and_replace(m, key3, key2, key2);
433 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "src/test/test-hashmap-ordered.c"
, 433, __PRETTY_FUNCTION__); } while (0)
;
434 r = ordered_hashmap_get(m, key2);
435 assert_se(r == key2)do { if ((__builtin_expect(!!(!(r == key2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == key2"), "src/test/test-hashmap-ordered.c"
, 435, __PRETTY_FUNCTION__); } while (0)
;
436 assert_se(!ordered_hashmap_get(m, key3))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, key3)
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, key3)"
), "src/test/test-hashmap-ordered.c", 436, __PRETTY_FUNCTION__
); } while (0)
;
437
438 /* Repeat this test several times to increase the chance of hitting
439 * the less likely case in ordered_hashmap_remove_and_replace where it
440 * compensates for the backward shift. */
441 for (i = 0; i < 20; i++) {
442 ordered_hashmap_clear(m);
443
444 for (j = 1; j < 7; j++)
445 ordered_hashmap_put(m, UINT_TO_PTR(10*i + j)((void *) ((uintptr_t) (10*i + j))), UINT_TO_PTR(10*i + j)((void *) ((uintptr_t) (10*i + j))));
446 valid = ordered_hashmap_remove_and_replace(m, UINT_TO_PTR(10*i + 1)((void *) ((uintptr_t) (10*i + 1))),
447 UINT_TO_PTR(10*i + 2)((void *) ((uintptr_t) (10*i + 2))),
448 UINT_TO_PTR(10*i + 2)((void *) ((uintptr_t) (10*i + 2))));
449 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "src/test/test-hashmap-ordered.c"
, 449, __PRETTY_FUNCTION__); } while (0)
;
450 assert_se(!ordered_hashmap_get(m, UINT_TO_PTR(10*i + 1)))do { if ((__builtin_expect(!!(!(!ordered_hashmap_get(m, ((void
*) ((uintptr_t) (10*i + 1)))))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!ordered_hashmap_get(m, UINT_TO_PTR(10*i + 1))"
), "src/test/test-hashmap-ordered.c", 450, __PRETTY_FUNCTION__
); } while (0)
;
451 for (j = 2; j < 7; j++) {
452 r = ordered_hashmap_get(m, UINT_TO_PTR(10*i + j)((void *) ((uintptr_t) (10*i + j))));
453 assert_se(r == UINT_TO_PTR(10*i + j))do { if ((__builtin_expect(!!(!(r == ((void *) ((uintptr_t) (
10*i + j))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("r == UINT_TO_PTR(10*i + j)"), "src/test/test-hashmap-ordered.c"
, 453, __PRETTY_FUNCTION__); } while (0)
;
454 }
455 }
456}
457
458static void test_ordered_hashmap_ensure_allocated(void) {
459 OrderedHashmap *m;
460 int valid_ordered_hashmap;
461
462 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 462, __func__, "%s", __func__
) : -abs(_e); })
;
463
464 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
465
466 valid_ordered_hashmap = ordered_hashmap_ensure_allocated(&m, &string_hash_ops)internal_ordered_hashmap_ensure_allocated(&m, &string_hash_ops
)
;
467 assert_se(valid_ordered_hashmap == 0)do { if ((__builtin_expect(!!(!(valid_ordered_hashmap == 0)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("valid_ordered_hashmap == 0"
), "src/test/test-hashmap-ordered.c", 467, __PRETTY_FUNCTION__
); } while (0)
;
468
469 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
469, __PRETTY_FUNCTION__); } while (0)
;
470 ordered_hashmap_free(m);
471}
472
473static void test_ordered_hashmap_foreach_key(void) {
474 OrderedHashmap *m;
475 Iterator i;
476 bool_Bool key_found[] = { false0, false0, false0, false0 };
477 const char *s;
478 const char *key;
479 static const char key_table[] =
480 "key 1\0"
481 "key 2\0"
482 "key 3\0"
483 "key 4\0";
484
485 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 485, __func__, "%s", __func__
) : -abs(_e); })
;
486
487 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
488
489 NULSTR_FOREACH(key, key_table)for ((key) = (key_table); (key) && *(key); (key) = strchr
((key), 0)+1)
490 ordered_hashmap_put(m, key, (void*) (const char*) "my dummy val");
491
492 ORDERED_HASHMAP_FOREACH_KEY(s, key, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((m), &(
i), (void**)&(s), (const void**) &(key)); )
{
493 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "src/test/test-hashmap-ordered.c",
493, __PRETTY_FUNCTION__); } while (0)
;
494 if (!key_found[0] && streq(key, "key 1")(strcmp((key),("key 1")) == 0))
495 key_found[0] = true1;
496 else if (!key_found[1] && streq(key, "key 2")(strcmp((key),("key 2")) == 0))
497 key_found[1] = true1;
498 else if (!key_found[2] && streq(key, "key 3")(strcmp((key),("key 3")) == 0))
499 key_found[2] = true1;
500 else if (!key_found[3] && streq(key, "fail")(strcmp((key),("fail")) == 0))
501 key_found[3] = true1;
502 }
503
504 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
504, __PRETTY_FUNCTION__); } while (0)
;
505 assert_se(key_found[0] && key_found[1] && key_found[2] && !key_found[3])do { if ((__builtin_expect(!!(!(key_found[0] && key_found
[1] && key_found[2] && !key_found[3])),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("key_found[0] && key_found[1] && key_found[2] && !key_found[3]"
), "src/test/test-hashmap-ordered.c", 505, __PRETTY_FUNCTION__
); } while (0)
;
506
507 ordered_hashmap_free(m);
508}
509
510static void test_ordered_hashmap_foreach(void) {
511 OrderedHashmap *m;
512 Iterator i;
513 bool_Bool value_found[] = { false0, false0, false0, false0 };
514 char *val1, *val2, *val3, *val4, *s;
515 unsigned count;
516
517 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 517, __func__, "%s", __func__
) : -abs(_e); })
;
518
519 val1 = strdup("my val1");
520 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 520, __PRETTY_FUNCTION__); } while (0)
;
521 val2 = strdup("my val2");
522 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 522, __PRETTY_FUNCTION__); } while (0)
;
523 val3 = strdup("my val3");
524 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 524, __PRETTY_FUNCTION__); } while (0)
;
525 val4 = strdup("my val4");
526 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 526, __PRETTY_FUNCTION__); } while (0)
;
527
528 m = NULL((void*)0);
529
530 count = 0;
531 ORDERED_HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((m), &(
i), (void**)&(s), ((void*)0)); )
532 count++;
533 assert_se(count == 0)do { if ((__builtin_expect(!!(!(count == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("count == 0"), "src/test/test-hashmap-ordered.c"
, 533, __PRETTY_FUNCTION__); } while (0)
;
534
535 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
536
537 count = 0;
538 ORDERED_HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((m), &(
i), (void**)&(s), ((void*)0)); )
539 count++;
540 assert_se(count == 0)do { if ((__builtin_expect(!!(!(count == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("count == 0"), "src/test/test-hashmap-ordered.c"
, 540, __PRETTY_FUNCTION__); } while (0)
;
541
542 ordered_hashmap_put(m, "Key 1", val1);
543 ordered_hashmap_put(m, "Key 2", val2);
544 ordered_hashmap_put(m, "Key 3", val3);
545 ordered_hashmap_put(m, "Key 4", val4);
546
547 ORDERED_HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((m), &(
i), (void**)&(s), ((void*)0)); )
{
548 if (!value_found[0] && streq(s, val1)(strcmp((s),(val1)) == 0))
549 value_found[0] = true1;
550 else if (!value_found[1] && streq(s, val2)(strcmp((s),(val2)) == 0))
551 value_found[1] = true1;
552 else if (!value_found[2] && streq(s, val3)(strcmp((s),(val3)) == 0))
553 value_found[2] = true1;
554 else if (!value_found[3] && streq(s, val4)(strcmp((s),(val4)) == 0))
555 value_found[3] = true1;
556 }
557
558 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
558, __PRETTY_FUNCTION__); } while (0)
;
559 assert_se(value_found[0] && value_found[1] && value_found[2] && value_found[3])do { if ((__builtin_expect(!!(!(value_found[0] && value_found
[1] && value_found[2] && value_found[3])),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("value_found[0] && value_found[1] && value_found[2] && value_found[3]"
), "src/test/test-hashmap-ordered.c", 559, __PRETTY_FUNCTION__
); } while (0)
;
560
561 ordered_hashmap_free_free(m);
562}
563
564static void test_ordered_hashmap_merge(void) {
565 OrderedHashmap *m;
566 OrderedHashmap *n;
567 char *val1, *val2, *val3, *val4, *r;
568
569 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 569, __func__, "%s", __func__
) : -abs(_e); })
;
570
571 val1 = strdup("my val1");
572 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 572, __PRETTY_FUNCTION__); } while (0)
;
573 val2 = strdup("my val2");
574 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 574, __PRETTY_FUNCTION__); } while (0)
;
575 val3 = strdup("my val3");
576 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 576, __PRETTY_FUNCTION__); } while (0)
;
577 val4 = strdup("my val4");
578 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 578, __PRETTY_FUNCTION__); } while (0)
;
579
580 n = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
581 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
582
583 ordered_hashmap_put(m, "Key 1", val1);
584 ordered_hashmap_put(m, "Key 2", val2);
585 ordered_hashmap_put(n, "Key 3", val3);
586 ordered_hashmap_put(n, "Key 4", val4);
587
588 assert_se(ordered_hashmap_merge(m, n) == 0)do { if ((__builtin_expect(!!(!(internal_hashmap_merge(__builtin_choose_expr
((__builtin_types_compatible_p(typeof(m), Hashmap*) || __builtin_types_compatible_p
(typeof(m), OrderedHashmap*)), (Hashmap*)(m), (void)0), __builtin_choose_expr
((__builtin_types_compatible_p(typeof(n), Hashmap*) || __builtin_types_compatible_p
(typeof(n), OrderedHashmap*)), (Hashmap*)(n), (void)0)) == 0)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_merge(m, n) == 0"
), "src/test/test-hashmap-ordered.c", 588, __PRETTY_FUNCTION__
); } while (0)
;
589 r = ordered_hashmap_get(m, "Key 3");
590 assert_se(r && streq(r, "my val3"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("my val3"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"my val3\")"
), "src/test/test-hashmap-ordered.c", 590, __PRETTY_FUNCTION__
); } while (0)
;
591 r = ordered_hashmap_get(m, "Key 4");
592 assert_se(r && streq(r, "my val4"))do { if ((__builtin_expect(!!(!(r && (strcmp((r),("my val4"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r && streq(r, \"my val4\")"
), "src/test/test-hashmap-ordered.c", 592, __PRETTY_FUNCTION__
); } while (0)
;
593
594 assert_se(n)do { if ((__builtin_expect(!!(!(n)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n"), "src/test/test-hashmap-ordered.c",
594, __PRETTY_FUNCTION__); } while (0)
;
595 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
595, __PRETTY_FUNCTION__); } while (0)
;
596 ordered_hashmap_free(n);
597 ordered_hashmap_free_free(m);
598}
599
600static void test_ordered_hashmap_contains(void) {
601 OrderedHashmap *m;
602 char *val1;
603
604 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 604, __func__, "%s", __func__
) : -abs(_e); })
;
605
606 val1 = strdup("my val");
607 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 607, __PRETTY_FUNCTION__); } while (0)
;
608
609 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
610
611 assert_se(!ordered_hashmap_contains(m, "Key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_contains(m, "Key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_contains(m, \"Key 1\")"
), "src/test/test-hashmap-ordered.c", 611, __PRETTY_FUNCTION__
); } while (0)
;
612 ordered_hashmap_put(m, "Key 1", val1);
613 assert_se(ordered_hashmap_contains(m, "Key 1"))do { if ((__builtin_expect(!!(!(ordered_hashmap_contains(m, "Key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_contains(m, \"Key 1\")"
), "src/test/test-hashmap-ordered.c", 613, __PRETTY_FUNCTION__
); } while (0)
;
614 assert_se(!ordered_hashmap_contains(m, "Key 2"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_contains(m, "Key 2"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_contains(m, \"Key 2\")"
), "src/test/test-hashmap-ordered.c", 614, __PRETTY_FUNCTION__
); } while (0)
;
615
616 assert_se(!ordered_hashmap_contains(NULL, "Key 1"))do { if ((__builtin_expect(!!(!(!ordered_hashmap_contains(((void
*)0), "Key 1"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!ordered_hashmap_contains(NULL, \"Key 1\")"), "src/test/test-hashmap-ordered.c"
, 616, __PRETTY_FUNCTION__); } while (0)
;
617
618 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
618, __PRETTY_FUNCTION__); } while (0)
;
619 ordered_hashmap_free_free(m);
620}
621
622static void test_ordered_hashmap_isempty(void) {
623 OrderedHashmap *m;
624 char *val1;
625
626 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 626, __func__, "%s", __func__
) : -abs(_e); })
;
627
628 val1 = strdup("my val");
629 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 629, __PRETTY_FUNCTION__); } while (0)
;
630
631 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
632
633 assert_se(ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(ordered_hashmap_isempty(m))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 633, __PRETTY_FUNCTION__
); } while (0)
;
634 ordered_hashmap_put(m, "Key 1", val1);
635 assert_se(!ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(!ordered_hashmap_isempty(m)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 635, __PRETTY_FUNCTION__
); } while (0)
;
636
637 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
637, __PRETTY_FUNCTION__); } while (0)
;
638 ordered_hashmap_free_free(m);
639}
640
641static void test_ordered_hashmap_size(void) {
642 OrderedHashmap *m;
643 char *val1, *val2, *val3, *val4;
644
645 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 645, __func__, "%s", __func__
) : -abs(_e); })
;
646
647 val1 = strdup("my val");
648 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "src/test/test-hashmap-ordered.c"
, 648, __PRETTY_FUNCTION__); } while (0)
;
649 val2 = strdup("my val");
650 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "src/test/test-hashmap-ordered.c"
, 650, __PRETTY_FUNCTION__); } while (0)
;
651 val3 = strdup("my val");
652 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "src/test/test-hashmap-ordered.c"
, 652, __PRETTY_FUNCTION__); } while (0)
;
653 val4 = strdup("my val");
654 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "src/test/test-hashmap-ordered.c"
, 654, __PRETTY_FUNCTION__); } while (0)
;
655
656 assert_se(ordered_hashmap_size(NULL) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_size(((void*)
0)) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_size(NULL) == 0"
), "src/test/test-hashmap-ordered.c", 656, __PRETTY_FUNCTION__
); } while (0)
;
657 assert_se(ordered_hashmap_buckets(NULL) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_buckets(((void
*)0)) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"ordered_hashmap_buckets(NULL) == 0"), "src/test/test-hashmap-ordered.c"
, 657, __PRETTY_FUNCTION__); } while (0)
;
658
659 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
660
661 ordered_hashmap_put(m, "Key 1", val1);
662 ordered_hashmap_put(m, "Key 2", val2);
663 ordered_hashmap_put(m, "Key 3", val3);
664 ordered_hashmap_put(m, "Key 4", val4);
665
666 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
666, __PRETTY_FUNCTION__); } while (0)
;
667 assert_se(ordered_hashmap_size(m) == 4)do { if ((__builtin_expect(!!(!(ordered_hashmap_size(m) == 4)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_size(m) == 4"
), "src/test/test-hashmap-ordered.c", 667, __PRETTY_FUNCTION__
); } while (0)
;
668 assert_se(ordered_hashmap_buckets(m) >= 4)do { if ((__builtin_expect(!!(!(ordered_hashmap_buckets(m) >=
4)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_buckets(m) >= 4"
), "src/test/test-hashmap-ordered.c", 668, __PRETTY_FUNCTION__
); } while (0)
;
669 ordered_hashmap_free_free(m);
670}
671
672static void test_ordered_hashmap_get(void) {
673 OrderedHashmap *m;
674 char *r;
675 char *val;
676
677 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 677, __func__, "%s", __func__
) : -abs(_e); })
;
678
679 val = strdup("my val");
680 assert_se(val)do { if ((__builtin_expect(!!(!(val)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val"), "src/test/test-hashmap-ordered.c"
, 680, __PRETTY_FUNCTION__); } while (0)
;
681
682 r = ordered_hashmap_get(NULL((void*)0), "Key 1");
683 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 683, __PRETTY_FUNCTION__); } while (0)
;
684
685 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
686
687 ordered_hashmap_put(m, "Key 1", val);
688
689 r = ordered_hashmap_get(m, "Key 1");
690 assert_se(streq(r, val))do { if ((__builtin_expect(!!(!((strcmp((r),(val)) == 0))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, val)"
), "src/test/test-hashmap-ordered.c", 690, __PRETTY_FUNCTION__
); } while (0)
;
691
692 r = ordered_hashmap_get(m, "no such key");
693 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 693, __PRETTY_FUNCTION__); } while (0)
;
694
695 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
695, __PRETTY_FUNCTION__); } while (0)
;
696 ordered_hashmap_free_free(m);
697}
698
699static void test_ordered_hashmap_get2(void) {
700 OrderedHashmap *m;
701 char *r;
702 char *val;
703 char key_orig[] = "Key 1";
704 void *key_copy;
705
706 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 706, __func__, "%s", __func__
) : -abs(_e); })
;
707
708 val = strdup("my val");
709 assert_se(val)do { if ((__builtin_expect(!!(!(val)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val"), "src/test/test-hashmap-ordered.c"
, 709, __PRETTY_FUNCTION__); } while (0)
;
710
711 key_copy = strdup(key_orig);
712 assert_se(key_copy)do { if ((__builtin_expect(!!(!(key_copy)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("key_copy"), "src/test/test-hashmap-ordered.c"
, 712, __PRETTY_FUNCTION__); } while (0)
;
713
714 r = ordered_hashmap_get2(NULL((void*)0), key_orig, &key_copy);
715 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 715, __PRETTY_FUNCTION__); } while (0)
;
716
717 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
718
719 ordered_hashmap_put(m, key_copy, val);
720 key_copy = NULL((void*)0);
721
722 r = ordered_hashmap_get2(m, key_orig, &key_copy);
723 assert_se(streq(r, val))do { if ((__builtin_expect(!!(!((strcmp((r),(val)) == 0))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(r, val)"
), "src/test/test-hashmap-ordered.c", 723, __PRETTY_FUNCTION__
); } while (0)
;
724 assert_se(key_orig != key_copy)do { if ((__builtin_expect(!!(!(key_orig != key_copy)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("key_orig != key_copy"), "src/test/test-hashmap-ordered.c"
, 724, __PRETTY_FUNCTION__); } while (0)
;
725 assert_se(streq(key_orig, key_copy))do { if ((__builtin_expect(!!(!((strcmp((key_orig),(key_copy)
) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(key_orig, key_copy)"
), "src/test/test-hashmap-ordered.c", 725, __PRETTY_FUNCTION__
); } while (0)
;
726
727 r = ordered_hashmap_get2(m, "no such key", NULL((void*)0));
728 assert_se(r == NULL)do { if ((__builtin_expect(!!(!(r == ((void*)0))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == NULL"), "src/test/test-hashmap-ordered.c"
, 728, __PRETTY_FUNCTION__); } while (0)
;
729
730 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
730, __PRETTY_FUNCTION__); } while (0)
;
731 ordered_hashmap_free_free_free(m);
732}
733
734static void crippled_ordered_hashmap_func(const void *p, struct siphash *state) {
735 return trivial_hash_func(INT_TO_PTR(PTR_TO_INT(p) & 0xff)((void *) ((intptr_t) (((int) ((intptr_t) (p))) & 0xff))), state);
736}
737
738static const struct hash_ops crippled_ordered_hashmap_ops = {
739 .hash = crippled_ordered_hashmap_func,
740 .compare = trivial_compare_func,
741};
742
743static void test_ordered_hashmap_many(void) {
744 OrderedHashmap *h;
745 unsigned i, j;
746 void *v, *k;
747 const struct {
748 const struct hash_ops *ops;
749 unsigned n_entries;
750 } tests[] = {
751 { .ops = NULL((void*)0), .n_entries = arg_slow ? 1 << 20 : 240 },
752 { .ops = &crippled_ordered_hashmap_ops, .n_entries = arg_slow ? 1 << 14 : 140 },
753 };
754
755 log_info("%s (%s)", __func__, arg_slow ? "slow" : "fast")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 755, __func__, "%s (%s)"
, __func__, arg_slow ? "slow" : "fast") : -abs(_e); })
;
756
757 for (j = 0; j < ELEMENTSOF(tests)__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(tests), typeof(&*(tests))), sizeof(tests)/sizeof(
(tests)[0]), ((void)0)))
; j++) {
758 assert_se(h = ordered_hashmap_new(tests[j].ops))do { if ((__builtin_expect(!!(!(h = internal_ordered_hashmap_new
(tests[j].ops ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("h = ordered_hashmap_new(tests[j].ops)"), "src/test/test-hashmap-ordered.c"
, 758, __PRETTY_FUNCTION__); } while (0)
;
759
760 for (i = 1; i < tests[j].n_entries*3; i+=3) {
761 assert_se(ordered_hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(h, ((void
*) ((uintptr_t) (i))), ((void *) ((uintptr_t) (i)))) >= 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0"
), "src/test/test-hashmap-ordered.c", 761, __PRETTY_FUNCTION__
); } while (0)
;
762 assert_se(PTR_TO_UINT(ordered_hashmap_get(h, UINT_TO_PTR(i))) == i)do { if ((__builtin_expect(!!(!(((unsigned int) ((uintptr_t) (
ordered_hashmap_get(h, ((void *) ((uintptr_t) (i))))))) == i)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("PTR_TO_UINT(ordered_hashmap_get(h, UINT_TO_PTR(i))) == i"
), "src/test/test-hashmap-ordered.c", 762, __PRETTY_FUNCTION__
); } while (0)
;
763 }
764
765 for (i = 1; i < tests[j].n_entries*3; i++)
766 assert_se(ordered_hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1))do { if ((__builtin_expect(!!(!(ordered_hashmap_contains(h, (
(void *) ((uintptr_t) (i)))) == (i % 3 == 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ordered_hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1)"
), "src/test/test-hashmap-ordered.c", 766, __PRETTY_FUNCTION__
); } while (0)
;
767
768 log_info("%u <= %u * 0.8 = %g", ordered_hashmap_size(h), ordered_hashmap_buckets(h), ordered_hashmap_buckets(h) * 0.8)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 768, __func__, "%u <= %u * 0.8 = %g"
, ordered_hashmap_size(h), ordered_hashmap_buckets(h), ordered_hashmap_buckets
(h) * 0.8) : -abs(_e); })
;
769
770 assert_se(ordered_hashmap_size(h) <= ordered_hashmap_buckets(h) * 0.8)do { if ((__builtin_expect(!!(!(ordered_hashmap_size(h) <=
ordered_hashmap_buckets(h) * 0.8)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ordered_hashmap_size(h) <= ordered_hashmap_buckets(h) * 0.8"
), "src/test/test-hashmap-ordered.c", 770, __PRETTY_FUNCTION__
); } while (0)
;
771 assert_se(ordered_hashmap_size(h) == tests[j].n_entries)do { if ((__builtin_expect(!!(!(ordered_hashmap_size(h) == tests
[j].n_entries)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_size(h) == tests[j].n_entries"), "src/test/test-hashmap-ordered.c"
, 771, __PRETTY_FUNCTION__); } while (0)
;
772
773 while (!ordered_hashmap_isempty(h)) {
774 k = ordered_hashmap_first_key(h);
775 v = ordered_hashmap_remove(h, k);
776 assert_se(v == k)do { if ((__builtin_expect(!!(!(v == k)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("v == k"), "src/test/test-hashmap-ordered.c"
, 776, __PRETTY_FUNCTION__); } while (0)
;
777 }
778
779 ordered_hashmap_free(h);
780 }
781}
782
783static void test_ordered_hashmap_first(void) {
784 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
785
786 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 786, __func__, "%s", __func__
) : -abs(_e); })
;
787
788 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
789 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
789, __PRETTY_FUNCTION__); } while (0)
;
790
791 assert_se(!ordered_hashmap_first(m))do { if ((__builtin_expect(!!(!(!ordered_hashmap_first(m))),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_first(m)"
), "src/test/test-hashmap-ordered.c", 791, __PRETTY_FUNCTION__
); } while (0)
;
792 assert_se(ordered_hashmap_put(m, "key 1", (void*) "val 1") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, (void*) "val 1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", (void*) \"val 1\") == 1"
), "src/test/test-hashmap-ordered.c", 792, __PRETTY_FUNCTION__
); } while (0)
;
793 assert_se(streq(ordered_hashmap_first(m), "val 1"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first
(m)),("val 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first(m), \"val 1\")"), "src/test/test-hashmap-ordered.c"
, 793, __PRETTY_FUNCTION__); } while (0)
;
794 assert_se(ordered_hashmap_put(m, "key 2", (void*) "val 2") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 2"
, (void*) "val 2") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 2\", (void*) \"val 2\") == 1"
), "src/test/test-hashmap-ordered.c", 794, __PRETTY_FUNCTION__
); } while (0)
;
795#ifdef ORDERED
796 assert_se(streq(ordered_hashmap_first(m), "val 1"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first
(m)),("val 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first(m), \"val 1\")"), "src/test/test-hashmap-ordered.c"
, 796, __PRETTY_FUNCTION__); } while (0)
;
797 assert_se(ordered_hashmap_remove(m, "key 1"))do { if ((__builtin_expect(!!(!(ordered_hashmap_remove(m, "key 1"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_remove(m, \"key 1\")"
), "src/test/test-hashmap-ordered.c", 797, __PRETTY_FUNCTION__
); } while (0)
;
798 assert_se(streq(ordered_hashmap_first(m), "val 2"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first
(m)),("val 2")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first(m), \"val 2\")"), "src/test/test-hashmap-ordered.c"
, 798, __PRETTY_FUNCTION__); } while (0)
;
799#endif
800}
801
802static void test_ordered_hashmap_first_key(void) {
803 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
804
805 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 805, __func__, "%s", __func__
) : -abs(_e); })
;
806
807 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
808 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
808, __PRETTY_FUNCTION__); } while (0)
;
809
810 assert_se(!ordered_hashmap_first_key(m))do { if ((__builtin_expect(!!(!(!ordered_hashmap_first_key(m)
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_first_key(m)"
), "src/test/test-hashmap-ordered.c", 810, __PRETTY_FUNCTION__
); } while (0)
;
811 assert_se(ordered_hashmap_put(m, "key 1", NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 811, __PRETTY_FUNCTION__); } while (0)
;
812 assert_se(streq(ordered_hashmap_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first_key
(m)),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first_key(m), \"key 1\")"), "src/test/test-hashmap-ordered.c"
, 812, __PRETTY_FUNCTION__); } while (0)
;
813 assert_se(ordered_hashmap_put(m, "key 2", NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 2"
, ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 2\", NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 813, __PRETTY_FUNCTION__); } while (0)
;
814#ifdef ORDERED
815 assert_se(streq(ordered_hashmap_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first_key
(m)),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first_key(m), \"key 1\")"), "src/test/test-hashmap-ordered.c"
, 815, __PRETTY_FUNCTION__); } while (0)
;
816 assert_se(ordered_hashmap_remove(m, "key 1") == NULL)do { if ((__builtin_expect(!!(!(ordered_hashmap_remove(m, "key 1"
) == ((void*)0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_remove(m, \"key 1\") == NULL"), "src/test/test-hashmap-ordered.c"
, 816, __PRETTY_FUNCTION__); } while (0)
;
817 assert_se(streq(ordered_hashmap_first_key(m), "key 2"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_first_key
(m)),("key 2")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_first_key(m), \"key 2\")"), "src/test/test-hashmap-ordered.c"
, 817, __PRETTY_FUNCTION__); } while (0)
;
818#endif
819}
820
821static void test_ordered_hashmap_steal_first_key(void) {
822 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
823
824 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 824, __func__, "%s", __func__
) : -abs(_e); })
;
825
826 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
827 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
827, __PRETTY_FUNCTION__); } while (0)
;
828
829 assert_se(!ordered_hashmap_steal_first_key(m))do { if ((__builtin_expect(!!(!(!ordered_hashmap_steal_first_key
(m))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ordered_hashmap_steal_first_key(m)"
), "src/test/test-hashmap-ordered.c", 829, __PRETTY_FUNCTION__
); } while (0)
;
830 assert_se(ordered_hashmap_put(m, "key 1", NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 830, __PRETTY_FUNCTION__); } while (0)
;
831 assert_se(streq(ordered_hashmap_steal_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((ordered_hashmap_steal_first_key
(m)),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(ordered_hashmap_steal_first_key(m), \"key 1\")"), "src/test/test-hashmap-ordered.c"
, 831, __PRETTY_FUNCTION__); } while (0)
;
832
833 assert_se(ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(ordered_hashmap_isempty(m))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 833, __PRETTY_FUNCTION__
); } while (0)
;
834}
835
836static void test_ordered_hashmap_steal_first(void) {
837 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
838 int seen[3] = {};
839 char *val;
840
841 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 841, __func__, "%s", __func__
) : -abs(_e); })
;
842
843 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
844 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
844, __PRETTY_FUNCTION__); } while (0)
;
845
846 assert_se(ordered_hashmap_put(m, "key 1", (void*) "1") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, (void*) "1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", (void*) \"1\") == 1"), "src/test/test-hashmap-ordered.c"
, 846, __PRETTY_FUNCTION__); } while (0)
;
847 assert_se(ordered_hashmap_put(m, "key 2", (void*) "22") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 2"
, (void*) "22") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 2\", (void*) \"22\") == 1"),
"src/test/test-hashmap-ordered.c", 847, __PRETTY_FUNCTION__)
; } while (0)
;
848 assert_se(ordered_hashmap_put(m, "key 3", (void*) "333") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 3"
, (void*) "333") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 3\", (void*) \"333\") == 1")
, "src/test/test-hashmap-ordered.c", 848, __PRETTY_FUNCTION__
); } while (0)
;
849
850 while ((val = ordered_hashmap_steal_first(m)))
851 seen[strlen(val) - 1]++;
852
853 assert_se(seen[0] == 1 && seen[1] == 1 && seen[2] == 1)do { if ((__builtin_expect(!!(!(seen[0] == 1 && seen[
1] == 1 && seen[2] == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("seen[0] == 1 && seen[1] == 1 && seen[2] == 1"
), "src/test/test-hashmap-ordered.c", 853, __PRETTY_FUNCTION__
); } while (0)
;
854
855 assert_se(ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(ordered_hashmap_isempty(m))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 855, __PRETTY_FUNCTION__
); } while (0)
;
856}
857
858static void test_ordered_hashmap_clear_free_free(void) {
859 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
860
861 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 861, __func__, "%s", __func__
) : -abs(_e); })
;
4
Assuming the condition is false
5
'?' condition is false
862
863 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
864 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "src/test/test-hashmap-ordered.c",
864, __PRETTY_FUNCTION__); } while (0)
;
6
Assuming 'm' is non-null
7
Taking false branch
8
Loop condition is false. Exiting loop
865
866 assert_se(ordered_hashmap_put(m, strdup("key 1"), NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, strdup
("key 1"), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, strdup(\"key 1\"), NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 866, __PRETTY_FUNCTION__); } while (0)
;
9
Assuming the condition is true
10
Taking false branch
11
Loop condition is false. Exiting loop
867 assert_se(ordered_hashmap_put(m, strdup("key 2"), NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, strdup
("key 2"), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, strdup(\"key 2\"), NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 867, __PRETTY_FUNCTION__); } while (0)
;
12
Assuming the condition is true
13
Taking false branch
14
Loop condition is false. Exiting loop
868 assert_se(ordered_hashmap_put(m, strdup("key 3"), NULL) == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, strdup
("key 3"), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, strdup(\"key 3\"), NULL) == 1"), "src/test/test-hashmap-ordered.c"
, 868, __PRETTY_FUNCTION__); } while (0)
;
15
Memory is allocated
16
Assuming the condition is true
17
Potential memory leak
869
870 ordered_hashmap_clear_free_free(m);
871 assert_se(ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(ordered_hashmap_isempty(m))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 871, __PRETTY_FUNCTION__
); } while (0)
;
872}
873
874static void test_ordered_hashmap_reserve(void) {
875 _cleanup_ordered_hashmap_free___attribute__((cleanup(ordered_hashmap_freep))) OrderedHashmap *m = NULL((void*)0);
876
877 log_info("%s", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "src/test/test-hashmap-ordered.c", 877, __func__, "%s", __func__
) : -abs(_e); })
;
878
879 m = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
880
881 assert_se(ordered_hashmap_reserve(m, 1) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_reserve(m, 1)
== 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_reserve(m, 1) == 0"
), "src/test/test-hashmap-ordered.c", 881, __PRETTY_FUNCTION__
); } while (0)
;
882 assert_se(ordered_hashmap_buckets(m) < 1000)do { if ((__builtin_expect(!!(!(ordered_hashmap_buckets(m) <
1000)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_buckets(m) < 1000"
), "src/test/test-hashmap-ordered.c", 882, __PRETTY_FUNCTION__
); } while (0)
;
883 assert_se(ordered_hashmap_reserve(m, 1000) == 0)do { if ((__builtin_expect(!!(!(ordered_hashmap_reserve(m, 1000
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_reserve(m, 1000) == 0"
), "src/test/test-hashmap-ordered.c", 883, __PRETTY_FUNCTION__
); } while (0)
;
884 assert_se(ordered_hashmap_buckets(m) >= 1000)do { if ((__builtin_expect(!!(!(ordered_hashmap_buckets(m) >=
1000)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_buckets(m) >= 1000"
), "src/test/test-hashmap-ordered.c", 884, __PRETTY_FUNCTION__
); } while (0)
;
885 assert_se(ordered_hashmap_isempty(m))do { if ((__builtin_expect(!!(!(ordered_hashmap_isempty(m))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ordered_hashmap_isempty(m)"
), "src/test/test-hashmap-ordered.c", 885, __PRETTY_FUNCTION__
); } while (0)
;
886
887 assert_se(ordered_hashmap_put(m, "key 1", (void*) "val 1") == 1)do { if ((__builtin_expect(!!(!(ordered_hashmap_put(m, "key 1"
, (void*) "val 1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_put(m, \"key 1\", (void*) \"val 1\") == 1"
), "src/test/test-hashmap-ordered.c", 887, __PRETTY_FUNCTION__
); } while (0)
;
888
889 assert_se(ordered_hashmap_reserve(m, UINT_MAX) == -ENOMEM)do { if ((__builtin_expect(!!(!(ordered_hashmap_reserve(m, (2147483647
*2U +1U)) == -12)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_reserve(m, UINT_MAX) == -ENOMEM"), "src/test/test-hashmap-ordered.c"
, 889, __PRETTY_FUNCTION__); } while (0)
;
890 assert_se(ordered_hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM)do { if ((__builtin_expect(!!(!(ordered_hashmap_reserve(m, (2147483647
*2U +1U) - 1) == -12)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ordered_hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM"), "src/test/test-hashmap-ordered.c"
, 890, __PRETTY_FUNCTION__); } while (0)
;
891}
892
893void test_ordered_hashmap_funcs(void) {
894 int r;
895
896 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
897 log_open();
898
899 r = getenv_bool("SYSTEMD_SLOW_TESTS");
900 arg_slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT0;
1
Assuming 'r' is < 0
2
'?' condition is false
901
902 test_ordered_hashmap_copy();
903 test_ordered_hashmap_get_strv();
904 test_ordered_hashmap_move_one();
905 test_ordered_hashmap_move();
906 test_ordered_hashmap_replace();
907 test_ordered_hashmap_update();
908 test_ordered_hashmap_put();
909 test_ordered_hashmap_remove();
910 test_ordered_hashmap_remove2();
911 test_ordered_hashmap_remove_value();
912 test_ordered_hashmap_remove_and_put();
913 test_ordered_hashmap_remove_and_replace();
914 test_ordered_hashmap_ensure_allocated();
915 test_ordered_hashmap_foreach();
916 test_ordered_hashmap_foreach_key();
917 test_ordered_hashmap_contains();
918 test_ordered_hashmap_merge();
919 test_ordered_hashmap_isempty();
920 test_ordered_hashmap_get();
921 test_ordered_hashmap_get2();
922 test_ordered_hashmap_size();
923 test_ordered_hashmap_many();
924 test_ordered_hashmap_first();
925 test_ordered_hashmap_first_key();
926 test_ordered_hashmap_steal_first_key();
927 test_ordered_hashmap_steal_first();
928 test_ordered_hashmap_clear_free_free();
3
Calling 'test_ordered_hashmap_clear_free_free'
929 test_ordered_hashmap_reserve();
930}