fix & add: testcases for refs #885, refs #1031

This commit is contained in:
Ken Sato
2018-03-01 15:41:58 +09:00
parent afcf1a24aa
commit 3432f46d8b
15 changed files with 320 additions and 42 deletions

View File

@ -24,7 +24,7 @@ int main(int argc, char** argv)
} }
OKNG(tmp_flag != 1, "check SIGKILL act"); OKNG(tmp_flag != 1, "check SIGKILL act");
rc = sigaction(SIGKILL, NULL, &old_act); rc = sigaction(SIGSTOP, NULL, &old_act);
OKNG(rc != 0, "sigaction to get SIGSTOP action"); OKNG(rc != 0, "sigaction to get SIGSTOP action");
tmp_flag = 0; tmp_flag = 0;

View File

@ -63,29 +63,29 @@ CT_005: 複数回(非上書き)のSIG_RESETHAND 指定時の動作
CT_006: 設定中のハンドラ情報の取得 (上書き時) CT_006: 設定中のハンドラ情報の取得 (上書き時)
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定 1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. sigaction(SIGUSR1, NULL, &act) で設定情報を取得 2. sigaction(SIGUSR1, NULL, &act) で設定情報を取得できる
3. SIG_RESETHANDを指定しないsigaction()でSIG_USR1にデフォルトハンドラを設定 3. SIG_RESETHANDを指定しないsigaction()でSIG_USR1にデフォルトハンドラを設定
4. sigaction(SIGUSR1, NULL, &act) で設定情報を取得 4. sigaction(SIGUSR1, NULL, &act) で3.で指定した設定情報を取得できる
CT_007: 設定中のハンドラ情報の取得 (デフォルトに戻った時) CT_007: 設定中のハンドラ情報の取得 (デフォルトに戻った時)
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定 1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. 自身にSIGUSR1を送る 2. 自身にSIGUSR1を送る
3. 1.で登録したハンドラが呼び出される 3. 1.で登録したハンドラが呼び出される
4. sigaction(SIGUSR1, NULL, &act) で設定情報を取得 4. sigaction(SIGUSR1, NULL, &act) で設定情報を取得できる
CT_008: 不正なsig_numへのハンドラ登録 CT_008: 不正なsig_numへのハンドラ登録
1. 範囲外(上限、下限)のsignumへのハンドラ登録 1. 範囲外(上限、下限)のsignumへのハンドラ登録が失敗する
2. SIGKILL, SIGSTOPへのハンドラ登録 2. SIGKILL, SIGSTOPへのハンドラ登録が失敗する
CT_009: SIGKILL, SIGSTOPのハンドラ情報の取得 CT_009: SIGKILL, SIGSTOPのハンドラ情報の取得
1. sigaction(SIGKILL, NULL, &act) で設定情報を取得 1. sigaction(SIGKILL, NULL, &act) で設定情報を取得できる
2. sigaction(SIGSTOP, NULL, &act) で設定情報を取得 2. sigaction(SIGSTOP, NULL, &act) で設定情報を取得できる
CT_010: sig_numの有効確認 CT_010: sig_numの有効確認
1. sigaction(SIGUSR1, NULL, NULL) で有効かどうかを確認 1. sigaction(SIGUSR1, NULL, NULL) が成功する(有効)
2. sigaction(SIGKILL, NULL, NULL) で有効かどうかを確認 2. sigaction(SIGKILL, NULL, NULL) が成功する(有効)
3. sigaction(SIGSTOP, NULL, NULL) で有効かどうかを確認 3. sigaction(SIGSTOP, NULL, NULL) が成功する(有効)
4. sigaction(_NSIG, NULL, NULL) で有効かどうかを確認 4. sigaction(_NSIG, NULL, NULL) が失敗する(無効)
3. 結果 3. 結果
テストプログラムの実行結果をresult.log に示す。 テストプログラムの実行結果をresult.log に示す。

View File

@ -65,6 +65,12 @@ int main(int argc, char** argv)
/* detach child */ /* detach child */
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL); rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
OKNG(rc != 0, "ptrace_detach"); OKNG(rc != 0, "ptrace_detach");
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -65,6 +65,12 @@ int main(int argc, char** argv)
/* continue child */ /* continue child */
rc = ptrace(PTRACE_CONT, pid, NULL, NULL); rc = ptrace(PTRACE_CONT, pid, NULL, NULL);
OKNG(rc != 0, "ptrace_cont"); OKNG(rc != 0, "ptrace_cont");
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -91,18 +91,6 @@ int main(int argc, char** argv)
rc = waitpid(pid, &status, 0); rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid"); CHKANDJUMP(rc == -1, "waitpid");
if (WIFEXITED(status)) {
printf("exited:%d\n", WEXITSTATUS(status));
}
if (WIFSIGNALED(status)) {
printf("signaled\n");
}
if (WIFCONTINUED(status)) {
printf("continued\n");
}
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped again"); CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped again");
/* detach child */ /* detach child */
@ -111,6 +99,12 @@ printf("continued\n");
/* wake child */ /* wake child */
sem_post(cwait); sem_post(cwait);
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -64,6 +64,11 @@ int main(int argc, char** argv)
/* wake child */ /* wake child */
sem_post(cwait); sem_post(cwait);
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -69,6 +69,12 @@ int main(int argc, char** argv)
/* detach child */ /* detach child */
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL); rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
OKNG(rc != 0, "ptrace_detach"); OKNG(rc != 0, "ptrace_detach");
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -57,6 +57,12 @@ int main(int argc, char** argv)
/* wake child */ /* wake child */
sem_post(cwait); sem_post(cwait);
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -68,6 +68,12 @@ int main(int argc, char** argv)
/* wake child */ /* wake child */
sem_post(cwait); sem_post(cwait);
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -75,6 +75,12 @@ int main(int argc, char** argv)
/* wake child */ /* wake child */
sem_post(cwait); sem_post(cwait);
/* wait child's exit */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child is not exited");
} }
printf("*** %s PASSED\n\n", TEST_NAME); printf("*** %s PASSED\n\n", TEST_NAME);

View File

@ -0,0 +1,100 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <semaphore.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include "./test_chk.h"
#define TEST_NAME "CT_010"
int main(int argc, char** argv)
{
pid_t tracer_pid = 0, tracee_pid =0;
sem_t *pwait = NULL;
sem_t *tracer_wait = NULL;
sem_t *tracee_wait = NULL;
void *mem, *attach;
int rc = 0;
int status;
printf("*** %s start *******************************\n", TEST_NAME);
pwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
tracer_wait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
tracee_wait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
CHKANDJUMP(!pwait || !tracer_wait || !tracee_wait, "mmap for sem");
rc |= sem_init(pwait, 1, 0);
rc |= sem_init(tracer_wait, 1, 0);
rc |= sem_init(tracee_wait, 1, 0);
CHKANDJUMP(rc, "sem_init");
tracee_pid = fork();
CHKANDJUMP(tracee_pid == -1, "fork tracee");
if (tracee_pid == 0) { /* tracee */
/* wake tracer*/
sem_post(tracer_wait);
/* wait */
sem_wait(tracee_wait);
_exit(123);
} else { /* parent */
tracer_pid = fork();
CHKANDJUMP(tracer_pid == -1, "fork tracer");
if (tracer_pid == 0) { /* tracer */
/* wait */
sem_wait(tracer_wait);
/* attach tracee */
rc = ptrace(PTRACE_ATTACH, tracee_pid, NULL, NULL);
OKNG(rc != 0, "ptrace_attach by tracer");
/* wake tracee */
sem_post(tracee_wait);
/* wait tracee stop */
rc = waitpid(tracee_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFSTOPPED(status), "tracee is not stopped");
/* detach tracee */
rc = ptrace(PTRACE_DETACH, tracee_pid, NULL, NULL);
OKNG(rc != 0, "ptrace_detach by tracer");
/* wait after detach (failed)*/
rc = waitpid(tracee_pid, &status, 0);
OKNG(rc != -1, "waitpid by tracer after detach (failed)");
_exit(234);
} else { /* parent */
rc = waitpid(tracee_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
OKNG(!WIFEXITED(status), "waitpid for tracee by parent");
rc = waitpid(tracer_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child(tracer) is not exited");
}
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

View File

@ -0,0 +1,102 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <semaphore.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include "./test_chk.h"
#define TEST_NAME "CT_011"
int main(int argc, char** argv)
{
pid_t tracer_pid = 0, tracee_pid =0;
sem_t *pwait = NULL;
sem_t *tracer_wait = NULL;
sem_t *tracee_wait = NULL;
void *mem, *attach;
int rc = 0;
int status;
printf("*** %s start *******************************\n", TEST_NAME);
pwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
tracer_wait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
tracee_wait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
CHKANDJUMP(!pwait || !tracer_wait || !tracee_wait, "mmap for sem");
rc |= sem_init(pwait, 1, 0);
rc |= sem_init(tracer_wait, 1, 0);
rc |= sem_init(tracee_wait, 1, 0);
CHKANDJUMP(rc, "sem_init");
tracee_pid = fork();
CHKANDJUMP(tracee_pid == -1, "fork tracee");
if (tracee_pid == 0) { /* tracee */
/* wake tracer*/
sem_post(tracer_wait);
/* wait */
sem_wait(tracee_wait);
_exit(123);
} else { /* parent */
tracer_pid = fork();
CHKANDJUMP(tracer_pid == -1, "fork tracer");
if (tracer_pid == 0) { /* tracer */
/* wait */
sem_wait(tracer_wait);
/* attach tracee */
rc = ptrace(PTRACE_ATTACH, tracee_pid, NULL, NULL);
OKNG(rc != 0, "ptrace_attach");
/* wake tracee */
sem_post(tracee_wait);
/* wait tracee stop */
rc = waitpid(tracee_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFSTOPPED(status), "tracee is not stopped");
/* continue child */
rc = ptrace(PTRACE_CONT, tracee_pid, NULL, NULL);
OKNG(rc != 0, "ptrace_cont");
/* wait tracee's exit */
rc = waitpid(tracee_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
OKNG(!WIFEXITED(status), "waitpid for tracee by tracer without detach");
_exit(234);
} else { /* parent */
rc = waitpid(tracee_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
OKNG(!WIFEXITED(status), "waitpid for tracee by parent");
rc = waitpid(tracer_pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
CHKANDJUMP(!WIFEXITED(status), "child(tracer) is not exited");
}
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

View File

@ -2,7 +2,7 @@ CC = gcc
MCK_DIR=/home/satoken/ppos MCK_DIR=/home/satoken/ppos
MCEXEC=$(MCK_DIR)/bin/mcexec MCEXEC=$(MCK_DIR)/bin/mcexec
TARGET=CT_001 CT_002 CT_003 CT_004 CT_005 CT_006 CT_007 CT_008 CT_009 TARGET=CT_001 CT_002 CT_003 CT_004 CT_005 CT_006 CT_007 CT_008 CT_009 CT_010 CT_011
CPPFLAGS = CPPFLAGS =
LDFLAGS = -pthread LDFLAGS = -pthread
@ -36,6 +36,12 @@ CT_008: CT_008.c
CT_009: CT_009.c CT_009: CT_009.c
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
CT_010: CT_010.c
$(CC) -o $@ $^ $(LDFLAGS)
CT_011: CT_011.c
$(CC) -o $@ $^ $(LDFLAGS)
test: all test: all
$(MCEXEC) ./CT_001 $(MCEXEC) ./CT_001
$(MCEXEC) ./CT_002 $(MCEXEC) ./CT_002
@ -47,6 +53,8 @@ test: all
$(MCEXEC) ./CT_007 $(MCEXEC) ./CT_007
$(MCEXEC) ./CT_008 $(MCEXEC) ./CT_008
$(MCEXEC) ./CT_009 $(MCEXEC) ./CT_009
$(MCEXEC) ./CT_010
$(MCEXEC) ./CT_011
clean: clean:
rm -f $(TARGET) *.o rm -f $(TARGET) *.o

View File

@ -21,43 +21,62 @@ McKernelでのptraceのattach/detach操作の基本動作確認9項目
2. テスト項目 2. テスト項目
CT_001: 通常のattach detach 操作 CT_001: 通常のattach detach 操作
1. 親プロセスが子プロセスにattach 1. 親プロセスが子プロセスにattach
2. 親プロセスが子プロセスをdetach 2. 親プロセスがwait()で子プロセスの停止を回収
3. プロセスが終了 3. プロセスが子プロセスをdetach
4. 親プロセスがwait()で子プロセス終了を回収 4. 子プロセス終了
5. 親プロセスがwait()で子プロセスの終了を回収
CT_002: tracee(子プロセス)がdetachせずに終了 CT_002: tracee(子プロセス)がdetachせずに終了
1. 親プロセスが子プロセスにattach 1. 親プロセスが子プロセスにattach
2. プロセスが終了 2. プロセスがwait()で子プロセスの停止を回収
3. 親プロセスがwait()で子プロセスの終了を回収 3. 親プロセスが子プロセスに再開指示(ptrace_cont)
4. 子プロセスが終了
5. 親プロセスがwait()で子プロセスの終了を回収
CT_003: tracer(親プロセス)がdetachしないまま先に終了 CT_003: tracer(親プロセス)がdetachしないまま先に終了
1. 親プロセスが子プロセスにattach 1. 親プロセスが子プロセスにattach
2. 親プロセスが子プロセスに再開指示した直後に終了 2. 親プロセスがwait()で子プロセスの停止を回収
3. 子プロセスが終了 3. 親プロセスが子プロセスに再開指示した直後に終了
4. 子プロセスが終了
CT_004: 複数回のattach -> detach 操作 CT_004: 複数回のattach -> detach 操作
1. 親プロセスが子プロセスにattach 1. 親プロセスが子プロセスにattach
2. 親プロセスが子プロセスにdetach 2. 親プロセスがwait()で子プロセスの停止を回収
3. 再び、親プロセスが子プロセスにattach 3. 親プロセスが子プロセスにdetach
4. 親プロセスが子プロセスにdetach 4. 再び、親プロセスが子プロセスにattach
5. 親プロセスがwait()で子プロセスの停止を回収
6. 親プロセスが子プロセスにdetach
7. 親プロセスがwait()で子プロセスの終了を回収
CT_005: 不正なpid指定のattach CT_005: 不正なpid指定のattach
1. 不正なpid(0, 1, 負数)を指定したattach 1. 不正なpid(0, 1, 負数)を指定したattachが失敗
2. 自身のpidを指定したattach 2. 自身のpidを指定したattachが失敗
CT_006: attach済の子プロセスへのattach① CT_006: attach済の子プロセスへのattach①
1. 既にattachしている子プロセスへ再びattach 1. 既にattachしている子プロセスへ再びattachが失敗
CT_007: attach済の子プロセスへのattach② CT_007: attach済の子プロセスへのattach②
1. tracemeした子プロセスへattach 1. tracemeした子プロセスへattachが失敗
CT_008: 不正なpid指定のdetach CT_008: 不正なpid指定のdetach
1. 不正なpid(0, 1, 負数)を指定したdetach 1. 不正なpid(0, 1, 負数)を指定したdetachが失敗
2. attachしていない子プロセスのpidを指定したdetach 2. attachしていない子プロセスのpidを指定したdetachが失敗
3. 自身のpidを指定したattachが失敗
CT_009: detach済の子プロセスへのdetach CT_009: detach済の子プロセスへのdetach
1. 既にdetachしていいる子プロセスへ再びdetach 1. 既にdetachしていいる子プロセスへ再びdetach
CT_010: 親子関係ではないプロセス間でのattach
1. 親プロセスが2つの子プロセス(tracerプロセス, traceeプロセスとする)をforkする
2. tracerプロセスがtraceeプロセスをattach
3. tracerプロセスがwait()でtraceeプロセスの停止を回収
4. tracerプロセスがtraceeプロセスに再開を指示
5. traceeプロセスが終了する
6. tracerプロセスがtraceeプロセスにdetach
7. tracerプロセスがwait()でtraceeプロセスの終了を回収
8. tracerプロセスが終了
9. 親プロセスがwait()でtracee,tracerプロセスの終了を回収
3. 結果 3. 結果
テストプログラムの実行結果をresult.log に示す。 テストプログラムの実行結果をresult.log に示す。
上記の10項目がPASSしていることを確認した。 上記の11項目がPASSしていることを確認した。

View File

@ -75,4 +75,18 @@ RESULT: ok
[OK] ptrace_detach faild [double detach] [OK] ptrace_detach faild [double detach]
*** CT_009 PASSED *** CT_009 PASSED
/home/satoken/ppos/bin/mcexec ./CT_010
*** CT_010 start *******************************
[OK] ptrace_attach by tracer
[OK] ptrace_detach by tracer
[OK] waitpid by tracer after detach (failed)
[OK] waitpid for tracee by parent
*** CT_010 PASSED
/home/satoken/ppos/bin/mcexec ./CT_011
*** CT_011 start *******************************
[OK] ptrace_attach
[OK] ptrace_cont
[OK] waitpid for tracee by tracer without detach
[OK] waitpid for tracee by parent
*** CT_011 PASSED