diff --git a/libc-test/src/functionalext/info/fatal_message.c b/libc-test/src/functionalext/info/fatal_message.c index ed48ee3ea67b8c4614825d70f17ecc3f13a36823..2c1a172c33cb1d490e96f6fea5cb1b5555c48682 100644 --- a/libc-test/src/functionalext/info/fatal_message.c +++ b/libc-test/src/functionalext/info/fatal_message.c @@ -31,6 +31,14 @@ t_error("[%s] failed\n"); \ } while (0) +#define FORK(fpid) \ + do \ + { \ + if (fpid < 0) { \ + t_error("error in fork!");\ + } \ + } while (0) + typedef void (*TEST_FUN)(void); static const int WAIT_TIME = 1; @@ -61,9 +69,8 @@ static void fatal_message_0020(void) pid_t fpid; fpid = fork(); - if (fpid < 0) { - t_printf("error in fork!"); - } else if (fpid == 0) { + FORK(fpid); + if (fpid == 0) { pidChild = getpid(); set_fatal_message(msg); fatal_message = get_fatal_message(); @@ -96,9 +103,8 @@ static void fatal_message_0030(void) // start process fpid = fork(); - if (fpid < 0) { - t_printf("error in fork!"); - } else if (fpid == 0) { + FORK(fpid); + if (fpid == 0) { pidChild = getpid(); } else { pidParent = getpid(); @@ -148,9 +154,8 @@ static void fatal_message_0040(void) // start process fpid = fork(); - if (fpid < 0) { - t_printf("error in fork!"); - } else if (fpid == 0) { + FORK(fpid); + if (fpid == 0) { pidChild = getpid(); } else { pidParent = getpid(); @@ -236,13 +241,12 @@ static void fatal_message_0060(void) pid_t fpid; fpid = fork(); - if (fpid < 0) { - t_printf("error in fork!"); - } else if (fpid == 0) { + FORK(fpid); + if (fpid == 0) { pidChild = getpid(); set_fatal_message(msg); fatal_message = get_fatal_message(); - EXPECT_TRUE(fatal_message->msg == msg); + EXPECT_TRUE(fatal_message == NULL); exit(pidChild); } } diff --git a/libc-test/src/functionalext/unittest/BUILD.gn b/libc-test/src/functionalext/unittest/BUILD.gn index f4b234ec15d8713e7e5a391d6c99a21b8454653c..9859ca31c76d3a344026ccd19aa45faf733133cb 100644 --- a/libc-test/src/functionalext/unittest/BUILD.gn +++ b/libc-test/src/functionalext/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at