]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
3ffd12bf YW |
2 | |
3 | #include <pthread.h> | |
4 | ||
5 | #include "process-util.h" | |
6 | #include "set.h" | |
7 | #include "tests.h" | |
8 | ||
9 | #define NUM 100 | |
10 | ||
11 | static void* thread(void *p) { | |
12 | Set **s = p; | |
13 | ||
14 | assert_se(s); | |
15 | assert_se(*s); | |
16 | ||
17 | assert_se(!is_main_thread()); | |
18 | assert_se(set_size(*s) == NUM); | |
19 | *s = set_free(*s); | |
20 | ||
21 | return NULL; | |
22 | } | |
23 | ||
24 | static void test_one(const char *val) { | |
25 | pthread_t t; | |
26 | int x[NUM] = {}; | |
27 | unsigned i; | |
28 | Set *s; | |
29 | ||
30 | log_info("Testing with SYSTEMD_MEMPOOL=%s", val); | |
31 | assert_se(setenv("SYSTEMD_MEMPOOL", val, true) == 0); | |
32 | assert_se(is_main_thread()); | |
33 | ||
34 | assert_se(s = set_new(NULL)); | |
35 | for (i = 0; i < NUM; i++) | |
36 | assert_se(set_put(s, &x[i])); | |
37 | ||
38 | assert_se(pthread_create(&t, NULL, thread, &s) == 0); | |
39 | assert_se(pthread_join(t, NULL) == 0); | |
40 | ||
41 | assert_se(!s); | |
42 | } | |
43 | ||
44 | int main(int argc, char *argv[]) { | |
45 | test_setup_logging(LOG_DEBUG); | |
46 | ||
47 | test_one("0"); | |
48 | /* The value $SYSTEMD_MEMPOOL= is cached. So the following | |
49 | * test should also succeed. */ | |
50 | test_one("1"); | |
51 | ||
52 | return 0; | |
53 | } |