From: Lennart Poettering Date: Tue, 28 May 2024 08:01:24 +0000 (+0200) Subject: test: add superficial test for partscan test X-Git-Tag: v256-rc4~99^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3455bcb0dfba585b9c4cccd3b1dd6f7df51b9b72;p=thirdparty%2Fsystemd.git test: add superficial test for partscan test --- diff --git a/src/test/test-blockdev-util.c b/src/test/test-blockdev-util.c index 134386c3f68..19626e0b771 100644 --- a/src/test/test-blockdev-util.c +++ b/src/test/test-blockdev-util.c @@ -1,7 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "blockdev-util.h" +#include "device-util.h" #include "errno-util.h" +#include "fd-util.h" #include "tests.h" static void test_path_is_encrypted_one(const char *p, int expect) { @@ -38,4 +40,39 @@ TEST(path_is_encrypted) { test_path_is_encrypted_one("/dev", booted > 0 ? false : -1); } +TEST(partscan_enabled) { + + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; + int r; + + assert_se(sd_device_enumerator_new(&e) >= 0); + assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0); + assert_se(sd_device_enumerator_add_match_subsystem(e, "block", /* match = */ true) >= 0); + + FOREACH_DEVICE(e, dev) { + _cleanup_close_ int fd = -EBADF; + const char *name; + + r = sd_device_get_devname(dev, &name); + if (r < 0) { + log_warning_errno(r, "Found block device without a name, skipping."); + continue; + } + + fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); + if (fd < 0) { + log_warning_errno(fd, "Found block device '%s' which we cannot open, skipping: %m", name); + continue; + } + + r = blockdev_partscan_enabled(fd); + if (r < 0) { + log_warning_errno(r, "Failed to determine if block device '%s' has partition scanning enabled, skipping: %m", name); + continue; + } + + log_info("%s has partition scanning enabled: %s", name, yes_no(r)); + } +} + DEFINE_TEST_MAIN(LOG_INFO);