Compare commits

...

2 Commits

Author SHA1 Message Date
Busayo Dada 75b3b1c8fa
Merge 5134ed4230 into a035eaa227 2025-04-17 13:30:32 +00:00
Busayo Dada 5134ed4230 test: add test for getting block device devnum from file 2025-04-17 10:06:42 +01:00
1 changed files with 43 additions and 1 deletions

View File

@ -1,10 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "blockdev-util.h"
#include "device-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "path-util.h"
#include "sd-device.h"
#include "tests.h"
#include "tmpfile-util.h"
static void test_path_is_encrypted_one(const char *p, int expect) {
int r;
@ -26,6 +33,36 @@ static void test_path_is_encrypted_one(const char *p, int expect) {
assert_se(expect < 0 || ((r > 0) == (expect > 0)));
}
TEST(get_block_device) {
_cleanup_free_ char *path = NULL, *devnode = NULL;
_cleanup_(sd_device_unrefp) sd_device *sd_dev = NULL;
int r;
dev_t devnum;
ASSERT_OK(mkdtemp_malloc(NULL, &path));
size_t len = strlen(path) + strlen("/loop0") + 1;
devnode = malloc(len);
ASSERT_OK(devnode != NULL);
snprintf(devnode, len, "%s/loop0", path);
ASSERT_OK(mknod(devnode, S_IFBLK | 0600, makedev(7, 0)));
r = get_block_device(devnode, &devnum);
ASSERT_OK(r);
r = sd_device_new_from_devnum(&sd_dev, 'b', devnum);
ASSERT_OK(r);
r = device_is_devtype(sd_dev, "disk");
ASSERT_OK(r);
sd_device *parent = NULL;
r = sd_device_get_parent(sd_dev, &parent);
ASSERT_OK(r);
}
TEST(path_is_encrypted) {
int booted = sd_booted(); /* If this is run in build environments such as koji, /dev/ might be a
* regular fs. Don't assume too much if not running under systemd. */
@ -75,4 +112,9 @@ TEST(partscan_enabled) {
}
}
DEFINE_TEST_MAIN(LOG_INFO);
static int intro(void) {
log_show_color(true);
return EXIT_SUCCESS;
}
DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);