1 /*
2  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <sys/utsname.h>
19 #include "test.h"
20 #include "tst_kernel.h"
21 
tst_kernel_bits(void)22 int tst_kernel_bits(void)
23 {
24 	struct utsname buf;
25 	int kernel_bits;
26 
27 	if (uname(&buf)) {
28 		tst_brkm(TBROK | TERRNO, NULL, "uname()");
29 		return -1;
30 	}
31 
32 	kernel_bits = strstr(buf.machine, "64") ? 64 : 32;
33 
34 	/*
35 	 * ARM64 (aarch64) defines 32-bit compatibility modes as
36 	 * armv8l and armv8b (little and big endian).
37 	 * s390x is 64bit but not contain 64 in the words.
38 	 */
39 	if (!strcmp(buf.machine, "armv8l") || !strcmp(buf.machine, "armv8b")
40 			|| !strcmp(buf.machine, "s390x"))
41 		kernel_bits = 64;
42 
43 	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
44 	         buf.machine, kernel_bits);
45 
46 	return kernel_bits;
47 }
48