summaryrefslogtreecommitdiffstats
path: root/src/libudev
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-12-31 21:22:23 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-01-18 23:04:19 +0100
commit772e0a76f34914f6f81205e912e4744c6b23f704 (patch)
treef208265db38921d66e7fa4d2b4632eb2926fe4be /src/libudev
parenttest: move tests for libudev into src/libudev (diff)
downloadsystemd-772e0a76f34914f6f81205e912e4744c6b23f704.tar.xz
systemd-772e0a76f34914f6f81205e912e4744c6b23f704.zip
test: rewrite test-sd-device-thread.c to depend only on libsystemd
Similarly, this makes test-udev-device-thread.c depend only on libudev.
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/test-udev-device-thread.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/libudev/test-udev-device-thread.c b/src/libudev/test-udev-device-thread.c
index a493152d4a..3f0341a698 100644
--- a/src/libudev/test-udev-device-thread.c
+++ b/src/libudev/test-udev-device-thread.c
@@ -1,36 +1,53 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include <errno.h>
#include <pthread.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "libudev.h"
-#include "macro.h"
+#define handle_error_errno(error, msg) \
+ ({ \
+ errno = abs(error); \
+ perror(msg); \
+ EXIT_FAILURE; \
+ })
static void* thread(void *p) {
struct udev_device **d = p;
- assert_se(!(*d = udev_device_unref(*d)));
+ *d = udev_device_unref(*d);
return NULL;
}
int main(int argc, char *argv[]) {
struct udev_device *loopback;
+ struct udev_list_entry *entry, *e;
pthread_t t;
+ int r;
- assert_se(unsetenv("SYSTEMD_MEMPOOL") == 0);
+ unsetenv("SYSTEMD_MEMPOOL");
- assert_se(loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo"));
+ loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo");
+ if (!loopback)
+ return handle_error_errno(errno, "Failed to create loopback device object");
- assert_se(udev_device_get_properties_list_entry(loopback));
+ entry = udev_device_get_properties_list_entry(loopback);
+ udev_list_entry_foreach(e, entry)
+ printf("%s=%s\n", udev_list_entry_get_name(e), udev_list_entry_get_value(e));
- assert_se(pthread_create(&t, NULL, thread, &loopback) == 0);
- assert_se(pthread_join(t, NULL) == 0);
+ r = pthread_create(&t, NULL, thread, &loopback);
+ if (r != 0)
+ return handle_error_errno(r, "Failed to create thread");
- assert_se(!loopback);
+ r = pthread_join(t, NULL);
+ if (r != 0)
+ return handle_error_errno(r, "Failed to wait thread finished");
+
+ if (loopback)
+ return handle_error_errno(r, "loopback device is not unref()ed");
return 0;
}