• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2004, Bull S.A..  All rights reserved.
3  * Created by: Sebastien Decugis
4 
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  *
17 
18  * This sample test aims to check the following assertion:
19  * The function fails and return EPERM if caller has not the
20  * privilege to perform the operation.
21 
22  * The steps are:
23  * -> if this implementation does not support privileges, return PTS_UNSUPPORTED
24  * -> Otherwise, use the implementation features to come to a situation where
25  *      pthread_mutex_init should fail because of the privileges, and then check
26  *      that the return code is EPERM.
27  * -> return PTS_UNTESTED if the architecture is not present in the test.
28  */
29 
30  /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
31 #define _POSIX_C_SOURCE 200112L
32 
33 /********************************************************************************************/
34 /****************************** standard includes *****************************************/
35 /********************************************************************************************/
36 #include <pthread.h>
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <stdlib.h>
40 #include <errno.h>
41 #include <stdarg.h>
42 #include <sys/utsname.h>
43 #include <string.h>
44 
45 /********************************************************************************************/
46 /******************************   Test framework   *****************************************/
47 /********************************************************************************************/
48 #include "../../testfrmw/testfrmw.h"
49 #include "../../testfrmw/testfrmw.c"
50  /* This header is responsible for defining the following macros:
51   * UNRESOLVED(ret, descr);
52   *    where descr is a description of the error and ret is an int (error code for example)
53   * FAILED(descr);
54   *    where descr is a short text saying why the test has failed.
55   * PASSED();
56   *    No parameter.
57   *
58   * Both three macros shall terminate the calling process.
59   * The testcase shall not terminate in any other maneer.
60   *
61   * The other file defines the functions
62   * void output_init()
63   * void output(char * string, ...)
64   *
65   * Those may be used to output information.
66   */
67 
68 /********************************************************************************************/
69 /********************************** Configuration ******************************************/
70 /********************************************************************************************/
71 #ifndef VERBOSE
72 #define VERBOSE 1
73 #endif
74 
75 #ifndef PTS_UNSUPPORTED
76 #define PTS_UNSUPPORTED 4
77 #endif
78 #ifndef PTS_UNTESTED
79 #define PTS_UNTESTED 5
80 #endif
81 
82 /********************************************************************************************/
83 /***********************************    Test case   *****************************************/
84 /********************************************************************************************/
main(void)85 int main(void)
86 {
87 	int ret;
88 	struct utsname un;
89 
90 	output_init();
91 	ret = uname(&un);
92 	if (ret == -1) {
93 		UNRESOLVED(errno, "Unable to get Implementation name");
94 	}
95 #if VERBOSE > 0
96 	output("Implementation is: \n\t%s\n\t%s\n\t%s\n", un.sysname,
97 	       un.release, un.version);
98 #endif
99 
100 	/* If we are running Linux */
101 	if (strcmp(un.sysname, "Linux") == 0) {
102 		/* Linux does not provide privilege access to pthread_mutex_init function */
103 		ret = PTS_UNSUPPORTED;
104 		output("Linux does not provide this feature\n");
105 		output_fini();
106 		return ret;
107 	}
108 
109 	/* If we are running AIX */
110 	if (strcmp(un.sysname, "AIX") == 0) {
111 		;
112 	}
113 	/* If we are running Solaris */
114 	if (strcmp(un.sysname, "SunOS") == 0) {
115 		;
116 	}
117 
118 	output("This implementation is not tested yet\n");
119 	output_fini();
120 	return PTS_UNTESTED;
121 }
122