summaryrefslogtreecommitdiff
path: root/src/test/test-set-disable-mempool.c
blob: e7dbf61c281f904f3bf7590c7dff3126b1f29b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* SPDX-License-Identifier: LGPL-2.1+ */

//#include <pthread.h>

//#include "process-util.h"
//#include "set.h"
//#include "tests.h"

#define NUM 100

static void* thread(void *p) {
        Set **s = p;

        assert_se(s);
        assert_se(*s);

        assert_se(!is_main_thread());
        assert_se(set_size(*s) == NUM);
        *s = set_free(*s);

        return NULL;
}

static void test_one(const char *val) {
        pthread_t t;
        int x[NUM] = {};
        unsigned i;
        Set *s;

        log_info("Testing with SYSTEMD_MEMPOOL=%s", val);
        assert_se(setenv("SYSTEMD_MEMPOOL", val, true) == 0);
        assert_se(is_main_thread());

        assert_se(s = set_new(NULL));
        for (i = 0; i < NUM; i++)
                assert_se(set_put(s, &x[i]));

        assert_se(pthread_create(&t, NULL, thread, &s) == 0);
        assert_se(pthread_join(t, NULL) == 0);

        assert_se(!s);
}

int main(int argc, char *argv[]) {
        log_set_max_level(LOG_DEBUG);
        log_parse_environment();
        log_open();

        test_one("0");
        /* The value $SYSTEMD_MEMPOOL= is cached. So the following
         * test should also succeed. */
        test_one("1");

        return 0;
}