diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-24 15:52:13 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-24 16:12:15 +0100 |
commit | 543497fa34ccd754d9278124ca0c8e45fe1d3005 (patch) | |
tree | 7acf8c1a07c07c863730b3acfed1a780f65f9c01 /src/test/test-process-util.c | |
parent | core: normalize ioprio values we acquire from kernel (diff) | |
download | systemd-543497fa34ccd754d9278124ca0c8e45fe1d3005.tar.xz systemd-543497fa34ccd754d9278124ca0c8e45fe1d3005.zip |
test: add test for ioprio normalization
Diffstat (limited to '')
-rw-r--r-- | src/test/test-process-util.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index dc45712937..cc0f870e57 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -726,32 +726,38 @@ static void test_pid_to_ptr(void) { assert_se(PTR_TO_PID(PID_TO_PTR(INT32_MIN)) == INT32_MIN); } -static void test_ioprio_class_from_to_string_one(const char *val, int expected) { +static void test_ioprio_class_from_to_string_one(const char *val, int expected, int normalized) { assert_se(ioprio_class_from_string(val) == expected); if (expected >= 0) { _cleanup_free_ char *s = NULL; unsigned ret; + int combined; assert_se(ioprio_class_to_string_alloc(expected, &s) == 0); - /* We sometimes get a class number and sometimes a number back */ + /* We sometimes get a class number and sometimes a name back */ assert_se(streq(s, val) || safe_atou(val, &ret) == 0); + + /* Make sure normalization works, i.e. NONE → BE gets normalized */ + combined = ioprio_normalize(ioprio_prio_value(expected, 0)); + assert_se(ioprio_prio_class(combined) == normalized); + assert_se(expected != IOPRIO_CLASS_NONE || ioprio_prio_data(combined) == 4); } } static void test_ioprio_class_from_to_string(void) { log_info("/* %s */", __func__); - test_ioprio_class_from_to_string_one("none", IOPRIO_CLASS_NONE); - test_ioprio_class_from_to_string_one("realtime", IOPRIO_CLASS_RT); - test_ioprio_class_from_to_string_one("best-effort", IOPRIO_CLASS_BE); - test_ioprio_class_from_to_string_one("idle", IOPRIO_CLASS_IDLE); - test_ioprio_class_from_to_string_one("0", 0); - test_ioprio_class_from_to_string_one("1", 1); - test_ioprio_class_from_to_string_one("7", 7); - test_ioprio_class_from_to_string_one("8", 8); - test_ioprio_class_from_to_string_one("9", -EINVAL); - test_ioprio_class_from_to_string_one("-1", -EINVAL); + test_ioprio_class_from_to_string_one("none", IOPRIO_CLASS_NONE, IOPRIO_CLASS_BE); + test_ioprio_class_from_to_string_one("realtime", IOPRIO_CLASS_RT, IOPRIO_CLASS_RT); + test_ioprio_class_from_to_string_one("best-effort", IOPRIO_CLASS_BE, IOPRIO_CLASS_BE); + test_ioprio_class_from_to_string_one("idle", IOPRIO_CLASS_IDLE, IOPRIO_CLASS_IDLE); + test_ioprio_class_from_to_string_one("0", IOPRIO_CLASS_NONE, IOPRIO_CLASS_BE); + test_ioprio_class_from_to_string_one("1", 1, 1); + test_ioprio_class_from_to_string_one("7", 7, 7); + test_ioprio_class_from_to_string_one("8", 8, 8); + test_ioprio_class_from_to_string_one("9", -EINVAL, -EINVAL); + test_ioprio_class_from_to_string_one("-1", -EINVAL, -EINVAL); } static void test_setpriority_closest(void) { |