add test for portability (kahansei_kojo in dev_V)
This commit is contained in:
16
test/portability/Makefile
Normal file
16
test/portability/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
CC=gcc
|
||||
MCEXEC=/home/satoken/ppos/bin/mcexec
|
||||
TARGET=futex_wake_op unhandled_page_fault
|
||||
all:: $(TARGET)
|
||||
|
||||
futex_wake_op: futex_wake_op.c
|
||||
$(CC) -o futex_wake_op -pthread $<
|
||||
|
||||
unhandled_page_fualt: unhandled_page_fault.c
|
||||
$(CC) -o unhandled_page_fault $<
|
||||
|
||||
test:: $(TARGET)
|
||||
-$(MCEXEC) ./futex_wake_op
|
||||
-$(MCEXEC) ./unhandled_page_fault
|
||||
clean::
|
||||
rm -f $(TARGET)
|
||||
6
test/portability/README
Normal file
6
test/portability/README
Normal file
@ -0,0 +1,6 @@
|
||||
# 本テストは、McKernel 基本機構の開発 V の
|
||||
# 作業項目(4) カーネルのアーキテクチャに渡る可搬性向上 に関するテストである
|
||||
|
||||
# 実行方法
|
||||
$ make test
|
||||
|
||||
48
test/portability/futex_wake_op.c
Normal file
48
test/portability/futex_wake_op.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <linux/futex.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int uaddr1 = 0;
|
||||
int uaddr2 = 0;
|
||||
|
||||
pid_t gettid()
|
||||
{
|
||||
return syscall(SYS_gettid);
|
||||
}
|
||||
|
||||
static void * waker (void *ptr)
|
||||
{
|
||||
int rc;
|
||||
sleep(1);
|
||||
|
||||
rc = syscall(SYS_futex, &uaddr1, FUTEX_WAKE_OP, 1, NULL, &uaddr2, FUTEX_OP(0, 0, 1, 0));
|
||||
|
||||
printf("futex_wake_op return:%d\n", rc);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int rc;
|
||||
pthread_t thr;
|
||||
|
||||
pthread_create(&thr, NULL, waker, NULL);
|
||||
|
||||
rc = syscall(SYS_futex, &uaddr1, FUTEX_WAIT, uaddr1, NULL, NULL, 0);
|
||||
|
||||
printf("futex_wait return:%d\n", rc);
|
||||
|
||||
pthread_join(thr, NULL);
|
||||
|
||||
printf("[OK] futex_wake_op_01 : succeed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
test/portability/unhandled_page_fault.c
Normal file
21
test/portability/unhandled_page_fault.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define ARRAY_SIZE 10
|
||||
|
||||
void handler(int sig) {
|
||||
printf("[OK] unhandled_page_fault_01: received SIGSEGV\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int* test = NULL;
|
||||
|
||||
signal(SIGSEGV, handler);
|
||||
printf("try to access out of range!\n");
|
||||
*test = 99;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user