1 /*
2 * Copyright (c) 2020-2021 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 "hks_test_log.h"
17
18 #include "securec.h"
19
20 #include "stdlib.h"
21
22 #define MAX_LOG_BUFF_LEN 512
23 #define WAIT_TO_LOG_DONE 100000
24
HksTestLog(uint32_t logLevel,const char * funcName,int32_t lineNo,const char * format,...)25 void HksTestLog(uint32_t logLevel, const char *funcName, int32_t lineNo, const char *format, ...)
26 {
27 char buf[MAX_LOG_BUFF_LEN] = { 0 };
28
29 va_list ap;
30 va_start(ap, format);
31 int32_t ret = vsnprintf_s(buf, MAX_LOG_BUFF_LEN, MAX_LOG_BUFF_LEN - 1, format, ap);
32 va_end(ap);
33 if (ret < 0) {
34 printf("hks log concatenate error.");
35 return;
36 }
37
38 switch (logLevel) {
39 case HKS_LOG_LEVEL_I:
40 printf("[INFO] %s [%d]: %s\n", funcName, lineNo, buf);
41 break;
42 case HKS_LOG_LEVEL_E:
43 printf("[ERROR] %s [%d]: %s\n", funcName, lineNo, buf);
44 break;
45 case HKS_LOG_LEVEL_W:
46 printf("[WARNING] %s [%d]: %s\n", funcName, lineNo, buf);
47 break;
48 case HKS_LOG_LEVEL_D:
49 printf("[DEBUG] %s [%d]: %s\n", funcName, lineNo, buf);
50 break;
51 default:
52 return;
53 }
54 }
55
HksAssertLog(bool test)56 void HksAssertLog(bool test)
57 {
58 if (!(test)) {
59 HKS_TEST_LOG_E("[ASSERT] :fail\n");
60 }
61 }
62