Test "ptrace: support for attaching child_process to parent" on arm64
Change-Id: I752542b6bfbf023d22e91f909518660afbff813c Refs: #885
This commit is contained in:
committed by
Masamichi Takagi
parent
cf113d392a
commit
f240671fc8
48
test/mng_mod/issues/885/arm64/Makefile
Normal file
48
test/mng_mod/issues/885/arm64/Makefile
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
## Makefile COPYRIGHT FUJITSU LIMITED 2018 ##
|
||||||
|
CC = gcc
|
||||||
|
TARGET=CT_001 CT_002 CT_003 CT_004 CT_005 CT_006 CT_007 CT_008 CT_009 CT_010 CT_011
|
||||||
|
|
||||||
|
CPPFLAGS =
|
||||||
|
LDFLAGS = -pthread
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
CT_001: CT_001.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_002: CT_002.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_003: CT_003.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_004: CT_004.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_005: CT_005.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_006: CT_006.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_007: CT_007.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_008: CT_008.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_009: CT_009.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_010: CT_010.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
CT_011: CT_011.c
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
test: all
|
||||||
|
./run.sh
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(TARGET) *.o
|
||||||
|
|
||||||
96
test/mng_mod/issues/885/arm64/README
Normal file
96
test/mng_mod/issues/885/arm64/README
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/* README COPYRIGHT FUJITSU LIMITED 2018 */
|
||||||
|
|
||||||
|
ptraceのトレース対象がdetachされずに終了を試みた場合の終了
|
||||||
|
および終了報告機能テストセットREADME
|
||||||
|
|
||||||
|
(1) テストの実行方法
|
||||||
|
以下の手順でテストを実行する
|
||||||
|
1. $HOME/.mck_test_configを用意する
|
||||||
|
当該ファイルは、McKernelをビルドした際に生成されるmck_test_config.sample ファイルを
|
||||||
|
$HOMEにコピーし、適宜編集する
|
||||||
|
2. make test を実行する
|
||||||
|
|
||||||
|
(2) テスト項目詳細
|
||||||
|
1. Issueで報告されたテストプログラムによる確認
|
||||||
|
ISSUE01,02(test_mck ptrace #19,#20) traceeがtracerからdetachされないまま終了しても問題がないこと。
|
||||||
|
⇒ 実行結果表示として、RESULT: ok が表示されればOK
|
||||||
|
|
||||||
|
2.McKernelでのptraceのattach/detachの基本動作確認
|
||||||
|
CT_001: 通常のattach detach 操作
|
||||||
|
1. 親プロセスが子プロセスにattach
|
||||||
|
2. 親プロセスがwait()で子プロセスの停止を回収
|
||||||
|
3. 親プロセスが子プロセスをdetach
|
||||||
|
4. 子プロセスが終了
|
||||||
|
5. 親プロセスがwait()で子プロセスの終了を回収
|
||||||
|
|
||||||
|
CT_002: tracee(子プロセス)がdetachせずに終了
|
||||||
|
1. 親プロセスが子プロセスにattach
|
||||||
|
2. 親プロセスがwait()で子プロセスの停止を回収
|
||||||
|
3. 親プロセスが子プロセスに再開指示(ptrace_cont)
|
||||||
|
4. 子プロセスが終了
|
||||||
|
5. 親プロセスがwait()で子プロセスの終了を回収
|
||||||
|
|
||||||
|
CT_003: tracer(親プロセス)がdetachしないまま先に終了
|
||||||
|
1. 親プロセスが子プロセスにattach
|
||||||
|
2. 親プロセスがwait()で子プロセスの停止を回収
|
||||||
|
3. 親プロセスが子プロセスに再開指示した直後に終了
|
||||||
|
4. 子プロセスが終了
|
||||||
|
|
||||||
|
CT_004: 複数回のattach -> detach 操作
|
||||||
|
1. 親プロセスが子プロセスにattach
|
||||||
|
2. 親プロセスがwait()で子プロセスの停止を回収
|
||||||
|
3. 親プロセスが子プロセスにdetach
|
||||||
|
4. 再び、親プロセスが子プロセスにattach
|
||||||
|
5. 親プロセスがwait()で子プロセスの停止を回収
|
||||||
|
6. 親プロセスが子プロセスにdetach
|
||||||
|
7. 親プロセスがwait()で子プロセスの終了を回収
|
||||||
|
|
||||||
|
CT_005: 不正なpid指定のattach
|
||||||
|
1. 不正なpid(0, 1, 負数)を指定したattachが失敗
|
||||||
|
2. 自身のpidを指定したattachが失敗
|
||||||
|
|
||||||
|
CT_006: attach済の子プロセスへのattach①
|
||||||
|
1. 既にattachしている子プロセスへ再びattachが失敗
|
||||||
|
|
||||||
|
CT_007: attach済の子プロセスへのattach②
|
||||||
|
1. tracemeした子プロセスへattachが失敗
|
||||||
|
|
||||||
|
CT_008: 不正なpid指定のdetach
|
||||||
|
1. 不正なpid(0, 1, 負数)を指定したdetachが失敗
|
||||||
|
2. attachしていない子プロセスのpidを指定したdetachが失敗
|
||||||
|
3. 自身のpidを指定したattachが失敗
|
||||||
|
|
||||||
|
CT_009: 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) 実行結果ログ
|
||||||
|
result.logファイル内に実行時のログを記載する。
|
||||||
|
実行に利用したIHK/McKernelは、IA版における下記の版数相当の
|
||||||
|
arm64版移植IHK/McKernelである。
|
||||||
|
|
||||||
|
IHK
|
||||||
|
commit d6fcbee8cb91f9ec4b49f97c918e696ac0335aaf
|
||||||
|
Author: Shiratori, Takehiro <fj0300es@aa.jp.fujitsu.com>
|
||||||
|
Date: Tue Oct 16 16:25:33 2018 +0900
|
||||||
|
|
||||||
|
McKernel
|
||||||
|
commit 6f9fef2b13447c74c36d15cf5ebd186f8395ccca
|
||||||
|
Author: Ken Sato <ken.sato.ty@hitachi-solutions.com>
|
||||||
|
Date: Tue Sep 25 10:05:41 2018 +0900
|
||||||
|
|
||||||
|
(4) 備考
|
||||||
|
特になし。
|
||||||
|
|
||||||
|
|
||||||
|
以上。
|
||||||
82
test/mng_mod/issues/885/arm64/result.log
Normal file
82
test/mng_mod/issues/885/arm64/result.log
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
gcc -o CT_001 CT_001.c -pthread
|
||||||
|
gcc -o CT_002 CT_002.c -pthread
|
||||||
|
gcc -o CT_003 CT_003.c -pthread
|
||||||
|
gcc -o CT_004 CT_004.c -pthread
|
||||||
|
gcc -o CT_005 CT_005.c -pthread
|
||||||
|
gcc -o CT_006 CT_006.c -pthread
|
||||||
|
gcc -o CT_007 CT_007.c -pthread
|
||||||
|
gcc -o CT_008 CT_008.c -pthread
|
||||||
|
gcc -o CT_009 CT_009.c -pthread
|
||||||
|
gcc -o CT_010 CT_010.c -pthread
|
||||||
|
gcc -o CT_011 CT_011.c -pthread
|
||||||
|
./run.sh
|
||||||
|
mcstop+release.sh ... done
|
||||||
|
mcreboot.sh -c 4-7 -m 2G ... done
|
||||||
|
*** CT_001 start *******************************
|
||||||
|
[OK] ptrace_attach
|
||||||
|
[OK] ptrace_detach
|
||||||
|
*** CT_001 PASSED
|
||||||
|
|
||||||
|
*** CT_002 start *******************************
|
||||||
|
[OK] ptrace_attach
|
||||||
|
[OK] ptrace_cont
|
||||||
|
*** CT_002 PASSED
|
||||||
|
|
||||||
|
*** CT_003 start *******************************
|
||||||
|
[OK] orphan process
|
||||||
|
*** CT_003 PASSED
|
||||||
|
|
||||||
|
*** CT_004 start *******************************
|
||||||
|
[OK] ptrace_attach
|
||||||
|
[OK] ptrace_detach
|
||||||
|
[OK] ptrace_attach again
|
||||||
|
[OK] ptrace_detach again
|
||||||
|
*** CT_004 PASSED
|
||||||
|
|
||||||
|
*** CT_005 start *******************************
|
||||||
|
[OK] ptrace_attach 0 failed [invalid pid]
|
||||||
|
[OK] ptrace_attach 1 failed [invalid pid]
|
||||||
|
[OK] ptrace_attach self failed [invalid pid]
|
||||||
|
*** CT_005 PASSED
|
||||||
|
|
||||||
|
*** CT_006 start *******************************
|
||||||
|
[OK] ptrace_attach
|
||||||
|
[OK] ptrace_attach failed [double attach]
|
||||||
|
[OK] ptrace_detach
|
||||||
|
*** CT_006 PASSED
|
||||||
|
|
||||||
|
*** CT_007 start *******************************
|
||||||
|
[OK] ptrace_attach failed [after traceme]
|
||||||
|
*** CT_007 PASSED
|
||||||
|
|
||||||
|
*** CT_008 start *******************************
|
||||||
|
[OK] ptrace_detach 0 failed [invalid pid]
|
||||||
|
[OK] ptrace_detach 1 failed [invalid pid]
|
||||||
|
[OK] ptrace_detach child failed [not attached]
|
||||||
|
[OK] ptrace_detach self failed [invalid pid]
|
||||||
|
*** CT_008 PASSED
|
||||||
|
|
||||||
|
*** CT_009 start *******************************
|
||||||
|
[OK] ptrace_attach
|
||||||
|
[OK] ptrace_detach
|
||||||
|
[OK] ptrace_detach faild [double detach]
|
||||||
|
*** CT_009 PASSED
|
||||||
|
|
||||||
|
*** CT_010 start *******************************
|
||||||
|
[OK] waitpid for tracee by parent
|
||||||
|
*** CT_010 PASSED
|
||||||
|
|
||||||
|
*** CT_011 start *******************************
|
||||||
|
[OK] waitpid for tracee by parent
|
||||||
|
*** CT_011 PASSED
|
||||||
|
|
||||||
|
TEST_SUITE: ptrace
|
||||||
|
TEST_NUMBER: 19
|
||||||
|
ARGS:
|
||||||
|
child is stopped.
|
||||||
|
RESULT: ok
|
||||||
|
TEST_SUITE: ptrace
|
||||||
|
TEST_NUMBER: 20
|
||||||
|
ARGS:
|
||||||
|
child detach OK.
|
||||||
|
RESULT: ok
|
||||||
22
test/mng_mod/issues/885/arm64/run.sh
Executable file
22
test/mng_mod/issues/885/arm64/run.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
## run.sh COPYRIGHT FUJITSU LIMITED 2018 ##
|
||||||
|
|
||||||
|
USELTP=0
|
||||||
|
USEOSTEST=1
|
||||||
|
|
||||||
|
. ../../../../common.sh
|
||||||
|
|
||||||
|
${MCEXEC} ./CT_001
|
||||||
|
${MCEXEC} ./CT_002
|
||||||
|
${MCEXEC} ./CT_003
|
||||||
|
sleep 2
|
||||||
|
${MCEXEC} ./CT_004
|
||||||
|
${MCEXEC} ./CT_005
|
||||||
|
${MCEXEC} ./CT_006
|
||||||
|
${MCEXEC} ./CT_007
|
||||||
|
${MCEXEC} ./CT_008
|
||||||
|
${MCEXEC} ./CT_009
|
||||||
|
${MCEXEC} ./CT_010
|
||||||
|
${MCEXEC} ./CT_011
|
||||||
|
${MCEXEC} ${TESTMCK} -s ptrace -n 19
|
||||||
|
${MCEXEC} ${TESTMCK} -s ptrace -n 20
|
||||||
83
test/mng_mod/issues/885/x86_64/CT_001.c
Normal file
83
test/mng_mod/issues/885/x86_64/CT_001.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#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_001"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* detach child */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
83
test/mng_mod/issues/885/x86_64/CT_002.c
Normal file
83
test/mng_mod/issues/885/x86_64/CT_002.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#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_002"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* continue child */
|
||||||
|
rc = ptrace(PTRACE_CONT, pid, NULL, NULL);
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
80
test/mng_mod/issues/885/x86_64/CT_003.c
Normal file
80
test/mng_mod/issues/885/x86_64/CT_003.c
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#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_003"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
OKNG(getppid() != 1, "orphan process");
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* continue child */
|
||||||
|
rc = ptrace(PTRACE_CONT, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_cont");
|
||||||
|
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("*** %s PASSED\n\n", TEST_NAME);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
117
test/mng_mod/issues/885/x86_64/CT_004.c
Normal file
117
test/mng_mod/issues/885/x86_64/CT_004.c
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#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_004"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* detach child */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_detach");
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach again");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped again");
|
||||||
|
|
||||||
|
/* detach child */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_detach again");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
81
test/mng_mod/issues/885/x86_64/CT_005.c
Normal file
81
test/mng_mod/issues/885/x86_64/CT_005.c
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#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_005"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* invalid attach */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, 0, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_attach 0 failed [invalid pid]");
|
||||||
|
|
||||||
|
/* invalid attach */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, 1, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_attach 1 failed [invalid pid]");
|
||||||
|
|
||||||
|
/* invalid attach */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, getpid(), NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_attach self failed [invalid pid]");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
87
test/mng_mod/issues/885/x86_64/CT_006.c
Normal file
87
test/mng_mod/issues/885/x86_64/CT_006.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#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_006"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* normal attach */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* attach twice*/
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_attach failed [double attach]");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* detach child */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
75
test/mng_mod/issues/885/x86_64/CT_007.c
Normal file
75
test/mng_mod/issues/885/x86_64/CT_007.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#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_007"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
rc = ptrace(PTRACE_TRACEME, 0, NULL, NULL);
|
||||||
|
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach after traceme*/
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_attach failed [after traceme]");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
86
test/mng_mod/issues/885/x86_64/CT_008.c
Normal file
86
test/mng_mod/issues/885/x86_64/CT_008.c
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#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_008"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* invalid detach */
|
||||||
|
rc = ptrace(PTRACE_DETACH, 0, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_detach 0 failed [invalid pid]");
|
||||||
|
|
||||||
|
/* invalid detach */
|
||||||
|
rc = ptrace(PTRACE_DETACH, 1, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_detach 1 failed [invalid pid]");
|
||||||
|
|
||||||
|
/* invalid detach */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_detach child failed [not attached]");
|
||||||
|
|
||||||
|
/* invalid detach */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_detach self failed [invalid pid]");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
93
test/mng_mod/issues/885/x86_64/CT_009.c
Normal file
93
test/mng_mod/issues/885/x86_64/CT_009.c
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
#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_009"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
sem_t *pwait = NULL;
|
||||||
|
sem_t *cwait = 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);
|
||||||
|
cwait = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(!pwait || !cwait, "mmap for sem");
|
||||||
|
|
||||||
|
rc |= sem_init(pwait, 1, 0);
|
||||||
|
rc |= sem_init(cwait, 1, 0);
|
||||||
|
|
||||||
|
CHKANDJUMP(rc, "sem_init");
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
CHKANDJUMP(pid == -1, "fork");
|
||||||
|
|
||||||
|
if (pid == 0) { /* child */
|
||||||
|
/* wake parent */
|
||||||
|
sem_post(pwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
/* wait */
|
||||||
|
sem_wait(cwait);
|
||||||
|
|
||||||
|
_exit(123);
|
||||||
|
} else { /* parent */
|
||||||
|
/* wait */
|
||||||
|
sem_wait(pwait);
|
||||||
|
|
||||||
|
/* attach child */
|
||||||
|
rc = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_attach");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
sem_post(cwait);
|
||||||
|
|
||||||
|
/* wait child stop */
|
||||||
|
rc = waitpid(pid, &status, 0);
|
||||||
|
CHKANDJUMP(rc == -1, "waitpid");
|
||||||
|
|
||||||
|
CHKANDJUMP(!WIFSTOPPED(status), "child is not stopped");
|
||||||
|
|
||||||
|
/* detach child */
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc != 0, "ptrace_detach");
|
||||||
|
|
||||||
|
/* detach child twice*/
|
||||||
|
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
OKNG(rc == 0, "ptrace_detach faild [double detach]");
|
||||||
|
|
||||||
|
/* wake child */
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fn_fail:
|
||||||
|
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
100
test/mng_mod/issues/885/x86_64/CT_010.c
Normal file
100
test/mng_mod/issues/885/x86_64/CT_010.c
Normal 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;
|
||||||
|
}
|
||||||
102
test/mng_mod/issues/885/x86_64/CT_011.c
Normal file
102
test/mng_mod/issues/885/x86_64/CT_011.c
Normal 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;
|
||||||
|
}
|
||||||
25
test/mng_mod/issues/885/x86_64/test_chk.h
Normal file
25
test/mng_mod/issues/885/x86_64/test_chk.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef HEADER_TEST_CHK_H
|
||||||
|
#define HEADER_TEST_CHK_H
|
||||||
|
|
||||||
|
#define CHKANDJUMP(cond, ...) \
|
||||||
|
do { \
|
||||||
|
if (cond) { \
|
||||||
|
fprintf(stderr, " [NG] "); \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
fprintf(stderr, " failed\n"); \
|
||||||
|
goto fn_fail; \
|
||||||
|
} \
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
#define OKNG(cond, ...) \
|
||||||
|
do { \
|
||||||
|
if (cond) { \
|
||||||
|
CHKANDJUMP(cond, __VA_ARGS__); \
|
||||||
|
} else { \
|
||||||
|
fprintf(stdout, " [OK] "); \
|
||||||
|
fprintf(stdout, __VA_ARGS__); \
|
||||||
|
fprintf(stdout, "\n"); \
|
||||||
|
} \
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user