Bug Summary

File:build-scan/../src/test/test-hashmap-plain.c
Warning:line 864, 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-plain.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-plain.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2/***
3 Copyright © 2013 Daniel Buch
4***/
5
6#include "alloc-util.h"
7#include "env-util.h"
8#include "hashmap.h"
9#include "log.h"
10#include "string-util.h"
11#include "strv.h"
12#include "util.h"
13
14static bool_Bool arg_slow = false0;
15
16void test_hashmap_funcs(void);
17
18static void test_hashmap_replace(void) {
19 Hashmap *m;
20 char *val1, *val2, *val3, *val4, *val5, *r;
21
22 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-plain.c", 22, __func__, "%s", __func__
) : -abs(_e); })
;
23
24 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
25
26 val1 = strdup("val1");
27 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 27, __PRETTY_FUNCTION__); } while (0)
;
28 val2 = strdup("val2");
29 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 29, __PRETTY_FUNCTION__); } while (0)
;
30 val3 = strdup("val3");
31 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 31, __PRETTY_FUNCTION__); } while (0)
;
32 val4 = strdup("val4");
33 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 33, __PRETTY_FUNCTION__); } while (0)
;
34 val5 = strdup("val5");
35 assert_se(val5)do { if ((__builtin_expect(!!(!(val5)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val5"), "../src/test/test-hashmap-plain.c"
, 35, __PRETTY_FUNCTION__); } while (0)
;
36
37 hashmap_put(m, "key 1", val1);
38 hashmap_put(m, "key 2", val2);
39 hashmap_put(m, "key 3", val3);
40 hashmap_put(m, "key 4", val4);
41
42 hashmap_replace(m, "key 3", val1);
43 r = hashmap_get(m, "key 3");
44 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-plain.c", 44, __PRETTY_FUNCTION__
); } while (0)
;
45
46 hashmap_replace(m, "key 5", val5);
47 r = hashmap_get(m, "key 5");
48 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-plain.c", 48, __PRETTY_FUNCTION__
); } while (0)
;
49
50 free(val1);
51 free(val2);
52 free(val3);
53 free(val4);
54 free(val5);
55 hashmap_free(m);
56}
57
58static void test_hashmap_copy(void) {
59 Hashmap *m, *copy;
60 char *val1, *val2, *val3, *val4, *r;
61
62 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-plain.c", 62, __func__, "%s", __func__
) : -abs(_e); })
;
63
64 val1 = strdup("val1");
65 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 65, __PRETTY_FUNCTION__); } while (0)
;
66 val2 = strdup("val2");
67 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 67, __PRETTY_FUNCTION__); } while (0)
;
68 val3 = strdup("val3");
69 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 69, __PRETTY_FUNCTION__); } while (0)
;
70 val4 = strdup("val4");
71 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 71, __PRETTY_FUNCTION__); } while (0)
;
72
73 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
74
75 hashmap_put(m, "key 1", val1);
76 hashmap_put(m, "key 2", val2);
77 hashmap_put(m, "key 3", val3);
78 hashmap_put(m, "key 4", val4);
79
80 copy = hashmap_copy(m);
81
82 r = hashmap_get(copy, "key 1");
83 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-plain.c", 83, __PRETTY_FUNCTION__
); } while (0)
;
84 r = hashmap_get(copy, "key 2");
85 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-plain.c", 85, __PRETTY_FUNCTION__
); } while (0)
;
86 r = hashmap_get(copy, "key 3");
87 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-plain.c", 87, __PRETTY_FUNCTION__
); } while (0)
;
88 r = hashmap_get(copy, "key 4");
89 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-plain.c", 89, __PRETTY_FUNCTION__
); } while (0)
;
90
91 hashmap_free_free(copy);
92 hashmap_free(m);
93}
94
95static void test_hashmap_get_strv(void) {
96 Hashmap *m;
97 char **strv;
98 char *val1, *val2, *val3, *val4;
99
100 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-plain.c", 100, __func__, "%s", __func__
) : -abs(_e); })
;
101
102 val1 = strdup("val1");
103 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 103, __PRETTY_FUNCTION__); } while (0)
;
104 val2 = strdup("val2");
105 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 105, __PRETTY_FUNCTION__); } while (0)
;
106 val3 = strdup("val3");
107 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 107, __PRETTY_FUNCTION__); } while (0)
;
108 val4 = strdup("val4");
109 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 109, __PRETTY_FUNCTION__); } while (0)
;
110
111 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
112
113 hashmap_put(m, "key 1", val1);
114 hashmap_put(m, "key 2", val2);
115 hashmap_put(m, "key 3", val3);
116 hashmap_put(m, "key 4", val4);
117
118 strv = hashmap_get_strv(m);
119
120#ifndef ORDERED
121 strv = strv_sort(strv);
122#endif
123
124 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-plain.c", 124, __PRETTY_FUNCTION__
); } while (0)
;
125 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-plain.c", 125, __PRETTY_FUNCTION__
); } while (0)
;
126 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-plain.c", 126, __PRETTY_FUNCTION__
); } while (0)
;
127 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-plain.c", 127, __PRETTY_FUNCTION__
); } while (0)
;
128
129 strv_free(strv);
130
131 hashmap_free(m);
132}
133
134static void test_hashmap_move_one(void) {
135 Hashmap *m, *n;
136 char *val1, *val2, *val3, *val4, *r;
137
138 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-plain.c", 138, __func__, "%s", __func__
) : -abs(_e); })
;
139
140 val1 = strdup("val1");
141 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 141, __PRETTY_FUNCTION__); } while (0)
;
142 val2 = strdup("val2");
143 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 143, __PRETTY_FUNCTION__); } while (0)
;
144 val3 = strdup("val3");
145 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 145, __PRETTY_FUNCTION__); } while (0)
;
146 val4 = strdup("val4");
147 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 147, __PRETTY_FUNCTION__); } while (0)
;
148
149 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
150 n = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
151
152 hashmap_put(m, "key 1", val1);
153 hashmap_put(m, "key 2", val2);
154 hashmap_put(m, "key 3", val3);
155 hashmap_put(m, "key 4", val4);
156
157 assert_se(hashmap_move_one(n, NULL, "key 3") == -ENOENT)do { if ((__builtin_expect(!!(!(hashmap_move_one(n, ((void*)0
), "key 3") == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_move_one(n, NULL, \"key 3\") == -ENOENT"), "../src/test/test-hashmap-plain.c"
, 157, __PRETTY_FUNCTION__); } while (0)
;
158 assert_se(hashmap_move_one(n, m, "key 5") == -ENOENT)do { if ((__builtin_expect(!!(!(hashmap_move_one(n, m, "key 5"
) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move_one(n, m, \"key 5\") == -ENOENT"
), "../src/test/test-hashmap-plain.c", 158, __PRETTY_FUNCTION__
); } while (0)
;
159 assert_se(hashmap_move_one(n, m, "key 3") == 0)do { if ((__builtin_expect(!!(!(hashmap_move_one(n, m, "key 3"
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move_one(n, m, \"key 3\") == 0"
), "../src/test/test-hashmap-plain.c", 159, __PRETTY_FUNCTION__
); } while (0)
;
160 assert_se(hashmap_move_one(n, m, "key 4") == 0)do { if ((__builtin_expect(!!(!(hashmap_move_one(n, m, "key 4"
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move_one(n, m, \"key 4\") == 0"
), "../src/test/test-hashmap-plain.c", 160, __PRETTY_FUNCTION__
); } while (0)
;
161
162 r = hashmap_get(n, "key 3");
163 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-plain.c", 163, __PRETTY_FUNCTION__
); } while (0)
;
164 r = hashmap_get(n, "key 4");
165 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-plain.c", 165, __PRETTY_FUNCTION__
); } while (0)
;
166 r = hashmap_get(m, "key 3");
167 assert_se(!r)do { if ((__builtin_expect(!!(!(!r)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!r"), "../src/test/test-hashmap-plain.c"
, 167, __PRETTY_FUNCTION__); } while (0)
;
168
169 assert_se(hashmap_move_one(n, m, "key 3") == -EEXIST)do { if ((__builtin_expect(!!(!(hashmap_move_one(n, m, "key 3"
) == -17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move_one(n, m, \"key 3\") == -EEXIST"
), "../src/test/test-hashmap-plain.c", 169, __PRETTY_FUNCTION__
); } while (0)
;
170
171 hashmap_free_free(m);
172 hashmap_free_free(n);
173}
174
175static void test_hashmap_move(void) {
176 Hashmap *m, *n;
177 char *val1, *val2, *val3, *val4, *r;
178
179 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-plain.c", 179, __func__, "%s", __func__
) : -abs(_e); })
;
180
181 val1 = strdup("val1");
182 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 182, __PRETTY_FUNCTION__); } while (0)
;
183 val2 = strdup("val2");
184 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 184, __PRETTY_FUNCTION__); } while (0)
;
185 val3 = strdup("val3");
186 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 186, __PRETTY_FUNCTION__); } while (0)
;
187 val4 = strdup("val4");
188 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 188, __PRETTY_FUNCTION__); } while (0)
;
189
190 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
191 n = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
192
193 hashmap_put(n, "key 1", strdup(val1));
194 hashmap_put(m, "key 1", val1);
195 hashmap_put(m, "key 2", val2);
196 hashmap_put(m, "key 3", val3);
197 hashmap_put(m, "key 4", val4);
198
199 assert_se(hashmap_move(n, NULL) == 0)do { if ((__builtin_expect(!!(!(hashmap_move(n, ((void*)0)) ==
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move(n, NULL) == 0"
), "../src/test/test-hashmap-plain.c", 199, __PRETTY_FUNCTION__
); } while (0)
;
200 assert_se(hashmap_move(n, m) == 0)do { if ((__builtin_expect(!!(!(hashmap_move(n, m) == 0)),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_move(n, m) == 0"
), "../src/test/test-hashmap-plain.c", 200, __PRETTY_FUNCTION__
); } while (0)
;
201
202 assert_se(hashmap_size(m) == 1)do { if ((__builtin_expect(!!(!(hashmap_size(m) == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_size(m) == 1"), "../src/test/test-hashmap-plain.c"
, 202, __PRETTY_FUNCTION__); } while (0)
;
203 r = hashmap_get(m, "key 1");
204 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-plain.c", 204, __PRETTY_FUNCTION__
); } while (0)
;
205
206 r = hashmap_get(n, "key 1");
207 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-plain.c", 207, __PRETTY_FUNCTION__
); } while (0)
;
208 r = hashmap_get(n, "key 2");
209 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-plain.c", 209, __PRETTY_FUNCTION__
); } while (0)
;
210 r = hashmap_get(n, "key 3");
211 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-plain.c", 211, __PRETTY_FUNCTION__
); } while (0)
;
212 r = hashmap_get(n, "key 4");
213 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-plain.c", 213, __PRETTY_FUNCTION__
); } while (0)
;
214
215 hashmap_free_free(m);
216 hashmap_free_free(n);
217}
218
219static void test_hashmap_update(void) {
220 Hashmap *m;
221 char *val1, *val2, *r;
222
223 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-plain.c", 223, __func__, "%s", __func__
) : -abs(_e); })
;
224
225 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
226 val1 = strdup("old_value");
227 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 227, __PRETTY_FUNCTION__); } while (0)
;
228 val2 = strdup("new_value");
229 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 229, __PRETTY_FUNCTION__); } while (0)
;
230
231 hashmap_put(m, "key 1", val1);
232 r = hashmap_get(m, "key 1");
233 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-plain.c", 233, __PRETTY_FUNCTION__
); } while (0)
;
234
235 assert_se(hashmap_update(m, "key 2", val2) == -ENOENT)do { if ((__builtin_expect(!!(!(hashmap_update(m, "key 2", val2
) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_update(m, \"key 2\", val2) == -ENOENT"
), "../src/test/test-hashmap-plain.c", 235, __PRETTY_FUNCTION__
); } while (0)
;
236 r = hashmap_get(m, "key 1");
237 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-plain.c", 237, __PRETTY_FUNCTION__
); } while (0)
;
238
239 assert_se(hashmap_update(m, "key 1", val2) == 0)do { if ((__builtin_expect(!!(!(hashmap_update(m, "key 1", val2
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_update(m, \"key 1\", val2) == 0"
), "../src/test/test-hashmap-plain.c", 239, __PRETTY_FUNCTION__
); } while (0)
;
240 r = hashmap_get(m, "key 1");
241 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-plain.c", 241, __PRETTY_FUNCTION__
); } while (0)
;
242
243 free(val1);
244 free(val2);
245 hashmap_free(m);
246}
247
248static void test_hashmap_put(void) {
249 Hashmap *m = NULL((void*)0);
250 int valid_hashmap_put;
251 void *val1 = (void*) "val 1";
252 void *val2 = (void*) "val 2";
253 _cleanup_free___attribute__((cleanup(freep))) char* key1 = NULL((void*)0);
254
255 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-plain.c", 255, __func__, "%s", __func__
) : -abs(_e); })
;
256
257 assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0)do { if ((__builtin_expect(!!(!(internal_hashmap_ensure_allocated
(&m, &string_hash_ops ) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_ensure_allocated(&m, &string_hash_ops) >= 0"
), "../src/test/test-hashmap-plain.c", 257, __PRETTY_FUNCTION__
); } while (0)
;
258 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 258, __PRETTY_FUNCTION__); } while (0)
;
259
260 valid_hashmap_put = hashmap_put(m, "key 1", val1);
261 assert_se(valid_hashmap_put == 1)do { if ((__builtin_expect(!!(!(valid_hashmap_put == 1)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("valid_hashmap_put == 1"
), "../src/test/test-hashmap-plain.c", 261, __PRETTY_FUNCTION__
); } while (0)
;
262 assert_se(hashmap_put(m, "key 1", val1) == 0)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", val1)
== 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_put(m, \"key 1\", val1) == 0"
), "../src/test/test-hashmap-plain.c", 262, __PRETTY_FUNCTION__
); } while (0)
;
263 assert_se(hashmap_put(m, "key 1", val2) == -EEXIST)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", val2)
== -17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_put(m, \"key 1\", val2) == -EEXIST"
), "../src/test/test-hashmap-plain.c", 263, __PRETTY_FUNCTION__
); } while (0)
;
264 key1 = strdup("key 1");
265 assert_se(hashmap_put(m, key1, val1) == 0)do { if ((__builtin_expect(!!(!(hashmap_put(m, key1, val1) ==
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_put(m, key1, val1) == 0"
), "../src/test/test-hashmap-plain.c", 265, __PRETTY_FUNCTION__
); } while (0)
;
266 assert_se(hashmap_put(m, key1, val2) == -EEXIST)do { if ((__builtin_expect(!!(!(hashmap_put(m, key1, val2) ==
-17)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_put(m, key1, val2) == -EEXIST"
), "../src/test/test-hashmap-plain.c", 266, __PRETTY_FUNCTION__
); } while (0)
;
267
268 hashmap_free(m);
269}
270
271static void test_hashmap_remove(void) {
272 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
273 char *r;
274
275 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-plain.c", 275, __func__, "%s", __func__
) : -abs(_e); })
;
276
277 r = hashmap_remove(NULL((void*)0), "key 1");
278 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-plain.c"
, 278, __PRETTY_FUNCTION__); } while (0)
;
279
280 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
281 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 281, __PRETTY_FUNCTION__); } while (0)
;
282
283 r = hashmap_remove(m, "no such key");
284 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-plain.c"
, 284, __PRETTY_FUNCTION__); } while (0)
;
285
286 hashmap_put(m, "key 1", (void*) "val 1");
287 hashmap_put(m, "key 2", (void*) "val 2");
288
289 r = hashmap_remove(m, "key 1");
290 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-plain.c", 290, __PRETTY_FUNCTION__
); } while (0)
;
291
292 r = hashmap_get(m, "key 2");
293 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-plain.c", 293, __PRETTY_FUNCTION__
); } while (0)
;
294 assert_se(!hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!hashmap_get(m, "key 1"))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_get(m, \"key 1\")"
), "../src/test/test-hashmap-plain.c", 294, __PRETTY_FUNCTION__
); } while (0)
;
295}
296
297static void test_hashmap_remove2(void) {
298 _cleanup_hashmap_free_free_free___attribute__((cleanup(hashmap_free_free_freep))) Hashmap *m = NULL((void*)0);
299 char key1[] = "key 1";
300 char key2[] = "key 2";
301 char val1[] = "val 1";
302 char val2[] = "val 2";
303 void *r, *r2;
304
305 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-plain.c", 305, __func__, "%s", __func__
) : -abs(_e); })
;
306
307 r = hashmap_remove2(NULL((void*)0), "key 1", &r2);
308 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-plain.c"
, 308, __PRETTY_FUNCTION__); } while (0)
;
309
310 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
311 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 311, __PRETTY_FUNCTION__); } while (0)
;
312
313 r = hashmap_remove2(m, "no such key", &r2);
314 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-plain.c"
, 314, __PRETTY_FUNCTION__); } while (0)
;
315
316 hashmap_put(m, strdup(key1), strdup(val1));
317 hashmap_put(m, strdup(key2), strdup(val2));
318
319 r = hashmap_remove2(m, key1, &r2);
320 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-plain.c", 320, __PRETTY_FUNCTION__
); } while (0)
;
321 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-plain.c", 321, __PRETTY_FUNCTION__
); } while (0)
;
322 free(r);
323 free(r2);
324
325 r = hashmap_get(m, key2);
326 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-plain.c", 326, __PRETTY_FUNCTION__
); } while (0)
;
327 assert_se(!hashmap_get(m, key1))do { if ((__builtin_expect(!!(!(!hashmap_get(m, key1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_get(m, key1)"), "../src/test/test-hashmap-plain.c"
, 327, __PRETTY_FUNCTION__); } while (0)
;
328}
329
330static void test_hashmap_remove_value(void) {
331 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
332 char *r;
333
334 char val1[] = "val 1";
335 char val2[] = "val 2";
336
337 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-plain.c", 337, __func__, "%s", __func__
) : -abs(_e); })
;
338
339 r = hashmap_remove_value(NULL((void*)0), "key 1", val1);
340 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-plain.c"
, 340, __PRETTY_FUNCTION__); } while (0)
;
341
342 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
343 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 343, __PRETTY_FUNCTION__); } while (0)
;
344
345 r = hashmap_remove_value(m, "key 1", val1);
346 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-plain.c"
, 346, __PRETTY_FUNCTION__); } while (0)
;
347
348 hashmap_put(m, "key 1", val1);
349 hashmap_put(m, "key 2", val2);
350
351 r = hashmap_remove_value(m, "key 1", val1);
352 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-plain.c", 352, __PRETTY_FUNCTION__
); } while (0)
;
353
354 r = hashmap_get(m, "key 2");
355 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-plain.c", 355, __PRETTY_FUNCTION__
); } while (0)
;
356 assert_se(!hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!hashmap_get(m, "key 1"))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_get(m, \"key 1\")"
), "../src/test/test-hashmap-plain.c", 356, __PRETTY_FUNCTION__
); } while (0)
;
357
358 r = hashmap_remove_value(m, "key 2", val1);
359 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-plain.c"
, 359, __PRETTY_FUNCTION__); } while (0)
;
360
361 r = hashmap_get(m, "key 2");
362 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-plain.c", 362, __PRETTY_FUNCTION__
); } while (0)
;
363 assert_se(!hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!hashmap_get(m, "key 1"))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_get(m, \"key 1\")"
), "../src/test/test-hashmap-plain.c", 363, __PRETTY_FUNCTION__
); } while (0)
;
364}
365
366static void test_hashmap_remove_and_put(void) {
367 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
368 int valid;
369 char *r;
370
371 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-plain.c", 371, __func__, "%s", __func__
) : -abs(_e); })
;
372
373 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
374 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 374, __PRETTY_FUNCTION__); } while (0)
;
375
376 valid = hashmap_remove_and_put(m, "invalid key", "new key", NULL((void*)0));
377 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "../src/test/test-hashmap-plain.c"
, 377, __PRETTY_FUNCTION__); } while (0)
;
378
379 valid = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
380 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "../src/test/test-hashmap-plain.c"
, 380, __PRETTY_FUNCTION__); } while (0)
;
381
382 valid = hashmap_remove_and_put(NULL((void*)0), "key 1", "key 2", (void*) (const char *) "val 2");
383 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "../src/test/test-hashmap-plain.c"
, 383, __PRETTY_FUNCTION__); } while (0)
;
384
385 valid = hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2");
386 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "../src/test/test-hashmap-plain.c"
, 386, __PRETTY_FUNCTION__); } while (0)
;
387
388 r = hashmap_get(m, "key 2");
389 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-plain.c", 389, __PRETTY_FUNCTION__
); } while (0)
;
390 assert_se(!hashmap_get(m, "key 1"))do { if ((__builtin_expect(!!(!(!hashmap_get(m, "key 1"))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_get(m, \"key 1\")"
), "../src/test/test-hashmap-plain.c", 390, __PRETTY_FUNCTION__
); } while (0)
;
391
392 valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3");
393 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "../src/test/test-hashmap-plain.c"
, 393, __PRETTY_FUNCTION__); } while (0)
;
394 valid = hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2");
395 assert_se(valid == -EEXIST)do { if ((__builtin_expect(!!(!(valid == -17)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -EEXIST"), "../src/test/test-hashmap-plain.c"
, 395, __PRETTY_FUNCTION__); } while (0)
;
396}
397
398static void test_hashmap_remove_and_replace(void) {
399 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
400 int valid;
401 void *key1 = UINT_TO_PTR(1)((void *) ((uintptr_t) (1)));
402 void *key2 = UINT_TO_PTR(2)((void *) ((uintptr_t) (2)));
403 void *key3 = UINT_TO_PTR(3)((void *) ((uintptr_t) (3)));
404 void *r;
405 int i, j;
406
407 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-plain.c", 407, __func__, "%s", __func__
) : -abs(_e); })
;
408
409 m = hashmap_new(&trivial_hash_ops)internal_hashmap_new(&trivial_hash_ops );
410 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 410, __PRETTY_FUNCTION__); } while (0)
;
411
412 valid = hashmap_remove_and_replace(m, key1, key2, NULL((void*)0));
413 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "../src/test/test-hashmap-plain.c"
, 413, __PRETTY_FUNCTION__); } while (0)
;
414
415 valid = hashmap_put(m, key1, key1);
416 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "../src/test/test-hashmap-plain.c"
, 416, __PRETTY_FUNCTION__); } while (0)
;
417
418 valid = hashmap_remove_and_replace(NULL((void*)0), key1, key2, key2);
419 assert_se(valid == -ENOENT)do { if ((__builtin_expect(!!(!(valid == -2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == -ENOENT"), "../src/test/test-hashmap-plain.c"
, 419, __PRETTY_FUNCTION__); } while (0)
;
420
421 valid = hashmap_remove_and_replace(m, key1, key2, key2);
422 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "../src/test/test-hashmap-plain.c"
, 422, __PRETTY_FUNCTION__); } while (0)
;
423
424 r = hashmap_get(m, key2);
425 assert_se(r == key2)do { if ((__builtin_expect(!!(!(r == key2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == key2"), "../src/test/test-hashmap-plain.c"
, 425, __PRETTY_FUNCTION__); } while (0)
;
426 assert_se(!hashmap_get(m, key1))do { if ((__builtin_expect(!!(!(!hashmap_get(m, key1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_get(m, key1)"), "../src/test/test-hashmap-plain.c"
, 426, __PRETTY_FUNCTION__); } while (0)
;
427
428 valid = hashmap_put(m, key3, key3);
429 assert_se(valid == 1)do { if ((__builtin_expect(!!(!(valid == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 1"), "../src/test/test-hashmap-plain.c"
, 429, __PRETTY_FUNCTION__); } while (0)
;
430 valid = hashmap_remove_and_replace(m, key3, key2, key2);
431 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "../src/test/test-hashmap-plain.c"
, 431, __PRETTY_FUNCTION__); } while (0)
;
432 r = hashmap_get(m, key2);
433 assert_se(r == key2)do { if ((__builtin_expect(!!(!(r == key2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("r == key2"), "../src/test/test-hashmap-plain.c"
, 433, __PRETTY_FUNCTION__); } while (0)
;
434 assert_se(!hashmap_get(m, key3))do { if ((__builtin_expect(!!(!(!hashmap_get(m, key3))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_get(m, key3)"), "../src/test/test-hashmap-plain.c"
, 434, __PRETTY_FUNCTION__); } while (0)
;
435
436 /* Repeat this test several times to increase the chance of hitting
437 * the less likely case in hashmap_remove_and_replace where it
438 * compensates for the backward shift. */
439 for (i = 0; i < 20; i++) {
440 hashmap_clear(m);
441
442 for (j = 1; j < 7; j++)
443 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))));
444 valid = hashmap_remove_and_replace(m, UINT_TO_PTR(10*i + 1)((void *) ((uintptr_t) (10*i + 1))),
445 UINT_TO_PTR(10*i + 2)((void *) ((uintptr_t) (10*i + 2))),
446 UINT_TO_PTR(10*i + 2)((void *) ((uintptr_t) (10*i + 2))));
447 assert_se(valid == 0)do { if ((__builtin_expect(!!(!(valid == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid == 0"), "../src/test/test-hashmap-plain.c"
, 447, __PRETTY_FUNCTION__); } while (0)
;
448 assert_se(!hashmap_get(m, UINT_TO_PTR(10*i + 1)))do { if ((__builtin_expect(!!(!(!hashmap_get(m, ((void *) ((uintptr_t
) (10*i + 1)))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!hashmap_get(m, UINT_TO_PTR(10*i + 1))"), "../src/test/test-hashmap-plain.c"
, 448, __PRETTY_FUNCTION__); } while (0)
;
449 for (j = 2; j < 7; j++) {
450 r = hashmap_get(m, UINT_TO_PTR(10*i + j)((void *) ((uintptr_t) (10*i + j))));
451 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-plain.c"
, 451, __PRETTY_FUNCTION__); } while (0)
;
452 }
453 }
454}
455
456static void test_hashmap_ensure_allocated(void) {
457 Hashmap *m;
458 int valid_hashmap;
459
460 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-plain.c", 460, __func__, "%s", __func__
) : -abs(_e); })
;
461
462 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
463
464 valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops)internal_hashmap_ensure_allocated(&m, &string_hash_ops
)
;
465 assert_se(valid_hashmap == 0)do { if ((__builtin_expect(!!(!(valid_hashmap == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("valid_hashmap == 0"), "../src/test/test-hashmap-plain.c"
, 465, __PRETTY_FUNCTION__); } while (0)
;
466
467 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 467, __PRETTY_FUNCTION__); } while (0)
;
468 hashmap_free(m);
469}
470
471static void test_hashmap_foreach_key(void) {
472 Hashmap *m;
473 Iterator i;
474 bool_Bool key_found[] = { false0, false0, false0, false0 };
475 const char *s;
476 const char *key;
477 static const char key_table[] =
478 "key 1\0"
479 "key 2\0"
480 "key 3\0"
481 "key 4\0";
482
483 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-plain.c", 483, __func__, "%s", __func__
) : -abs(_e); })
;
484
485 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
486
487 NULSTR_FOREACH(key, key_table)for ((key) = (key_table); (key) && *(key); (key) = strchr
((key), 0)+1)
488 hashmap_put(m, key, (void*) (const char*) "my dummy val");
489
490 HASHMAP_FOREACH_KEY(s, key, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m), &(i), (void
**)&(s), (const void**) &(key)); )
{
491 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/test/test-hashmap-plain.c"
, 491, __PRETTY_FUNCTION__); } while (0)
;
492 if (!key_found[0] && streq(key, "key 1")(strcmp((key),("key 1")) == 0))
493 key_found[0] = true1;
494 else if (!key_found[1] && streq(key, "key 2")(strcmp((key),("key 2")) == 0))
495 key_found[1] = true1;
496 else if (!key_found[2] && streq(key, "key 3")(strcmp((key),("key 3")) == 0))
497 key_found[2] = true1;
498 else if (!key_found[3] && streq(key, "fail")(strcmp((key),("fail")) == 0))
499 key_found[3] = true1;
500 }
501
502 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 502, __PRETTY_FUNCTION__); } while (0)
;
503 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-plain.c", 503, __PRETTY_FUNCTION__
); } while (0)
;
504
505 hashmap_free(m);
506}
507
508static void test_hashmap_foreach(void) {
509 Hashmap *m;
510 Iterator i;
511 bool_Bool value_found[] = { false0, false0, false0, false0 };
512 char *val1, *val2, *val3, *val4, *s;
513 unsigned count;
514
515 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-plain.c", 515, __func__, "%s", __func__
) : -abs(_e); })
;
516
517 val1 = strdup("my val1");
518 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 518, __PRETTY_FUNCTION__); } while (0)
;
519 val2 = strdup("my val2");
520 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 520, __PRETTY_FUNCTION__); } while (0)
;
521 val3 = strdup("my val3");
522 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 522, __PRETTY_FUNCTION__); } while (0)
;
523 val4 = strdup("my val4");
524 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 524, __PRETTY_FUNCTION__); } while (0)
;
525
526 m = NULL((void*)0);
527
528 count = 0;
529 HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m), &(i), (void
**)&(s), ((void*)0)); )
530 count++;
531 assert_se(count == 0)do { if ((__builtin_expect(!!(!(count == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("count == 0"), "../src/test/test-hashmap-plain.c"
, 531, __PRETTY_FUNCTION__); } while (0)
;
532
533 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
534
535 count = 0;
536 HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m), &(i), (void
**)&(s), ((void*)0)); )
537 count++;
538 assert_se(count == 0)do { if ((__builtin_expect(!!(!(count == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("count == 0"), "../src/test/test-hashmap-plain.c"
, 538, __PRETTY_FUNCTION__); } while (0)
;
539
540 hashmap_put(m, "Key 1", val1);
541 hashmap_put(m, "Key 2", val2);
542 hashmap_put(m, "Key 3", val3);
543 hashmap_put(m, "Key 4", val4);
544
545 HASHMAP_FOREACH(s, m, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m), &(i), (void
**)&(s), ((void*)0)); )
{
546 if (!value_found[0] && streq(s, val1)(strcmp((s),(val1)) == 0))
547 value_found[0] = true1;
548 else if (!value_found[1] && streq(s, val2)(strcmp((s),(val2)) == 0))
549 value_found[1] = true1;
550 else if (!value_found[2] && streq(s, val3)(strcmp((s),(val3)) == 0))
551 value_found[2] = true1;
552 else if (!value_found[3] && streq(s, val4)(strcmp((s),(val4)) == 0))
553 value_found[3] = true1;
554 }
555
556 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 556, __PRETTY_FUNCTION__); } while (0)
;
557 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-plain.c", 557, __PRETTY_FUNCTION__
); } while (0)
;
558
559 hashmap_free_free(m);
560}
561
562static void test_hashmap_merge(void) {
563 Hashmap *m;
564 Hashmap *n;
565 char *val1, *val2, *val3, *val4, *r;
566
567 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-plain.c", 567, __func__, "%s", __func__
) : -abs(_e); })
;
568
569 val1 = strdup("my val1");
570 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 570, __PRETTY_FUNCTION__); } while (0)
;
571 val2 = strdup("my val2");
572 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 572, __PRETTY_FUNCTION__); } while (0)
;
573 val3 = strdup("my val3");
574 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 574, __PRETTY_FUNCTION__); } while (0)
;
575 val4 = strdup("my val4");
576 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 576, __PRETTY_FUNCTION__); } while (0)
;
577
578 n = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
579 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
580
581 hashmap_put(m, "Key 1", val1);
582 hashmap_put(m, "Key 2", val2);
583 hashmap_put(n, "Key 3", val3);
584 hashmap_put(n, "Key 4", val4);
585
586 assert_se(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, ("hashmap_merge(m, n) == 0"
), "../src/test/test-hashmap-plain.c", 586, __PRETTY_FUNCTION__
); } while (0)
;
587 r = hashmap_get(m, "Key 3");
588 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-plain.c", 588, __PRETTY_FUNCTION__
); } while (0)
;
589 r = hashmap_get(m, "Key 4");
590 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-plain.c", 590, __PRETTY_FUNCTION__
); } while (0)
;
591
592 assert_se(n)do { if ((__builtin_expect(!!(!(n)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n"), "../src/test/test-hashmap-plain.c"
, 592, __PRETTY_FUNCTION__); } while (0)
;
593 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 593, __PRETTY_FUNCTION__); } while (0)
;
594 hashmap_free(n);
595 hashmap_free_free(m);
596}
597
598static void test_hashmap_contains(void) {
599 Hashmap *m;
600 char *val1;
601
602 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-plain.c", 602, __func__, "%s", __func__
) : -abs(_e); })
;
603
604 val1 = strdup("my val");
605 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 605, __PRETTY_FUNCTION__); } while (0)
;
606
607 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
608
609 assert_se(!hashmap_contains(m, "Key 1"))do { if ((__builtin_expect(!!(!(!hashmap_contains(m, "Key 1")
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_contains(m, \"Key 1\")"
), "../src/test/test-hashmap-plain.c", 609, __PRETTY_FUNCTION__
); } while (0)
;
610 hashmap_put(m, "Key 1", val1);
611 assert_se(hashmap_contains(m, "Key 1"))do { if ((__builtin_expect(!!(!(hashmap_contains(m, "Key 1"))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_contains(m, \"Key 1\")"
), "../src/test/test-hashmap-plain.c", 611, __PRETTY_FUNCTION__
); } while (0)
;
612 assert_se(!hashmap_contains(m, "Key 2"))do { if ((__builtin_expect(!!(!(!hashmap_contains(m, "Key 2")
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_contains(m, \"Key 2\")"
), "../src/test/test-hashmap-plain.c", 612, __PRETTY_FUNCTION__
); } while (0)
;
613
614 assert_se(!hashmap_contains(NULL, "Key 1"))do { if ((__builtin_expect(!!(!(!hashmap_contains(((void*)0),
"Key 1"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"!hashmap_contains(NULL, \"Key 1\")"), "../src/test/test-hashmap-plain.c"
, 614, __PRETTY_FUNCTION__); } while (0)
;
615
616 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 616, __PRETTY_FUNCTION__); } while (0)
;
617 hashmap_free_free(m);
618}
619
620static void test_hashmap_isempty(void) {
621 Hashmap *m;
622 char *val1;
623
624 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-plain.c", 624, __func__, "%s", __func__
) : -abs(_e); })
;
625
626 val1 = strdup("my val");
627 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 627, __PRETTY_FUNCTION__); } while (0)
;
628
629 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
630
631 assert_se(hashmap_isempty(m))do { if ((__builtin_expect(!!(!(hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 631, __PRETTY_FUNCTION__); } while (0)
;
632 hashmap_put(m, "Key 1", val1);
633 assert_se(!hashmap_isempty(m))do { if ((__builtin_expect(!!(!(!hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 633, __PRETTY_FUNCTION__); } while (0)
;
634
635 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 635, __PRETTY_FUNCTION__); } while (0)
;
636 hashmap_free_free(m);
637}
638
639static void test_hashmap_size(void) {
640 Hashmap *m;
641 char *val1, *val2, *val3, *val4;
642
643 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-plain.c", 643, __func__, "%s", __func__
) : -abs(_e); })
;
644
645 val1 = strdup("my val");
646 assert_se(val1)do { if ((__builtin_expect(!!(!(val1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val1"), "../src/test/test-hashmap-plain.c"
, 646, __PRETTY_FUNCTION__); } while (0)
;
647 val2 = strdup("my val");
648 assert_se(val2)do { if ((__builtin_expect(!!(!(val2)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val2"), "../src/test/test-hashmap-plain.c"
, 648, __PRETTY_FUNCTION__); } while (0)
;
649 val3 = strdup("my val");
650 assert_se(val3)do { if ((__builtin_expect(!!(!(val3)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val3"), "../src/test/test-hashmap-plain.c"
, 650, __PRETTY_FUNCTION__); } while (0)
;
651 val4 = strdup("my val");
652 assert_se(val4)do { if ((__builtin_expect(!!(!(val4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val4"), "../src/test/test-hashmap-plain.c"
, 652, __PRETTY_FUNCTION__); } while (0)
;
653
654 assert_se(hashmap_size(NULL) == 0)do { if ((__builtin_expect(!!(!(hashmap_size(((void*)0)) == 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_size(NULL) == 0"
), "../src/test/test-hashmap-plain.c", 654, __PRETTY_FUNCTION__
); } while (0)
;
655 assert_se(hashmap_buckets(NULL) == 0)do { if ((__builtin_expect(!!(!(hashmap_buckets(((void*)0)) ==
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_buckets(NULL) == 0"
), "../src/test/test-hashmap-plain.c", 655, __PRETTY_FUNCTION__
); } while (0)
;
656
657 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
658
659 hashmap_put(m, "Key 1", val1);
660 hashmap_put(m, "Key 2", val2);
661 hashmap_put(m, "Key 3", val3);
662 hashmap_put(m, "Key 4", val4);
663
664 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 664, __PRETTY_FUNCTION__); } while (0)
;
665 assert_se(hashmap_size(m) == 4)do { if ((__builtin_expect(!!(!(hashmap_size(m) == 4)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_size(m) == 4"), "../src/test/test-hashmap-plain.c"
, 665, __PRETTY_FUNCTION__); } while (0)
;
666 assert_se(hashmap_buckets(m) >= 4)do { if ((__builtin_expect(!!(!(hashmap_buckets(m) >= 4)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_buckets(m) >= 4"
), "../src/test/test-hashmap-plain.c", 666, __PRETTY_FUNCTION__
); } while (0)
;
667 hashmap_free_free(m);
668}
669
670static void test_hashmap_get(void) {
671 Hashmap *m;
672 char *r;
673 char *val;
674
675 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-plain.c", 675, __func__, "%s", __func__
) : -abs(_e); })
;
676
677 val = strdup("my val");
678 assert_se(val)do { if ((__builtin_expect(!!(!(val)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val"), "../src/test/test-hashmap-plain.c"
, 678, __PRETTY_FUNCTION__); } while (0)
;
679
680 r = hashmap_get(NULL((void*)0), "Key 1");
681 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-plain.c"
, 681, __PRETTY_FUNCTION__); } while (0)
;
682
683 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
684
685 hashmap_put(m, "Key 1", val);
686
687 r = hashmap_get(m, "Key 1");
688 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-plain.c", 688, __PRETTY_FUNCTION__
); } while (0)
;
689
690 r = hashmap_get(m, "no such key");
691 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-plain.c"
, 691, __PRETTY_FUNCTION__); } while (0)
;
692
693 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 693, __PRETTY_FUNCTION__); } while (0)
;
694 hashmap_free_free(m);
695}
696
697static void test_hashmap_get2(void) {
698 Hashmap *m;
699 char *r;
700 char *val;
701 char key_orig[] = "Key 1";
702 void *key_copy;
703
704 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-plain.c", 704, __func__, "%s", __func__
) : -abs(_e); })
;
705
706 val = strdup("my val");
707 assert_se(val)do { if ((__builtin_expect(!!(!(val)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("val"), "../src/test/test-hashmap-plain.c"
, 707, __PRETTY_FUNCTION__); } while (0)
;
708
709 key_copy = strdup(key_orig);
710 assert_se(key_copy)do { if ((__builtin_expect(!!(!(key_copy)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("key_copy"), "../src/test/test-hashmap-plain.c"
, 710, __PRETTY_FUNCTION__); } while (0)
;
711
712 r = hashmap_get2(NULL((void*)0), key_orig, &key_copy);
713 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-plain.c"
, 713, __PRETTY_FUNCTION__); } while (0)
;
714
715 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
716
717 hashmap_put(m, key_copy, val);
718 key_copy = NULL((void*)0);
719
720 r = hashmap_get2(m, key_orig, &key_copy);
721 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-plain.c", 721, __PRETTY_FUNCTION__
); } while (0)
;
722 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-plain.c"
, 722, __PRETTY_FUNCTION__); } while (0)
;
723 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-plain.c", 723, __PRETTY_FUNCTION__
); } while (0)
;
724
725 r = hashmap_get2(m, "no such key", NULL((void*)0));
726 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-plain.c"
, 726, __PRETTY_FUNCTION__); } while (0)
;
727
728 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 728, __PRETTY_FUNCTION__); } while (0)
;
729 hashmap_free_free_free(m);
730}
731
732static void crippled_hashmap_func(const void *p, struct siphash *state) {
733 return trivial_hash_func(INT_TO_PTR(PTR_TO_INT(p) & 0xff)((void *) ((intptr_t) (((int) ((intptr_t) (p))) & 0xff))), state);
734}
735
736static const struct hash_ops crippled_hashmap_ops = {
737 .hash = crippled_hashmap_func,
738 .compare = trivial_compare_func,
739};
740
741static void test_hashmap_many(void) {
742 Hashmap *h;
743 unsigned i, j;
744 void *v, *k;
745 const struct {
746 const struct hash_ops *ops;
747 unsigned n_entries;
748 } tests[] = {
749 { .ops = NULL((void*)0), .n_entries = arg_slow ? 1 << 20 : 240 },
750 { .ops = &crippled_hashmap_ops, .n_entries = arg_slow ? 1 << 14 : 140 },
751 };
752
753 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-plain.c", 753, __func__, "%s (%s)"
, __func__, arg_slow ? "slow" : "fast") : -abs(_e); })
;
754
755 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++) {
756 assert_se(h = hashmap_new(tests[j].ops))do { if ((__builtin_expect(!!(!(h = internal_hashmap_new(tests
[j].ops ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"h = hashmap_new(tests[j].ops)"), "../src/test/test-hashmap-plain.c"
, 756, __PRETTY_FUNCTION__); } while (0)
;
757
758 for (i = 1; i < tests[j].n_entries*3; i+=3) {
759 assert_se(hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0)do { if ((__builtin_expect(!!(!(hashmap_put(h, ((void *) ((uintptr_t
) (i))), ((void *) ((uintptr_t) (i)))) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0"
), "../src/test/test-hashmap-plain.c", 759, __PRETTY_FUNCTION__
); } while (0)
;
760 assert_se(PTR_TO_UINT(hashmap_get(h, UINT_TO_PTR(i))) == i)do { if ((__builtin_expect(!!(!(((unsigned int) ((uintptr_t) (
hashmap_get(h, ((void *) ((uintptr_t) (i))))))) == i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("PTR_TO_UINT(hashmap_get(h, UINT_TO_PTR(i))) == i"
), "../src/test/test-hashmap-plain.c", 760, __PRETTY_FUNCTION__
); } while (0)
;
761 }
762
763 for (i = 1; i < tests[j].n_entries*3; i++)
764 assert_se(hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1))do { if ((__builtin_expect(!!(!(hashmap_contains(h, ((void *)
((uintptr_t) (i)))) == (i % 3 == 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1)"
), "../src/test/test-hashmap-plain.c", 764, __PRETTY_FUNCTION__
); } while (0)
;
765
766 log_info("%u <= %u * 0.8 = %g", hashmap_size(h), hashmap_buckets(h), 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-plain.c", 766, __func__, "%u <= %u * 0.8 = %g"
, hashmap_size(h), hashmap_buckets(h), hashmap_buckets(h) * 0.8
) : -abs(_e); })
;
767
768 assert_se(hashmap_size(h) <= hashmap_buckets(h) * 0.8)do { if ((__builtin_expect(!!(!(hashmap_size(h) <= hashmap_buckets
(h) * 0.8)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"hashmap_size(h) <= hashmap_buckets(h) * 0.8"), "../src/test/test-hashmap-plain.c"
, 768, __PRETTY_FUNCTION__); } while (0)
;
769 assert_se(hashmap_size(h) == tests[j].n_entries)do { if ((__builtin_expect(!!(!(hashmap_size(h) == tests[j].n_entries
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_size(h) == tests[j].n_entries"
), "../src/test/test-hashmap-plain.c", 769, __PRETTY_FUNCTION__
); } while (0)
;
770
771 while (!hashmap_isempty(h)) {
772 k = hashmap_first_key(h);
773 v = hashmap_remove(h, k);
774 assert_se(v == k)do { if ((__builtin_expect(!!(!(v == k)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("v == k"), "../src/test/test-hashmap-plain.c"
, 774, __PRETTY_FUNCTION__); } while (0)
;
775 }
776
777 hashmap_free(h);
778 }
779}
780
781static void test_hashmap_first(void) {
782 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
783
784 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-plain.c", 784, __func__, "%s", __func__
) : -abs(_e); })
;
785
786 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
787 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 787, __PRETTY_FUNCTION__); } while (0)
;
788
789 assert_se(!hashmap_first(m))do { if ((__builtin_expect(!!(!(!hashmap_first(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_first(m)"), "../src/test/test-hashmap-plain.c"
, 789, __PRETTY_FUNCTION__); } while (0)
;
790 assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", (void
*) "val 1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 1\", (void*) \"val 1\") == 1"), "../src/test/test-hashmap-plain.c"
, 790, __PRETTY_FUNCTION__); } while (0)
;
791 assert_se(streq(hashmap_first(m), "val 1"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first(m)),("val 1"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(hashmap_first(m), \"val 1\")"
), "../src/test/test-hashmap-plain.c", 791, __PRETTY_FUNCTION__
); } while (0)
;
792 assert_se(hashmap_put(m, "key 2", (void*) "val 2") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 2", (void
*) "val 2") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 2\", (void*) \"val 2\") == 1"), "../src/test/test-hashmap-plain.c"
, 792, __PRETTY_FUNCTION__); } while (0)
;
793#ifdef ORDERED
794 assert_se(streq(hashmap_first(m), "val 1"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first(m)),("val 1"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(hashmap_first(m), \"val 1\")"
), "../src/test/test-hashmap-plain.c", 794, __PRETTY_FUNCTION__
); } while (0)
;
795 assert_se(hashmap_remove(m, "key 1"))do { if ((__builtin_expect(!!(!(hashmap_remove(m, "key 1"))),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_remove(m, \"key 1\")"
), "../src/test/test-hashmap-plain.c", 795, __PRETTY_FUNCTION__
); } while (0)
;
796 assert_se(streq(hashmap_first(m), "val 2"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first(m)),("val 2"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(hashmap_first(m), \"val 2\")"
), "../src/test/test-hashmap-plain.c", 796, __PRETTY_FUNCTION__
); } while (0)
;
797#endif
798}
799
800static void test_hashmap_first_key(void) {
801 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
802
803 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-plain.c", 803, __func__, "%s", __func__
) : -abs(_e); })
;
804
805 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
806 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 806, __PRETTY_FUNCTION__); } while (0)
;
807
808 assert_se(!hashmap_first_key(m))do { if ((__builtin_expect(!!(!(!hashmap_first_key(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!hashmap_first_key(m)"), "../src/test/test-hashmap-plain.c"
, 808, __PRETTY_FUNCTION__); } while (0)
;
809 assert_se(hashmap_put(m, "key 1", NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", ((void
*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"hashmap_put(m, \"key 1\", NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 809, __PRETTY_FUNCTION__); } while (0)
;
810 assert_se(streq(hashmap_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first_key(m)
),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(hashmap_first_key(m), \"key 1\")"), "../src/test/test-hashmap-plain.c"
, 810, __PRETTY_FUNCTION__); } while (0)
;
811 assert_se(hashmap_put(m, "key 2", NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 2", ((void
*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"hashmap_put(m, \"key 2\", NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 811, __PRETTY_FUNCTION__); } while (0)
;
812#ifdef ORDERED
813 assert_se(streq(hashmap_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first_key(m)
),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(hashmap_first_key(m), \"key 1\")"), "../src/test/test-hashmap-plain.c"
, 813, __PRETTY_FUNCTION__); } while (0)
;
814 assert_se(hashmap_remove(m, "key 1") == NULL)do { if ((__builtin_expect(!!(!(hashmap_remove(m, "key 1") ==
((void*)0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("hashmap_remove(m, \"key 1\") == NULL"), "../src/test/test-hashmap-plain.c"
, 814, __PRETTY_FUNCTION__); } while (0)
;
815 assert_se(streq(hashmap_first_key(m), "key 2"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_first_key(m)
),("key 2")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(hashmap_first_key(m), \"key 2\")"), "../src/test/test-hashmap-plain.c"
, 815, __PRETTY_FUNCTION__); } while (0)
;
816#endif
817}
818
819static void test_hashmap_steal_first_key(void) {
820 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
821
822 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-plain.c", 822, __func__, "%s", __func__
) : -abs(_e); })
;
823
824 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
825 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 825, __PRETTY_FUNCTION__); } while (0)
;
826
827 assert_se(!hashmap_steal_first_key(m))do { if ((__builtin_expect(!!(!(!hashmap_steal_first_key(m)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!hashmap_steal_first_key(m)"
), "../src/test/test-hashmap-plain.c", 827, __PRETTY_FUNCTION__
); } while (0)
;
828 assert_se(hashmap_put(m, "key 1", NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", ((void
*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"hashmap_put(m, \"key 1\", NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 828, __PRETTY_FUNCTION__); } while (0)
;
829 assert_se(streq(hashmap_steal_first_key(m), "key 1"))do { if ((__builtin_expect(!!(!((strcmp((hashmap_steal_first_key
(m)),("key 1")) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("streq(hashmap_steal_first_key(m), \"key 1\")"), "../src/test/test-hashmap-plain.c"
, 829, __PRETTY_FUNCTION__); } while (0)
;
830
831 assert_se(hashmap_isempty(m))do { if ((__builtin_expect(!!(!(hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 831, __PRETTY_FUNCTION__); } while (0)
;
832}
833
834static void test_hashmap_steal_first(void) {
835 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
836 int seen[3] = {};
837 char *val;
838
839 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-plain.c", 839, __func__, "%s", __func__
) : -abs(_e); })
;
840
841 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
842 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 842, __PRETTY_FUNCTION__); } while (0)
;
843
844 assert_se(hashmap_put(m, "key 1", (void*) "1") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", (void
*) "1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 1\", (void*) \"1\") == 1"), "../src/test/test-hashmap-plain.c"
, 844, __PRETTY_FUNCTION__); } while (0)
;
845 assert_se(hashmap_put(m, "key 2", (void*) "22") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 2", (void
*) "22") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 2\", (void*) \"22\") == 1"), "../src/test/test-hashmap-plain.c"
, 845, __PRETTY_FUNCTION__); } while (0)
;
846 assert_se(hashmap_put(m, "key 3", (void*) "333") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 3", (void
*) "333") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 3\", (void*) \"333\") == 1"), "../src/test/test-hashmap-plain.c"
, 846, __PRETTY_FUNCTION__); } while (0)
;
847
848 while ((val = hashmap_steal_first(m)))
849 seen[strlen(val) - 1]++;
850
851 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-plain.c", 851, __PRETTY_FUNCTION__
); } while (0)
;
852
853 assert_se(hashmap_isempty(m))do { if ((__builtin_expect(!!(!(hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 853, __PRETTY_FUNCTION__); } while (0)
;
854}
855
856static void test_hashmap_clear_free_free(void) {
857 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
858
859 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-plain.c", 859, __func__, "%s", __func__
) : -abs(_e); })
;
4
Assuming the condition is false
5
'?' condition is false
860
861 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
862 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-hashmap-plain.c"
, 862, __PRETTY_FUNCTION__); } while (0)
;
6
Assuming 'm' is non-null
7
Taking false branch
8
Loop condition is false. Exiting loop
863
864 assert_se(hashmap_put(m, strdup("key 1"), NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, strdup("key 1"
), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, strdup(\"key 1\"), NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 864, __PRETTY_FUNCTION__); } while (0)
;
9
Memory is allocated
10
Assuming the condition is true
11
Potential memory leak
865 assert_se(hashmap_put(m, strdup("key 2"), NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, strdup("key 2"
), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, strdup(\"key 2\"), NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 865, __PRETTY_FUNCTION__); } while (0)
;
866 assert_se(hashmap_put(m, strdup("key 3"), NULL) == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, strdup("key 3"
), ((void*)0)) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, strdup(\"key 3\"), NULL) == 1"), "../src/test/test-hashmap-plain.c"
, 866, __PRETTY_FUNCTION__); } while (0)
;
867
868 hashmap_clear_free_free(m);
869 assert_se(hashmap_isempty(m))do { if ((__builtin_expect(!!(!(hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 869, __PRETTY_FUNCTION__); } while (0)
;
870}
871
872static void test_hashmap_reserve(void) {
873 _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *m = NULL((void*)0);
874
875 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-plain.c", 875, __func__, "%s", __func__
) : -abs(_e); })
;
876
877 m = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
878
879 assert_se(hashmap_reserve(m, 1) == 0)do { if ((__builtin_expect(!!(!(hashmap_reserve(m, 1) == 0)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_reserve(m, 1) == 0"
), "../src/test/test-hashmap-plain.c", 879, __PRETTY_FUNCTION__
); } while (0)
;
880 assert_se(hashmap_buckets(m) < 1000)do { if ((__builtin_expect(!!(!(hashmap_buckets(m) < 1000)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_buckets(m) < 1000"
), "../src/test/test-hashmap-plain.c", 880, __PRETTY_FUNCTION__
); } while (0)
;
881 assert_se(hashmap_reserve(m, 1000) == 0)do { if ((__builtin_expect(!!(!(hashmap_reserve(m, 1000) == 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_reserve(m, 1000) == 0"
), "../src/test/test-hashmap-plain.c", 881, __PRETTY_FUNCTION__
); } while (0)
;
882 assert_se(hashmap_buckets(m) >= 1000)do { if ((__builtin_expect(!!(!(hashmap_buckets(m) >= 1000
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("hashmap_buckets(m) >= 1000"
), "../src/test/test-hashmap-plain.c", 882, __PRETTY_FUNCTION__
); } while (0)
;
883 assert_se(hashmap_isempty(m))do { if ((__builtin_expect(!!(!(hashmap_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("hashmap_isempty(m)"), "../src/test/test-hashmap-plain.c"
, 883, __PRETTY_FUNCTION__); } while (0)
;
884
885 assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1)do { if ((__builtin_expect(!!(!(hashmap_put(m, "key 1", (void
*) "val 1") == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_put(m, \"key 1\", (void*) \"val 1\") == 1"), "../src/test/test-hashmap-plain.c"
, 885, __PRETTY_FUNCTION__); } while (0)
;
886
887 assert_se(hashmap_reserve(m, UINT_MAX) == -ENOMEM)do { if ((__builtin_expect(!!(!(hashmap_reserve(m, (2147483647
*2U +1U)) == -12)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_reserve(m, UINT_MAX) == -ENOMEM"), "../src/test/test-hashmap-plain.c"
, 887, __PRETTY_FUNCTION__); } while (0)
;
888 assert_se(hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM)do { if ((__builtin_expect(!!(!(hashmap_reserve(m, (2147483647
*2U +1U) - 1) == -12)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM"), "../src/test/test-hashmap-plain.c"
, 888, __PRETTY_FUNCTION__); } while (0)
;
889}
890
891void test_hashmap_funcs(void) {
892 int r;
893
894 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
895 log_open();
896
897 r = getenv_bool("SYSTEMD_SLOW_TESTS");
898 arg_slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT0;
1
Assuming 'r' is < 0
2
'?' condition is false
899
900 test_hashmap_copy();
901 test_hashmap_get_strv();
902 test_hashmap_move_one();
903 test_hashmap_move();
904 test_hashmap_replace();
905 test_hashmap_update();
906 test_hashmap_put();
907 test_hashmap_remove();
908 test_hashmap_remove2();
909 test_hashmap_remove_value();
910 test_hashmap_remove_and_put();
911 test_hashmap_remove_and_replace();
912 test_hashmap_ensure_allocated();
913 test_hashmap_foreach();
914 test_hashmap_foreach_key();
915 test_hashmap_contains();
916 test_hashmap_merge();
917 test_hashmap_isempty();
918 test_hashmap_get();
919 test_hashmap_get2();
920 test_hashmap_size();
921 test_hashmap_many();
922 test_hashmap_first();
923 test_hashmap_first_key();
924 test_hashmap_steal_first_key();
925 test_hashmap_steal_first();
926 test_hashmap_clear_free_free();
3
Calling 'test_hashmap_clear_free_free'
927 test_hashmap_reserve();
928}