提交 8f552543 编写于 作者: O olefirenque 提交者: sosnin-vladimir
上级 8c4b9427
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <test.h> #include <test.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#define EXPECT_TRUE(c) \ #define EXPECT_TRUE(c) \
do \ do \
...@@ -29,13 +30,6 @@ ...@@ -29,13 +30,6 @@
if (!(c)) \ if (!(c)) \
t_error("[%s] failed\n"); \ t_error("[%s] failed\n"); \
} while (0) } while (0)
// val1 == val2
#define EXPECT_EQ(a, b) \
do \
{ \
if ((a) != (b)) \
t_error("failed %d != %d \n", a, b); \
} while (0)
typedef void (*TEST_FUN)(void); typedef void (*TEST_FUN)(void);
static const int WAIT_TIME = 1; static const int WAIT_TIME = 1;
...@@ -61,6 +55,7 @@ static void fatal_message_0020(void) ...@@ -61,6 +55,7 @@ static void fatal_message_0020(void)
const char msg[1024] = {"abcdefghijklmnopqrstuvwxyz1234567890"}; const char msg[1024] = {"abcdefghijklmnopqrstuvwxyz1234567890"};
fatal_msg_t *fatal_message = NULL; fatal_msg_t *fatal_message = NULL;
int childRet = 0;
int pidParent = 0; int pidParent = 0;
int pidChild = 0; int pidChild = 0;
...@@ -73,8 +68,10 @@ static void fatal_message_0020(void) ...@@ -73,8 +68,10 @@ static void fatal_message_0020(void)
set_fatal_message(msg); set_fatal_message(msg);
fatal_message = get_fatal_message(); fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msg) == 0); EXPECT_TRUE(strcmp(fatal_message->msg, msg) == 0);
exit(pidChild); exit(0);
} }
waitpid(fpid, &childRet, 0);
EXPECT_TRUE(childRet == 0);
} }
/** /**
...@@ -89,6 +86,7 @@ static void fatal_message_0030(void) ...@@ -89,6 +86,7 @@ static void fatal_message_0030(void)
const char msgChild[1024] = {"msgChild"}; const char msgChild[1024] = {"msgChild"};
const char msgParent[1024] = {"msgParent"}; const char msgParent[1024] = {"msgParent"};
int childRet = 0;
int pidChild = 0; int pidChild = 0;
int pidParent = 0; int pidParent = 0;
int pidCParent = 0; int pidCParent = 0;
...@@ -115,13 +113,14 @@ static void fatal_message_0030(void) ...@@ -115,13 +113,14 @@ static void fatal_message_0030(void)
set_fatal_message(msgParent); set_fatal_message(msgParent);
fatal_message = get_fatal_message(); fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0); EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0);
exit(pidCChild); exit(0);
} else { } else {
pidCParent = getpid(); pidCParent = getpid();
set_fatal_message(msgChild); set_fatal_message(msgChild);
fatal_message = get_fatal_message(); fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgChild) == 0); EXPECT_TRUE(strcmp(fatal_message->msg, msgChild) == 0);
exit(pidCParent); waitpid(fpidChild, &childRet, 0);
EXPECT_TRUE(childRet == 0);
} }
} }
} }
...@@ -139,6 +138,7 @@ static void fatal_message_0040(void) ...@@ -139,6 +138,7 @@ static void fatal_message_0040(void)
const char msgChild[1024] = {"msgChild004"}; const char msgChild[1024] = {"msgChild004"};
const char msgParent[1024] = {"msgParent004"}; const char msgParent[1024] = {"msgParent004"};
int childRet = 0;
int pidChild = 0; int pidChild = 0;
int pidParent = 0; int pidParent = 0;
int pidCParent = 0; int pidCParent = 0;
...@@ -170,7 +170,8 @@ static void fatal_message_0040(void) ...@@ -170,7 +170,8 @@ static void fatal_message_0040(void)
set_fatal_message(msgParent); set_fatal_message(msgParent);
fatal_message = get_fatal_message(); fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0); EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0);
exit(pidCParent); waitpid(fpidChild, &childRet, 0);
EXPECT_TRUE(childRet != 0);
} }
} }
} }
...@@ -231,9 +232,17 @@ TEST_FUN G_Fun_Array[] = { ...@@ -231,9 +232,17 @@ TEST_FUN G_Fun_Array[] = {
int main(void) int main(void)
{ {
int childPid, childRet;
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) { for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos](); // Run each function in a new process to
// keep the initial state of fatal_message.
if ((childPid = fork()) == 0) {
G_Fun_Array[pos]();
exit(0);
}
waitpid(childPid, &childRet, 0);
EXPECT_TRUE(childRet == 0);
} }
return t_status; return t_status;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册