From: Daniel Braunwarth Date: Sat, 27 Aug 2022 08:56:03 +0000 (+0200) Subject: test: extend ConditionFirmware tests X-Git-Tag: v252-rc1~265 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8d2039c0a102dfb067fd2d5f4fb1b138da7f575;p=thirdparty%2Fsystemd.git test: extend ConditionFirmware tests --- diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 10494b010c3..8fcaacc1721 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -306,11 +306,78 @@ TEST(condition_test_architecture) { condition_free(condition); } -TEST(condition_test_firmware_smbios_field) { +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); + 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()); + condition_free(condition); +} + +TEST(condition_test_firmware_device_tree) { + Condition *condition; + bool is_device_tree_system; + + /* device-tree parameter */ + 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); + 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); + condition_free(condition); + } else { + _cleanup_free_ char *dtcompat = NULL; + _cleanup_strv_free_ char **dtcompatlist = NULL; + size_t dtcompat_size; + int r; + + 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); + if (r == -ENOENT) + assert_se(condition_test(condition, environ) == 0); + else + assert_se(condition_test(condition, environ) < 0); + condition_free(condition); + return; + } + + dtcompatlist = strv_parse_nulstr(dtcompat, dtcompat_size); + + 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); + condition_free(condition); + } + } +} + +TEST(condition_test_firmware_smbios) { + Condition *condition; _cleanup_free_ char *bios_vendor = NULL, *bios_version = NULL; const char *expression; - Condition *condition; + /* smbios-field parameter */ /* Test some malformed smbios-field arguments */ condition = condition_new(CONDITION_FIRMWARE, "smbios-field()", false, false); assert_se(condition);