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;
108 if (Progname = strrchr(argv[0], '/')) {
115 while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
127 if (optind + 2 != argc) {
130 ls_path = argv[optind];
131 pathname = argv[optind+1];
133 if (dm_init_service(&name) == -1) {
134 fprintf(stderr, "Can't initialize the DMAPI\n");
137 if (sid == DM_NO_SESSION)
138 find_test_session(&sid);
140 printf("Beginning access rights testing...\n");
142 sprintf(fname_a, "%s/DMAPI_rights_test_file_a", pathname);
143 sprintf(command, "cp %s %s\n", ls_path, fname_a);
146 if (dm_path_to_handle(fname_a, &ap, &alen)) {
147 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
152 sprintf(fname_b, "%s/DMAPI_rights_test_file_b", pathname);
153 sprintf(command, "cp %s %s\n", ls_path, fname_b);
156 if (dm_path_to_handle(fname_b, &bp, &blen)) {
157 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
162 sprintf(fname_c, "%s/DMAPI_rights_test_file_c", pathname);
163 sprintf(command, "cp %s %s\n", ls_path, fname_c);
166 if (dm_path_to_handle(fname_c, &cp, &clen)) {
167 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
172 if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
173 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
178 sprintf(pathname, "%s/DMAPI_rights_test_dir", pathname);
179 sprintf(command, "mkdir %s\n", pathname);
182 if (dm_path_to_handle(pathname, &dir_hanp, &dir_hlen)) {
183 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
188 /* Test remaining functions for appropriate
189 * right requirements...
190 *------------------------------------------------------------*/
192 dm_off_t off = (dm_off_t)0;
195 SHAREDTEST("get_allocinfo", ap, alen, test_token,
196 dm_get_allocinfo(sid, ap, alen, test_token,
197 &off, 1, &extent, &nelem_ret))
199 /*------------------------------------------------------------*/
201 void *bufp=(void*)malloc(5*sizeof(dm_attrlist_t));
203 SHAREDTEST("getall_dmattr", ap, alen, test_token,
204 dm_getall_dmattr(sid, ap, alen, test_token,
207 /*------------------------------------------------------------*/
210 SHAREDTEST("init_attrloc", dir_hanp, dir_hlen, test_token,
211 dm_init_attrloc(sid, dir_hanp, dir_hlen, test_token,
214 /*------------------------------------------------------------*/
216 mkdir_by_handle is NOT SUPPORTED in current SGI DMAPI
219 SHAREDTEST("mkdir_by_handle", fs_hanp, fs_hlen, test_token,
220 dm_mkdir_by_handle(sid, fs_hanp, fs_hlen, test_token,
221 dir_hanp, dir_hlen, "FUBAR_DIR"))
224 /*------------------------------------------------------------*/
225 { dm_eventset_t eventset;
227 EXCLTEST("set_disp", fs_hanp, fs_hlen, test_token,
228 dm_set_disp(sid, fs_hanp, fs_hlen, test_token,
229 &eventset, DM_EVENT_MAX))
231 /*------------------------------------------------------------*/
232 { dm_attrname_t attrname={"TEST"};
233 EXCLTEST("set_return...", fs_hanp, fs_hlen, test_token,
234 dm_set_return_on_destroy(sid, fs_hanp, fs_hlen, test_token,
237 /*------------------------------------------------------------*/
239 /* Create the tokens */
240 for (i=1; i<NUM_TOKENS; i++){
241 if (dm_create_userevent(sid, 0, 0, &token[i])==-1) {
242 fprintf(stderr, "Couldn't create token %d.\n", i);
248 "rights-on-NO_TOKEN",
249 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
252 "rights-on-NO_TOKEN",
253 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
256 if (dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_SHARED))
257 printf("ERROR: Request for SHARED failed on handle a, token 1");
258 if (dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_SHARED))
259 printf("ERROR: Request for SHARED failed on handle a, token 2");
261 /* --- These WOULD be correct tests,
262 --- if rights were fully implemented.
264 ERRTEST(EAGAIN, "EXCL request",
265 dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_EXCL))
266 ERRTEST(EAGAIN, "EXCL request",
267 dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_EXCL))
268 ERRTEST(EAGAIN, "upgrade",
269 dm_upgrade_right(sid, ap, alen, token[1]))
274 for (i=1; i<NUM_TOKENS; i++)
275 dm_respond_event(sid, token[i], DM_RESP_CONTINUE, 0, 0, 0);
277 sprintf(command, "rm %s\n", fname_a);
280 sprintf(command, "rm %s\n", fname_b);
283 sprintf(command, "rm %s\n", fname_c);
286 sprintf(command, "rmdir %s\n", pathname);
289 dm_handle_free(ap, alen);
290 dm_handle_free(bp, blen);
291 dm_handle_free(cp, clen);
293 printf("Access rights testing complete.\n");