1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <info/fatal_message.h> 17 18 #include <errno.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <string.h> 22 #include <test.h> 23 #include <pthread.h> 24 #include <unistd.h> 25 #include "functionalext.h" 26 27 typedef void (*TEST_FUN)(void); 28 static const int WAIT_TIME = 1; 29 30 /** 31 * @tc.name : set_fatal_message 32 * @tc.desc : Test the function of set_fatal_message. 33 * @tc.level : Level 0 34 */ fatal_message_0010(void)35static void fatal_message_0010(void) 36 { 37 const char msg[1024] = {"abcdefghijklmnopqrstuvwxyz1234567890"}; 38 fatal_msg_t *fatal_message = NULL; 39 int pidChild = 0; 40 pid_t fpid; 41 fpid = fork(); 42 if (fpid < 0) { 43 t_printf("error in fork!"); 44 } else if (fpid == 0) { 45 pidChild = getpid(); 46 set_fatal_message(msg); 47 fatal_message = get_fatal_message(); 48 EXPECT_EQ("fatal_message_0010", fatal_message, NULL); 49 exit(pidChild); 50 } 51 } 52 53 TEST_FUN G_Fun_Array[] = { 54 fatal_message_0010, 55 }; 56 main(void)57int main(void) 58 { 59 int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); 60 for (int pos = 0; pos < num; ++pos) { 61 G_Fun_Array[pos](); 62 } 63 64 return t_status; 65 } 66