xref: /aosp_15_r20/external/ltp/testcases/lib/tst_check_kconfigs.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
3*49cdfc7eSAndroid Build Coastguard Worker 
4*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
5*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
6*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
7*49cdfc7eSAndroid Build Coastguard Worker #include "tst_kconfig.h"
8*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char * argv[])9*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
10*49cdfc7eSAndroid Build Coastguard Worker {
11*49cdfc7eSAndroid Build Coastguard Worker 	char *str = argv[1];
12*49cdfc7eSAndroid Build Coastguard Worker 	char *delim = argv[2];
13*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int i, cnt = 1, ret = 0;
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker 	switch(argc) {
16*49cdfc7eSAndroid Build Coastguard Worker 	case 2:
17*49cdfc7eSAndroid Build Coastguard Worker 		delim = ",";
18*49cdfc7eSAndroid Build Coastguard Worker 	break;
19*49cdfc7eSAndroid Build Coastguard Worker 	case 3:
20*49cdfc7eSAndroid Build Coastguard Worker 		if (strlen(delim) > 1) {
21*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr, "The delim must be a single character\n");
22*49cdfc7eSAndroid Build Coastguard Worker 			return 1;
23*49cdfc7eSAndroid Build Coastguard Worker 		}
24*49cdfc7eSAndroid Build Coastguard Worker 	break;
25*49cdfc7eSAndroid Build Coastguard Worker 	default:
26*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "Please provide kernel kconfig list and delim "
27*49cdfc7eSAndroid Build Coastguard Worker 				"(optinal, default value is ',')\n");
28*49cdfc7eSAndroid Build Coastguard Worker 		return 1;
29*49cdfc7eSAndroid Build Coastguard Worker 	}
30*49cdfc7eSAndroid Build Coastguard Worker 
31*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; str[i]; i++) {
32*49cdfc7eSAndroid Build Coastguard Worker 		if (str[i] == delim[0])
33*49cdfc7eSAndroid Build Coastguard Worker 			cnt++;
34*49cdfc7eSAndroid Build Coastguard Worker 	}
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker 	char **kconfigs = malloc(++cnt * sizeof(char *));
37*49cdfc7eSAndroid Build Coastguard Worker 	if (!kconfigs) {
38*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "malloc failed\n");
39*49cdfc7eSAndroid Build Coastguard Worker 		return 1;
40*49cdfc7eSAndroid Build Coastguard Worker 	}
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < cnt; i++)
43*49cdfc7eSAndroid Build Coastguard Worker 		kconfigs[i] = strtok_r(str, delim, &str);
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_kconfig_check((const char * const*)kconfigs))
46*49cdfc7eSAndroid Build Coastguard Worker 		ret = 1;
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker 	free(kconfigs);
49*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
50*49cdfc7eSAndroid Build Coastguard Worker }
51