diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-30 21:58:59 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-30 21:58:59 +0200 |
commit | bca895c4f4e5ca1d5459a2c9206dba9019d31775 (patch) | |
tree | 836df59873eb2e58f41f068cb9a56107ce76ff91 | |
parent | basic/fileio: fix reading of not-too-small virtual files (diff) | |
download | systemd-bca895c4f4e5ca1d5459a2c9206dba9019d31775.tar.xz systemd-bca895c4f4e5ca1d5459a2c9206dba9019d31775.zip |
test-fileio: test for read_full_virtual_file()
It was already called through other places, but indirectly.
Let's add some direct invocations.
-rw-r--r-- | src/test/test-fileio.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 659b690082..c5c8116e96 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -9,6 +9,7 @@ #include "ctype.h" #include "env-file.h" #include "env-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -964,6 +965,24 @@ static void test_read_full_file_offset_size(void) { rbuf = mfree(rbuf); } +static void test_read_full_virtual_file(void) { + const char *filename; + int r; + + FOREACH_STRING(filename, + "/proc/1/cmdline", + "/etc/nsswitch.conf", + "/sys/kernel/uevent_seqnum") { + + _cleanup_free_ char *buf = NULL; + size_t size = 0; + + r = read_full_virtual_file(filename, &buf, &size); + log_info_errno(r, "read_full_virtual_file(\"%s\"): %m (%zu bytes)", filename, size); + assert_se(r == 0 || ERRNO_IS_PRIVILEGE(r) || r == -ENOENT); + } +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_DEBUG); @@ -991,6 +1010,7 @@ int main(int argc, char *argv[]) { test_read_nul_string(); test_read_full_file_socket(); test_read_full_file_offset_size(); + test_read_full_virtual_file(); return 0; } |