test: Add testcase for #1031
Refs: #1031 Change-Id: I6a51596b84a97329ba7d5b765c8471246dcf85df
This commit is contained in:
committed by
Masamichi Takagi
parent
992705d465
commit
04e54ead5d
66
test/issues/1031/CT_002.c
Normal file
66
test/issues/1031/CT_002.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user