xref: /aosp_15_r20/external/kmod/testsuite/test-depmod.c (revision cc4ad7da8cefe208cb129ac2aa9a357c7c72deb2)
1 /*
2  * Copyright (C) 2012-2013  ProFUSION embedded systems
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <errno.h>
19 #include <inttypes.h>
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 
26 #include "testsuite.h"
27 
28 #define MODULES_UNAME "4.4.4"
29 #define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed"
30 #define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_modules_order_for_compressed(const struct test * t)31 static noreturn int depmod_modules_order_for_compressed(const struct test *t)
32 {
33 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
34 	const char *const args[] = {
35 		progname,
36 		NULL,
37 	};
38 
39 	test_spawn_prog(progname, args);
40 	exit(EXIT_FAILURE);
41 }
42 
43 DEFINE_TEST(depmod_modules_order_for_compressed,
44 	.description = "check if depmod let aliases in right order when using compressed modules",
45 	.config = {
46 		[TC_UNAME_R] = MODULES_UNAME,
47 		[TC_ROOTFS] = MODULES_ORDER_ROOTFS,
48 	},
49 	.output = {
50 		.files = (const struct keyval[]) {
51 			{ MODULES_ORDER_LIB_MODULES "/correct-modules.alias",
52 			  MODULES_ORDER_LIB_MODULES "/modules.alias" },
53 			{ }
54 		},
55 	});
56 
57 #define MODULES_OUTDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-outdir"
58 #define MODULES_OUTDIR_LIB_MODULES_OUTPUT MODULES_OUTDIR_ROOTFS "/outdir" MODULE_DIRECTORY "/" MODULES_UNAME
59 #define MODULES_OUTDIR_LIB_MODULES_INPUT MODULES_OUTDIR_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_modules_outdir(const struct test * t)60 static noreturn int depmod_modules_outdir(const struct test *t)
61 {
62 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
63 	const char *const args[] = {
64 		progname,
65 		"--outdir", MODULES_OUTDIR_ROOTFS "/outdir/",
66 		NULL,
67 	};
68 
69 	test_spawn_prog(progname, args);
70 	exit(EXIT_FAILURE);
71 }
72 
73 DEFINE_TEST(depmod_modules_outdir,
74 	.description = "check if depmod honours the outdir option",
75 	.config = {
76 		[TC_UNAME_R] = MODULES_UNAME,
77 		[TC_ROOTFS] = MODULES_OUTDIR_ROOTFS,
78 	},
79 	.output = {
80 		.files = (const struct keyval[]) {
81 			{ MODULES_OUTDIR_LIB_MODULES_OUTPUT "/modules.dep",
82 			  MODULES_OUTDIR_ROOTFS "/correct-modules.dep" },
83 			{ MODULES_OUTDIR_LIB_MODULES_OUTPUT "/modules.alias",
84 			  MODULES_OUTDIR_ROOTFS "/correct-modules.alias" },
85 			{ }
86 		},
87 	});
88 
89 #define SEARCH_ORDER_SIMPLE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-simple"
90 #define SEARCH_ORDER_SIMPLE_LIB_MODULES SEARCH_ORDER_SIMPLE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_search_order_simple(const struct test * t)91 static noreturn int depmod_search_order_simple(const struct test *t)
92 {
93 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
94 	const char *const args[] = {
95 		progname,
96 		NULL,
97 	};
98 
99 	test_spawn_prog(progname, args);
100 	exit(EXIT_FAILURE);
101 }
102 DEFINE_TEST(depmod_search_order_simple,
103 	.description = "check if depmod honor search order in config",
104 	.config = {
105 		[TC_UNAME_R] = MODULES_UNAME,
106 		[TC_ROOTFS] = SEARCH_ORDER_SIMPLE_ROOTFS,
107 	},
108 	.output = {
109 		.files = (const struct keyval[]) {
110 			{ SEARCH_ORDER_SIMPLE_LIB_MODULES "/correct-modules.dep",
111 			  SEARCH_ORDER_SIMPLE_LIB_MODULES "/modules.dep" },
112 			{ }
113 		},
114 	});
115 
116 #define SEARCH_ORDER_SAME_PREFIX_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-same-prefix"
117 #define SEARCH_ORDER_SAME_PREFIX_LIB_MODULES SEARCH_ORDER_SAME_PREFIX_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_search_order_same_prefix(const struct test * t)118 static noreturn int depmod_search_order_same_prefix(const struct test *t)
119 {
120 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
121 	const char *const args[] = {
122 		progname,
123 		NULL,
124 	};
125 
126 	test_spawn_prog(progname, args);
127 	exit(EXIT_FAILURE);
128 }
129 DEFINE_TEST(depmod_search_order_same_prefix,
130 	.description = "check if depmod honor search order in config with same prefix",
131 	.config = {
132 		[TC_UNAME_R] = MODULES_UNAME,
133 		[TC_ROOTFS] = SEARCH_ORDER_SAME_PREFIX_ROOTFS,
134 	},
135 	.output = {
136 		.files = (const struct keyval[]) {
137 			{ SEARCH_ORDER_SAME_PREFIX_LIB_MODULES "/correct-modules.dep",
138 			  SEARCH_ORDER_SAME_PREFIX_LIB_MODULES "/modules.dep" },
139 			{ }
140 		},
141 	});
142 
143 #define DETECT_LOOP_ROOTFS TESTSUITE_ROOTFS "test-depmod/detect-loop"
depmod_detect_loop(const struct test * t)144 static noreturn int depmod_detect_loop(const struct test *t)
145 {
146 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
147 	const char *const args[] = {
148 		progname,
149 		NULL,
150 	};
151 
152 	test_spawn_prog(progname, args);
153 	exit(EXIT_FAILURE);
154 }
155 DEFINE_TEST(depmod_detect_loop,
156 	.description = "check if depmod detects module loops correctly",
157 	.config = {
158 		[TC_UNAME_R] = MODULES_UNAME,
159 		[TC_ROOTFS] = DETECT_LOOP_ROOTFS,
160 	},
161 	.expected_fail = true,
162 	.output = {
163 		.err = DETECT_LOOP_ROOTFS "/correct.txt",
164 	});
165 
166 #define SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-first"
167 #define SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_search_order_external_first(const struct test * t)168 static noreturn int depmod_search_order_external_first(const struct test *t)
169 {
170 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
171 	const char *const args[] = {
172 		progname,
173 		NULL,
174 	};
175 
176 	test_spawn_prog(progname, args);
177 	exit(EXIT_FAILURE);
178 }
179 DEFINE_TEST(depmod_search_order_external_first,
180 	.description = "check if depmod honor external keyword with higher priority",
181 	.config = {
182 		[TC_UNAME_R] = MODULES_UNAME,
183 		[TC_ROOTFS] = SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS,
184 	},
185 	.output = {
186 		.files = (const struct keyval[]) {
187 			{ SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES "/correct-modules.dep",
188 			  SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES "/modules.dep" },
189 			{ }
190 		},
191 	});
192 
193 #define SEARCH_ORDER_EXTERNAL_LAST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-last"
194 #define SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES SEARCH_ORDER_EXTERNAL_LAST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_search_order_external_last(const struct test * t)195 static noreturn int depmod_search_order_external_last(const struct test *t)
196 {
197 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
198 	const char *const args[] = {
199 		progname,
200 		NULL,
201 	};
202 
203 	test_spawn_prog(progname, args);
204 	exit(EXIT_FAILURE);
205 }
206 DEFINE_TEST(depmod_search_order_external_last,
207 	.description = "check if depmod honor external keyword with lower priority",
208 	.config = {
209 		[TC_UNAME_R] = MODULES_UNAME,
210 		[TC_ROOTFS] = SEARCH_ORDER_EXTERNAL_LAST_ROOTFS,
211 	},
212 	.output = {
213 		.files = (const struct keyval[]) {
214 			{ SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES "/correct-modules.dep",
215 			  SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES "/modules.dep" },
216 			{ }
217 		},
218 	});
219 
220 #define SEARCH_ORDER_OVERRIDE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-override"
221 #define SEARCH_ORDER_OVERRIDE_LIB_MODULES SEARCH_ORDER_OVERRIDE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
depmod_search_order_override(const struct test * t)222 static noreturn int depmod_search_order_override(const struct test *t)
223 {
224 	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
225 	const char *const args[] = {
226 		progname,
227 		NULL,
228 	};
229 
230 	test_spawn_prog(progname, args);
231 	exit(EXIT_FAILURE);
232 }
233 DEFINE_TEST(depmod_search_order_override,
234 	.description = "check if depmod honor override keyword",
235 	.config = {
236 		[TC_UNAME_R] = MODULES_UNAME,
237 		[TC_ROOTFS] = SEARCH_ORDER_OVERRIDE_ROOTFS,
238 	},
239 	.output = {
240 		.files = (const struct keyval[]) {
241 			{ SEARCH_ORDER_OVERRIDE_LIB_MODULES "/correct-modules.dep",
242 			  SEARCH_ORDER_OVERRIDE_LIB_MODULES "/modules.dep" },
243 			{ }
244 		},
245 	});
246 
247 TESTSUITE_MAIN();
248