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/
33 #include <sys/types.h>
39 #include <lib/errtest.h>
45 /*---------------------------------------------------------------------------
46 Automated test of the DMAPI functions:
53 test_dmattr [-v] [-n num] [-l length] [-s sid] directory
57 is the path to a specific copy of ls, important only for its size
59 is the pathname to a DMAPI filesystem
61 is the number of files to create for the test.
63 is the length of the attribute value for the test.
65 is the session ID whose attributes you are interested in.
67 ----------------------------------------------------------------------------*/
69 #define VALUE_LENGTH 22
70 #define NUM_ITERATIONS 50
72 extern char *sys_errlist[];
85 fprintf(stderr, "usage:\t%s [-v] [-n number] [-l length] "
86 "[-s sid] ls_path pathname\n", Progname);
96 dm_sessid_t sid = DM_NO_SESSION;
99 dm_attrname_t *attrnamep;
100 size_t buflen=VALUE_LENGTH;
111 int num_iter = NUM_ITERATIONS;
115 dm_size_t config_retval;
116 dm_token_t test_token;
117 struct stat *statbuf;
118 struct stat *checkbuf;
120 if (Progname = strrchr(argv[0], '/')) {
126 /* Crack and validate the command line options. */
128 while ((opt = getopt(argc, argv, "vn:l:s:")) != EOF) {
134 num_iter = atoi(optarg);
137 buflen = atoi(optarg);
146 if (optind + 2 != argc)
148 ls_path = argv[optind];
149 dir_name = argv[optind+1];
152 (char *)(malloc (buflen * sizeof(char)));
154 (struct stat *)(malloc (num_iter * sizeof(struct stat)));
156 (struct stat *)(malloc (num_iter * sizeof(struct stat)));
158 (char **)(malloc (num_iter * sizeof(char *)));
159 if (bufp==NULL || test_array==NULL ||
160 statbuf==NULL || checkbuf==NULL) {
161 printf("Malloc failed\n");
164 for (i=0; i<num_iter; i++) {
166 (char*)(malloc (buflen * sizeof(char)));
167 if (test_array[i] == NULL) {
168 printf("Malloc failed\n");
173 if (dm_init_service(&name) == -1) {
174 fprintf(stderr, "Can't inititalize the DMAPI\n");
177 if (sid == DM_NO_SESSION)
178 find_test_session(&sid);
180 printf("Attribute tests beginning...\n");
182 attrnamep = (dm_attrname_t *)("DMATTR");
184 /* File creation loop*/
185 for (i=0; i < num_iter; i++) {
186 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
188 sprintf(command, "cp %s %s \n", ls_path, test_file);
193 for (i=0; i < num_iter; i++) {
194 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
197 if (stat(test_file, &(statbuf[i]))){
199 "Error: unable to stat the test file; %s (before set)\n",
202 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
203 fprintf(stderr, "can't get handle for %s; bypassing test\n",
207 for (j=0; j < VALUE_LENGTH; j++) {
208 test_array[i][j]=(char)(rand()/128);;
210 /* buflen is already set (to VALUE_LENGTH) */
211 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep,
212 (i<num_iter/2)?0:1, buflen, test_array[i])) {
213 fprintf(stderr, "dm_set_dmattr failed on test %d, %s\n",
218 printf("Report: success with set #%d.\n", i);
225 for (i=0; i < num_iter; i++) {
226 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
229 if (stat(test_file, &(checkbuf[i]))){
231 "Error: unable to stat the test file; %s (before get)\n",
234 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
235 fprintf(stderr, "can't get handle for %s; bypassing test\n",
239 if (dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, buflen,
241 if (errno == E2BIG) {
242 fprintf(stderr, "dm_get_dmattr buffer too small, "
243 "should be %d bytes\n", rlenp);
245 fprintf(stderr, "dm_get_dmattr failed (%s) for test file %d\n",
250 /* Compare bufp with test_array[i]: */
251 if (strncmp(test_array[i], bufp, buflen)){
252 printf("ERROR: failure on get test #%d.\n", i);
255 printf("Report: success with get #%d. "
256 "(output matches expectation)\n",i);
262 /* It's time for timestamp checking! */
263 for (i=0; i < num_iter; i++) {
265 if ((statbuf[i].st_atime == checkbuf[i].st_atime) &&
266 (statbuf[i].st_mtime == checkbuf[i].st_mtime) &&
267 (statbuf[i].st_ctime == checkbuf[i].st_ctime))
269 if ((statbuf[i].st_atim.tv_sec == checkbuf[i].st_atim.tv_sec) &&
270 (statbuf[i].st_atim.tv_nsec == checkbuf[i].st_atim.tv_nsec) &&
271 (statbuf[i].st_mtim.tv_sec == checkbuf[i].st_mtim.tv_sec) &&
272 (statbuf[i].st_mtim.tv_nsec == checkbuf[i].st_mtim.tv_nsec) &&
273 (statbuf[i].st_ctim.tv_sec == checkbuf[i].st_ctim.tv_sec) &&
274 (statbuf[i].st_ctim.tv_nsec == checkbuf[i].st_ctim.tv_nsec))
277 if (i < num_iter/2) {
278 /* Time stamp did not change, correctly */
280 fprintf(stdout, "Report: Time stamp was correctly "
281 "unchanged by test %d.\n", i);
285 /* Time stamp did not change, but should have */
286 fprintf(stdout, "Error: the time stamp should have "
287 "changed in test file %d\n", i);
291 /* Time stamp changed, but should not have. */
292 if (i < num_iter/2) {
293 fprintf(stdout, "Error: the time stamp should not"
294 "change in test file %d\n", i);
297 /* Time stamp changed, and should have. */
299 fprintf(stdout, "Report: Time stamp was correctly "
300 "changed by test %d.\n", i);
308 for (i=0; i < num_iter; i++) {
309 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
312 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
313 fprintf(stderr, "can't get handle for %s; bypassing test\n",
317 if (dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN, setdtime,
319 fprintf(stderr, "dm_remove_dmattr failed (%s) on test #%d\n",
324 printf("Report: success with remove test #%d.\n",i);
330 for (i=0; i < num_iter; i++) {
331 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
333 sprintf(command, "rm %s \n", test_file);
337 /*************************************\
338 |* Correct-input testing complete. *|
339 |* Beginning improper-input testing. *|
340 \*************************************/
341 sprintf(test_file, "%s/DMAPI_attribute_test_file.ERRNO",
343 sprintf(command, "cp %s %s\n", ls_path, test_file);
346 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
347 fprintf(stderr, "can't get handle for %s; bypassing errno tests\n",
352 printf("\t(errno subtests beginning...)\n");
353 /**** SET tests ****/
354 /*---------------------------------------------------------*/
355 dm_get_config(hanp, hlen, DM_CONFIG_MAX_ATTRIBUTE_SIZE,
360 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
361 attrnamep, setdtime, (config_retval+1),
363 /*---------------------------------------------------------*/
364 EXCLTEST("set", hanp, hlen, test_token,
365 dm_set_dmattr(sid, hanp, hlen, test_token,
366 attrnamep, 0, buflen, "no right"))
367 /*---------------------------------------------------------*/
369 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
370 fprintf(stderr, "Cannot create a test handle (%s); "
371 "skipping EBADF test\n", ERR_NAME);
374 ((char *) test_vp)[hlen/2]++;
377 dm_set_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
378 attrnamep, 0, buflen, "EBADF"))
379 dm_handle_free(test_vp, hlen);
382 /*---------------------------------------------------------*/
385 dm_set_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
386 attrnamep, 0, buflen, "EBADF"))
387 /*---------------------------------------------------------*/
390 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
391 (dm_attrname_t*)(-1000), 0,
392 buflen, "EFAULT_test" ))
395 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
396 attrnamep, 0, buflen, (void*)(-1000)))
397 /*---------------------------------------------------------*/
400 dm_set_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
401 attrnamep, 0, buflen,
403 /*---------------------------------------------------------*/
405 "set (bad session id)",
406 dm_set_dmattr((dm_sessid_t)(-1000), hanp, hlen,
407 DM_NO_TOKEN, attrnamep, 0, buflen,
408 "EINVAL_bad_session_id"))
410 /**** GET tests ****/
411 /*---------------------------------------------------------*/
412 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
413 attrnamep, 0, buflen,
414 "ERRNO for GET_DMATTR");
415 /*---------------------------------------------------------*/
418 dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
419 attrnamep, 0, bufp, &rlenp))
420 /*---------------------------------------------------------*/
421 SHAREDTEST("get", hanp, hlen, test_token,
422 dm_get_dmattr(sid, hanp, hlen, test_token,
423 attrnamep, buflen, bufp, &rlenp))
424 /*---------------------------------------------------------*/
426 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
427 fprintf(stderr, "Cannot create a test handle (%s); "
428 "skipping EBADF test\n", ERR_NAME);
431 ((char *) test_vp)[hlen/2]++;
434 dm_get_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
435 attrnamep, buflen, bufp, &rlenp))
436 dm_handle_free(test_vp, hlen);
439 /*---------------------------------------------------------*/
442 dm_get_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
443 attrnamep, buflen, bufp, &rlenp))
444 /*---------------------------------------------------------*/
446 "get (invalid session)",
447 dm_get_dmattr((dm_sessid_t)(-1000), hanp, hlen, DM_NO_TOKEN,
448 attrnamep, buflen, bufp, &rlenp))
449 /*---------------------------------------------------------*/
451 "get (invalid token)",
452 dm_get_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
453 attrnamep, buflen, bufp, &rlenp))
454 /*---------------------------------------------------------*/
457 dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
458 (dm_attrname_t *)("NO_SUCH_ENTRY"),
459 buflen, bufp, &rlenp))
460 /*---------------------------------------------------------*/
462 /**** REMOVE tests ****/
463 /*---------------------------------------------------------*/
464 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
465 attrnamep, 0, buflen,
467 EXCLTEST("remove", hanp, hlen, test_token,
468 dm_remove_dmattr(sid, hanp, hlen, test_token,
470 /*---------------------------------------------------------*/
472 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep,
473 0, buflen, "ERRNO for DMATTR")) {
474 printf("ERROR in setting dmattr for remove_dmattr test. (%s)\n",
477 else if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
478 fprintf(stderr, "Cannot create a test handle (%s); "
479 "skipping EBADF test\n", ERR_NAME);
482 ((char *) test_vp)[hlen/2]++;
485 dm_remove_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
487 dm_handle_free(test_vp, hlen);
490 /*---------------------------------------------------------*/
491 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, 0,
492 buflen, "ERRNO for DMATTR")) {
493 printf("ERROR in setting dmattr for remove_dmattr test. (%s)\n",
499 dm_remove_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
502 /*---------------------------------------------------------*/
505 dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
507 /*---------------------------------------------------------*/
509 "remove (bad token)",
510 dm_remove_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
512 /*---------------------------------------------------------*/
514 "remove (bad session)",
515 dm_remove_dmattr(-1, hanp, hlen, DM_NO_TOKEN,
517 /*---------------------------------------------------------*/
520 sprintf(test_file, "%s/DMAPI_attribute_test_file.ERRNO",
522 sprintf(command, "rm %s\n", test_file);
524 printf("\t(errno subtests complete)\n");
526 /**********************************\
527 |* End of improper-input testing. *|
528 \**********************************/
531 printf("Attribute tests complete!\n");
533 dm_handle_free(hanp, hlen);