2 * Copyright (c) 2000-2001 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[];
83 fprintf(stderr, "usage:\t%s [-v] [-n number] [-l length] "
84 "[-s sid] ls_path pathname\n", Progname);
94 dm_sessid_t sid = DM_NO_SESSION;
97 dm_attrname_t *attrnamep;
98 size_t buflen=VALUE_LENGTH;
109 int num_iter = NUM_ITERATIONS;
113 dm_size_t config_retval;
114 dm_token_t test_token;
115 struct stat *statbuf;
116 struct stat *checkbuf;
118 if (Progname = strrchr(argv[0], '/')) {
124 /* Crack and validate the command line options. */
126 while ((opt = getopt(argc, argv, "vn:l:s:")) != EOF) {
132 num_iter = atoi(optarg);
135 buflen = atoi(optarg);
144 if (optind + 2 != argc)
146 ls_path = argv[optind];
147 dir_name = argv[optind+1];
150 (char *)(malloc (buflen * sizeof(char)));
152 (struct stat *)(malloc (num_iter * sizeof(struct stat)));
154 (struct stat *)(malloc (num_iter * sizeof(struct stat)));
156 (char **)(malloc (num_iter * sizeof(char *)));
157 if (bufp==NULL || test_array==NULL ||
158 statbuf==NULL || checkbuf==NULL) {
159 printf("Malloc failed\n");
162 for (i=0; i<num_iter; i++) {
164 (char*)(malloc (buflen * sizeof(char)));
165 if (test_array[i] == NULL) {
166 printf("Malloc failed\n");
171 if (dm_init_service(&name) == -1) {
172 fprintf(stderr, "Can't initialize the DMAPI\n");
175 if (sid == DM_NO_SESSION)
176 find_test_session(&sid);
178 printf("Attribute tests beginning...\n");
180 attrnamep = (dm_attrname_t *)("DMATTR");
182 /* File creation loop*/
183 for (i=0; i < num_iter; i++) {
184 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
186 sprintf(command, "cp %s %s \n", ls_path, test_file);
191 for (i=0; i < num_iter; i++) {
192 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
195 if (stat(test_file, &(statbuf[i]))){
197 "Error: unable to stat the test file; %s (before set)\n",
200 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
201 fprintf(stderr, "can't get handle for %s; bypassing test\n",
205 for (j=0; j < VALUE_LENGTH; j++) {
206 test_array[i][j]=(char)(rand()/128);;
208 /* buflen is already set (to VALUE_LENGTH) */
209 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep,
210 (i<num_iter/2)?0:1, buflen, test_array[i])) {
211 fprintf(stderr, "dm_set_dmattr failed on test %d, %s\n",
216 printf("Report: success with set #%d.\n", i);
223 for (i=0; i < num_iter; i++) {
224 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
227 if (stat(test_file, &(checkbuf[i]))){
229 "Error: unable to stat the test file; %s (before get)\n",
232 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
233 fprintf(stderr, "can't get handle for %s; bypassing test\n",
237 if (dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, buflen,
239 if (errno == E2BIG) {
240 fprintf(stderr, "dm_get_dmattr buffer too small, "
241 "should be %d bytes\n", rlenp);
243 fprintf(stderr, "dm_get_dmattr failed (%s) for test file %d\n",
248 /* Compare bufp with test_array[i]: */
249 if (strncmp(test_array[i], bufp, buflen)){
250 printf("ERROR: failure on get test #%d.\n", i);
253 printf("Report: success with get #%d. "
254 "(output matches expectation)\n",i);
260 /* It's time for timestamp checking! */
261 for (i=0; i < num_iter; i++) {
263 if ((statbuf[i].st_atime == checkbuf[i].st_atime) &&
264 (statbuf[i].st_mtime == checkbuf[i].st_mtime) &&
265 (statbuf[i].st_ctime == checkbuf[i].st_ctime))
267 if ((statbuf[i].st_atim.tv_sec == checkbuf[i].st_atim.tv_sec) &&
268 (statbuf[i].st_atim.tv_nsec == checkbuf[i].st_atim.tv_nsec) &&
269 (statbuf[i].st_mtim.tv_sec == checkbuf[i].st_mtim.tv_sec) &&
270 (statbuf[i].st_mtim.tv_nsec == checkbuf[i].st_mtim.tv_nsec) &&
271 (statbuf[i].st_ctim.tv_sec == checkbuf[i].st_ctim.tv_sec) &&
272 (statbuf[i].st_ctim.tv_nsec == checkbuf[i].st_ctim.tv_nsec))
275 if (i < num_iter/2) {
276 /* Time stamp did not change, correctly */
278 fprintf(stdout, "Report: Time stamp was correctly "
279 "unchanged by test %d.\n", i);
283 /* Time stamp did not change, but should have */
284 fprintf(stdout, "Error: the time stamp should have "
285 "changed in test file %d\n", i);
289 /* Time stamp changed, but should not have. */
290 if (i < num_iter/2) {
291 fprintf(stdout, "Error: the time stamp should not"
292 "change in test file %d\n", i);
295 /* Time stamp changed, and should have. */
297 fprintf(stdout, "Report: Time stamp was correctly "
298 "changed by test %d.\n", i);
306 for (i=0; i < num_iter; i++) {
307 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
310 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
311 fprintf(stderr, "can't get handle for %s; bypassing test\n",
315 if (dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN, setdtime,
317 fprintf(stderr, "dm_remove_dmattr failed (%s) on test #%d\n",
322 printf("Report: success with remove test #%d.\n",i);
328 for (i=0; i < num_iter; i++) {
329 sprintf(test_file, "%s/DMAPI_attribute_test_file.%d",
331 sprintf(command, "rm %s \n", test_file);
335 /*************************************\
336 |* Correct-input testing complete. *|
337 |* Beginning improper-input testing. *|
338 \*************************************/
339 sprintf(test_file, "%s/DMAPI_attribute_test_file.ERRNO",
341 sprintf(command, "cp %s %s\n", ls_path, test_file);
344 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
345 fprintf(stderr, "can't get handle for %s; bypassing errno tests\n",
350 printf("\t(errno subtests beginning...)\n");
351 /**** SET tests ****/
352 /*---------------------------------------------------------*/
353 dm_get_config(hanp, hlen, DM_CONFIG_MAX_ATTRIBUTE_SIZE,
358 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
359 attrnamep, setdtime, (config_retval+1),
361 /*---------------------------------------------------------*/
362 EXCLTEST("set", hanp, hlen, test_token,
363 dm_set_dmattr(sid, hanp, hlen, test_token,
364 attrnamep, 0, buflen, "no right"))
365 /*---------------------------------------------------------*/
367 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
368 fprintf(stderr, "Cannot create a test handle (%s); "
369 "skipping EBADF test\n", ERR_NAME);
372 ((char *) test_vp)[hlen/2]++;
375 dm_set_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
376 attrnamep, 0, buflen, "EBADF"))
377 dm_handle_free(test_vp, hlen);
380 /*---------------------------------------------------------*/
383 dm_set_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
384 attrnamep, 0, buflen, "EBADF"))
385 /*---------------------------------------------------------*/
388 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
389 (dm_attrname_t*)(-1000), 0,
390 buflen, "EFAULT_test" ))
393 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
394 attrnamep, 0, buflen, (void*)(-1000)))
395 /*---------------------------------------------------------*/
398 dm_set_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
399 attrnamep, 0, buflen,
401 /*---------------------------------------------------------*/
403 "set (bad session id)",
404 dm_set_dmattr((dm_sessid_t)(-1000), hanp, hlen,
405 DM_NO_TOKEN, attrnamep, 0, buflen,
406 "EINVAL_bad_session_id"))
408 /**** GET tests ****/
409 /*---------------------------------------------------------*/
410 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
411 attrnamep, 0, buflen,
412 "ERRNO for GET_DMATTR");
413 /*---------------------------------------------------------*/
416 dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
417 attrnamep, 0, bufp, &rlenp))
418 /*---------------------------------------------------------*/
419 SHAREDTEST("get", hanp, hlen, test_token,
420 dm_get_dmattr(sid, hanp, hlen, test_token,
421 attrnamep, buflen, bufp, &rlenp))
422 /*---------------------------------------------------------*/
424 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
425 fprintf(stderr, "Cannot create a test handle (%s); "
426 "skipping EBADF test\n", ERR_NAME);
429 ((char *) test_vp)[hlen/2]++;
432 dm_get_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
433 attrnamep, buflen, bufp, &rlenp))
434 dm_handle_free(test_vp, hlen);
437 /*---------------------------------------------------------*/
440 dm_get_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
441 attrnamep, buflen, bufp, &rlenp))
442 /*---------------------------------------------------------*/
444 "get (invalid session)",
445 dm_get_dmattr((dm_sessid_t)(-1000), hanp, hlen, DM_NO_TOKEN,
446 attrnamep, buflen, bufp, &rlenp))
447 /*---------------------------------------------------------*/
449 "get (invalid token)",
450 dm_get_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
451 attrnamep, buflen, bufp, &rlenp))
452 /*---------------------------------------------------------*/
455 dm_get_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
456 (dm_attrname_t *)("NO_SUCH_ENTRY"),
457 buflen, bufp, &rlenp))
458 /*---------------------------------------------------------*/
460 /**** REMOVE tests ****/
461 /*---------------------------------------------------------*/
462 dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
463 attrnamep, 0, buflen,
465 EXCLTEST("remove", hanp, hlen, test_token,
466 dm_remove_dmattr(sid, hanp, hlen, test_token,
468 /*---------------------------------------------------------*/
470 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep,
471 0, buflen, "ERRNO for DMATTR")) {
472 printf("ERROR in setting dmattr for remove_dmattr test. (%s)\n",
475 else if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
476 fprintf(stderr, "Cannot create a test handle (%s); "
477 "skipping EBADF test\n", ERR_NAME);
480 ((char *) test_vp)[hlen/2]++;
483 dm_remove_dmattr(sid, test_vp, hlen, DM_NO_TOKEN,
485 dm_handle_free(test_vp, hlen);
488 /*---------------------------------------------------------*/
489 if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, 0,
490 buflen, "ERRNO for DMATTR")) {
491 printf("ERROR in setting dmattr for remove_dmattr test. (%s)\n",
497 dm_remove_dmattr(sid, hanp, hlen-1, DM_NO_TOKEN,
500 /*---------------------------------------------------------*/
503 dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
505 /*---------------------------------------------------------*/
507 "remove (bad token)",
508 dm_remove_dmattr(sid, hanp, hlen, (dm_token_t)(-1000),
510 /*---------------------------------------------------------*/
512 "remove (bad session)",
513 dm_remove_dmattr(-1, hanp, hlen, DM_NO_TOKEN,
515 /*---------------------------------------------------------*/
518 sprintf(test_file, "%s/DMAPI_attribute_test_file.ERRNO",
520 sprintf(command, "rm %s\n", test_file);
522 printf("\t(errno subtests complete)\n");
524 /**********************************\
525 |* End of improper-input testing. *|
526 \**********************************/
529 printf("Attribute tests complete!\n");
531 dm_handle_free(hanp, hlen);