diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2021-03-25 00:39:37 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2021-03-25 00:39:37 (GMT) |
commit | feb20aac304b39e18c70f88cae2f7cf7d5c82db2 (patch) | |
tree | e15d7e751af4e3c42e77ea955d91db4cf27a71cf /test/atomic_reader.c | |
parent | bdac2ecdbff2c389a222b3d93ff1eb1d23ec6b23 (diff) | |
download | hdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.zip hdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.tar.gz hdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.tar.bz2 |
Formats the source and updates the gcc warning pragmas
Diffstat (limited to 'test/atomic_reader.c')
-rw-r--r-- | test/atomic_reader.c | 121 |
1 files changed, 59 insertions, 62 deletions
diff --git a/test/atomic_reader.c b/test/atomic_reader.c index 5c1241f..d849631 100644 --- a/test/atomic_reader.c +++ b/test/atomic_reader.c @@ -42,7 +42,7 @@ /* Local Macros */ /****************/ -#define FILENAME "atomic_data" +#define FILENAME "atomic_data" #define READ_TRIES 20 #define OPEN_TRIES 50 @@ -51,10 +51,8 @@ /********************/ static void usage(void); -int verify(int fd, unsigned int k); -void print_info(int *info, unsigned int lastr, unsigned iteration); - - +int verify(int fd, unsigned int k); +void print_info(int *info, unsigned int lastr, unsigned iteration); /*------------------------------------------------------------------------- * Function: usage @@ -78,7 +76,6 @@ usage(void) printf("\n"); } /* usage() */ - /*------------------------------------------------------------------------- * Function: verify * @@ -106,66 +103,64 @@ usage(void) int verify(int fd, unsigned int k) { - unsigned int i; /* local index variable */ - ssize_t bytes_read; /* the number of bytes read */ - unsigned int *buf = NULL; /* buffer to hold data read */ + unsigned int i; /* local index variable */ + ssize_t bytes_read; /* the number of bytes read */ + unsigned int *buf = NULL; /* buffer to hold data read */ /* Allocate buffer for data read */ - if((buf = (unsigned int *)malloc(k * sizeof(unsigned int))) == NULL) { + if ((buf = (unsigned int *)malloc(k * sizeof(unsigned int))) == NULL) { printf("READER: error from malloc\n"); goto error; } /* end if */ /* Position the file at the beginning */ - if(lseek(fd, (off_t)0, SEEK_SET) < 0) { + if (lseek(fd, (off_t)0, SEEK_SET) < 0) { printf("READER: error from lseek\n"); goto error; } /* end if */ /* Read the whole file */ - if((bytes_read = read(fd, buf, (k * sizeof(unsigned int)))) < 0) { + if ((bytes_read = read(fd, buf, (k * sizeof(unsigned int)))) < 0) { printf("READER: error from read\n"); goto error; } /* end if */ /* Verify the bytes read are correct */ - if(bytes_read != (ssize_t)(k*sizeof(unsigned int))) { + if (bytes_read != (ssize_t)(k * sizeof(unsigned int))) { printf("READER: error from bytes read=%lu\n", (unsigned long)bytes_read); goto error; } /* end if */ /* Verify data read */ - for(i=0; i < k; i++) { - if(buf[i] != i) + for (i = 0; i < k; i++) { + if (buf[i] != i) break; } /* end for */ - if(i < k) { + if (i < k) { /* Compare the beginning and ending sentinel values */ - if(buf[k-1] != (i-1)) { - printf("FAIL IN READER: ...beginning sentinel value=%u, i=%u\n", (i-1), i); - printf("FAIL IN READER: buf[%u]=%u\n", i-1, buf[i-1]); + if (buf[k - 1] != (i - 1)) { + printf("FAIL IN READER: ...beginning sentinel value=%u, i=%u\n", (i - 1), i); + printf("FAIL IN READER: buf[%u]=%u\n", i - 1, buf[i - 1]); printf("FAIL IN READER: buf[%u]=%u\n", i, buf[i]); - printf("FAIL IN READER: buf[%u]=%u\n", i+1, buf[i+1]); - printf("FAIL IN READER: ...ending sentinel value=%u\n", buf[k-1]); + printf("FAIL IN READER: buf[%u]=%u\n", i + 1, buf[i + 1]); + printf("FAIL IN READER: ...ending sentinel value=%u\n", buf[k - 1]); goto error; } /* end if */ - } /* end if */ + } /* end if */ /* Free the buffer */ - if(buf) + if (buf) free(buf); return 0; error: /* Free the buffer */ - if(buf) + if (buf) free(buf); return -1; } /* end verify() */ - - /*------------------------------------------------------------------------- * Function: print_info * @@ -183,17 +178,16 @@ error: void print_info(int *info, unsigned int lastr, unsigned iteration) { - unsigned j; /* local index variable */ + unsigned j; /* local index variable */ printf("--------statistics for %u reads (iteration %u)--------\n", lastr, iteration); - for(j = 0; j <= READ_TRIES; j++) + for (j = 0; j <= READ_TRIES; j++) printf("# of %u re-tries = %u\n", j, info[j]); printf("--------end statistics for %u reads (iteration %u)--------\n", lastr, iteration); } /* print_info() */ - /*------------------------------------------------------------------------- * Function: main * @@ -222,32 +216,32 @@ print_info(int *info, unsigned int lastr, unsigned iteration) int main(int argc, char *argv[]) { - int fd = -1; /* file descriptor */ - unsigned int j=0, i=0, m=0; /* local index variables */ - int temp; /* temporary variable */ - unsigned int iterations = 0; /* the input for "-i" */ - unsigned num = 0; /* the input for "-n" */ - int opt = 0; /* option char */ - int info[READ_TRIES+1]; /* re-tries statistics */ + int fd = -1; /* file descriptor */ + unsigned int j = 0, i = 0, m = 0; /* local index variables */ + int temp; /* temporary variable */ + unsigned int iterations = 0; /* the input for "-i" */ + unsigned num = 0; /* the input for "-n" */ + int opt = 0; /* option char */ + int info[READ_TRIES + 1]; /* re-tries statistics */ /* Ensure the expected # of arguments */ - if(argc != 5) { + if (argc != 5) { usage(); exit(EXIT_FAILURE); } /* end if */ /* Parse command line options */ - while((opt = getopt(argc, argv, "n:i:")) != -1) { - switch(opt) { + while ((opt = getopt(argc, argv, "n:i:")) != -1) { + switch (opt) { case 'n': - if((temp = atoi(optarg)) < 0) { + if ((temp = atoi(optarg)) < 0) { usage(); exit(EXIT_FAILURE); } /* end if */ num = (unsigned int)temp; break; case 'i': - if((temp = atoi(optarg)) < 0) { + if ((temp = atoi(optarg)) < 0) { usage(); exit(EXIT_FAILURE); } /* end if */ @@ -257,35 +251,36 @@ main(int argc, char *argv[]) printf("Invalid option encountered\n"); break; } /* end switch */ - } /* end while */ + } /* end while */ printf("READER: number of integers to read = %u; # of iterations = %d\n", num, iterations); printf("\n"); - for(i = 1; i <= iterations; i++) { + for (i = 1; i <= iterations; i++) { unsigned opens = OPEN_TRIES; printf("READER: *****start iteration %u*****\n", i); /* Ensure open and file size are done properly */ - while(opens--) { + while (opens--) { struct stat sinfo; memset(&sinfo, 0, sizeof(sinfo)); - if((fd = open(FILENAME, O_RDONLY, 0644)) < 0) { + if ((fd = open(FILENAME, O_RDONLY, 0644)) < 0) { printf("READER: error from open--retry open again\n"); - } else { + } + else { printf("READER: open succeed\n"); - if((fstat(fd, &sinfo) == 0) && - (sinfo.st_size == (off_t)(num * sizeof(unsigned int)))) { + if ((fstat(fd, &sinfo) == 0) && (sinfo.st_size == (off_t)(num * sizeof(unsigned int)))) { printf("READER: file size is correct--%u\n", (unsigned int)sinfo.st_size); break; } /* end if */ - printf("READER: error from fstat or file size of %u is incorrect--retry open again\n", (unsigned int)sinfo.st_size); - if(close(fd) < 0) { + printf("READER: error from fstat or file size of %u is incorrect--retry open again\n", + (unsigned int)sinfo.st_size); + if (close(fd) < 0) { printf("READER: error from close\n"); return EXIT_FAILURE; } /* end if */ @@ -294,38 +289,41 @@ main(int argc, char *argv[]) } /* end while */ - if(fd < 0) { - printf("READER: *****open failure/incorrect file size for all %u tries, continue next iteration*****\n\n", OPEN_TRIES); + if (fd < 0) { + printf("READER: *****open failure/incorrect file size for all %u tries, continue next " + "iteration*****\n\n", + OPEN_TRIES); continue; } /* end if */ memset(info, 0, sizeof(info)); /* Read and verify data */ - for(j = 1; j <= num; j++) { + for (j = 1; j <= num; j++) { printf("READER: doing read %u\n", j); - if(verify(fd, num) < 0) { + if (verify(fd, num) < 0) { printf("READER: error from read %u\n", j); /* Perform re-read to see if correct data is obtained */ - for(m = 1; m <= READ_TRIES; m++) { + for (m = 1; m <= READ_TRIES; m++) { printf("READER: ===============going to do re-read try %u\n", m); - if(verify(fd, num) < 0) + if (verify(fd, num) < 0) printf("READER: ===============error from re-read try %u\n", m); else { ++info[m]; printf("READER: ===============SUCCESS from re-read try %u\n", m); break; } /* end else */ - } /* end for */ + } /* end for */ - if(m > READ_TRIES) { + if (m > READ_TRIES) { printf("READER: ===============error from all re-read tries: %u\n", READ_TRIES); printf("READER:*****ERROR--stop on read %u\n", j); break; } /* end if */ - } else { + } + else { ++info[0]; printf("READER: success from read %u\n", j); } /* end else */ @@ -333,10 +331,10 @@ main(int argc, char *argv[]) } /* end for */ /* Print the statistics for re-reads */ - print_info(info, j-1, i); + print_info(info, j - 1, i); /* Close the file */ - if(close(fd) < 0) { + if (close(fd) < 0) { printf("READER: error from close\n"); return EXIT_FAILURE; } /* end if */ @@ -358,4 +356,3 @@ main(void) } /* end main() */ #endif /* WIN32 / MINGW32 */ - |