test: add superficial test for partscan test

This commit is contained in:
Lennart Poettering
2024-05-28 11:08:06 +02:00
parent fa65917623
commit 3455bcb0df
+37
View File
@@ -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);