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[];
84 fprintf(stderr, "usage:\t%s [-v] [-s sid] ls_path pathname\n",
95 dm_sessid_t sid = DM_NO_SESSION;
96 char *dir_name = NULL;
100 dm_size_t curlength = 0;
115 struct stat checkbuf;
116 dm_token_t test_token;
121 if (Progname = strrchr(argv[0], '/')) {
127 /* Crack and validate the command line options. */
129 while ((opt = getopt(argc, argv, "vs:")) != EOF) {
141 if (optind + 2 != argc)
143 ls_path = argv[optind];
144 dir_name = argv[optind+1];
146 if (dm_init_service(&name) == -1) {
147 fprintf(stderr, "Can't inititalize the DMAPI\n");
150 if (sid == DM_NO_SESSION)
151 find_test_session(&sid);
153 /* Get a random character for read/write tests */
154 srand((unsigned int)time(NULL));
157 printf("Invisible read/write tests beginning...\n");
159 /* File creation loop*/
160 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
161 for (j=0; j<OFF_MAX; j+=OFF_STEP) {
162 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
164 sprintf(command, "cp %s %s\n", ls_path, test_file);
169 /* Write to files, then read them to check for correct results.
170 Do timestamp checking along the way. */
172 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
173 for (j=0; j<OFF_MAX; j+=OFF_STEP) {
175 #define max(a,b) ((a) > (b) ? (a) : (b))
176 length = max((dm_size_t)(i), length);
177 offset = (dm_off_t)(j);
179 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
182 if (stat(test_file, &statbuf)){
184 "Error: unable to stat test file; %s (before test)\n",
189 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
190 fprintf(stderr, "can't get handle for %s; bypassing test\n",
195 if (length > curlength) {
198 if ((bufp = malloc(length)) == NULL) {
199 fprintf(stderr, "malloc of %llu bytes failed\n", length);
203 memset(bufp, ch, length);
206 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
207 0, offset, length, bufp);
210 fprintf(stderr, "dm_write_invis failed, %s\n", ERR_NAME);
212 } else if (rc != length) {
213 fprintf(stderr, "expected to write %lld bytes, actually "
214 "wrote %lld\n", length, rc);
220 /* Timestamp checking, part 1 */
221 if (stat(test_file, &checkbuf)){
223 "Error: unable to stat the test file; %s (after write)\n",
228 if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
229 (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
230 (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
231 (statbuf.st_mtim.tv_nsec == checkbuf.st_mtim.tv_nsec) &&
232 (statbuf.st_ctim.tv_sec == checkbuf.st_ctim.tv_sec) &&
233 (statbuf.st_ctim.tv_nsec == checkbuf.st_ctim.tv_nsec))
235 if ((statbuf.st_atime == checkbuf.st_atime) &&
236 (statbuf.st_mtime == checkbuf.st_mtime) &&
237 (statbuf.st_ctime == checkbuf.st_ctime))
241 printf("Report: time stamp unchanged by write\n");
245 printf("Error: time stamp changed by write\n");
249 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
250 offset, length, bufp);
252 fprintf(stderr, "dm_read_invis failed, %s\n", ERR_NAME);
255 else if (rc != length) {
256 fprintf(stderr, "expected to read %lld bytes, actually "
257 "wrote %lld\n", length, rc);
261 /* Be sure the buffer is filled with the test char */
264 if (((char *)bufp)[k] == ch) {
265 if (Vflag) printf(".");
269 printf("Error!(line=%d)\n", __LINE__);
274 if (Vflag) printf("\n");
277 /* Timestamp checking, part 2 */
278 if (stat(test_file, &statbuf)){
280 "Error: unable to stat the test file; %s (after write)\n",
285 if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
286 (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
287 (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
288 (statbuf.st_mtim.tv_nsec == checkbuf.st_mtim.tv_nsec) &&
289 (statbuf.st_ctim.tv_sec == checkbuf.st_ctim.tv_sec) &&
290 (statbuf.st_ctim.tv_nsec == checkbuf.st_ctim.tv_nsec))
292 if ((statbuf.st_atime == checkbuf.st_atime) &&
293 (statbuf.st_mtime == checkbuf.st_mtime) &&
294 (statbuf.st_ctime == checkbuf.st_ctime))
298 printf("Report: time stamp unchanged by read\n");
302 printf("Error: time stamp changed by read\n");
305 } /* for (j=0; j<OFF_MAX; j+=OFF_STEP) */
306 } /* for(i=0; i<LEN_MAX; i+=LEN_STEP) */
308 /* File deletion loop*/
309 for(i=0; i<LEN_MAX; i+=LEN_STEP) {
310 for(j=0; j<OFF_MAX; j+=OFF_STEP) {
311 sprintf(test_file, "%s/DMAPI_invis_test_file.%02d%02d",
313 sprintf(command, "rm %s\n", test_file);
318 /*************************************\
319 |* Correct-input testing complete. *|
320 |* Beginning improper-input testing. *|
321 \*************************************/
322 sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO",
324 sprintf(command, "cp %s %s\n", ls_path, test_file);
327 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
328 fprintf(stderr, "can't get handle for %s; bypassing errno tests\n",
333 /* Try writing a character waaaaaay up in the millions range */
334 sprintf(bufp, "%c", ch);
335 if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
336 (1000000*(unsigned int)(ch)), 1, bufp)==-1){
337 printf("Error invis-writing %s at byte %u million: %s\n",
338 (char*)bufp, (unsigned int)ch, ERR_NAME);
340 else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
341 (1000000*(unsigned int)(ch)), 1, bufp)==-1){
342 printf("Error invis-reading at byte %u million: %s\n",
343 (unsigned int)ch, ERR_NAME);
345 else if (((char*)bufp)[0]!=ch) {
346 printf("Error: wanted to read %c and instead got %s.\n",
350 printf("Report: \"%c\" was written and \"%s\" was read "
351 "at byte %d million.\n", ch, (char*)bufp, ch);
355 /* Try writing a character in the 2 gigabyte (2^31) range */
356 sprintf(bufp, "%c", ch);
357 if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
358 2147840000, 1, bufp)==-1){
359 printf("Error invis-writing %s at 2 gigabytes: %s\n",
360 (char*)bufp, ERR_NAME);
362 else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
363 2147840000, 1, bufp)==-1){
364 printf("Error invis-reading at 2 gigabytes: %s\n",
367 else if (((char*)bufp)[0]!=ch) {
368 printf("Error: wanted to read %c and instead got %s.\n",
372 printf("Report: \"%c\" was written and \"%s\" was read "
373 "at 2147840000 bytes\n\t(a bit over 2 gigabytes).\n",
378 printf("\t(errno subtests beginning...)\n");
379 /**** WRITE tests ****/
380 /*---------------------------------------------------------*/
381 EXCLTEST("write", hanp, hlen, test_token,
382 dm_write_invis(sid, hanp, hlen, test_token,
383 0, 0, 13, "write test 1"))
384 /*---------------------------------------------------------*/
385 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
387 "Cannot create a test handle (%s); skipping EBADF test\n",
391 ((char *) test_vp)[hlen/2]++;
394 dm_write_invis(sid, test_vp, hlen, DM_NO_TOKEN,
398 dm_read_invis(sid, test_vp, hlen, DM_NO_TOKEN,
400 dm_handle_free(test_vp, hlen);
403 /*---------------------------------------------------------*/
406 dm_write_invis(sid, hanp, hlen-1, DM_NO_TOKEN,
408 /*---------------------------------------------------------*/
411 dm_write_invis(sid, NULL, hlen, DM_NO_TOKEN,
413 /*---------------------------------------------------------*/
415 PROBLEM: write_invis refuses to produce EINVAL for
416 lengths that will not fit in a dm_size_t.
419 "(bad length) write",
420 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
421 0, 4096, (long long)0xFFFFFFFFFFFFFFFFLL,
422 "write invalid length test"))
424 /*---------------------------------------------------------*/
426 PROBLEM (somewhat fixed): A signal is sent, rather than EFBIG.
427 Presumably, this signal is needed to comply with...something.
428 If this is uncommented, the program will abort here, with the
429 error message "exceeded file size limit".
433 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
434 0, (long long)0xFFFFFFFFFFLL,
435 (long long)0xFFFFFFFFFFLL,
438 /*---------------------------------------------------------*/
441 "(bad offset) write",
442 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
443 0, (dm_size_t) ULONG_MAX, 5,
444 "write invalid offset test"))
448 "(bad offset) write",
449 dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
450 0, (dm_size_t) ULONGLONG_MAX, 5,
451 "write invalid offset test"))
455 /*---------------------------------------------------------*/
458 dm_write_invis(-100, hanp, hlen, DM_NO_TOKEN,
459 0, 0, 26, "write invalid offset test"))
462 /**** READ tests ****/
463 /*---------------------------------------------------------*/
464 SHAREDTEST("read", hanp, hlen, test_token,
465 dm_read_invis(sid, hanp, hlen, test_token,
467 /*---------------------------------------------------------*/
470 dm_read_invis(sid, hanp, hlen-1, DM_NO_TOKEN,
472 /*---------------------------------------------------------*/
475 dm_read_invis(sid, NULL, hlen, DM_NO_TOKEN,
477 /*---------------------------------------------------------*/
481 dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
482 ULONG_MAX, 5, bufp));
487 dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
488 ULONGLONG_MAX, 5, bufp));
492 /*---------------------------------------------------------*/
495 dm_read_invis(-100, hanp, hlen, DM_NO_TOKEN,
497 /*---------------------------------------------------------*/
498 printf("\t(errno subtests complete!)\n");
500 sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO",
502 sprintf(command, "rm %s \n", test_file);
505 printf("Invisible read/write tests complete.\n");
507 dm_handle_free(hanp, hlen);