test: Add testcase for #1111

Refs: #1111
Change-Id: Ifdf25a9ce98ef495200daf1c24d7ac2c81b3ef17
This commit is contained in:
Ken Sato
2018-06-27 23:12:43 +09:00
committed by Masamichi Takagi
parent 04e54ead5d
commit c6cc0bf07a
10 changed files with 437 additions and 0 deletions

65
test/issues/1111/C1111.sh Normal file
View File

@ -0,0 +1,65 @@
#!/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 5 2>&1 | tee ./RT_001.txt
if grep "RESULT: ok" ./RT_001.txt > /dev/null 2>&1 ; then
echo "*** RT_001: PASSED"
else
echo "*** RT_001: FAILED"
fi
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

50
test/issues/1111/CT_001.c Normal file
View File

@ -0,0 +1,50 @@
#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 status;
int tmp_flag = 0;
struct sigaction sa, old_act;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
sa.sa_handler = test_handler;
sa.sa_flags = SA_RESETHAND;
rc = sigaction(SIGUSR1, &sa, NULL);
OKNG(rc != 0, "sigaction with SA_RESETHAND");
rc = sigaction(SIGUSR1, NULL, &old_act);
OKNG(rc != 0, "sigaction to get current action");
if (old_act.sa_handler == test_handler &&
old_act.sa_flags & SA_RESETHAND) {
tmp_flag = 1;
}
OKNG(tmp_flag != 1, "check current act");
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

53
test/issues/1111/CT_002.c Normal file
View File

@ -0,0 +1,53 @@
#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 status;
int tmp_flag = 0;
struct sigaction sa, old_act;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
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, NULL, &old_act);
OKNG(rc != 0, "sigaction to get current action");
if (old_act.sa_handler == SIG_DFL) {
tmp_flag = 1;
}
OKNG(tmp_flag != 1, "check current act (after reset)");
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

47
test/issues/1111/CT_003.c Normal file
View File

@ -0,0 +1,47 @@
#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 status;
int tmp_flag = 0;
struct sigaction sa, old_act;
printf("*** %s start *******************************\n", TEST_NAME);
handled_cnt = 0;
rc = sigaction(0, &sa, NULL);
OKNG(rc != -1, "sigaction 0 failed");
rc = sigaction(_NSIG, &sa, NULL);
OKNG(rc != -1, "sigaction _NSIG failed");
rc = sigaction(SIGKILL, &sa, NULL);
OKNG(rc != -1, "sigaction SIGKILL failed");
rc = sigaction(SIGSTOP, &sa, NULL);
OKNG(rc != -1, "sigaction SIGSTOP failed");
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

44
test/issues/1111/CT_004.c Normal file
View File

@ -0,0 +1,44 @@
#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 main(int argc, char **argv)
{
int rc = 0;
int status;
int tmp_flag = 0;
struct sigaction old_act;
printf("*** %s start *******************************\n", TEST_NAME);
rc = sigaction(SIGKILL, NULL, &old_act);
OKNG(rc != 0, "sigaction to get SIGKILL action");
if (old_act.sa_handler == SIG_DFL) {
tmp_flag = 1;
}
OKNG(tmp_flag != 1, "check SIGKILL act");
rc = sigaction(SIGSTOP, NULL, &old_act);
OKNG(rc != 0, "sigaction to get SIGSTOP action");
tmp_flag = 0;
if (old_act.sa_handler == SIG_DFL) {
tmp_flag = 1;
}
OKNG(tmp_flag != 1, "check SIGSTOP act");
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

37
test/issues/1111/CT_005.c Normal file
View File

@ -0,0 +1,37 @@
#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 main(int argc, char **argv)
{
int rc = 0;
int status;
printf("*** %s start *******************************\n", TEST_NAME);
rc = sigaction(SIGUSR1, NULL, NULL);
OKNG(rc != 0, "SIGUSR1 is valid");
rc = sigaction(SIGKILL, NULL, NULL);
OKNG(rc != 0, "SIGKILL is valid");
rc = sigaction(SIGSTOP, NULL, NULL);
OKNG(rc != 0, "SIGSTOP is valid");
rc = sigaction(_NSIG, NULL, NULL);
OKNG(rc != -1, "_NSIG is invalid");
printf("*** %s PASSED\n\n", TEST_NAME);
return 0;
fn_fail:
printf("*** %s FAILED\n\n", TEST_NAME);
return -1;
}

29
test/issues/1111/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 ./C1111.sh
clean:
rm -f $(TARGET) *.o

44
test/issues/1111/README Normal file
View File

@ -0,0 +1,44 @@
【Issue#1111 動作確認】
□ テスト内容
1. Issueで報告された再現プログラムでの確認
RT_001: ostest-rt_sigaction.005 による確認
テストが正常に終了し、「RESULT: ok」が出力される
2. 既存のsigaction機能に影響がないことを確認
CT_001: 設定中のハンドラ情報の取得 (上書き時)
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. sigaction(SIGUSR1, NULL, &act) で設定情報を取得できる
3. SIG_RESETHANDを指定しないsigaction()でSIG_USR1にデフォルトハンドラを設定
4. sigaction(SIGUSR1, NULL, &act) で3.で指定した設定情報を取得できる
CT_002: 設定中のハンドラ情報の取得 (デフォルトに戻った時)
1. SIG_RESETHANDを指定したsigaction()でSIG_USR1にハンドラを設定
2. 自身にSIGUSR1を送る
3. 1.で登録したハンドラが呼び出される
4. sigaction(SIGUSR1, NULL, &act) で設定情報を取得できる
CT_003: 不正なsig_numへのハンドラ登録
1. 範囲外(上限、下限)のsignumへのハンドラ登録が失敗する
2. SIGKILL, SIGSTOPへのハンドラ登録が失敗する
CT_004: SIGKILL, SIGSTOPのハンドラ情報の取得
1. sigaction(SIGKILL, NULL, &act) で設定情報を取得できる
2. sigaction(SIGSTOP, NULL, &act) で設定情報を取得できる
CT_005: sig_numの有効確認
1. sigaction(SIGUSR1, NULL, NULL) が成功する(有効)
2. sigaction(SIGKILL, NULL, NULL) が成功する(有効)
3. sigaction(SIGSTOP, NULL, NULL) が成功する(有効)
4. sigaction(_NSIG, NULL, NULL) が失敗する(無効)
□ 実行手順
$ make test
実行できない場合は、C1111.shの以下の行を適切に書き換えた後に実行。
BIN= mcexec が存在するパス
SBIN= mcreboot.sh が存在するパス
OSTEST= OSTESTが存在するパス
□ 実行結果
result.log 参照。
すべての項目をPASSしていることを確認。

View File

@ -0,0 +1,45 @@
*** RT_001 start *******************************
TEST_SUITE: rt_sigaction
TEST_NUMBER: 5
ARGS:
sigaction(-1) = -1 (errno=22)
sigaction(65) = -1 (errno=22)
sigaction(9) = -1 (errno=22)
sigaction(19) = -1 (errno=22)
RESULT: ok
*** RT_001: PASSED
*** CT_001 start *******************************
[OK] sigaction with SA_RESETHAND
[OK] sigaction to get current action
[OK] check current act
*** CT_001 PASSED
*** CT_002 start *******************************
[OK] sigaction with SA_RESETHAND
send 1st SIGUSR1
[OK] invoked test_handler
[OK] sigaction to get current action
[OK] check current act (after reset)
*** CT_002 PASSED
*** CT_003 start *******************************
[OK] sigaction 0 failed
[OK] sigaction _NSIG failed
[OK] sigaction SIGKILL failed
[OK] sigaction SIGSTOP failed
*** CT_003 PASSED
*** CT_004 start *******************************
[OK] sigaction to get SIGKILL action
[OK] check SIGKILL act
[OK] sigaction to get SIGSTOP action
[OK] check SIGSTOP act
*** CT_004 PASSED
*** CT_005 start *******************************
[OK] SIGUSR1 is valid
[OK] SIGKILL is valid
[OK] SIGSTOP is valid
[OK] _NSIG is invalid
*** 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