test: Add test programs for #1242
Change-Id: Ib3b5d5b661e0cd027711a815d9da2e308cedeffc Refs: #1242
This commit is contained in:
committed by
Dominique Martinet
parent
9f7425c152
commit
d29419d336
6
test/issues/1242/Makefile
Normal file
6
test/issues/1242/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
# Makefile COPYRIGHT FUJITSU LIMITED 2018
|
||||
target:
|
||||
gcc -O0 -g main.c -o a.out
|
||||
|
||||
clean:
|
||||
rm -f a.out
|
||||
20
test/issues/1242/README
Normal file
20
test/issues/1242/README
Normal file
@ -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
|
||||
54
test/issues/1242/main.c
Normal file
54
test/issues/1242/main.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* main.c COPYRIGHT FUJITSU LIMITED 2018 */
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user