2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #include <sys/types.h>
40 #include <lib/dmport.h>
42 #include <lib/errtest.h>
48 /*---------------------------------------------------------------------------
49 Automated test of access rights, involving many DMAPI functions
52 test_rights [-s sid] [-v] ls_path pathname
56 is the session ID whose events you you are interested in.
58 is the path to a copy of ls, which will be copied as a test file.
60 is the filesystem to use for the test.
61 ----------------------------------------------------------------------------*/
76 "Usage: %s [-v] [-s sid] ls_path pathname\n",
83 main(int argc, char **argv) {
85 dm_sessid_t sid = DM_NO_SESSION;
86 dm_token_t token[NUM_TOKENS];
87 dm_token_t test_token;
109 if (Progname = strrchr(argv[0], '/')) {
116 while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
128 if (optind + 2 != argc) {
131 ls_path = argv[optind];
132 pathname = argv[optind+1];
134 if (dm_init_service(&name) == -1) {
135 fprintf(stderr, "Can't inititalize the DMAPI\n");
138 if (sid == DM_NO_SESSION)
139 find_test_session(&sid);
141 printf("Beginning access rights testing...\n");
143 sprintf(fname_a, "%s/DMAPI_rights_test_file_a", pathname);
144 sprintf(command, "cp %s %s\n", ls_path, fname_a);
147 if (dm_path_to_handle(fname_a, &ap, &alen)) {
148 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
153 sprintf(fname_b, "%s/DMAPI_rights_test_file_b", pathname);
154 sprintf(command, "cp %s %s\n", ls_path, fname_b);
157 if (dm_path_to_handle(fname_b, &bp, &blen)) {
158 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
163 sprintf(fname_c, "%s/DMAPI_rights_test_file_c", pathname);
164 sprintf(command, "cp %s %s\n", ls_path, fname_c);
167 if (dm_path_to_handle(fname_c, &cp, &clen)) {
168 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
173 if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
174 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
179 sprintf(pathname, "%s/DMAPI_rights_test_dir", pathname);
180 sprintf(command, "mkdir %s\n", pathname);
183 if (dm_path_to_handle(pathname, &dir_hanp, &dir_hlen)) {
184 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
189 /* Test remaining functions for appropriate
190 * right requirements...
191 *------------------------------------------------------------*/
193 dm_off_t off = (dm_off_t)0;
196 SHAREDTEST("get_allocinfo", ap, alen, test_token,
197 dm_get_allocinfo(sid, ap, alen, test_token,
198 &off, 1, &extent, &nelem_ret))
200 /*------------------------------------------------------------*/
202 void *bufp=(void*)malloc(5*sizeof(dm_attrlist_t));
204 SHAREDTEST("getall_dmattr", ap, alen, test_token,
205 dm_getall_dmattr(sid, ap, alen, test_token,
208 /*------------------------------------------------------------*/
211 SHAREDTEST("init_attrloc", dir_hanp, dir_hlen, test_token,
212 dm_init_attrloc(sid, dir_hanp, dir_hlen, test_token,
215 /*------------------------------------------------------------*/
216 /* mkdir_by_handle is NOT SUPPORTED in current SGI DMAPI
218 SHAREDTEST("mkdir_by_handle", fs_hanp, fs_hlen, test_token,
219 dm_mkdir_by_handle(sid, fs_hanp, fs_hlen, test_token,
220 dir_hanp, dir_hlen, "FUBAR_DIR"))
222 /*------------------------------------------------------------*/
223 { dm_eventset_t eventset;
225 EXCLTEST("set_disp", fs_hanp, fs_hlen, test_token,
226 dm_set_disp(sid, fs_hanp, fs_hlen, test_token,
227 &eventset, DM_EVENT_MAX))
229 /*------------------------------------------------------------*/
230 { dm_attrname_t attrname={"TEST"};
231 EXCLTEST("set_return...", fs_hanp, fs_hlen, test_token,
232 dm_set_return_on_destroy(sid, fs_hanp, fs_hlen, test_token,
235 /*------------------------------------------------------------*/
237 /* Create the tokens */
238 for (i=1; i<NUM_TOKENS; i++){
239 if (dm_create_userevent(sid, 0, 0, &token[i])==-1) {
240 fprintf(stderr, "Couldn't create token %d.\n", i);
246 "rights-on-NO_TOKEN",
247 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
250 "rights-on-NO_TOKEN",
251 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
254 if (dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_SHARED))
255 printf("ERROR: Request for SHARED failed on handle a, token 1");
256 if (dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_SHARED))
257 printf("ERROR: Request for SHARED failed on handle a, token 2");
259 /* --- These WOULD be correct tests,
260 --- if rights were fully implemented.
262 ERRTEST(EAGAIN, "EXCL request",
263 dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_EXCL))
264 ERRTEST(EAGAIN, "EXCL request",
265 dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_EXCL))
266 ERRTEST(EAGAIN, "upgrade",
267 dm_upgrade_right(sid, ap, alen, token[1]))
272 for (i=1; i<NUM_TOKENS; i++)
273 dm_respond_event(sid, token[i], DM_RESP_CONTINUE, 0, 0, 0);
275 sprintf(command, "rm %s\n", fname_a);
278 sprintf(command, "rm %s\n", fname_b);
281 sprintf(command, "rm %s\n", fname_c);
284 sprintf(command, "rmdir %s\n", pathname);
287 dm_handle_free(ap, alen);
288 dm_handle_free(bp, blen);
289 dm_handle_free(cp, clen);
291 printf("Access rights testing complete.\n");