blockdev-util: split out partition device node generation from dissect-util.c
This commit is contained in:
@@ -77,4 +77,30 @@ TEST(partscan_enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_partition_node_of_one(const char *main, unsigned partition, const char *result, int retval) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
int r;
|
||||
|
||||
r = partition_node_of(main, partition, &s);
|
||||
ASSERT_EQ(r, retval);
|
||||
if (r < 0)
|
||||
return;
|
||||
ASSERT_STREQ(s, result);
|
||||
|
||||
log_info("%s with %u → %s", main, partition, result);
|
||||
}
|
||||
|
||||
TEST(partition_node_of) {
|
||||
test_partition_node_of_one("/dev/sda", 2, "/dev/sda2", 0);
|
||||
test_partition_node_of_one("sda", 3, "sda3", 0);
|
||||
test_partition_node_of_one("/dev/nvme0n1", 7, "/dev/nvme0n1p7", 0);
|
||||
test_partition_node_of_one("nvme0n1", 8, "nvme0n1p8", 0);
|
||||
test_partition_node_of_one("/dev/loop1", 3, "/dev/loop1p3", 0);
|
||||
test_partition_node_of_one("", 1, NULL, -EINVAL);
|
||||
test_partition_node_of_one("/", 1, NULL, -EADDRNOTAVAIL);
|
||||
test_partition_node_of_one("/dev/", 1, NULL, -EISDIR);
|
||||
test_partition_node_of_one("/sda", 1, "/sda1", 0);
|
||||
test_partition_node_of_one(".", 1, NULL, -EADDRNOTAVAIL);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
||||
Reference in New Issue
Block a user