test: Add testcase for #1031

Refs: #1031
Change-Id: I6a51596b84a97329ba7d5b765c8471246dcf85df
This commit is contained in:
Ken Sato
2018-06-27 22:53:49 +09:00
committed by Masamichi Takagi
parent 992705d465
commit 04e54ead5d
10 changed files with 586 additions and 0 deletions

61
test/issues/1031/C1031.sh Normal file
View File

@ -0,0 +1,61 @@
#!/bin/sh
BIN=
SBIN=
OSTEST=
BOOTPARAM="-c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24"
if [ -f ../../../config.h ]; then
str=`grep "^#define BINDIR " ../../../config.h | head -1 | sed 's/^#define BINDIR /BINDIR=/'`
eval $str
fi
if [ "x$BINDIR" = x ];then
BINDIR="$BIN"
fi
if [ -f ../../../Makefile ]; then
str=`grep ^SBINDIR ../../../Makefile | head -1 | sed 's/ //g'`
eval $str
fi
if [ "x$SBINDIR" = x ];then
SBINDIR="$SBIN"
fi
if [ -f $HOME/ostest/bin/test_mck ]; then
OSTESTDIR=$HOME/ostest/
fi
if [ "x$OSTESTDIR" = x ]; then
OSTESTDIR="$OSTEST"
fi
if [ ! -x $SBINDIR/mcstop+release.sh ]; then
echo mcstop+release: not found >&2
exit 1
fi
echo -n "mcstop+release.sh ... "
sudo $SBINDIR/mcstop+release.sh
echo "done"
if [ ! -x $SBINDIR/mcreboot.sh ]; then
echo mcreboot: not found >&2
exit 1
fi
echo -n "mcreboot.sh $BOOTPARAM ... "
sudo $SBINDIR/mcreboot.sh $BOOTPARAM
echo "done"
if [ ! -x $BINDIR/mcexec ]; then
echo mcexec: not found >&2
exit 1
fi
echo "*** RT_001 start *******************************"
sudo $BINDIR/mcexec $OSTESTDIR/bin/test_mck -s rt_sigaction -n 4
echo "*** RT_001: CHECK \"Terminate by signal 10\""
echo ""
sudo $BINDIR/mcexec ./CT_001
sudo $BINDIR/mcexec ./CT_002
sudo $BINDIR/mcexec ./CT_003
sudo $BINDIR/mcexec ./CT_004
sudo $BINDIR/mcexec ./CT_005

64
test/issues/1031/CT_001.c Normal file
View File

@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "./test_chk.h"
#define TEST_NAME "CT_001"
int handled_cnt;
void test_handler(int sig)
{
handled_cnt++;
}
int main(int argc, char **argv)
{
int rc = 0;
int pid = 0;
int status;
int tmp_flag = 0;
struct sigaction sa;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
pid = fork();
CHKANDJUMP(pid == -1, "fork");
if (pid == 0) { /* child */
sa.sa_handler = test_handler;
sa.sa_flags = SA_RESETHAND;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND");
printf(" send 1st SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 1, "invoked test_handler");
printf(" send 2nd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(1, "can't reach here");
} else { /* parent */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGUSR1) {
tmp_flag = 1;
}
}
OKNG(tmp_flag != 1, "child is killed by SIGUSR1");
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

66
test/issues/1031/CT_002.c Normal file
View File

@ -0,0 +1,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "./test_chk.h"
#define TEST_NAME "CT_002"
int handled_cnt;
void test_handler(int sig)
{
handled_cnt++;
}
int main(int argc, char **argv)
{
int rc = 0;
int pid = 0;
int status;
int tmp_flag = 0;
struct sigaction sa;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
pid = fork();
CHKANDJUMP(pid == -1, "fork");
if (pid == 0) { /* child */
sa.sa_handler = test_handler;
sa.sa_flags = 0;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction (no SA_RESETHAND)");
printf(" send 1st SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 1, "invoked test_handler");
printf(" send 2nd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 2, "invoked test_handler again");
_exit(123);
} else { /* parent */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
if (!WIFSIGNALED(status) &&
WIFEXITED(status)) {
if (WEXITSTATUS(status) == 123) {
tmp_flag = 1;
}
}
OKNG(tmp_flag != 1, "child exited normaly");
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

70
test/issues/1031/CT_003.c Normal file
View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "./test_chk.h"
#define TEST_NAME "CT_003"
int handled_cnt;
void test_handler(int sig)
{
handled_cnt++;
}
int main(int argc, char **argv)
{
int rc = 0;
int pid = 0;
int status;
int tmp_flag = 0;
struct sigaction sa;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
pid = fork();
CHKANDJUMP(pid == -1, "fork");
if (pid == 0) { /* child */
sa.sa_handler = test_handler;
sa.sa_flags |= SA_RESETHAND;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND");
sa.sa_flags = 0;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction (rewrite no SA_RESETHAND)");
printf(" send 1st SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 1, "invoked test_handler");
printf(" send 2nd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 2, "invoked test_handler again");
_exit(123);
} else { /* parent */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
if (!WIFSIGNALED(status) &&
WIFEXITED(status)) {
if (WEXITSTATUS(status) == 123) {
tmp_flag = 1;
}
}
OKNG(tmp_flag != 1, "child exited normaly");
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

83
test/issues/1031/CT_004.c Normal file
View File

@ -0,0 +1,83 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "./test_chk.h"
#define TEST_NAME "CT_004"
int handled_cnt;
int handled_cnt2;
void test_handler(int sig)
{
handled_cnt++;
}
void test_handler2(int sig)
{
handled_cnt2++;
}
int main(int argc, char **argv)
{
int rc = 0;
int pid = 0;
int status;
int tmp_flag = 0;
struct sigaction sa;
struct sigaction sa2;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
handled_cnt2 = 0;
pid = fork();
CHKANDJUMP(pid == -1, "fork");
if (pid == 0) { /* child */
sa.sa_handler = test_handler;
sa.sa_flags |= SA_RESETHAND;
sa2.sa_handler = test_handler2;
sa2.sa_flags |= SA_RESETHAND;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND to SIGUSR1");
rc = sigaction(SIGUSR2, &sa2, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND to SIGUSR2");
printf(" send 1st SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 1, "invoked test_handler");
printf(" send 1st SIGUSR2\n");
kill(getpid(), SIGUSR2);
OKNG(handled_cnt2 != 1, "invoked test_handler2");
printf(" send 2nd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(1, "can't reach here");
} else { /* parent */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGUSR1) {
tmp_flag = 1;
}
}
OKNG(tmp_flag != 1, "child is killed by SIGUSR1");
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

72
test/issues/1031/CT_005.c Normal file
View File

@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "./test_chk.h"
#define TEST_NAME "CT_005"
int handled_cnt;
void test_handler(int sig)
{
handled_cnt++;
}
int main(int argc, char **argv)
{
int rc = 0;
int pid = 0;
int status;
int tmp_flag = 0;
struct sigaction sa;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
pid = fork();
CHKANDJUMP(pid == -1, "fork");
if (pid == 0) { /* child */
sa.sa_handler = test_handler;
sa.sa_flags = SA_RESETHAND;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND");
printf(" send 1st SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 1, "invoked test_handler");
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND again");
printf(" send 2nd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(handled_cnt != 2, "invoked test_handler again");
printf(" send 3rd SIGUSR1\n");
kill(getpid(), SIGUSR1);
OKNG(1, "can't reach here");
} else { /* parent */
rc = waitpid(pid, &status, 0);
CHKANDJUMP(rc == -1, "waitpid");
if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGUSR1) {
tmp_flag = 1;
}
}
OKNG(tmp_flag != 1, "child is killed by SIGUSR1");
}
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

29
test/issues/1031/Makefile Normal file
View File

@ -0,0 +1,29 @@
CC = gcc
TARGET=CT_001 CT_002 CT_003 CT_004 CT_005
CPPFLAGS =
LDFLAGS =
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)
test: all
@sh ./C1031.sh
clean:
rm -f $(TARGET) *.o

60
test/issues/1031/README Normal file
View File

@ -0,0 +1,60 @@
【Issue#1031 動作確認】
□ テスト内容
1. Issueで報告された再現プログラムでの確認
RT_001: ostest-rt_sigaction.004 による確認
SIGUSR1 でプロセスが終了し、「Terminate by signal 10」が出力される
2. 既存のsigaction機能に影響がないことを確認
CT_001: SIG_RESETHAND 指定時の動作
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. 自身にSIGUSR1を送る
3. 1.で登録したハンドラが呼び出される
4. 自身にSIGUSR1を送る
5. 1.で登録したハンドラが呼び出されず、プロセスが終了する
CT_002: SIG_RESETHAND 未指定時の動作
1. SIG_RESETHANDを指定しないsigaction()でSIGUSR1にハンドラを設定
2. 自身にSIGUSR1を送る
3. 1.で登録したハンドラが呼び出される
4. 自身にSIGUSR1を送る
5. 1.で登録したハンドラが呼び出される
CT_003: SIG_RESETHANDO 指定ハンドラへの上書き登録時の動作
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. SIG_RESETHANDを指定しないsigaction()でSIG_USR1にハンドラを設定
3. 自身にSIGUSR1を送る
4. 2.で登録したハンドラが呼び出される
5. 自身にSIGUSR1を送る
6. 2.で登録したハンドラが呼び出される
CT_004: 複数のsig_numへのハンドラ登録時の動作
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. SIG_RESETHANDを指定したsigaction()でSIG_USR2にハンドラを設定
3. 自身にSIGUSR1を送る
4. 1.で登録したハンドラが呼び出される
5. 自身にSIGUSR2を送る
6. 2.で登録したハンドラが呼び出される
7. 自身にSIGUSR1を送る
8. 1.で登録したハンドラが呼び出されず、プロセスが終了する
CT_005: 複数回(非上書き)のSIG_RESETHAND 指定時の動作
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. 自身にSIGUSR1を送る
3. 1.で登録したハンドラが呼び出される
4. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
5. 自身にSIGUSR1を送る
6. 4.で登録したハンドラが呼び出される
7. 自身にSIGUSR1を送る
8. 4.で登録したハンドラが呼び出されず、プロセスが終了する
□ 実行手順
$ make test
実行できない場合は、C1031.shの以下の行を適切に書き換えた後に実行。
BIN= mcexec が存在するパス
SBIN= mcreboot.sh が存在するパス
OSTEST= OSTESTが存在するパス
□ 実行結果
result.log 参照。
すべての項目をPASSしていることを確認。

View File

@ -0,0 +1,58 @@
*** RT_001 start *******************************
TEST_SUITE: rt_sigaction
TEST_NUMBER: 4
ARGS:
/-------- Signal handler will activate -------/
sig#10 is handled.
/------ Process will terminate by signal -----/
Terminate by signal 10
*** RT_001: CHECK "Terminate by signal 10"
*** CT_001 start *******************************
[OK] sigaction with SA_RESETHAND
send 1st SIGUSR1
[OK] invoked test_handler
send 2nd SIGUSR1
[OK] child is killed by SIGUSR1
*** CT_001 PASSED
*** CT_002 start *******************************
[OK] sigaction (no SA_RESETHAND)
send 1st SIGUSR1
[OK] invoked test_handler
send 2nd SIGUSR1
[OK] invoked test_handler again
[OK] child exited normaly
*** CT_002 PASSED
*** CT_003 start *******************************
[OK] sigaction with SA_RESETHAND
[OK] sigaction (rewrite no SA_RESETHAND)
send 1st SIGUSR1
[OK] invoked test_handler
send 2nd SIGUSR1
[OK] invoked test_handler again
[OK] child exited normaly
*** CT_003 PASSED
*** CT_004 start *******************************
[OK] sigaction with SA_RESETHAND to SIGUSR1
[OK] sigaction with SA_RESETHAND to SIGUSR2
send 1st SIGUSR1
[OK] invoked test_handler
send 1st SIGUSR2
[OK] invoked test_handler2
send 2nd SIGUSR1
[OK] child is killed by SIGUSR1
*** CT_004 PASSED
*** CT_005 start *******************************
[OK] sigaction with SA_RESETHAND
send 1st SIGUSR1
[OK] invoked test_handler
[OK] sigaction with SA_RESETHAND again
send 2nd SIGUSR1
[OK] invoked test_handler again
send 3rd SIGUSR1
[OK] child is killed by SIGUSR1
*** CT_005 PASSED

View File

@ -0,0 +1,23 @@
#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