1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz> 4 */ 5 6 #ifndef TST_KCONFIG_H__ 7 #define TST_KCONFIG_H__ 8 9 #include <stdbool.h> 10 #include <stddef.h> 11 12 /** 13 * Initialization helper macro for struct tst_kconfig_var. Requires <string.h> 14 */ 15 #define TST_KCONFIG_INIT(confname) { \ 16 .id = confname, \ 17 .id_len = strlen(confname) \ 18 } 19 20 struct tst_kconfig_var { 21 char id[64]; 22 unsigned int id_len; 23 char choice; 24 char *val; 25 }; 26 27 /** 28 * 29 * Reads a kernel config, parses it and writes results into an array of 30 * tst_kconfig_var structures. 31 * 32 * The path to the kernel config should be autodetected in most of the cases as 33 * the code looks for know locations. It can be explicitly set/overridden with 34 * the KCONFIG_PATH environment variable as well. 35 * 36 * The caller has to initialize the tst_kconfig_var structure. The id has to be 37 * filled with config variable name such as 'CONFIG_FOO', the id_len should 38 * hold the id string length and the choice and val has to be zeroed. 39 * 40 * After a call to this function each choice be set as follows: 41 * 42 * 'm' - config option set to m 43 * 'y' - config option set to y 44 * 'v' - config option set to other value 45 * 'n' - config option is not set 46 * 0 - config option not found 47 * 48 * In the case that match is set to 'v' the val pointer points to a newly 49 * allocated string that holds the value. 50 * 51 * @param vars An array of caller initialized tst_kconfig_var structures. 52 * @param vars_len Length of the vars array. 53 */ 54 void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len); 55 56 /** 57 * Checks if required kernel configuration options are set in the kernel 58 * config. Return 0 if every config is satisfied and return 1 if at least 59 * one is missing. 60 * 61 * The config options can be passed in two different formats, either 62 * "CONFIG_FOO" in which case the option has to be set in order to continue the 63 * test or with an explicit value "CONFIG_FOO=bar" in which case the value has 64 * to match. 65 * 66 * @param kconfigs NULL-terminated array of config strings needed for the testrun. 67 */ 68 int tst_kconfig_check(const char *const kconfigs[]); 69 70 /** 71 * Macro to prepare a tst_kcmdline_var structure with a given parameter name. 72 * 73 * It initializes the .key field with the provided name, sets the .value field 74 * to an empty string, and marks the parameter as not found (.found = false). 75 * 76 * This macro is typically used to prepopulate an array with configuration 77 * parameters before processing the actual command line arguments. 78 */ 79 #define TST_KCMDLINE_INIT(paraname) { \ 80 .key = paraname, \ 81 .value = "", \ 82 .found = false \ 83 } 84 85 /** 86 * Structure for storing command-line parameter key and its corresponding 87 * value, and a flag indicating whether the parameter was found. 88 */ 89 struct tst_kcmdline_var { 90 const char *key; 91 char value[256]; 92 bool found; 93 }; 94 95 /** 96 * Parses command-line parameters from /proc/cmdline and stores them in params array. 97 * params: The array of tst_kcmdline_var structures to be filled with parsed key-value pairs. 98 * params_len: The length of the params array, indicating how many parameters to parse. 99 */ 100 void tst_kcmdline_parse(struct tst_kcmdline_var params[], size_t params_len); 101 102 /* 103 * tst_has_slow_kconfig() - Check if any performance-degrading kernel configs are enabled. 104 * 105 * This function iterates over the list of slow kernel configuration options 106 * (`tst_slow_kconfigs`) and checks if any of them are enabled in the running kernel. 107 * 108 * Return: 109 * - 1 if at least one slow kernel config is enabled. 110 * - 0 if none of the slow kernel configs are enabled. 111 */ 112 int tst_has_slow_kconfig(void); 113 114 #endif /* TST_KCONFIG_H__ */ 115