1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 <stdio.h>
17 #include <stdarg.h>
18 #include "securec.h"
19 #include "common_def.h"
20 #include "test_suite_channel.h"
21 #include "test_suite_log.h"
22
23 #define LOG_STRING_MAX_LENGTH 100
24
25 static test_suite_channel_funcs_t *g_test_suite_log_channel_funcs = NULL;
26 static int32_t g_test_suite_result;
27
test_suite_log_get_channel_funcs(void)28 void test_suite_log_get_channel_funcs(void)
29 {
30 g_test_suite_log_channel_funcs = test_suite_channel_get_funcs();
31 }
32
test_suite_log_char(char data)33 void test_suite_log_char(char data)
34 {
35 g_test_suite_log_channel_funcs->send_char(data);
36 }
37
test_suite_log_string(const char * str)38 void test_suite_log_string(const char *str)
39 {
40 g_test_suite_log_channel_funcs->send(str);
41 }
42
test_suite_log_stringf(const char * str,...)43 void test_suite_log_stringf(const char *str, ...)
44 {
45 static char s[LOG_STRING_MAX_LENGTH];
46 va_list args;
47 int32_t str_len;
48
49 va_start(args, str);
50 str_len = vsprintf_s(s, sizeof(s), str, args);
51 va_end(args);
52
53 if (str_len < 0) {
54 return;
55 }
56
57 test_suite_log_string(s);
58 }
59
test_suite_log_line(char * line)60 void test_suite_log_line(char *line)
61 {
62 g_test_suite_log_channel_funcs->send_line(line);
63 }
64
test_suite_log_set_test_result(int result)65 void test_suite_log_set_test_result(int result)
66 {
67 g_test_suite_result = result;
68 }
69
test_suite_log_get_test_result(void)70 int test_suite_log_get_test_result(void)
71 {
72 return g_test_suite_result;
73 }
74