]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-device/test-sd-device.c
Merge pull request #10159 from poettering/killall-spree-kernel-thread
[thirdparty/systemd.git] / src / libsystemd / sd-device / test-sd-device.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "device-enumerator-private.h"
4 #include "device-private.h"
5 #include "device-util.h"
6 #include "string-util.h"
7 #include "tests.h"
8 #include "util.h"
9
10 static void test_sd_device_basic(void) {
11 _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
12 sd_device *d;
13
14 assert_se(sd_device_enumerator_new(&e) >= 0);
15 assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0);
16 FOREACH_DEVICE(e, d) {
17 const char *syspath, *devpath, *subsystem, *val;
18 dev_t devnum;
19 usec_t usec;
20 int i, r;
21
22 assert_se(sd_device_get_syspath(d, &syspath) >= 0);
23
24 r = sd_device_get_subsystem(d, &subsystem);
25 assert_se(r >= 0 || r == -ENOENT);
26
27 r = sd_device_get_devtype(d, &val);
28 assert_se(r >= 0 || r == -ENOENT);
29
30 r = sd_device_get_devnum(d, &devnum);
31 assert_se(r >= 0 || r == -ENOENT);
32
33 r = sd_device_get_ifindex(d, &i);
34 assert_se(r >= 0 || r == -ENOENT);
35
36 r = sd_device_get_driver(d, &val);
37 assert_se(r >= 0 || r == -ENOENT);
38
39 assert_se(sd_device_get_devpath(d, &devpath) >= 0);
40
41 r = sd_device_get_devname(d, &val);
42 assert_se(r >= 0 || r == -ENOENT);
43
44 assert_se(sd_device_get_sysname(d, &val) >= 0);
45
46 r = sd_device_get_sysnum(d, &val);
47 assert_se(r >= 0 || r == -ENOENT);
48
49 i = 0;
50 assert_se(sd_device_get_is_initialized(d, &i) >= 0);
51 if (i > 0) {
52 r = sd_device_get_usec_since_initialized(d, &usec);
53 assert_se(r >= 0 || r == -ENODATA);
54 }
55
56 r = sd_device_get_sysattr_value(d, "name_assign_type", &val);
57 assert_se(r >= 0 || IN_SET(r, -ENOENT, -EINVAL));
58
59 r = sd_device_get_property_value(d, "ID_NET_DRIVER", &val);
60 assert_se(r >= 0 || r == -ENOENT);
61
62 log_debug("syspath:%s devpath:%s subsystem:%s", syspath, devpath, strempty(subsystem));
63 }
64 }
65
66 int main(int argc, char **argv) {
67 test_setup_logging(LOG_INFO);
68
69 test_sd_device_basic();
70 return 0;
71 }