77
test/mng_mod/issues/885/CT_001.c
Normal file
77
test/mng_mod/issues/885/CT_001.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#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");
|
||||
}
|
||||
|
||||
printf("*** %s PASSED\n\n", TEST_NAME);
|
||||
return 0;
|
||||
|
||||
fn_fail:
|
||||
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||
|
||||
return -1;
|
||||
}
|
||||
77
test/mng_mod/issues/885/CT_002.c
Normal file
77
test/mng_mod/issues/885/CT_002.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#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");
|
||||
}
|
||||
|
||||
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/CT_003.c
Normal file
80
test/mng_mod/issues/885/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;
|
||||
}
|
||||
123
test/mng_mod/issues/885/CT_004.c
Normal file
123
test/mng_mod/issues/885/CT_004.c
Normal file
@@ -0,0 +1,123 @@
|
||||
#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");
|
||||
|
||||
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");
|
||||
|
||||
/* detach child */
|
||||
rc = ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||
OKNG(rc != 0, "ptrace_detach again");
|
||||
|
||||
/* wake child */
|
||||
sem_post(cwait);
|
||||
}
|
||||
|
||||
printf("*** %s PASSED\n\n", TEST_NAME);
|
||||
return 0;
|
||||
|
||||
fn_fail:
|
||||
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||
|
||||
return -1;
|
||||
}
|
||||
76
test/mng_mod/issues/885/CT_005.c
Normal file
76
test/mng_mod/issues/885/CT_005.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#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);
|
||||
|
||||
}
|
||||
|
||||
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/CT_006.c
Normal file
81
test/mng_mod/issues/885/CT_006.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_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");
|
||||
}
|
||||
|
||||
printf("*** %s PASSED\n\n", TEST_NAME);
|
||||
return 0;
|
||||
|
||||
fn_fail:
|
||||
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||
|
||||
return -1;
|
||||
}
|
||||
69
test/mng_mod/issues/885/CT_007.c
Normal file
69
test/mng_mod/issues/885/CT_007.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
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/CT_008.c
Normal file
80
test/mng_mod/issues/885/CT_008.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_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);
|
||||
|
||||
}
|
||||
|
||||
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/CT_009.c
Normal file
87
test/mng_mod/issues/885/CT_009.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_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);
|
||||
}
|
||||
|
||||
printf("*** %s PASSED\n\n", TEST_NAME);
|
||||
return 0;
|
||||
|
||||
fn_fail:
|
||||
printf("*** %s FAILED\n\n", TEST_NAME);
|
||||
|
||||
return -1;
|
||||
}
|
||||
53
test/mng_mod/issues/885/Makefile
Normal file
53
test/mng_mod/issues/885/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
CC = gcc
|
||||
MCK_DIR=/home/satoken/ppos
|
||||
|
||||
MCEXEC=$(MCK_DIR)/bin/mcexec
|
||||
TARGET=CT_001 CT_002 CT_003 CT_004 CT_005 CT_006 CT_007 CT_008 CT_009
|
||||
|
||||
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)
|
||||
|
||||
test: all
|
||||
$(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
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) *.o
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
【Issue#885 動作確認】
|
||||
Issue#885が解決され、既存機能に影響がないことをIssueで報告されたテストプログラム(2項目)と、
|
||||
McKernelでのptraceのattach/detach操作の基本動作確認(8項目)の計10項目のテストによって確認した。
|
||||
McKernelでのptraceのattach/detach操作の基本動作確認(9項目)の計11項目のテストによって確認した。
|
||||
なお、各テストの実行結果は./result.log として格納している。
|
||||
|
||||
①Issueで報告されたテストプログラムによる確認
|
||||
@@ -45,15 +45,17 @@ CT_005: 不正なpid指定のattach
|
||||
1. 不正なpid(0, 1, 負数)を指定したattach
|
||||
2. 自身のpidを指定したattach
|
||||
|
||||
CT_006: attach済の子プロセスへのattach
|
||||
CT_006: attach済の子プロセスへのattach①
|
||||
1. 既にattachしている子プロセスへ再びattach
|
||||
2. tracemeした子プロセスへattach
|
||||
|
||||
CT_007: 不正なpid指定のdetach
|
||||
CT_007: attach済の子プロセスへのattach②
|
||||
1. tracemeした子プロセスへattach
|
||||
|
||||
CT_008: 不正なpid指定のdetach
|
||||
1. 不正なpid(0, 1, 負数)を指定したdetach
|
||||
2. attachしていない子プロセスのpidを指定したdetach
|
||||
|
||||
CT_008: detach済の子プロセスへのdetach
|
||||
CT_009: detach済の子プロセスへのdetach
|
||||
1. 既にdetachしていいる子プロセスへ再びdetach
|
||||
|
||||
3. 結果
|
||||
|
||||
78
test/mng_mod/issues/885/result.log
Normal file
78
test/mng_mod/issues/885/result.log
Normal file
@@ -0,0 +1,78 @@
|
||||
①Issueで報告されたテストプログラムによる確認
|
||||
$ mcexec test_set/bin/test_mck -s ptrace -n 19
|
||||
TEST_SUITE: ptrace
|
||||
TEST_NUMBER: 19
|
||||
ARGS:
|
||||
child is stopped.
|
||||
RESULT: ok
|
||||
|
||||
$ mcexec test_set/bin/test_mck -s ptrace -n 20
|
||||
TEST_SUITE: ptrace
|
||||
TEST_NUMBER: 20
|
||||
ARGS:
|
||||
child detach OK.
|
||||
RESULT: ok
|
||||
|
||||
②McKernelでのptraceのattach/detachの基本動作確認
|
||||
/home/satoken/ppos/bin/mcexec ./CT_001
|
||||
*** CT_001 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_detach
|
||||
*** CT_001 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_002
|
||||
*** CT_002 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_cont
|
||||
*** CT_002 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_003
|
||||
*** CT_003 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_cont
|
||||
[OK] orphan process
|
||||
*** CT_003 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_004
|
||||
*** CT_004 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_detach
|
||||
[OK] ptrace_attach again
|
||||
[OK] ptrace_detach again
|
||||
*** CT_004 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_005
|
||||
*** 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
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_006
|
||||
*** CT_006 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_attach failed [double attach]
|
||||
[OK] ptrace_detach
|
||||
*** CT_006 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_007
|
||||
*** CT_007 start *******************************
|
||||
[OK] ptrace_attach failed [after traceme]
|
||||
*** CT_007 PASSED
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_008
|
||||
*** 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
|
||||
|
||||
/home/satoken/ppos/bin/mcexec ./CT_009
|
||||
*** CT_009 start *******************************
|
||||
[OK] ptrace_attach
|
||||
[OK] ptrace_detach
|
||||
[OK] ptrace_detach faild [double detach]
|
||||
*** CT_009 PASSED
|
||||
|
||||
|
||||
25
test/mng_mod/issues/885/test_chk.h
Normal file
25
test/mng_mod/issues/885/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