2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would 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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <sys/types.h>
26 #include <lib/dmport.h>
28 #include <lib/errtest.h>
34 /*---------------------------------------------------------------------------
35 Automated test of access rights, involving many DMAPI functions
38 test_rights [-s sid] [-v] ls_path pathname
42 is the session ID whose events you you are interested in.
44 is the path to a copy of ls, which will be copied as a test file.
46 is the filesystem to use for the test.
47 ----------------------------------------------------------------------------*/
62 "Usage: %s [-v] [-s sid] ls_path pathname\n",
69 main(int argc, char **argv) {
71 dm_sessid_t sid = DM_NO_SESSION;
72 dm_token_t token[NUM_TOKENS];
73 dm_token_t test_token;
94 if (Progname = strrchr(argv[0], '/')) {
101 while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
113 if (optind + 2 != argc) {
116 ls_path = argv[optind];
117 pathname = argv[optind+1];
119 if (dm_init_service(&name) == -1) {
120 fprintf(stderr, "Can't initialize the DMAPI\n");
123 if (sid == DM_NO_SESSION)
124 find_test_session(&sid);
126 printf("Beginning access rights testing...\n");
128 sprintf(fname_a, "%s/DMAPI_rights_test_file_a", pathname);
129 sprintf(command, "cp %s %s\n", ls_path, fname_a);
132 if (dm_path_to_handle(fname_a, &ap, &alen)) {
133 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
138 sprintf(fname_b, "%s/DMAPI_rights_test_file_b", pathname);
139 sprintf(command, "cp %s %s\n", ls_path, fname_b);
142 if (dm_path_to_handle(fname_b, &bp, &blen)) {
143 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
148 sprintf(fname_c, "%s/DMAPI_rights_test_file_c", pathname);
149 sprintf(command, "cp %s %s\n", ls_path, fname_c);
152 if (dm_path_to_handle(fname_c, &cp, &clen)) {
153 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
158 if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
159 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
164 sprintf(pathname, "%s/DMAPI_rights_test_dir", pathname);
165 sprintf(command, "mkdir %s\n", pathname);
168 if (dm_path_to_handle(pathname, &dir_hanp, &dir_hlen)) {
169 fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
174 /* Test remaining functions for appropriate
175 * right requirements...
176 *------------------------------------------------------------*/
178 dm_off_t off = (dm_off_t)0;
181 SHAREDTEST("get_allocinfo", ap, alen, test_token,
182 dm_get_allocinfo(sid, ap, alen, test_token,
183 &off, 1, &extent, &nelem_ret))
185 /*------------------------------------------------------------*/
187 void *bufp=(void*)malloc(5*sizeof(dm_attrlist_t));
189 SHAREDTEST("getall_dmattr", ap, alen, test_token,
190 dm_getall_dmattr(sid, ap, alen, test_token,
193 /*------------------------------------------------------------*/
196 SHAREDTEST("init_attrloc", dir_hanp, dir_hlen, test_token,
197 dm_init_attrloc(sid, dir_hanp, dir_hlen, test_token,
200 /*------------------------------------------------------------*/
202 mkdir_by_handle is NOT SUPPORTED in current SGI DMAPI
205 SHAREDTEST("mkdir_by_handle", fs_hanp, fs_hlen, test_token,
206 dm_mkdir_by_handle(sid, fs_hanp, fs_hlen, test_token,
207 dir_hanp, dir_hlen, "FUBAR_DIR"))
210 /*------------------------------------------------------------*/
211 { dm_eventset_t eventset;
213 EXCLTEST("set_disp", fs_hanp, fs_hlen, test_token,
214 dm_set_disp(sid, fs_hanp, fs_hlen, test_token,
215 &eventset, DM_EVENT_MAX))
217 /*------------------------------------------------------------*/
218 { dm_attrname_t attrname={"TEST"};
219 EXCLTEST("set_return...", fs_hanp, fs_hlen, test_token,
220 dm_set_return_on_destroy(sid, fs_hanp, fs_hlen, test_token,
223 /*------------------------------------------------------------*/
225 /* Create the tokens */
226 for (i=1; i<NUM_TOKENS; i++){
227 if (dm_create_userevent(sid, 0, 0, &token[i])==-1) {
228 fprintf(stderr, "Couldn't create token %d.\n", i);
234 "rights-on-NO_TOKEN",
235 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
238 "rights-on-NO_TOKEN",
239 dm_request_right(sid, ap, alen, DM_NO_TOKEN,
242 if (dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_SHARED))
243 printf("ERROR: Request for SHARED failed on handle a, token 1");
244 if (dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_SHARED))
245 printf("ERROR: Request for SHARED failed on handle a, token 2");
247 /* --- These WOULD be correct tests,
248 --- if rights were fully implemented.
250 ERRTEST(EAGAIN, "EXCL request",
251 dm_request_right(sid, ap, alen, token[1], 0, DM_RIGHT_EXCL))
252 ERRTEST(EAGAIN, "EXCL request",
253 dm_request_right(sid, ap, alen, token[2], 0, DM_RIGHT_EXCL))
254 ERRTEST(EAGAIN, "upgrade",
255 dm_upgrade_right(sid, ap, alen, token[1]))
260 for (i=1; i<NUM_TOKENS; i++)
261 dm_respond_event(sid, token[i], DM_RESP_CONTINUE, 0, 0, 0);
263 sprintf(command, "rm %s\n", fname_a);
266 sprintf(command, "rm %s\n", fname_b);
269 sprintf(command, "rm %s\n", fname_c);
272 sprintf(command, "rmdir %s\n", pathname);
275 dm_handle_free(ap, alen);
276 dm_handle_free(bp, blen);
277 dm_handle_free(cp, clen);
279 printf("Access rights testing complete.\n");