From e16868dede6455cab644805af6fe1ac312775e13 Mon Sep 17 00:00:00 2001 From: Gluster Ant Date: Wed, 12 Sep 2018 17:52:45 +0530 Subject: Land part 2 of clang-format changes Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu --- tests/bugs/write-behind/bug-1058663.c | 158 ++++++++++++----------- tests/bugs/write-behind/bug-1279730.c | 232 ++++++++++++++++++---------------- 2 files changed, 206 insertions(+), 184 deletions(-) (limited to 'tests/bugs/write-behind') diff --git a/tests/bugs/write-behind/bug-1058663.c b/tests/bugs/write-behind/bug-1058663.c index 5e522e98048..aedf97d7487 100644 --- a/tests/bugs/write-behind/bug-1058663.c +++ b/tests/bugs/write-behind/bug-1058663.c @@ -19,101 +19,105 @@ static int sigbus_received; /* test for truncate()/seek()/write()/mmap() * There should ne no SIGBUS triggered. */ -void seek_write(char *filename) +void +seek_write(char *filename) { - int fd; - uint8_t *map; - int i; - - fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0600); - lseek(fd, FILE_SIZE - 1, SEEK_SET); - write(fd, "\xff", 1); - - map = mmap(NULL, FILE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0); - for (i = 0; i < (FILE_SIZE - 1); i++) { - if (map[i] != 0) /* should never be true */ - abort(); - } - munmap(map, FILE_SIZE); - - close(fd); + int fd; + uint8_t *map; + int i; + + fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600); + lseek(fd, FILE_SIZE - 1, SEEK_SET); + write(fd, "\xff", 1); + + map = mmap(NULL, FILE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0); + for (i = 0; i < (FILE_SIZE - 1); i++) { + if (map[i] != 0) /* should never be true */ + abort(); + } + munmap(map, FILE_SIZE); + + close(fd); } -int read_after_eof(char *filename) +int +read_after_eof(char *filename) { - int ret = 0; - int fd; - char *data; - uint8_t *map; - - fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0600); - lseek(fd, FILE_SIZE - 1, SEEK_SET); - write(fd, "\xff", 1); - - /* trigger verify that reading after EOF fails */ - ret = read(fd, data, FILE_SIZE / 2); - if (ret != 0) - return 1; - - /* map an area of 1 byte after FILE_SIZE */ - map = mmap(NULL, 1, PROT_READ, MAP_PRIVATE, fd, FILE_SIZE); - /* map[0] is an access after EOF, it should trigger SIGBUS */ - if (map[0] != 0) - /* it is expected that we exit before we get here */ - if (!sigbus_received) - return 1; - munmap(map, FILE_SIZE); - - close(fd); - - return ret; + int ret = 0; + int fd; + char *data; + uint8_t *map; + + fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600); + lseek(fd, FILE_SIZE - 1, SEEK_SET); + write(fd, "\xff", 1); + + /* trigger verify that reading after EOF fails */ + ret = read(fd, data, FILE_SIZE / 2); + if (ret != 0) + return 1; + + /* map an area of 1 byte after FILE_SIZE */ + map = mmap(NULL, 1, PROT_READ, MAP_PRIVATE, fd, FILE_SIZE); + /* map[0] is an access after EOF, it should trigger SIGBUS */ + if (map[0] != 0) + /* it is expected that we exit before we get here */ + if (!sigbus_received) + return 1; + munmap(map, FILE_SIZE); + + close(fd); + + return ret; } /* signal handler for SIGBUS */ -void catch_sigbus(int signum) +void +catch_sigbus(int signum) { - switch (signum) { + switch (signum) { #ifdef __NetBSD__ - /* Depending on architecture, we can get SIGSEGV */ - case SIGSEGV: /* FALLTHROUGH */ + /* Depending on architecture, we can get SIGSEGV */ + case SIGSEGV: /* FALLTHROUGH */ #endif - case SIGBUS: - sigbus_received++; - if (!expect_sigbus) - exit(EXIT_FAILURE); - if (sigbus_received >= MAX_SIGBUS) - exit(EXIT_SUCCESS); - break; - default: - printf("Unexpected signal received: %d\n", signum); - } + case SIGBUS: + sigbus_received++; + if (!expect_sigbus) + exit(EXIT_FAILURE); + if (sigbus_received >= MAX_SIGBUS) + exit(EXIT_SUCCESS); + break; + default: + printf("Unexpected signal received: %d\n", signum); + } } -int main(int argc, char **argv) +int +main(int argc, char **argv) { - int i = 0; + int i = 0; - if (argc == 1) { - printf("Usage: %s \n", argv[0]); - return EXIT_FAILURE; - } + if (argc == 1) { + printf("Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } #ifdef __NetBSD__ - /* Depending on architecture, we can get SIGSEGV */ - signal(SIGSEGV, catch_sigbus); + /* Depending on architecture, we can get SIGSEGV */ + signal(SIGSEGV, catch_sigbus); #endif - signal(SIGBUS, catch_sigbus); + signal(SIGBUS, catch_sigbus); - /* the next test should not trigger SIGBUS */ - expect_sigbus = 0; - for (i = 0; i < RUN_LOOP; i++) { - seek_write(argv[1]); - } + /* the next test should not trigger SIGBUS */ + expect_sigbus = 0; + for (i = 0; i < RUN_LOOP; i++) { + seek_write(argv[1]); + } - /* the next test should trigger SIGBUS */ - expect_sigbus = 1; - if (read_after_eof(argv[1])) - return EXIT_FAILURE; + /* the next test should trigger SIGBUS */ + expect_sigbus = 1; + if (read_after_eof(argv[1])) + return EXIT_FAILURE; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/tests/bugs/write-behind/bug-1279730.c b/tests/bugs/write-behind/bug-1279730.c index 535d289c582..706ae67b102 100644 --- a/tests/bugs/write-behind/bug-1279730.c +++ b/tests/bugs/write-behind/bug-1279730.c @@ -8,124 +8,142 @@ #include int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - int fd = -1, ret = -1, len = 0; - char *path = NULL, buf[128] = {0, }, *cmd = NULL; - struct stat stbuf = {0, }; - int write_to_child[2] = {0, }, write_to_parent[2] = {0, }; + int fd = -1, ret = -1, len = 0; + char *path = NULL, + buf[128] = + { + 0, + }, + *cmd = NULL; + struct stat stbuf = { + 0, + }; + int write_to_child[2] = + { + 0, + }, + write_to_parent[2] = { + 0, + }; + + path = argv[1]; + cmd = argv[2]; + + assert(argc == 3); + + ret = pipe(write_to_child); + if (ret < 0) { + fprintf(stderr, + "creation of write-to-child pipe failed " + "(%s)\n", + strerror(errno)); + goto out; + } + + ret = pipe(write_to_parent); + if (ret < 0) { + fprintf(stderr, + "creation of write-to-parent pipe failed " + "(%s)\n", + strerror(errno)); + goto out; + } + + ret = fork(); + switch (ret) { + case 0: + close(write_to_child[1]); + close(write_to_parent[0]); + + /* child, wait for instructions to execute command */ + ret = read(write_to_child[0], buf, 128); + if (ret < 0) { + fprintf(stderr, "child: read on pipe failed (%s)\n", + strerror(errno)); + goto out; + } - path = argv[1]; - cmd = argv[2]; + system(cmd); + + ret = write(write_to_parent[1], "1", 2); + if (ret < 0) { + fprintf(stderr, "child: write to pipe failed (%s)\n", + strerror(errno)); + goto out; + } + break; - assert (argc == 3); + case -1: + fprintf(stderr, "fork failed (%s)\n", strerror(errno)); + goto out; + + default: + close(write_to_parent[1]); + close(write_to_child[0]); - ret = pipe (write_to_child); - if (ret < 0) { - fprintf (stderr, "creation of write-to-child pipe failed " - "(%s)\n", strerror (errno)); + fd = open(path, O_CREAT | O_RDWR | O_APPEND, S_IRWXU); + if (fd < 0) { + fprintf(stderr, "open failed (%s)\n", strerror(errno)); goto out; - } + } + + len = strlen("test-content") + 1; + ret = write(fd, "test-content", len); + + if (ret < len) { + fprintf(stderr, "write failed %d (%s)\n", ret, strerror(errno)); + } + + ret = pread(fd, buf, 128, 0); + if ((ret == len) && (strcmp(buf, "test-content") == 0)) { + fprintf(stderr, + "read should've failed as previous " + "write would've failed with EDQUOT, but its " + "successful"); + ret = -1; + goto out; + } - ret = pipe (write_to_parent); - if (ret < 0) { - fprintf (stderr, "creation of write-to-parent pipe failed " - "(%s)\n", strerror (errno)); + ret = write(write_to_child[1], "1", 2); + if (ret < 0) { + fprintf(stderr, "parent: write to pipe failed (%s)\n", + strerror(errno)); goto out; - } + } - ret = fork (); - switch (ret) { - case 0: - close (write_to_child[1]); - close (write_to_parent[0]); - - /* child, wait for instructions to execute command */ - ret = read (write_to_child[0], buf, 128); - if (ret < 0) { - fprintf (stderr, "child: read on pipe failed (%s)\n", - strerror (errno)); - goto out; - } - - system (cmd); - - ret = write (write_to_parent[1], "1", 2); - if (ret < 0) { - fprintf (stderr, "child: write to pipe failed (%s)\n", - strerror (errno)); - goto out; - } - break; + ret = read(write_to_parent[0], buf, 128); + if (ret < 0) { + fprintf(stderr, "parent: read from pipe failed (%s)\n", + strerror(errno)); + goto out; + } + + /* this will force a sync on cached-write and now that quota + limit is increased, sync will be successful. ignore return + value as fstat would fail with EDQUOT (picked up from + cached-write because of previous sync failure. + */ + fstat(fd, &stbuf); + + ret = pread(fd, buf, 128, 0); + if (ret != len) { + fprintf(stderr, + "post cmd read failed %d (data:%s) " + "(error:%s)\n", + ret, buf, strerror(errno)); + goto out; + } - case -1: - fprintf (stderr, "fork failed (%s)\n", strerror (errno)); + if (strcmp(buf, "test-content")) { + fprintf(stderr, "wrong data (%s)\n", buf); goto out; + } + } - default: - close (write_to_parent[1]); - close (write_to_child[0]); - - fd = open (path, O_CREAT | O_RDWR | O_APPEND, S_IRWXU); - if (fd < 0) { - fprintf (stderr, "open failed (%s)\n", - strerror (errno)); - goto out; - } - - len = strlen ("test-content") + 1; - ret = write (fd, "test-content", len); - - if (ret < len) { - fprintf (stderr, "write failed %d (%s)\n", ret, - strerror (errno)); - } - - ret = pread (fd, buf, 128, 0); - if ((ret == len) && (strcmp (buf, "test-content") == 0)) { - fprintf (stderr, "read should've failed as previous " - "write would've failed with EDQUOT, but its " - "successful"); - ret = -1; - goto out; - } - - ret = write (write_to_child[1], "1", 2); - if (ret < 0) { - fprintf (stderr, "parent: write to pipe failed (%s)\n", - strerror (errno)); - goto out; - } - - ret = read (write_to_parent[0], buf, 128); - if (ret < 0) { - fprintf (stderr, "parent: read from pipe failed (%s)\n", - strerror (errno)); - goto out; - } - - /* this will force a sync on cached-write and now that quota - limit is increased, sync will be successful. ignore return - value as fstat would fail with EDQUOT (picked up from - cached-write because of previous sync failure. - */ - fstat (fd, &stbuf); - - ret = pread (fd, buf, 128, 0); - if (ret != len) { - fprintf (stderr, "post cmd read failed %d (data:%s) " - "(error:%s)\n", ret, buf, strerror (errno)); - goto out; - } - - if (strcmp (buf, "test-content")) { - fprintf (stderr, "wrong data (%s)\n", buf); - goto out; - } - } - - ret = 0; + ret = 0; out: - return ret; + return ret; } -- cgit