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 /** 10 * Initialization helper macro for struct tst_kconfig_var. Requires <string.h> 11 */ 12 #define TST_KCONFIG_INIT(confname) { \ 13 .id = confname, \ 14 .id_len = strlen(confname) \ 15 } 16 17 struct tst_kconfig_var { 18 char id[64]; 19 unsigned int id_len; 20 char choice; 21 char *val; 22 }; 23 24 /** 25 * 26 * Reads a kernel config, parses it and writes results into an array of 27 * tst_kconfig_var structures. 28 * 29 * The path to the kernel config should be autodetected in most of the cases as 30 * the code looks for know locations. It can be explicitely set/overrided with 31 * the KCONFIG_PATH environment variable as well. 32 * 33 * The caller has to initialize the tst_kconfig_var structure. The id has to be 34 * filled with config variable name such as 'CONFIG_FOO', the id_len should 35 * hold the id string length and the choice and val has to be zeroed. 36 * 37 * After a call to this function each choice be set as follows: 38 * 39 * 'm' - config option set to m 40 * 'y' - config option set to y 41 * 'v' - config option set to other value 42 * 'n' - config option is not set 43 * 0 - config option not found 44 * 45 * In the case that match is set to 'v' the val pointer points to a newly 46 * allocated string that holds the value. 47 * 48 * @param vars An array of caller initalized tst_kconfig_var structures. 49 * @param vars_len Length of the vars array. 50 */ 51 void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len); 52 53 /** 54 * Checks if required kernel configuration options are set in the kernel 55 * config. Return 0 if every config is satisfied and return 1 if at least 56 * one is missing. 57 * 58 * The config options can be passed in two different formats, either 59 * "CONFIG_FOO" in which case the option has to be set in order to continue the 60 * test or with an explicit value "CONFIG_FOO=bar" in which case the value has 61 * to match. 62 * 63 * @param kconfigs NULL-terminated array of config strings needed for the testrun. 64 */ 65 int tst_kconfig_check(const char *const kconfigs[]); 66 67 #endif /* TST_KCONFIG_H__ */ 68