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 /*---------------------------------------------------------------------------
47 Automated test of the DMAPI functions dm_write_invis() and dm_read_invis()
51 test_invis [-s sid] [-v] ls_path pathname
55 is the session ID whose events you you are interested in.
57 is the path to a specific copy of ls, important only for its size
59 is the filesystem to use for the test.
61 DM_WRITE_SYNC is is not supported.
62 ----------------------------------------------------------------------------*/
70 extern char *sys_errlist[];
82 fprintf(stderr, "usage:\t%s [-v] [-s sid] ls_path pathname\n",
93 dm_sessid_t sid = DM_NO_SESSION;
94 char *dir_name = NULL;
98 dm_size_t curlength = 0;
113 struct stat checkbuf;
114 dm_token_t test_token;
119 if (Progname = strrchr(argv[0], '/')) {
125 /* Crack and validate the command line options. */
127 while ((opt = getopt(argc, argv, "vs:")) != EOF) {
139 if (optind + 2 != argc)
141 ls_path = argv[optind];
142 dir_name = argv[optind+1];
144 if (dm_init_service(&name) == -1) {
145 fprintf(stderr, "Can't inititalize the DMAPI\n");
148 if (sid == DM_NO_SESSION)
149 find_test_session(&sid);
151 /* Get a random character for read/write tests */
152 srand((unsigned int)time(NULL));
155 printf("Invisible read/write tests beginning...\n");
157 /* File creation loop*/
158 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
159 for (j=0; j<OFF_MAX; j+=OFF_STEP) {
160 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
162 sprintf(command, "cp %s %s\n", ls_path, test_file);
167 /* Write to files, then read them to check for correct results.
168 Do timestamp checking along the way. */
170 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
171 for (j=0; j<OFF_MAX; j+=OFF_STEP) {
173 #define max(a,b) ((a) > (b) ? (a) : (b))
174 length = max((dm_size_t)(i), length);
175 offset = (dm_off_t)(j);
177 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
180 if (stat(test_file, &statbuf)){
182 "Error: unable to stat test file; %s (before test)\n",
187 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
188 fprintf(stderr, "can't get handle for %s; bypassing test\n",
193 if (length > curlength) {
196 if ((bufp = malloc(length)) == NULL) {
197 fprintf(stderr, "malloc of %llu bytes failed\n", length);
201 memset(bufp, ch, length);
204 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
205 0, offset, length, bufp);
208 fprintf(stderr, "dm_write_invis failed, %s\n", ERR_NAME);
210 } else if (rc != length) {
211 fprintf(stderr, "expected to write %lld bytes, actually "
212 "wrote %lld\n", length, rc);
218 /* Timestamp checking, part 1 */
219 if (stat(test_file, &checkbuf)){
221 "Error: unable to stat the test file; %s (after write)\n",
226 if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
227 (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
228 (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
229 (statbuf.st_mtim.tv_nsec == checkbuf.st_mtim.tv_nsec) &&
230 (statbuf.st_ctim.tv_sec == checkbuf.st_ctim.tv_sec) &&
231 (statbuf.st_ctim.tv_nsec == checkbuf.st_ctim.tv_nsec))
233 if ((statbuf.st_atime == checkbuf.st_atime) &&
234 (statbuf.st_mtime == checkbuf.st_mtime) &&
235 (statbuf.st_ctime == checkbuf.st_ctime))
239 printf("Report: time stamp unchanged by write\n");
243 printf("Error: time stamp changed by write\n");
247 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
248 offset, length, bufp);
250 fprintf(stderr, "dm_read_invis failed, %s\n", ERR_NAME);
253 else if (rc != length) {
254 fprintf(stderr, "expected to read %lld bytes, actually "
255 "wrote %lld\n", length, rc);
259 /* Be sure the buffer is filled with the test char */
262 if (((char *)bufp)[k] == ch) {
263 if (Vflag) printf(".");
267 printf("Error!(line=%d)\n", __LINE__);
272 if (Vflag) printf("\n");
275 /* Timestamp checking, part 2 */
276 if (stat(test_file, &statbuf)){
278 "Error: unable to stat the test file; %s (after write)\n",
283 if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
284 (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
285 (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
286 (statbuf.st_mtim.tv_nsec == checkbuf.st_mtim.tv_nsec) &&
287 (statbuf.st_ctim.tv_sec == checkbuf.st_ctim.tv_sec) &&
288 (statbuf.st_ctim.tv_nsec == checkbuf.st_ctim.tv_nsec))
290 if ((statbuf.st_atime == checkbuf.st_atime) &&
291 (statbuf.st_mtime == checkbuf.st_mtime) &&
292 (statbuf.st_ctime == checkbuf.st_ctime))
296 printf("Report: time stamp unchanged by read\n");
300 printf("Error: time stamp changed by read\n");
303 } /* for (j=0; j<OFF_MAX; j+=OFF_STEP) */
304 } /* for(i=0; i<LEN_MAX; i+=LEN_STEP) */
306 /* File deletion loop*/
307 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
308 for(j=0; j<OFF_MAX; j+=OFF_STEP) {
309 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
311 sprintf(command, "rm %s\n", test_file);
316 /*************************************\
317 |* Correct-input testing complete. *|
318 |* Beginning improper-input testing. *|
319 \*************************************/
320 sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO",
322 sprintf(command, "cp %s %s\n", ls_path, test_file);
325 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
326 fprintf(stderr, "can't get handle for %s; bypassing errno tests\n",
331 /* Try writing a character waaaaaay up in the millions range */
332 sprintf(bufp, "%c", ch);
333 if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
334 (1000000*(unsigned int)(ch)), 1, bufp)==-1){
335 printf("Error invis-writing %s at byte %u million: %s\n",
336 (char*)bufp, (unsigned int)ch, ERR_NAME);
338 else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
339 (1000000*(unsigned int)(ch)), 1, bufp)==-1){
340 printf("Error invis-reading at byte %u million: %s\n",
341 (unsigned int)ch, ERR_NAME);
343 else if (((char*)bufp)[0]!=ch) {
344 printf("Error: wanted to read %c and instead got %s.\n",
348 printf("Report: \"%c\" was written and \"%s\" was read "
349 "at byte %d million.\n", ch, (char*)bufp, ch);
353 /* Try writing a character in the 2 gigabyte (2^31) range */
354 sprintf(bufp, "%c", ch);
355 if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
356 2147840000, 1, bufp)==-1){
357 printf("Error invis-writing %s at 2 gigabytes: %s\n",
358 (char*)bufp, ERR_NAME);
360 else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
361 2147840000, 1, bufp)==-1){
362 printf("Error invis-reading at 2 gigabytes: %s\n",
365 else if (((char*)bufp)[0]!=ch) {
366 printf("Error: wanted to read %c and instead got %s.\n",
370 printf("Report: \"%c\" was written and \"%s\" was read "
371 "at 2147840000 bytes\n\t(a bit over 2 gigabytes).\n",
376 printf("\t(errno subtests beginning...)\n");
377 /**** WRITE tests ****/
378 /*---------------------------------------------------------*/
379 EXCLTEST("write", hanp, hlen, test_token,
380 dm_write_invis(sid, hanp, hlen, test_token,
381 0, 0, 13, "write test 1"))
382 /*---------------------------------------------------------*/
383 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
385 "Cannot create a test handle (%s); skipping EBADF test\n",
389 ((char *) test_vp)[hlen/2]++;
392 dm_write_invis(sid, test_vp, hlen, DM_NO_TOKEN,
396 dm_read_invis(sid, test_vp, hlen, DM_NO_TOKEN,
398 dm_handle_free(test_vp, hlen);
401 /*---------------------------------------------------------*/
404 dm_write_invis(sid, hanp, hlen-1, DM_NO_TOKEN,
406 /*---------------------------------------------------------*/
409 dm_write_invis(sid, NULL, hlen, DM_NO_TOKEN,
411 /*---------------------------------------------------------*/
413 PROBLEM: write_invis refuses to produce EINVAL for
414 lengths that will not fit in a dm_size_t.
417 "(bad length) write",
418 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
419 0, 4096, (long long)0xFFFFFFFFFFFFFFFFLL,
420 "write invalid length test"))
422 /*---------------------------------------------------------*/
424 PROBLEM (somewhat fixed): A signal is sent, rather than EFBIG.
425 Presumably, this signal is needed to comply with...something.
426 If this is uncommented, the program will abort here, with the
427 error message "exceeded file size limit".
431 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
432 0, (long long)0xFFFFFFFFFFLL,
433 (long long)0xFFFFFFFFFFLL,
436 /*---------------------------------------------------------*/
439 "(bad offset) write",
440 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
441 0, (dm_size_t) ULONG_MAX, 5,
442 "write invalid offset test"))
446 "(bad offset) write",
447 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
448 0, (dm_size_t) ULONGLONG_MAX, 5,
449 "write invalid offset test"))
453 /*---------------------------------------------------------*/
456 dm_write_invis(-100, hanp, hlen, DM_NO_TOKEN,
457 0, 0, 26, "write invalid offset test"))
460 /**** READ tests ****/
461 /*---------------------------------------------------------*/
462 SHAREDTEST("read", hanp, hlen, test_token,
463 dm_read_invis(sid, hanp, hlen, test_token,
465 /*---------------------------------------------------------*/
468 dm_read_invis(sid, hanp, hlen-1, DM_NO_TOKEN,
470 /*---------------------------------------------------------*/
473 dm_read_invis(sid, NULL, hlen, DM_NO_TOKEN,
475 /*---------------------------------------------------------*/
479 dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
480 ULONG_MAX, 5, bufp));
485 dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
486 ULONGLONG_MAX, 5, bufp));
490 /*---------------------------------------------------------*/
493 dm_read_invis(-100, hanp, hlen, DM_NO_TOKEN,
495 /*---------------------------------------------------------*/
496 printf("\t(errno subtests complete!)\n");
498 sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO",
500 sprintf(command, "rm %s \n", test_file);
503 printf("Invisible read/write tests complete.\n");
505 dm_handle_free(hanp, hlen);