• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdint.h>
17 #include "securec.h"
18 #include "common_def.h"
19 #include "soc_osal.h"
20 #ifdef CONFIG_TESTSUITE_SUPPORT_MULTI_CORE
21 #include "ipc.h"
22 #include "test_suite_ipc.h"
23 #endif
24 #include "test_suite_console.h"
25 #include "test_suite_commands_processor.h"
26 #include "test_suite.h"
27 #include "test_suite_log.h"
28 #ifdef SUPPORT_AUDIO_LIEYIN_TOOL
29 #include "watchdog.h"
30 #endif
31 
32 #include "test_suite_task.h"
33 
34 #define TEST_SUITE_MSG_QUEUE_LEN      5
35 #define TEST_SUITE_RECEIVE_MSGQUEUE_BUFFER_SIZE TEST_SUITE_MSG_QUEUE_MAX_SIZE
36 #define TEST_SUITE_QUEUE_DELAY 0xFFFFFFFF
37 
38 osal_task *g_test_suite_task_id = NULL;
39 unsigned long g_test_suite_msg_queue_id;
40 #ifdef CONFIG_TESTSUITE_SUPPORT_MULTI_CORE
41 unsigned long g_test_suite_cmd_queue_id;
42 #endif
43 static char g_test_suite_command_buffer_array[CONFIG_TEST_SUITE_COMMAND_BUFFER_SIZE + 1];
44 static bool g_exit_test_suite_task = false;
45 
46 static int32_t test_suite_task_entry(void *data);
47 
test_suite_create_msgqueue(void)48 static void test_suite_create_msgqueue(void)
49 {
50     if (osal_msg_queue_create("test_suite_msg_queue", TEST_SUITE_MSG_QUEUE_LEN, \
51         (unsigned long *)&g_test_suite_msg_queue_id, 0, TEST_SUITE_MSG_QUEUE_MAX_SIZE) != OSAL_SUCCESS) {
52         test_suite_log_string("Testsuite message queue create failed!\n");
53     }
54 }
55 
test_suite_delete_msgqueue(void)56 static void test_suite_delete_msgqueue(void)
57 {
58     osal_msg_queue_delete(g_test_suite_msg_queue_id);
59 }
60 
test_suite_write_msgqueue(const uint8_t * buffer_addr,uint16_t buffer_size)61 int32_t test_suite_write_msgqueue(const uint8_t *buffer_addr, uint16_t buffer_size)
62 {
63     return osal_msg_queue_write_copy(g_test_suite_msg_queue_id, (void *)buffer_addr, \
64                                      (uint32_t)buffer_size, 0);
65 }
66 
test_suite_receive_msgqueue(char * buffer_addr,uint32_t * buffer_size)67 static int32_t test_suite_receive_msgqueue(char *buffer_addr, uint32_t *buffer_size)
68 {
69     return osal_msg_queue_read_copy(g_test_suite_msg_queue_id, (void *)buffer_addr, \
70                                     buffer_size, TEST_SUITE_QUEUE_DELAY);
71 }
72 #ifdef CONFIG_TESTSUITE_SUPPORT_MULTI_CORE
test_suite_create_cmd_queue(void)73 void test_suite_create_cmd_queue(void)
74 {
75     if (osal_msg_queue_create("test_suite_cmd_queue", TEST_SUITE_MSG_QUEUE_LEN, \
76         (unsigned long *)&g_test_suite_cmd_queue_id, 0, TEST_SUITE_MSG_QUEUE_MAX_SIZE) != OSAL_SUCCESS) {
77         test_suite_log_string("Testsuite message queue create failed!\n");
78     }
79 }
80 
test_suite_delete_cmd_queue(void)81 void test_suite_delete_cmd_queue(void)
82 {
83     osal_msg_queue_delete(g_test_suite_cmd_queue_id);
84 }
85 
test_suite_write_cmd_queue(const uint8_t * buffer_addr,uint16_t buffer_size)86 int32_t test_suite_write_cmd_queue(const uint8_t *buffer_addr, uint16_t buffer_size)
87 {
88     return osal_msg_queue_write_copy(g_test_suite_cmd_queue_id, (void *)buffer_addr, \
89                                      (uint32_t)buffer_size, 0);
90 }
91 
test_suite_receive_cmd_queue(char * buffer_addr,uint32_t * buffer_size)92 int32_t test_suite_receive_cmd_queue(char *buffer_addr, uint32_t *buffer_size)
93 {
94     return osal_msg_queue_read_copy(g_test_suite_cmd_queue_id, (void *)buffer_addr, \
95                                     buffer_size, TEST_SUITE_QUEUE_DELAY);
96 }
97 #endif
98 
test_suite_task_create(void)99 static void test_suite_task_create(void)
100 {
101     g_test_suite_task_id = osal_kthread_create((osal_kthread_handler)test_suite_task_entry, \
102                                                NULL, "test_suite_thread", CONFIG_TEST_SUITE_TASK_STACK_SIZE);
103     if (g_test_suite_task_id ==  NULL) {
104         test_suite_log_string("osal_kthread_create test_suite_task FAILED\n");
105     }
106 }
107 
test_suite_alloc(uint32_t len,char ** buf)108 int32_t test_suite_alloc(uint32_t len, char **buf)
109 {
110     *buf = (char *)osal_kmalloc(len, OSAL_GFP_KERNEL);
111     if (*buf == NULL) {
112         test_suite_log_string("Testsuite alloc commands buffer failed!\n");
113         return OSAL_FAILURE;
114     }
115     return OSAL_SUCCESS;
116 }
117 
test_suite_task_init(void)118 void test_suite_task_init(void)
119 {
120     test_suite_task_set_exit(false);
121     test_suite_create_msgqueue();
122 #ifdef CONFIG_TESTSUITE_SUPPORT_MULTI_CORE
123     test_suite_create_cmd_queue();
124     ipc_register_handler(IPC_ACTION_TS_MESSAGE_CNF, test_suite_commands_ipc_message_handler);
125 #endif
126     test_suite_task_create();
127 }
128 
test_suite_task_destroy(void)129 void test_suite_task_destroy(void)
130 {
131     test_suite_delete_msgqueue();
132     osal_kthread_destroy(g_test_suite_task_id, 0);
133 }
134 
test_suite_task_set_exit(bool status)135 void test_suite_task_set_exit(bool status)
136 {
137     g_exit_test_suite_task = status;
138 }
139 
test_suite_task_is_exit(void)140 bool test_suite_task_is_exit(void)
141 {
142     return g_exit_test_suite_task;
143 }
144 
test_suite_process_input(char * char_buf,uint16_t length)145 static void test_suite_process_input(char *char_buf, uint16_t length)
146 {
147     char received_char;
148     char *string = char_buf;
149     uint16_t len = length;
150 
151     /* process every character */
152     while (len > 0) {
153         received_char = *(string++);
154         test_suite_console_process_char(received_char);
155         len--;
156     }
157 }
158 
test_suite_rx_buf_init(char * buffer_addr,uint32_t * buffer_size)159 static void test_suite_rx_buf_init(char *buffer_addr, uint32_t *buffer_size)
160 {
161     *buffer_size = TEST_SUITE_RECEIVE_MSGQUEUE_BUFFER_SIZE;
162     (void)memset_s(buffer_addr, *buffer_size, 0, *buffer_size);
163 }
164 
165 #ifdef SUPPORT_AUDIO_LIEYIN_TOOL
test_suite_task_entry(void * data)166 static int32_t test_suite_task_entry(void *data)
167 {
168     unused(data);
169 
170     test_suite_console_enable();
171 
172     for (; ;) {
173         if (test_suite_task_is_exit() == true) {
174             break;
175         }
176 
177         uapi_watchdog_kick();
178 
179         uint32_t rx_length = CONFIG_TEST_SUITE_COMMAND_BUFFER_SIZE + 1;
180         test_suite_receive_msgqueue(g_test_suite_command_buffer_array, &rx_length);
181         if (rx_length == 0) {
182             continue;
183         }
184 
185         test_suite_console_disable();
186 
187         audio_lieyin_command_receive(g_test_suite_command_buffer_array, rx_length);
188         rx_length = CONFIG_TEST_SUITE_COMMAND_BUFFER_SIZE + 1;
189         memset_s(g_test_suite_command_buffer_array, rx_length, 0, rx_length);
190 
191         test_suite_console_enable();
192     }
193 
194     return OSAL_FAILURE;
195 }
196 #elif defined(CONFIG_TESTSUITE_IPC)
test_suite_task_entry(void * data)197 static int32_t test_suite_task_entry(void *data)
198 {
199     unused(data);
200     for (;;) {
201         if (test_suite_task_is_exit() == true) {
202             break;
203         }
204         char *rx_buf = g_test_suite_command_buffer_array;
205         uint32_t rx_length = TEST_SUITE_RECEIVE_MSGQUEUE_BUFFER_SIZE + 1;
206         test_suite_rx_buf_init(rx_buf, &rx_length);
207         test_suite_receive_msgqueue(rx_buf, &rx_length);
208         test_suite_function_execute_command(rx_buf);
209     }
210 }
211 #else
212 
test_suite_task_entry(void * data)213 static int32_t test_suite_task_entry(void *data)
214 {
215     unused(data);
216 
217     volatile char * const test_suite_command_buffer = g_test_suite_command_buffer_array;
218     test_suite_console_register_command_buffer((char *)test_suite_command_buffer);
219 
220     for (; ;) {
221         if (test_suite_task_is_exit() == true) {
222             break;
223         }
224         test_suite_console_enable();
225 
226         char *rx_buf;
227         uint32_t rx_length = TEST_SUITE_RECEIVE_MSGQUEUE_BUFFER_SIZE;
228         if (test_suite_alloc(rx_length, &rx_buf) != OSAL_SUCCESS) {
229             return OSAL_FAILURE;
230         }
231 
232         while (test_suite_console_is_enabled()) {
233             test_suite_rx_buf_init(rx_buf, &rx_length);
234             test_suite_receive_msgqueue(rx_buf, &rx_length);
235             test_suite_process_input(rx_buf, (uint16_t)rx_length);
236         }
237         osal_kfree(rx_buf);
238         test_suite_commands_prase((char *)test_suite_command_buffer);
239     }
240     return OSAL_FAILURE;
241 }
242 #endif
243 
test_suite_nonos_loop(void)244 void test_suite_nonos_loop(void)
245 {
246     static int flag = 0;
247     static volatile char * const test_suite_command_buffer = g_test_suite_command_buffer_array;
248 
249     if (flag == 0) {
250         test_suite_console_register_command_buffer((char *)test_suite_command_buffer);
251         flag = 1;
252     }
253 
254     if (test_suite_task_is_exit() == true) {
255         return;
256     }
257     test_suite_console_enable();
258 
259     char *rx_buf;
260     uint32_t rx_length = TEST_SUITE_RECEIVE_MSGQUEUE_BUFFER_SIZE;
261     if (test_suite_alloc(rx_length, &rx_buf) != OSAL_SUCCESS) {
262         return;
263     }
264 
265     while (test_suite_console_is_enabled()) {
266         test_suite_rx_buf_init(rx_buf, &rx_length);
267         test_suite_receive_msgqueue(rx_buf, &rx_length);
268         test_suite_process_input(rx_buf, (uint16_t)rx_length);
269     }
270     osal_kfree(rx_buf);
271     test_suite_commands_prase((char *)test_suite_command_buffer);
272 }
273 
274