diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-12-05 11:08:48 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-12-05 20:14:08 +0100 |
commit | 1526396807f9290fe0d065be310225e81d4588da (patch) | |
tree | 81e0f19879dd1f9997b7c0251071427638939006 /src/test/test-condition.c | |
parent | test-cgroup: use ASSERT_* macros (diff) | |
download | systemd-1526396807f9290fe0d065be310225e81d4588da.tar.xz systemd-1526396807f9290fe0d065be310225e81d4588da.zip |
test-condition: use ASSERT_* macros
Some strange asserts are dropped.
Diffstat (limited to '')
-rw-r--r-- | src/test/test-condition.c | 921 |
1 files changed, 367 insertions, 554 deletions
diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 76b2af91a9..a2884621ff 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -48,89 +48,72 @@ TEST(condition_test_path) { Condition *condition; - condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_EXISTS, "/bin/s?", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS, "/bin/s?", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, true)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_DIRECTORY, "/bin", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_DIRECTORY, "/bin", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_DIRECTORY_NOT_EMPTY, "/bin", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_DIRECTORY_NOT_EMPTY, "/bin", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_FILE_NOT_EMPTY, "/bin/sh", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FILE_NOT_EMPTY, "/bin/sh", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/bin/sh", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/bin/sh", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/etc/passwd", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/etc/passwd", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/proc", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/proc", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_READ_WRITE, "/tmp", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_READ_WRITE, "/tmp", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_ENCRYPTED, "/sys", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_ENCRYPTED, "/sys", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); } @@ -139,20 +122,16 @@ TEST(condition_test_control_group_hierarchy) { int r; r = cg_unified(); - if (IN_SET(r, -ENOMEDIUM, -ENOENT)) { - log_tests_skipped("cgroupfs is not mounted"); - return; - } - assert_se(r >= 0); + if (IN_SET(r, -ENOMEDIUM, -ENOENT)) + return (void) log_tests_skipped("cgroupfs is not mounted"); + ASSERT_OK(r); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "v1", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == (r < CGROUP_UNIFIED_ALL)); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "v1", false, false)); + ASSERT_OK_EQ(condition_test(condition, environ), r < CGROUP_UNIFIED_ALL); condition_free(condition); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "v2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == (r >= CGROUP_UNIFIED_ALL)); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "v2", false, false)); + ASSERT_OK_EQ(condition_test(condition, environ), r >= CGROUP_UNIFIED_ALL); condition_free(condition); } @@ -163,24 +142,20 @@ TEST(condition_test_control_group_controller) { int r; r = cg_unified(); - if (IN_SET(r, -ENOMEDIUM, -ENOENT)) { - log_tests_skipped("cgroupfs is not mounted"); - return; - } - assert_se(r >= 0); + if (IN_SET(r, -ENOMEDIUM, -ENOENT)) + return (void) log_tests_skipped("cgroupfs is not mounted"); + ASSERT_OK(r); /* Invalid controllers are ignored */ - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "thisisnotarealcontroller", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "thisisnotarealcontroller", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "thisisnotarealcontroller", false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, "thisisnotarealcontroller", false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - assert_se(cg_mask_supported(&system_mask) >= 0); + ASSERT_OK(cg_mask_supported(&system_mask)); /* Individual valid controllers one by one */ for (CGroupController controller = 0; controller < _CGROUP_CONTROLLER_MAX; controller++) { @@ -188,58 +163,49 @@ TEST(condition_test_control_group_controller) { log_info("chosen controller is '%s'", local_controller_name); if (system_mask & CGROUP_CONTROLLER_TO_MASK(controller)) { log_info("this controller is available"); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } else { log_info("this controller is unavailable"); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, local_controller_name, false, true)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); } } /* Multiple valid controllers at the same time */ - assert_se(cg_mask_to_string(system_mask, &controller_name) >= 0); + ASSERT_OK(cg_mask_to_string(system_mask, &controller_name)); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, strempty(controller_name), false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, strempty(controller_name), false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, strempty(controller_name), false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CONTROL_GROUP_CONTROLLER, strempty(controller_name), false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } TEST(condition_test_ac_power) { Condition *condition; - condition = condition_new(CONDITION_AC_POWER, "true", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_AC_POWER, "true", false, false)); assert_se(condition_test(condition, environ) == on_ac_power()); condition_free(condition); - condition = condition_new(CONDITION_AC_POWER, "false", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_AC_POWER, "false", false, false)); assert_se(condition_test(condition, environ) != on_ac_power()); condition_free(condition); - condition = condition_new(CONDITION_AC_POWER, "false", false, true); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_AC_POWER, "false", false, true)); assert_se(condition_test(condition, environ) == on_ac_power()); condition_free(condition); } @@ -253,35 +219,29 @@ TEST(condition_test_host) { r = sd_id128_get_machine(&id); if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r)) return (void) log_tests_skipped("/etc/machine-id missing"); - assert_se(r >= 0); + ASSERT_OK(r); - condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_HOST, "garbage value jjjjjjjjjjjjjj", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_HOST, "garbage value jjjjjjjjjjjjjj", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - hostname = gethostname_malloc(); - assert_se(hostname); + ASSERT_NOT_NULL(hostname = gethostname_malloc()); /* if hostname looks like an id128 then skip testing it */ if (id128_is_valid(hostname)) - log_notice("hostname is an id128, skipping test"); - else { - condition = condition_new(CONDITION_HOST, hostname, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); - condition_free(condition); - } + return (void) log_notice("hostname is an id128, skipping test"); + + ASSERT_NOT_NULL(condition = condition_new(CONDITION_HOST, hostname, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); + condition_free(condition); } TEST(condition_test_architecture) { @@ -289,25 +249,19 @@ TEST(condition_test_architecture) { const char *sa; Architecture a; - a = uname_architecture(); - assert_se(a >= 0); - - sa = architecture_to_string(a); - assert_se(sa); + ASSERT_OK(a = uname_architecture()); + ASSERT_NOT_NULL(sa = architecture_to_string(a)); - condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } @@ -315,15 +269,13 @@ TEST(condition_test_firmware) { Condition *condition; /* Empty parameter */ - condition = condition_new(CONDITION_FIRMWARE, "", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* uefi parameter */ - condition = condition_new(CONDITION_FIRMWARE, "uefi", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == is_efi_boot()); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "uefi", false, false)); + ASSERT_OK_EQ(condition_test(condition, environ), is_efi_boot()); condition_free(condition); } @@ -332,18 +284,16 @@ TEST(condition_test_firmware_device_tree) { bool is_device_tree_system; /* device-tree parameter */ - is_device_tree_system = (access("/sys/firmware/devicetree/", F_OK) == 0); + is_device_tree_system = access("/sys/firmware/devicetree/", F_OK) == 0; - condition = condition_new(CONDITION_FIRMWARE, "device-tree", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == is_device_tree_system); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "device-tree", false, false)); + ASSERT_OK_EQ(condition_test(condition, environ), is_device_tree_system); condition_free(condition); /* device-tree-compatible parameter */ if (!is_device_tree_system) { - condition = condition_new(CONDITION_FIRMWARE, "device-tree-compatible()", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "device-tree-compatible()", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } else { _cleanup_free_ char *dtcompat = NULL; @@ -353,12 +303,11 @@ TEST(condition_test_firmware_device_tree) { r = read_full_virtual_file("/proc/device-tree/compatible", &dtcompat, &dtcompat_size); if (r < 0) { - condition = condition_new(CONDITION_FIRMWARE, "device-tree-compatible()", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "device-tree-compatible()", false, false)); if (r == -ENOENT) - assert_se(condition_test(condition, environ) == 0); + ASSERT_OK_ZERO(condition_test(condition, environ)); else - assert_se(condition_test(condition, environ) < 0); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); return; } @@ -368,10 +317,9 @@ TEST(condition_test_firmware_device_tree) { STRV_FOREACH(c, dtcompatlist) { _cleanup_free_ char *expression = NULL; - assert_se(expression = strjoin("device-tree-compatible(", *c, ")")); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(expression = strjoin("device-tree-compatible(", *c, ")")); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); } } @@ -384,40 +332,33 @@ TEST(condition_test_firmware_smbios) { /* smbios-field parameter */ /* Test some malformed smbios-field arguments */ - condition = condition_new(CONDITION_FIRMWARE, "smbios-field()", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field()", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed)", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed)", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed=)", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed=)", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed=)", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(malformed=)", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(not_existing=nothing garbage)", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(not_existing=nothing garbage)", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); /* Test not existing SMBIOS field */ - condition = condition_new(CONDITION_FIRMWARE, "smbios-field(not_existing=nothing)", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, "smbios-field(not_existing=nothing)", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* Test with bios_vendor, if available */ @@ -432,33 +373,28 @@ TEST(condition_test_firmware_smbios) { /* Test equality / inequality using fnmatch() */ expression = strjoina("smbios-field(bios_vendor $= ", quote, bios_vendor, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_vendor$=", quote, bios_vendor, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_vendor !$= ", quote, bios_vendor, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_vendor!$=", quote, bios_vendor, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_vendor $= ", quote, bios_vendor, "*", quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); /* Test version comparison with bios_version, if available */ @@ -472,39 +408,33 @@ TEST(condition_test_firmware_smbios) { quote = strchr(bios_version, ' ') ? "\"" : ""; expression = strjoina("smbios-field(bios_version = ", quote, bios_version, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_version != ", quote, bios_version, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_version <= ", quote, bios_version, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_version >= ", quote, bios_version, quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_version < ", quote, bios_version, ".1", quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); expression = strjoina("smbios-field(bios_version > ", quote, bios_version, ".1", quote, ")"); - condition = condition_new(CONDITION_FIRMWARE, expression, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_FIRMWARE, expression, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } @@ -512,17 +442,15 @@ TEST(condition_test_kernel_command_line) { Condition *condition; int r; - condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false)); r = condition_test(condition, environ); if (ERRNO_IS_PRIVILEGE(r)) return; - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } @@ -531,140 +459,116 @@ TEST(condition_test_kernel_version) { struct utsname u; const char *v; - condition = condition_new(CONDITION_KERNEL_VERSION, "*thisreallyshouldntbeinthekernelversion*", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "*thisreallyshouldntbeinthekernelversion*", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "*", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "*", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); /* An artificially empty condition. It evaluates to true, but normally * such condition cannot be created, because the condition list is reset instead. */ - condition = condition_new(CONDITION_KERNEL_VERSION, "", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - assert_se(uname(&u) >= 0); + ASSERT_OK_ERRNO(uname(&u)); - condition = condition_new(CONDITION_KERNEL_VERSION, u.release, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, u.release, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); strshorten(u.release, 4); strcpy(strchr(u.release, 0), "*"); - condition = condition_new(CONDITION_KERNEL_VERSION, u.release, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, u.release, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); /* 0.1.2 would be a very very very old kernel */ - condition = condition_new(CONDITION_KERNEL_VERSION, "> 0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "> 0.1.2", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, ">0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, ">0.1.2", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "'>0.1.2' '<9.0.0'", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "'>0.1.2' '<9.0.0'", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "> 0.1.2 < 9.0.0", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "> 0.1.2 < 9.0.0", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, ">", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, ">", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, ">= 0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, ">= 0.1.2", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "< 0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "< 0.1.2", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "<= 0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "<= 0.1.2", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "= 0.1.2", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "= 0.1.2", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* 4711.8.15 is a very very very future kernel */ - condition = condition_new(CONDITION_KERNEL_VERSION, "< 4711.8.15", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "< 4711.8.15", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "<= 4711.8.15", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "<= 4711.8.15", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "= 4711.8.15", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "= 4711.8.15", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, "> 4711.8.15", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, "> 4711.8.15", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_KERNEL_VERSION, " >= 4711.8.15", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, " >= 4711.8.15", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - assert_se(uname(&u) >= 0); + ASSERT_OK_ERRNO(uname(&u)); v = strjoina(">=", u.release); - condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); v = strjoina("= ", u.release); - condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); v = strjoina("<=", u.release); - condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); v = strjoina("> ", u.release); - condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); v = strjoina("< ", u.release); - condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_KERNEL_VERSION, v, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } @@ -676,46 +580,39 @@ TEST(condition_test_credential) { assert_se(free_and_strdup(&d1, getenv("CREDENTIALS_DIRECTORY")) >= 0); assert_se(free_and_strdup(&d2, getenv("ENCRYPTED_CREDENTIALS_DIRECTORY")) >= 0); - assert_se(unsetenv("CREDENTIALS_DIRECTORY") >= 0); - assert_se(unsetenv("ENCRYPTED_CREDENTIALS_DIRECTORY") >= 0); + ASSERT_OK_ERRNO(unsetenv("CREDENTIALS_DIRECTORY")); + ASSERT_OK_ERRNO(unsetenv("ENCRYPTED_CREDENTIALS_DIRECTORY")); - condition = condition_new(CONDITION_CREDENTIAL, "definitelymissing", /* trigger= */ false, /* negate= */ false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CREDENTIAL, "definitelymissing", /* trigger= */ false, /* negate= */ false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* invalid */ - condition = condition_new(CONDITION_CREDENTIAL, "..", /* trigger= */ false, /* negate= */ false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CREDENTIAL, "..", /* trigger= */ false, /* negate= */ false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); assert_se(mkdtemp_malloc(NULL, &n1) >= 0); assert_se(mkdtemp_malloc(NULL, &n2) >= 0); - assert_se(setenv("CREDENTIALS_DIRECTORY", n1, /* overwrite= */ true) >= 0); - assert_se(setenv("ENCRYPTED_CREDENTIALS_DIRECTORY", n2, /* overwrite= */ true) >= 0); + ASSERT_OK_ERRNO(setenv("CREDENTIALS_DIRECTORY", n1, /* overwrite= */ true)); + ASSERT_OK_ERRNO(setenv("ENCRYPTED_CREDENTIALS_DIRECTORY", n2, /* overwrite= */ true)); - condition = condition_new(CONDITION_CREDENTIAL, "stillmissing", /* trigger= */ false, /* negate= */ false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CREDENTIAL, "stillmissing", /* trigger= */ false, /* negate= */ false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - assert_se(j = path_join(n1, "existing")); + ASSERT_NOT_NULL(j = path_join(n1, "existing")); assert_se(touch(j) >= 0); - assert_se(j); - condition = condition_new(CONDITION_CREDENTIAL, "existing", /* trigger= */ false, /* negate= */ false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CREDENTIAL, "existing", /* trigger= */ false, /* negate= */ false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); free(j); - assert_se(j = path_join(n2, "existing-encrypted")); + ASSERT_NOT_NULL(j = path_join(n2, "existing-encrypted")); assert_se(touch(j) >= 0); - assert_se(j); - condition = condition_new(CONDITION_CREDENTIAL, "existing-encrypted", /* trigger= */ false, /* negate= */ false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CREDENTIAL, "existing-encrypted", /* trigger= */ false, /* negate= */ false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); assert_se(set_unset_env("CREDENTIALS_DIRECTORY", d1, /* overwrite= */ true) >= 0); @@ -726,19 +623,16 @@ TEST(condition_test_credential) { TEST(condition_test_cpufeature) { Condition *condition; - condition = condition_new(CONDITION_CPU_FEATURE, "fpu", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_FEATURE, "fpu", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_FEATURE, "somecpufeaturethatreallydoesntmakesense", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_FEATURE, "somecpufeaturethatreallydoesntmakesense", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_FEATURE, "a", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_FEATURE, "a", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); } #endif @@ -746,48 +640,39 @@ TEST(condition_test_cpufeature) { TEST(condition_test_security) { Condition *condition; - condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "selinux", false, true); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "selinux", false, true)); assert_se(condition_test(condition, environ) != mac_selinux_use()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "apparmor", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "apparmor", false, false)); assert_se(condition_test(condition, environ) == mac_apparmor_use()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "tomoyo", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "tomoyo", false, false)); assert_se(condition_test(condition, environ) == mac_tomoyo_use()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "ima", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "ima", false, false)); assert_se(condition_test(condition, environ) == use_ima()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "smack", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "smack", false, false)); assert_se(condition_test(condition, environ) == mac_smack_use()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "audit", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "audit", false, false)); assert_se(condition_test(condition, environ) == use_audit()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "uefi-secureboot", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "uefi-secureboot", false, false)); assert_se(condition_test(condition, environ) == is_efi_secure_boot()); condition_free(condition); - condition = condition_new(CONDITION_SECURITY, "cvm", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_SECURITY, "cvm", false, false)); assert_se(condition_test(condition, environ) == (detect_confidential_virtualization() != CONFIDENTIAL_VIRTUALIZATION_NONE)); condition_free(condition); @@ -811,31 +696,27 @@ TEST(condition_test_virtualization) { Condition *condition; int r; - condition = condition_new(CONDITION_VIRTUALIZATION, "garbage oifdsjfoidsjoj", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_VIRTUALIZATION, "garbage oifdsjfoidsjoj", false, false)); r = condition_test(condition, environ); if (ERRNO_IS_PRIVILEGE(r)) return; log_info("ConditionVirtualization=garbage → %i", r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); - condition = condition_new(CONDITION_VIRTUALIZATION, "container", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_VIRTUALIZATION, "container", false, false)); r = condition_test(condition, environ); log_info("ConditionVirtualization=container → %i", r); assert_se(r == !!detect_container()); condition_free(condition); - condition = condition_new(CONDITION_VIRTUALIZATION, "vm", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_VIRTUALIZATION, "vm", false, false)); r = condition_test(condition, environ); log_info("ConditionVirtualization=vm → %i", r); assert_se(r == (detect_vm() && !detect_container())); condition_free(condition); - condition = condition_new(CONDITION_VIRTUALIZATION, "private-users", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_VIRTUALIZATION, "private-users", false, false)); r = condition_test(condition, environ); log_info("ConditionVirtualization=private-users → %i", r); assert_se(r == !!running_in_userns()); @@ -856,11 +737,10 @@ TEST(condition_test_virtualization) { "bhyve\0" "vm_other\0") { - condition = condition_new(CONDITION_VIRTUALIZATION, virt, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_VIRTUALIZATION, virt, false, false)); r = condition_test(condition, environ); log_info("ConditionVirtualization=%s → %i", virt, r); - assert_se(r >= 0); + ASSERT_OK(r); condition_free(condition); } } @@ -871,66 +751,58 @@ TEST(condition_test_user) { char* username; int r; - condition = condition_new(CONDITION_USER, "garbage oifdsjfoidsjoj", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, "garbage oifdsjfoidsjoj", false, false)); r = condition_test(condition, environ); log_info("ConditionUser=garbage → %i", r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); - assert_se(asprintf(&uid, "%"PRIu32, UINT32_C(0xFFFF)) > 0); - condition = condition_new(CONDITION_USER, uid, false, false); - assert_se(condition); + ASSERT_OK_POSITIVE(asprintf(&uid, "%"PRIu32, UINT32_C(0xFFFF))); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, uid, false, false)); r = condition_test(condition, environ); log_info("ConditionUser=%s → %i", uid, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); free(uid); - assert_se(asprintf(&uid, "%u", (unsigned)getuid()) > 0); - condition = condition_new(CONDITION_USER, uid, false, false); - assert_se(condition); + ASSERT_OK_POSITIVE(asprintf(&uid, "%u", (unsigned)getuid())); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, uid, false, false)); r = condition_test(condition, environ); log_info("ConditionUser=%s → %i", uid, r); - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); condition_free(condition); free(uid); - assert_se(asprintf(&uid, "%u", (unsigned)getuid()+1) > 0); - condition = condition_new(CONDITION_USER, uid, false, false); - assert_se(condition); + ASSERT_OK_POSITIVE(asprintf(&uid, "%u", (unsigned)getuid()+1)); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, uid, false, false)); r = condition_test(condition, environ); log_info("ConditionUser=%s → %i", uid, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); free(uid); - username = getusername_malloc(); - assert_se(username); - condition = condition_new(CONDITION_USER, username, false, false); - assert_se(condition); + ASSERT_NOT_NULL(username = getusername_malloc()); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, username, false, false)); r = condition_test(condition, environ); log_info("ConditionUser=%s → %i", username, r); - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); condition_free(condition); free(username); username = (char*)(geteuid() == 0 ? NOBODY_USER_NAME : "root"); - condition = condition_new(CONDITION_USER, username, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, username, false, false)); r = condition_test(condition, environ); log_info("ConditionUser=%s → %i", username, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); - condition = condition_new(CONDITION_USER, "@system", false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_USER, "@system", false, false)); r = condition_test(condition, environ); log_info("ConditionUser=@system → %i", r); if (uid_is_system(getuid()) || uid_is_system(geteuid())) - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); else - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); } @@ -942,20 +814,18 @@ TEST(condition_test_group) { int ngroups_max, ngroups, r, i; assert_se(0 < asprintf(&gid, "%u", UINT32_C(0xFFFF))); - condition = condition_new(CONDITION_GROUP, gid, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, gid, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", gid, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); free(gid); assert_se(0 < asprintf(&gid, "%u", getgid())); - condition = condition_new(CONDITION_GROUP, gid, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, gid, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", gid, r); - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); condition_free(condition); free(gid); @@ -972,34 +842,31 @@ TEST(condition_test_group) { _cleanup_free_ char *name = NULL; assert_se(0 < asprintf(&gid, "%u", gids[i])); - condition = condition_new(CONDITION_GROUP, gid, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, gid, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", gid, r); - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); condition_free(condition); free(gid); max_gid = gids[i] > max_gid ? gids[i] : max_gid; - name = gid_to_name(gids[i]); - assert_se(name); + ASSERT_NOT_NULL(name = gid_to_name(gids[i])); if (STR_IN_SET(name, "sbuild", "buildd")) return; /* Debian package build in chroot, groupnames won't match, skip */ - condition = condition_new(CONDITION_GROUP, name, false, false); - assert_se(condition); + + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, name, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", name, r); - assert_se(r > 0); + ASSERT_OK_POSITIVE(r); condition_free(condition); max_gid = gids[i] > max_gid ? gids[i] : max_gid; } assert_se(0 < asprintf(&gid, "%u", max_gid+1)); - condition = condition_new(CONDITION_GROUP, gid, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, gid, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", gid, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); free(gid); @@ -1011,11 +878,10 @@ TEST(condition_test_group) { return (void) log_tests_skipped("user is in both root and nobody group"); groupname = (char*)(getegid() == 0 ? NOBODY_GROUP_NAME : "root"); - condition = condition_new(CONDITION_GROUP, groupname, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_GROUP, groupname, false, false)); r = condition_test(condition, environ); log_info("ConditionGroup=%s → %i", groupname, r); - assert_se(r == 0); + ASSERT_OK_ZERO(r); condition_free(condition); } @@ -1025,8 +891,7 @@ static void test_condition_test_cpus_one(const char *s, bool result) { log_debug("%s=%s", condition_type_to_string(CONDITION_CPUS), s); - condition = condition_new(CONDITION_CPUS, s, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPUS, s, false, false)); r = condition_test(condition, environ); assert_se(r >= 0); @@ -1086,8 +951,7 @@ static void test_condition_test_memory_one(const char *s, bool result) { log_debug("%s=%s", condition_type_to_string(CONDITION_MEMORY), s); - condition = condition_new(CONDITION_MEMORY, s, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY, s, false, false)); r = condition_test(condition, environ); assert_se(r >= 0); @@ -1167,8 +1031,7 @@ static void test_condition_test_environment_one(const char *s, bool result) { log_debug("%s=%s", condition_type_to_string(CONDITION_ENVIRONMENT), s); - condition = condition_new(CONDITION_ENVIRONMENT, s, false, false); - assert_se(condition); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_ENVIRONMENT, s, false, false)); r = condition_test(condition, environ); assert_se(r >= 0); @@ -1177,7 +1040,7 @@ static void test_condition_test_environment_one(const char *s, bool result) { } TEST(condition_test_environment) { - assert_se(setenv("EXISTINGENVVAR", "foo", false) >= 0); + ASSERT_OK_ERRNO(setenv("EXISTINGENVVAR", "foo", false)); test_condition_test_environment_one("MISSINGENVVAR", false); test_condition_test_environment_one("MISSINGENVVAR=foo", false); @@ -1201,49 +1064,40 @@ TEST(condition_test_os_release) { if (strv_length(os_release_pairs) < 2) return; - condition = condition_new(CONDITION_OS_RELEASE, "_THISHOPEFULLYWONTEXIST=01234 56789", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "_THISHOPEFULLYWONTEXIST=01234 56789", false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONG FORMAT", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONG FORMAT", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONG!<>=FORMAT", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONG!<>=FORMAT", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONG FORMAT=", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONG FORMAT=", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONG =FORMAT", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONG =FORMAT", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONG = FORMAT", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONG = FORMAT", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRONGFORMAT= ", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRONGFORMAT= ", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "WRO NG=FORMAT", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == -EINVAL); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "WRO NG=FORMAT", false, false)); + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); - condition = condition_new(CONDITION_OS_RELEASE, "", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, "", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); /* load_os_release_pairs() removes quotes, we have to add them back, @@ -1251,28 +1105,24 @@ TEST(condition_test_os_release) { * which is wrong, as the value is not quoted anymore. */ const char *quote = strchr(os_release_pairs[1], ' ') ? "\"" : ""; key_value_pair = strjoina(os_release_pairs[0], "=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina(os_release_pairs[0], "!=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* Test fnmatch() operators */ key_value_pair = strjoina(os_release_pairs[0], "$=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina(os_release_pairs[0], "!$=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); /* Some distros (eg: Arch) do not set VERSION_ID */ @@ -1280,69 +1130,58 @@ TEST(condition_test_os_release) { return; key_value_pair = strjoina("VERSION_ID", "=", version_id); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "!=", version_id); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "<=", version_id); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", ">=", version_id); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "<", version_id, ".1"); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", ">", version_id, ".1"); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "=", version_id, " ", os_release_pairs[0], "=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "!=", version_id, " ", os_release_pairs[0], "=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "=", version_id, " ", os_release_pairs[0], "!=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "!=", version_id, " ", os_release_pairs[0], "!=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) == 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_ZERO(condition_test(condition, environ)); condition_free(condition); key_value_pair = strjoina("VERSION_ID", "<", version_id, ".1", " ", os_release_pairs[0], "=", quote, os_release_pairs[1], quote); - condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_OS_RELEASE, key_value_pair, false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); } @@ -1354,104 +1193,84 @@ TEST(condition_test_psi) { if (!is_pressure_supported()) return (void) log_notice("Pressure Stall Information (PSI) is not supported, skipping %s", __func__); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "sbarabau", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "sbarabau", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "10%sbarabau", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "10%sbarabau", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "10% sbarabau", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "10% sbarabau", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "-10", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "-10", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "10%/10min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "10%/10min", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "10min/10%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "10min/10%", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "10% 5min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "10% 5min", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "/5min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "/5min", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_IO_PRESSURE, "10s / ", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_IO_PRESSURE, "10s / ", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "100%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "100%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "0.0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "0.0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "100%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "100%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "0.0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "0.0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "0.01%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "0.01%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "0.0%/10sec", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "0.0%/10sec", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "100.0% / 1min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "100.0% / 1min", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_IO_PRESSURE, "50.0% / 1min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_IO_PRESSURE, "50.0% / 1min", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); r = cg_all_unified(); @@ -1469,34 +1288,28 @@ TEST(condition_test_psi) { if (!FLAGS_SET(mask, CGROUP_MASK_CPU)) return (void) log_notice("Requires the cgroup CPU controller, skipping %s", __func__); - condition = condition_new(CONDITION_MEMORY_PRESSURE, " : / ", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) < 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, " : / ", false, false)); + ASSERT_FAIL(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "hopefullythisisnotarealone.slice:100% / 10sec", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) > 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "hopefullythisisnotarealone.slice:100% / 10sec", false, false)); + ASSERT_OK_POSITIVE(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_CPU_PRESSURE, "-.slice:100.0% / 1min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_CPU_PRESSURE, "-.slice:100.0% / 1min", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "-.slice:0.0%/5min", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "-.slice:0.0%/5min", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_MEMORY_PRESSURE, "-.slice:100.0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_MEMORY_PRESSURE, "-.slice:100.0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); - condition = condition_new(CONDITION_IO_PRESSURE, "-.slice:0.0%", false, false); - assert_se(condition); - assert_se(condition_test(condition, environ) >= 0); + ASSERT_NOT_NULL(condition = condition_new(CONDITION_IO_PRESSURE, "-.slice:0.0%", false, false)); + ASSERT_OK(condition_test(condition, environ)); condition_free(condition); } |