diff --git a/test/issues/1242/Makefile b/test/issues/1242/Makefile new file mode 100644 index 00000000..58d66575 --- /dev/null +++ b/test/issues/1242/Makefile @@ -0,0 +1,6 @@ +# Makefile COPYRIGHT FUJITSU LIMITED 2018 +target: + gcc -O0 -g main.c -o a.out + +clean: + rm -f a.out diff --git a/test/issues/1242/README b/test/issues/1242/README new file mode 100644 index 00000000..010d34f1 --- /dev/null +++ b/test/issues/1242/README @@ -0,0 +1,20 @@ +========== +How to run +========== + +make +mcexec ./a.out + +================== +How to judge OK/NG +================== + +OK when: +1. No error in stdout +2. No error in kmsg (ihkosctl 0 kmsg) + +============== +What is tested +============== + +The behavior of madvise(..., MADV_REMOVE) on shmget memory \ No newline at end of file diff --git a/test/issues/1242/main.c b/test/issues/1242/main.c new file mode 100644 index 00000000..b122a7df --- /dev/null +++ b/test/issues/1242/main.c @@ -0,0 +1,54 @@ +/* main.c COPYRIGHT FUJITSU LIMITED 2018 */ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int ret; + int shmid = -1; + char *shm_addr = (void *)-1; + size_t shm_length; + const size_t pgsize = sysconf(_SC_PAGESIZE); + + printf("call shmget.\n"); + shm_length = pgsize; + shmid = shmget(IPC_PRIVATE, shm_length, IPC_CREAT | SHM_R | SHM_W); + if (shmid == -1) { + perror("shmget error."); + ret = EXIT_FAILURE; + goto out; + } + + printf("call shmat.\n"); + shm_addr = shmat(shmid, NULL, 0); + if (shm_addr == (void *)-1) { + perror("shmat error."); + ret = EXIT_FAILURE; + goto out; + } + memset(shm_addr, '0', shm_length); + + printf("call madvise.\n"); + ret = madvise(shm_addr, shm_length, MADV_REMOVE); + if (ret == -1) { + perror("madvise error."); + ret = EXIT_FAILURE; + goto out; + } + + ret = EXIT_SUCCESS; + printf("success.\n"); +out: + if (shm_addr != (void *)-1) { + shmdt(shm_addr); + } + + if (shmid != -1) { + shmctl(shmid, IPC_RMID, 0); + } + return ret; +}