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);