xref: /aosp_15_r20/external/ltp/testcases/realtime/func/pi-tests/testpi-0.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright © International Business Machines  Corp., 2005, 2008
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  *
19*49cdfc7eSAndroid Build Coastguard Worker  * NAME
20*49cdfc7eSAndroid Build Coastguard Worker  *      testpi-0.c
21*49cdfc7eSAndroid Build Coastguard Worker  *
22*49cdfc7eSAndroid Build Coastguard Worker  * DESCRIPTION
23*49cdfc7eSAndroid Build Coastguard Worker  *      This testcase checks whether priority inheritance support is present
24*49cdfc7eSAndroid Build Coastguard Worker  *      in the running kernel
25*49cdfc7eSAndroid Build Coastguard Worker  *
26*49cdfc7eSAndroid Build Coastguard Worker  * USAGE:
27*49cdfc7eSAndroid Build Coastguard Worker  *      Use run_auto.sh script in current directory to build and run test.
28*49cdfc7eSAndroid Build Coastguard Worker  *
29*49cdfc7eSAndroid Build Coastguard Worker  * AUTHOR
30*49cdfc7eSAndroid Build Coastguard Worker  *
31*49cdfc7eSAndroid Build Coastguard Worker  *
32*49cdfc7eSAndroid Build Coastguard Worker  * HISTORY
33*49cdfc7eSAndroid Build Coastguard Worker  *      2010-04-22 Code cleanup by Gowrishankar ([email protected])
34*49cdfc7eSAndroid Build Coastguard Worker  *
35*49cdfc7eSAndroid Build Coastguard Worker  *
36*49cdfc7eSAndroid Build Coastguard Worker  *****************************************************************************/
37*49cdfc7eSAndroid Build Coastguard Worker 
38*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <sched.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <pthread.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <librttest.h>
46*49cdfc7eSAndroid Build Coastguard Worker 
usage(void)47*49cdfc7eSAndroid Build Coastguard Worker void usage(void)
48*49cdfc7eSAndroid Build Coastguard Worker {
49*49cdfc7eSAndroid Build Coastguard Worker 	rt_help();
50*49cdfc7eSAndroid Build Coastguard Worker 	printf("testpi-0 specific options:\n");
51*49cdfc7eSAndroid Build Coastguard Worker 	printf("testpi-0 doesn't require any commandline options\n");
52*49cdfc7eSAndroid Build Coastguard Worker }
53*49cdfc7eSAndroid Build Coastguard Worker 
parse_args(int c,char * v)54*49cdfc7eSAndroid Build Coastguard Worker int parse_args(int c, char *v)
55*49cdfc7eSAndroid Build Coastguard Worker {
56*49cdfc7eSAndroid Build Coastguard Worker 
57*49cdfc7eSAndroid Build Coastguard Worker 	int handled = 1;
58*49cdfc7eSAndroid Build Coastguard Worker 	switch (c) {
59*49cdfc7eSAndroid Build Coastguard Worker 	case 'h':
60*49cdfc7eSAndroid Build Coastguard Worker 		usage();
61*49cdfc7eSAndroid Build Coastguard Worker 		exit(0);
62*49cdfc7eSAndroid Build Coastguard Worker 	default:
63*49cdfc7eSAndroid Build Coastguard Worker 		handled = 0;
64*49cdfc7eSAndroid Build Coastguard Worker 		break;
65*49cdfc7eSAndroid Build Coastguard Worker 	}
66*49cdfc7eSAndroid Build Coastguard Worker 	return handled;
67*49cdfc7eSAndroid Build Coastguard Worker }
68*49cdfc7eSAndroid Build Coastguard Worker 
69*49cdfc7eSAndroid Build Coastguard Worker /*
70*49cdfc7eSAndroid Build Coastguard Worker  * Test pthread creation at different thread priorities.
71*49cdfc7eSAndroid Build Coastguard Worker  */
main(int argc,char * argv[])72*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
73*49cdfc7eSAndroid Build Coastguard Worker {
74*49cdfc7eSAndroid Build Coastguard Worker 	char *pathbuf;
75*49cdfc7eSAndroid Build Coastguard Worker 	size_t n;
76*49cdfc7eSAndroid Build Coastguard Worker 
77*49cdfc7eSAndroid Build Coastguard Worker 	rt_init("h", parse_args, argc, argv);
78*49cdfc7eSAndroid Build Coastguard Worker 
79*49cdfc7eSAndroid Build Coastguard Worker 	n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t) 0);
80*49cdfc7eSAndroid Build Coastguard Worker 	pathbuf = malloc(n);
81*49cdfc7eSAndroid Build Coastguard Worker 	if (!pathbuf)
82*49cdfc7eSAndroid Build Coastguard Worker 		abort();
83*49cdfc7eSAndroid Build Coastguard Worker 	confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
84*49cdfc7eSAndroid Build Coastguard Worker 
85*49cdfc7eSAndroid Build Coastguard Worker 	printf("LIBC_VERSION: %s\n", pathbuf);
86*49cdfc7eSAndroid Build Coastguard Worker 	free(pathbuf);
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker 	n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t) 0);
89*49cdfc7eSAndroid Build Coastguard Worker 	pathbuf = malloc(n);
90*49cdfc7eSAndroid Build Coastguard Worker 	if (!pathbuf)
91*49cdfc7eSAndroid Build Coastguard Worker 		abort();
92*49cdfc7eSAndroid Build Coastguard Worker 	confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
93*49cdfc7eSAndroid Build Coastguard Worker 
94*49cdfc7eSAndroid Build Coastguard Worker 	printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
95*49cdfc7eSAndroid Build Coastguard Worker 	free(pathbuf);
96*49cdfc7eSAndroid Build Coastguard Worker 
97*49cdfc7eSAndroid Build Coastguard Worker 	if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1)
98*49cdfc7eSAndroid Build Coastguard Worker 		printf("No Prio inheritance support\n");
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker 	printf("Prio inheritance support present\n");
101*49cdfc7eSAndroid Build Coastguard Worker 
102*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
103*49cdfc7eSAndroid Build Coastguard Worker }
104