1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

test: add tests for $SYSTEMD_MEMPOOL=

This adds tests for b4f607433c and
205c085bc3 (#9792).
This commit is contained in:
Yu Watanabe 2018-10-12 11:12:07 +09:00
parent e7f7f19abc
commit 3ffd12bfbe
2 changed files with 57 additions and 0 deletions

View File

@ -399,6 +399,10 @@ tests += [
[],
[]],
[['src/test/test-set-disable-mempool.c'],
[],
[threads]],
[['src/test/test-bitmap.c'],
[],
[]],

View File

@ -0,0 +1,53 @@
/* 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[]) {
test_setup_logging(LOG_DEBUG);
test_one("0");
/* The value $SYSTEMD_MEMPOOL= is cached. So the following
* test should also succeed. */
test_one("1");
return 0;
}