summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-10-12 11:12:07 +0900
committerSven Eden <sven.eden@prydeworx.com>2018-10-29 10:18:31 +0100
commita8308748d4761dc4ba016faac02c0f9d5bc0d59f (patch)
tree53253475bc85e8847642609180d5a99f1fd565e5 /src/test
parentc38cb76e8aa42dcdbe5dacc0da55952a84afa7a6 (diff)
test: add tests for $SYSTEMD_MEMPOOL=
This adds tests for b4f607433cac749b617e15b3d5d122322ed2bc71 and 205c085bc36c2c61a09dc40621d8561b135d9b57 (#9792). (cherry picked from commit 3ffd12bfbe9f91b392d80fbf6a8b2def2a13bf6d)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build4
-rw-r--r--src/test/test-set-disable-mempool.c55
2 files changed, 59 insertions, 0 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index 0405fac52..dae520fe7 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -426,6 +426,10 @@ tests += [
[],
[]],
+ [['src/test/test-set-disable-mempool.c'],
+ [],
+ [threads]],
+
#if 0 /// UNNEEDED in elogind
# [['src/test/test-bitmap.c'],
# [],
diff --git a/src/test/test-set-disable-mempool.c b/src/test/test-set-disable-mempool.c
new file mode 100644
index 000000000..e7dbf61c2
--- /dev/null
+++ b/src/test/test-set-disable-mempool.c
@@ -0,0 +1,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;
+}