mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
Merge pull request #10369 from yuwata/test-mempool
meson,test: mempool related fixes and add tests for 'thread safety'
This commit is contained in:
commit
76137725f0
@ -1409,6 +1409,7 @@ install_libsystemd_static = static_library(
|
||||
journal_client_sources,
|
||||
basic_sources,
|
||||
basic_gcrypt_sources,
|
||||
disable_mempool_c,
|
||||
include_directories : includes,
|
||||
build_by_default : static_libsystemd != 'false',
|
||||
install : static_libsystemd != 'false',
|
||||
|
@ -1,8 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define FOREACH_DEVICE_PROPERTY(device, key, value) \
|
||||
for (key = sd_device_get_property_first(device, &(value)); \
|
||||
key; \
|
||||
|
39
src/libsystemd/sd-device/test-sd-device-thread.c
Normal file
39
src/libsystemd/sd-device/test-sd-device-thread.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "device-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
static void* thread(void *p) {
|
||||
sd_device **d = p;
|
||||
|
||||
assert_se(!(*d = sd_device_unref(*d)));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
sd_device *loopback;
|
||||
pthread_t t;
|
||||
const char *key, *value;
|
||||
|
||||
assert_se(unsetenv("SYSTEMD_MEMPOOL") == 0);
|
||||
|
||||
assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
|
||||
|
||||
FOREACH_DEVICE_PROPERTY(loopback, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
|
||||
assert_se(pthread_create(&t, NULL, thread, &loopback) == 0);
|
||||
assert_se(pthread_join(t, NULL) == 0);
|
||||
|
||||
assert_se(!loopback);
|
||||
|
||||
return 0;
|
||||
}
|
36
src/libsystemd/sd-device/test-udev-device-thread.c
Normal file
36
src/libsystemd/sd-device/test-udev-device-thread.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libudev.h"
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
static void* thread(void *p) {
|
||||
struct udev_device **d = p;
|
||||
|
||||
assert_se(!(*d = udev_device_unref(*d)));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct udev_device *loopback;
|
||||
pthread_t t;
|
||||
|
||||
assert_se(unsetenv("SYSTEMD_MEMPOOL") == 0);
|
||||
|
||||
assert_se(loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo"));
|
||||
|
||||
assert_se(udev_device_get_properties_list_entry(loopback));
|
||||
|
||||
assert_se(pthread_create(&t, NULL, thread, &loopback) == 0);
|
||||
assert_se(pthread_join(t, NULL) == 0);
|
||||
|
||||
assert_se(!loopback);
|
||||
|
||||
return 0;
|
||||
}
|
@ -399,6 +399,10 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-set-disable-mempool.c'],
|
||||
[],
|
||||
[threads]],
|
||||
|
||||
[['src/test/test-bitmap.c'],
|
||||
[],
|
||||
[]],
|
||||
@ -900,6 +904,18 @@ tests += [
|
||||
[['src/libsystemd/sd-device/test-sd-device.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/libsystemd/sd-device/test-sd-device-thread.c'],
|
||||
[libbasic,
|
||||
libshared_static,
|
||||
libsystemd],
|
||||
[threads]],
|
||||
|
||||
[['src/libsystemd/sd-device/test-udev-device-thread.c'],
|
||||
[libbasic,
|
||||
libshared_static,
|
||||
libudev],
|
||||
[threads]],
|
||||
]
|
||||
|
||||
if cxx.found()
|
||||
|
@ -1,22 +1,22 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <net/if.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "af-list.h"
|
||||
#include "alloc-util.h"
|
||||
#include "errno-list.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "hostname-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "local-addresses.h"
|
||||
#include "log.h"
|
||||
#include "nss-util.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "alloc-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "af-list.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "errno-list.h"
|
||||
#include "hostname-util.h"
|
||||
#include "local-addresses.h"
|
||||
|
||||
static const char* nss_status_to_string(enum nss_status status, char *buf, size_t buf_len) {
|
||||
switch (status) {
|
||||
|
53
src/test/test-set-disable-mempool.c
Normal file
53
src/test/test-set-disable-mempool.c
Normal 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;
|
||||
}
|
@ -124,6 +124,7 @@ install_libudev_static = static_library(
|
||||
shared_sources,
|
||||
libsystemd_sources,
|
||||
libudev_sources,
|
||||
disable_mempool_c,
|
||||
include_directories : includes,
|
||||
build_by_default : static_libudev != 'false',
|
||||
install : static_libudev != 'false',
|
||||
@ -135,7 +136,7 @@ install_libudev_static = static_library(
|
||||
|
||||
libudev = shared_library(
|
||||
'udev',
|
||||
'udev.h', # pick a header file at random to work around old meson bug
|
||||
disable_mempool_c,
|
||||
version : libudev_version,
|
||||
include_directories : includes,
|
||||
link_args : ['-shared',
|
||||
|
Loading…
Reference in New Issue
Block a user