diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-04-13 15:38:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-04-13 16:26:31 +0200 |
commit | 7176f06c9efea4b86f3f55e448fc80e16d43e54b (patch) | |
tree | 7143992013c291f643297d98ff003bf4bfbeaa1f /src/test/test-stat-util.c | |
parent | c87c30780624df257ed96909a2286b2b933f8c44 (diff) | |
download | systemd-7176f06c9efea4b86f3f55e448fc80e16d43e54b.tar.gz |
basic: split out dev_t related calls into new devno-util.[ch]
No actual code changes, just splitting out of some dev_t handling
related calls from stat-util.[ch], they are quite a number already, and
deserve their own module now I think.
Also, try to settle on the name "devnum" as the name for the concept,
instead of "devno" or "dev" or "devid". "devnum" is the name exported in
udev APIs, hence probably best to stick to that. (this just renames a
few symbols to "devum", local variables are left untouched, to make the
patch not too invasive)
No actual code changes.
Diffstat (limited to 'src/test/test-stat-util.c')
-rw-r--r-- | src/test/test-stat-util.c | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index 9975a1848d..c5afde02d0 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -149,88 +149,6 @@ TEST(fd_is_ns) { assert_se(IN_SET(fd_is_ns(fd, CLONE_NEWNET), 1, -EUCLEAN)); } -TEST(device_major_minor_valid) { - /* on glibc dev_t is 64bit, even though in the kernel it is only 32bit */ - assert_cc(sizeof(dev_t) == sizeof(uint64_t)); - - assert_se(DEVICE_MAJOR_VALID(0U)); - assert_se(DEVICE_MINOR_VALID(0U)); - - assert_se(DEVICE_MAJOR_VALID(1U)); - assert_se(DEVICE_MINOR_VALID(1U)); - - assert_se(!DEVICE_MAJOR_VALID(-1U)); - assert_se(!DEVICE_MINOR_VALID(-1U)); - - assert_se(DEVICE_MAJOR_VALID(1U << 10)); - assert_se(DEVICE_MINOR_VALID(1U << 10)); - - assert_se(DEVICE_MAJOR_VALID((1U << 12) - 1)); - assert_se(DEVICE_MINOR_VALID((1U << 20) - 1)); - - assert_se(!DEVICE_MAJOR_VALID((1U << 12))); - assert_se(!DEVICE_MINOR_VALID((1U << 20))); - - assert_se(!DEVICE_MAJOR_VALID(1U << 25)); - assert_se(!DEVICE_MINOR_VALID(1U << 25)); - - assert_se(!DEVICE_MAJOR_VALID(UINT32_MAX)); - assert_se(!DEVICE_MINOR_VALID(UINT32_MAX)); - - assert_se(!DEVICE_MAJOR_VALID(UINT64_MAX)); - assert_se(!DEVICE_MINOR_VALID(UINT64_MAX)); - - assert_se(DEVICE_MAJOR_VALID(major(0))); - assert_se(DEVICE_MINOR_VALID(minor(0))); -} - -static void test_device_path_make_canonical_one(const char *path) { - _cleanup_free_ char *resolved = NULL, *raw = NULL; - struct stat st; - dev_t devno; - mode_t mode; - int r; - - log_debug("> %s", path); - - if (stat(path, &st) < 0) { - assert_se(errno == ENOENT); - log_notice("Path %s not found, skipping test", path); - return; - } - - r = device_path_make_canonical(st.st_mode, st.st_rdev, &resolved); - if (r == -ENOENT) { - /* maybe /dev/char/x:y and /dev/block/x:y are missing in this test environment, because we - * run in a container or so? */ - log_notice("Device %s cannot be resolved, skipping test", path); - return; - } - - assert_se(r >= 0); - assert_se(path_equal(path, resolved)); - - assert_se(device_path_make_major_minor(st.st_mode, st.st_rdev, &raw) >= 0); - assert_se(device_path_parse_major_minor(raw, &mode, &devno) >= 0); - - assert_se(st.st_rdev == devno); - assert_se((st.st_mode & S_IFMT) == (mode & S_IFMT)); -} - -TEST(device_path_make_canonical) { - test_device_path_make_canonical_one("/dev/null"); - test_device_path_make_canonical_one("/dev/zero"); - test_device_path_make_canonical_one("/dev/full"); - test_device_path_make_canonical_one("/dev/random"); - test_device_path_make_canonical_one("/dev/urandom"); - test_device_path_make_canonical_one("/dev/tty"); - - if (is_device_node("/run/systemd/inaccessible/blk") > 0) { - test_device_path_make_canonical_one("/run/systemd/inaccessible/chr"); - test_device_path_make_canonical_one("/run/systemd/inaccessible/blk"); - } -} - TEST(dir_is_empty) { _cleanup_(rm_rf_physical_and_freep) char *empty_dir = NULL; _cleanup_free_ char *j = NULL, *jj = NULL; |