diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-12-09 00:57:06 +0900 |
---|---|---|
committer | Frantisek Sumsal <frantisek@sumsal.cz> | 2019-12-09 08:45:25 +0000 |
commit | 8ee08dc564cc960e9654d50a51fceefe882ff591 (patch) | |
tree | ca3d25b0d974d5d5bd430ca4bc29d53da9270548 | |
parent | bc942f69aa49b320d8ad385ac89b2fbb00c18e9c (diff) | |
download | systemd-8ee08dc564cc960e9654d50a51fceefe882ff591.tar.gz |
test: do not fail if new device is plugged during enumeration
-rw-r--r-- | src/libsystemd/sd-device/test-sd-device.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index 33a25d576a..ca9662b851 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -81,9 +81,10 @@ static void test_sd_device_enumerator_subsystems(void) { test_sd_device_one(d); } -static void test_sd_device_enumerator_filter_subsystem_one(const char *subsystem, Hashmap *h) { +static unsigned test_sd_device_enumerator_filter_subsystem_one(const char *subsystem, Hashmap *h) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; sd_device *d, *t; + unsigned n_new_dev = 0; assert_se(sd_device_enumerator_new(&e) >= 0); assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, true) >= 0); @@ -92,18 +93,27 @@ static void test_sd_device_enumerator_filter_subsystem_one(const char *subsystem const char *syspath; assert_se(sd_device_get_syspath(d, &syspath) >= 0); - assert_se(t = hashmap_remove(h, syspath)); + t = hashmap_remove(h, syspath); assert_se(!sd_device_unref(t)); - log_debug("Removed subsystem:%s syspath:%s", subsystem, syspath); + if (t) + log_debug("Removed subsystem:%s syspath:%s", subsystem, syspath); + else { + log_warning("New device found: subsystem:%s syspath:%s", subsystem, syspath); + n_new_dev++; + } } + /* Assume no device is unplugged. */ assert_se(hashmap_isempty(h)); + + return n_new_dev; } static void test_sd_device_enumerator_filter_subsystem(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_(hashmap_freep) Hashmap *subsystems; + unsigned n_new_dev = 0; sd_device *d; Hashmap *h; char *s; @@ -139,10 +149,16 @@ static void test_sd_device_enumerator_filter_subsystem(void) { } while ((h = hashmap_steal_first_key_and_value(subsystems, (void**) &s))) { - test_sd_device_enumerator_filter_subsystem_one(s, h); + n_new_dev += test_sd_device_enumerator_filter_subsystem_one(s, h); hashmap_free(h); free(s); } + + if (n_new_dev > 0) + log_warning("%u new device is found in re-scan", n_new_dev); + + /* Assume that not so many devices are plugged. */ + assert_se(n_new_dev <= 10); } int main(int argc, char **argv) { |