summaryrefslogtreecommitdiffstats
path: root/test/twriteorder.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /test/twriteorder.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'test/twriteorder.c')
-rw-r--r--test/twriteorder.c237
1 files changed, 122 insertions, 115 deletions
diff --git a/test/twriteorder.c b/test/twriteorder.c
index 04f3bc5..83a615c 100644
--- a/test/twriteorder.c
+++ b/test/twriteorder.c
@@ -11,52 +11,52 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***********************************************************
-*
-* Test program: twriteorder
-*
-* Test to verify that the write order is strictly consistent.
-* The SWMR feature requires that the order of write is strictly consistent.
-* "Strict consistency in computer science is the most stringent consistency
-* model. It says that a read operation has to return the result of the
-* latest write operation which occurred on that data item."--
-* (http://en.wikipedia.org/wiki/Linearizability#Definition_of_linearizability).
-* This is also an alternative form of what POSIX write require that after a
-* write operation has returned success, all reads issued afterward should
-* get the same data the write has written.
-*
-* Created: Albert Cheng, 2013/8/28.
-*************************************************************/
+ *
+ * Test program: twriteorder
+ *
+ * Test to verify that the write order is strictly consistent.
+ * The SWMR feature requires that the order of write is strictly consistent.
+ * "Strict consistency in computer science is the most stringent consistency
+ * model. It says that a read operation has to return the result of the
+ * latest write operation which occurred on that data item."--
+ * (http://en.wikipedia.org/wiki/Linearizability#Definition_of_linearizability).
+ * This is also an alternative form of what POSIX write require that after a
+ * write operation has returned success, all reads issued afterward should
+ * get the same data the write has written.
+ *
+ * Created: Albert Cheng, 2013/8/28.
+ *************************************************************/
/***********************************************************
-*
-* Algorithm
-*
-* The test simulates what SWMR does by writing chained blocks and see if
-* they can be read back correctly.
-* There is a writer process and multiple read processes.
-* The file is divided into 2KB partitions. Then writer writes 1 chained
-* block, each of 1KB big, in each partition after the first partition.
-* Each chained block has this structure:
-* Byte 0-3: offset address of its child block. The last child uses 0 as NULL.
-* Byte 4-1023: some artificial data.
-* The child block address of Block 1 is NULL (0).
-* The child block address of Block 2 is the offset address of Block 1.
-* The child block address of Block n is the offset address of Block n-1.
-* After all n blocks are written, the offset address of Block n is written
-* to the offset 0 of the first partition.
-* Therefore, by the time the offset address of Block n is written to this
-* position, all n chain-linked blocks have been written.
-*
-* The other reader processes will try to read the address value at the
-* offset 0. The value is initially NULL(0). When it changes to non-zero,
-* it signifies the writer process has written all the chain-link blocks
-* and they are ready for the reader processes to access.
-*
-* If the system, in which the writer and reader processes run, the readers
-* will always get all chain-linked blocks correctly. If the order of write
-* is not maintained, some reader processes may found unexpect block data.
-*
-*************************************************************/
+ *
+ * Algorithm
+ *
+ * The test simulates what SWMR does by writing chained blocks and see if
+ * they can be read back correctly.
+ * There is a writer process and multiple read processes.
+ * The file is divided into 2KB partitions. Then writer writes 1 chained
+ * block, each of 1KB big, in each partition after the first partition.
+ * Each chained block has this structure:
+ * Byte 0-3: offset address of its child block. The last child uses 0 as NULL.
+ * Byte 4-1023: some artificial data.
+ * The child block address of Block 1 is NULL (0).
+ * The child block address of Block 2 is the offset address of Block 1.
+ * The child block address of Block n is the offset address of Block n-1.
+ * After all n blocks are written, the offset address of Block n is written
+ * to the offset 0 of the first partition.
+ * Therefore, by the time the offset address of Block n is written to this
+ * position, all n chain-linked blocks have been written.
+ *
+ * The other reader processes will try to read the address value at the
+ * offset 0. The value is initially NULL(0). When it changes to non-zero,
+ * it signifies the writer process has written all the chain-link blocks
+ * and they are ready for the reader processes to access.
+ *
+ * If the system, in which the writer and reader processes run, the readers
+ * will always get all chain-linked blocks correctly. If the order of write
+ * is not maintained, some reader processes may found unexpect block data.
+ *
+ *************************************************************/
#include "h5test.h"
@@ -67,34 +67,38 @@
*/
#ifdef H5_HAVE_FORK
-#define DATAFILE "twriteorder.dat"
-/* #define READERS_MAX 10 */ /* max number of readers */
-#define BLOCKSIZE_DFT 1024 /* 1KB */
-#define PARTITION_DFT 2048 /* 2KB */
-#define NLINKEDBLOCKS_DFT 512 /* default 512 */
-#define SIZE_BLKADDR 4 /* expected sizeof blkaddr */
-#define Hgoto_error(val) {ret_value=val; goto done;}
+#define DATAFILE "twriteorder.dat"
+/* #define READERS_MAX 10 */ /* max number of readers */
+#define BLOCKSIZE_DFT 1024 /* 1KB */
+#define PARTITION_DFT 2048 /* 2KB */
+#define NLINKEDBLOCKS_DFT 512 /* default 512 */
+#define SIZE_BLKADDR 4 /* expected sizeof blkaddr */
+#define Hgoto_error(val) \
+ { \
+ ret_value = val; \
+ goto done; \
+ }
/* type declarations */
typedef enum part_t {
- UC_READWRITE = 0, /* both writer and reader */
- UC_WRITER, /* writer only */
- UC_READER /* reader only */
+ UC_READWRITE = 0, /* both writer and reader */
+ UC_WRITER, /* writer only */
+ UC_READER /* reader only */
} part_t;
/* prototypes */
-int create_wo_file(void);
-int write_wo_file(void);
-int read_wo_file(void);
+int create_wo_file(void);
+int write_wo_file(void);
+int read_wo_file(void);
void usage(const char *prog);
-int setup_parameters(int argc, char * const argv[]);
-int parse_option(int argc, char * const argv[]);
+int setup_parameters(int argc, char *const argv[]);
+int parse_option(int argc, char *const argv[]);
/* Global Variable definitions */
-const char *progname_g="twriteorder"; /* program name */
-int write_fd_g;
-int blocksize_g, part_size_g, nlinkedblock_g;
-part_t launch_g;
+const char *progname_g = "twriteorder"; /* program name */
+int write_fd_g;
+int blocksize_g, part_size_g, nlinkedblock_g;
+part_t launch_g;
/* Function definitions */
@@ -116,9 +120,9 @@ usage(const char *prog)
/* Setup test parameters by parsing command line options.
* Setup default values if not set by options. */
int
-parse_option(int argc, char * const argv[])
+parse_option(int argc, char *const argv[])
{
- int ret_value=0;
+ int ret_value = 0;
int c;
/* command line options: See function usage for a description */
const char *cmd_options = "hb:l:n:p:";
@@ -127,7 +131,7 @@ parse_option(int argc, char * const argv[])
opterr = 0;
while (1) {
- c = getopt (argc, argv, cmd_options);
+ c = getopt(argc, argv, cmd_options);
if (-1 == c)
break;
@@ -136,33 +140,33 @@ parse_option(int argc, char * const argv[])
usage(progname_g);
HDexit(EXIT_SUCCESS);
break;
- case 'b': /* number of planes to write/read */
+ case 'b': /* number of planes to write/read */
if ((blocksize_g = atoi(optarg)) <= 0) {
HDfprintf(stderr, "bad blocksize %s, must be a positive integer\n", optarg);
usage(progname_g);
Hgoto_error(-1);
};
break;
- case 'n': /* number of planes to write/read */
+ case 'n': /* number of planes to write/read */
if ((nlinkedblock_g = atoi(optarg)) < 2) {
HDfprintf(stderr, "bad number of linked blocks %s, must be greater than 1.\n", optarg);
usage(progname_g);
Hgoto_error(-1);
};
break;
- case 'p': /* number of planes to write/read */
+ case 'p': /* number of planes to write/read */
if ((part_size_g = atoi(optarg)) <= 0) {
HDfprintf(stderr, "bad partition size %s, must be a positive integer\n", optarg);
usage(progname_g);
Hgoto_error(-1);
};
break;
- case 'l': /* launch reader or writer only */
+ case 'l': /* launch reader or writer only */
switch (*optarg) {
- case 'r': /* reader only */
+ case 'r': /* reader only */
launch_g = UC_READER;
break;
- case 'w': /* writer only */
+ case 'w': /* writer only */
launch_g = UC_WRITER;
break;
default:
@@ -182,11 +186,12 @@ parse_option(int argc, char * const argv[])
HDfprintf(stderr, "Unexpected value is %d\n", c);
Hgoto_error(-1);
} /* end outer switch */
- } /* end while */
+ } /* end while */
/* verify partition size must be >= blocksize */
- if (part_size_g < blocksize_g ){
- HDfprintf(stderr, "Blocksize %d should not be bigger than partition size %d\n", blocksize_g, part_size_g);
+ if (part_size_g < blocksize_g) {
+ HDfprintf(stderr, "Blocksize %d should not be bigger than partition size %d\n", blocksize_g,
+ part_size_g);
Hgoto_error(-1);
}
@@ -198,16 +203,17 @@ done:
/* Setup parameters for the test case.
* Return: 0 succeed; -1 fail.
*/
-int setup_parameters(int argc, char * const argv[])
+int
+setup_parameters(int argc, char *const argv[])
{
/* test case defaults */
- blocksize_g = BLOCKSIZE_DFT;
- part_size_g = PARTITION_DFT;
+ blocksize_g = BLOCKSIZE_DFT;
+ part_size_g = PARTITION_DFT;
nlinkedblock_g = NLINKEDBLOCKS_DFT;
- launch_g = UC_READWRITE;
+ launch_g = UC_READWRITE;
/* parse options */
- if (parse_option(argc, argv) < 0){
+ if (parse_option(argc, argv) < 0) {
return -1;
}
@@ -225,19 +231,20 @@ int setup_parameters(int argc, char * const argv[])
*
* Return: 0 succeed; -1 fail.
*/
-int create_wo_file(void)
+int
+create_wo_file(void)
{
- int blkaddr = 0; /* blkaddress of next linked block */
- h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
+ int blkaddr = 0; /* blkaddress of next linked block */
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* Create the data file */
- if ((write_fd_g = HDopen(DATAFILE, O_RDWR|O_TRUNC|O_CREAT, H5_POSIX_CREATE_MODE_RW)) < 0) {
+ if ((write_fd_g = HDopen(DATAFILE, O_RDWR | O_TRUNC | O_CREAT, H5_POSIX_CREATE_MODE_RW)) < 0) {
HDprintf("WRITER: error from open\n");
return -1;
}
blkaddr = 0;
/* write it to partition 0 */
- if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr, (size_t)SIZE_BLKADDR)) != SIZE_BLKADDR){
+ if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr, (size_t)SIZE_BLKADDR)) != SIZE_BLKADDR) {
HDprintf("blkaddr write failed\n");
return -1;
}
@@ -246,14 +253,14 @@ int create_wo_file(void)
return 0;
}
-int write_wo_file(void)
+int
+write_wo_file(void)
{
- int blkaddr;
- int blkaddr_old=0;
- int i;
- char buffer[BLOCKSIZE_DFT];
- h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
-
+ int blkaddr;
+ int blkaddr_old = 0;
+ int i;
+ char buffer[BLOCKSIZE_DFT];
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* write block 1, 2, ... */
for (i = 1; i < nlinkedblock_g; i++) {
@@ -265,14 +272,14 @@ int write_wo_file(void)
HDmemcpy(&buffer[0], &blkaddr_old, sizeof(blkaddr_old));
/* fill the rest with the lowest byte of i */
- HDmemset(&buffer[4], i & 0xff, (size_t) (BLOCKSIZE_DFT-4));
+ HDmemset(&buffer[4], i & 0xff, (size_t)(BLOCKSIZE_DFT - 4));
/* write the block */
#ifdef DEBUG
HDprintf("writing block at %d\n", blkaddr);
#endif
HDlseek(write_fd_g, (HDoff_t)blkaddr, SEEK_SET);
- if ((bytes_wrote = HDwrite(write_fd_g, buffer, (size_t)blocksize_g)) != blocksize_g){
+ if ((bytes_wrote = HDwrite(write_fd_g, buffer, (size_t)blocksize_g)) != blocksize_g) {
HDprintf("blkaddr write failed in partition %d\n", i);
return -1;
}
@@ -283,7 +290,8 @@ int write_wo_file(void)
/* write the last blkaddr in partition 0 */
HDlseek(write_fd_g, (HDoff_t)0, SEEK_SET);
- if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr_old, (size_t)sizeof(blkaddr_old))) != sizeof(blkaddr_old)){
+ if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr_old, (size_t)sizeof(blkaddr_old))) !=
+ sizeof(blkaddr_old)) {
HDprintf("blkaddr write failed in partition %d\n", 0);
return -1;
}
@@ -295,13 +303,14 @@ int write_wo_file(void)
return 0;
}
-int read_wo_file(void)
+int
+read_wo_file(void)
{
- int read_fd;
- int blkaddr = 0;
- h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */
- int linkedblocks_read = 0;
- char buffer[BLOCKSIZE_DFT];
+ int read_fd;
+ int blkaddr = 0;
+ h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */
+ int linkedblocks_read = 0;
+ char buffer[BLOCKSIZE_DFT];
/* Open the data file */
if ((read_fd = HDopen(DATAFILE, O_RDONLY)) < 0) {
@@ -325,7 +334,7 @@ int read_wo_file(void)
#endif
while (blkaddr != 0) {
HDlseek(read_fd, (HDoff_t)blkaddr, SEEK_SET);
- if ((bytes_read = HDread(read_fd, buffer, (size_t)blocksize_g)) != blocksize_g){
+ if ((bytes_read = HDread(read_fd, buffer, (size_t)blocksize_g)) != blocksize_g) {
HDprintf("blkaddr read failed in partition %d\n", 0);
return -1;
}
@@ -344,7 +353,6 @@ int read_wo_file(void)
return 0;
}
-
/* Overall Algorithm:
* Parse options from user;
* Generate/pre-created the test file needed and close it;
@@ -357,15 +365,15 @@ main(int argc, char *argv[])
{
/*pid_t childpid[READERS_MAX];
int child_ret_value[READERS_MAX];*/
- pid_t childpid=0;
- int child_ret_value;
+ pid_t childpid = 0;
+ int child_ret_value;
pid_t mypid, tmppid;
- int child_status;
- int child_wait_option=0;
- int ret_value = 0;
+ int child_status;
+ int child_wait_option = 0;
+ int ret_value = 0;
/* initialization */
- if (setup_parameters(argc, argv) < 0){
+ if (setup_parameters(argc, argv) < 0) {
Hgoto_error(1);
}
@@ -389,9 +397,9 @@ main(int argc, char *argv[])
/* flush output before possible fork */
HDfflush(stdout);
- if (launch_g==UC_READWRITE) {
+ if (launch_g == UC_READWRITE) {
/* fork process */
- if((childpid = HDfork()) < 0) {
+ if ((childpid = HDfork()) < 0) {
HDperror("fork");
Hgoto_error(1);
};
@@ -403,7 +411,7 @@ main(int argc, char *argv[])
/* ============= */
if (launch_g != UC_WRITER) {
/* child process launch the reader */
- if(0 == childpid) {
+ if (0 == childpid) {
HDprintf("%d: launch reader process\n", mypid);
if (read_wo_file() < 0) {
HDfprintf(stderr, "read_wo_file encountered error\n");
@@ -437,7 +445,7 @@ main(int argc, char *argv[])
Hgoto_error(1);
}
if (WIFEXITED(child_status)) {
- if ((child_ret_value=WEXITSTATUS(child_status)) != 0) {
+ if ((child_ret_value = WEXITSTATUS(child_status)) != 0) {
HDprintf("%d: child process exited with non-zero code (%d)\n", mypid, child_ret_value);
Hgoto_error(2);
}
@@ -450,7 +458,7 @@ main(int argc, char *argv[])
done:
/* Print result and exit */
- if (ret_value != 0){
+ if (ret_value != 0) {
HDprintf("Error(s) encountered\n");
}
else {
@@ -470,4 +478,3 @@ main(void)
} /* end main() */
#endif /* H5_HAVE_FORK */
-