diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-12 11:45:20 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-12 17:54:23 +0900 |
commit | a6ee01caf3409ba9820e8824b9262fbac31a9f77 (patch) | |
tree | 6565dde8e730400c7ab7488445e6163010bc18ab /src/libsystemd/sd-device | |
parent | 657ccaac1b898e6cb4865df38d1cf09c50f6c0ac (diff) | |
download | systemd-a6ee01caf3409ba9820e8824b9262fbac31a9f77.tar.gz |
test: add test for 'thread safety' of sd-device
This adds a test for a5d8835c78112206bbf0812dd4cb471f803bfe88.
Diffstat (limited to 'src/libsystemd/sd-device')
-rw-r--r-- | src/libsystemd/sd-device/test-sd-device-thread.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/test-sd-device-thread.c b/src/libsystemd/sd-device/test-sd-device-thread.c new file mode 100644 index 0000000000..9f1c02373f --- /dev/null +++ b/src/libsystemd/sd-device/test-sd-device-thread.c @@ -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; +} |