diff options
author | Niels de Vos <ndevos@redhat.com> | 2014-12-26 12:57:48 +0100 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2015-01-06 03:24:24 -0800 |
commit | 64954eb3c58f4ef077e54e8a3726fd2d27419b12 (patch) | |
tree | 52cd5a39bbfda7442a5f0955ac2800b74a45b58a /tests/bugs/write-behind | |
parent | c4ab37c02e9edc23d0637e23d6f2b42d0827dad2 (diff) |
tests: move all test-cases into component subdirectories
There are around 300 regression tests, 250 being in tests/bugs. Running
partial set of tests/bugs is not easy because this is a flat directory
with almost all tests inside.
It would be valuable to make partial test/bugs easier, and allow the use
of mulitple build hosts for a single commit, each running a subset of
the tests for a quicker result.
Additional changes made:
- correct the include path for *.rc shell libraries and *.py utils
- make the testcases pass checkpatch
- arequal-checksum in afr/self-heal.t was never executed, now it is
- include.rc now complains loudly if it fails to find env.rc
Change-Id: I26ffd067e9853d3be1fd63b2f37d8aa0fd1b4fea
BUG: 1178685
Reported-by: Emmanuel Dreyfus <manu@netbsd.org>
Reported-by: Atin Mukherjee <amukherj@redhat.com>
URL: http://www.gluster.org/pipermail/gluster-devel/2014-December/043414.html
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/9353
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Emmanuel Dreyfus <manu@netbsd.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'tests/bugs/write-behind')
-rw-r--r-- | tests/bugs/write-behind/bug-1058663.c | 119 | ||||
-rw-r--r-- | tests/bugs/write-behind/bug-1058663.t | 28 |
2 files changed, 147 insertions, 0 deletions
diff --git a/tests/bugs/write-behind/bug-1058663.c b/tests/bugs/write-behind/bug-1058663.c new file mode 100644 index 00000000000..5e522e98048 --- /dev/null +++ b/tests/bugs/write-behind/bug-1058663.c @@ -0,0 +1,119 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <signal.h> + +#define FILE_SIZE 1048576 + +/* number of tests to run */ +#define RUN_LOOP 1000 + +/* number of SIGBUS before exiting */ +#define MAX_SIGBUS 1 +static int expect_sigbus; +static int sigbus_received; + +/* test for truncate()/seek()/write()/mmap() + * There should ne no SIGBUS triggered. + */ +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 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; +} + +/* signal handler for SIGBUS */ +void catch_sigbus(int signum) +{ + switch (signum) { +#ifdef __NetBSD__ + /* 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); + } +} + +int main(int argc, char **argv) +{ + int i = 0; + + if (argc == 1) { + printf("Usage: %s <filename>\n", argv[0]); + return EXIT_FAILURE; + } + +#ifdef __NetBSD__ + /* Depending on architecture, we can get SIGSEGV */ + signal(SIGSEGV, catch_sigbus); +#endif + 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 trigger SIGBUS */ + expect_sigbus = 1; + if (read_after_eof(argv[1])) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/tests/bugs/write-behind/bug-1058663.t b/tests/bugs/write-behind/bug-1058663.t new file mode 100644 index 00000000000..a900a6d7afa --- /dev/null +++ b/tests/bugs/write-behind/bug-1058663.t @@ -0,0 +1,28 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup; + +## Start and create a volume +TEST glusterd; +TEST pidof glusterd; +TEST $CLI volume info; + +TEST $CLI volume create $V0 $H0:$B0/$V0; +TEST $CLI volume start $V0; + +TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0 + +# compile the test program and run it +TEST $CC $(dirname $0)/bug-1058663.c -o $(dirname $0)/bug-1058663; +TEST $(dirname $0)/bug-1058663 $M0/bug-1058663.bin; +TEST rm -f $(dirname $0)/M0/bug-1058663.bin; + +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0 + +TEST $CLI volume stop $V0; +TEST $CLI volume delete $V0; + +cleanup; |