forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_mocks.c
More file actions
507 lines (416 loc) · 8.61 KB
/
common_mocks.c
File metadata and controls
507 lines (416 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019-2020 Intel Corporation. All rights reserved.
//
// Author: Jakub Dabek <jakub.dabek@linux.intel.com>
// Author: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
#include <errno.h>
#include <rtos/alloc.h>
#include <rtos/timer.h>
#include <sof/lib/mm_heap.h>
#include <sof/ipc/topology.h>
#include <sof/ipc/msg.h>
#include <sof/ipc/driver.h>
#include <sof/schedule/edf_schedule.h>
#include <sof/schedule/ll_schedule.h>
#include <sof/schedule/schedule.h>
#include <rtos/spinlock.h>
#include <sof/audio/component_ext.h>
#include <rtos/clk.h>
#include <sof/lib/notifier.h>
#include <rtos/wait.h>
#include <arch/lib/cpu.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#define WEAK __attribute__((weak))
/* global contexts */
WEAK struct ipc *_ipc;
#ifndef __ZEPHYR__
WEAK struct timer *platform_timer;
#endif
WEAK struct schedulers *schedulers;
WEAK struct sof sof;
WEAK struct tr_ctx buffer_tr;
WEAK struct tr_ctx comp_tr;
WEAK struct tr_ctx ipc_tr;
int host_trace_level = 1;
void WEAK *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes,
uint32_t alignment)
{
(void)flags;
(void)caps;
return calloc(bytes, 1);
}
void WEAK *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps,
size_t bytes)
{
(void)zone;
(void)flags;
(void)caps;
return calloc(bytes, 1);
}
void WEAK *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps,
size_t bytes, size_t old_bytes, uint32_t alignment)
{
(void)flags;
(void)caps;
(void)old_bytes;
return realloc(ptr, bytes);
}
void WEAK rfree(void *ptr)
{
free(ptr);
}
int WEAK memcpy_s(void *dest, size_t dest_size,
const void *src, size_t count)
{
if (!dest || !src)
return -EINVAL;
if ((dest >= src && (char *)dest < ((char *)src + count)) ||
(src >= dest && (char *)src < ((char *)dest + dest_size)))
return -EINVAL;
if (count > dest_size)
return -EINVAL;
memcpy(dest, src, count);
return 0;
}
int WEAK memset_s(void *dest, size_t size1,
int c, size_t size2)
{
if (!dest)
return -EINVAL;
memset(dest, c, size1);
return 0;
}
int WEAK rstrlen(const char *s)
{
return strlen(s);
}
void WEAK __panic(uint32_t p, char *filename, uint32_t linenum)
{
fail_msg("panic: %s:%d (code 0x%x)\n", filename, linenum, p);
exit(EXIT_FAILURE);
}
#if CONFIG_TRACE
void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count,
va_list args)
{
(void) send_atomic;
(void) log_entry;
(void) ctx;
(void) lvl;
(void) id_1;
(void) id_2;
(void) arg_count;
(void) args;
}
void WEAK _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
const struct tr_ctx *ctx, const uint32_t lvl,
uint32_t id_1, uint32_t id_2, int arg_count, ...)
{
}
void WEAK trace_flush_dma_to_mbox(void)
{
}
#endif
#if CONFIG_LIBRARY
volatile void *task_context_get(void);
#endif
volatile void * WEAK task_context_get(void)
{
return NULL;
}
#ifndef __ZEPHYR__
uint32_t WEAK _k_spin_lock_irq(struct k_spinlock *lock)
{
(void)lock;
return 0;
}
void WEAK _k_spin_unlock_irq(struct k_spinlock *lock, uint32_t flags, int line)
{
(void)lock;
(void)flags;
(void)line;
}
#endif
uint64_t WEAK platform_timer_get(struct timer *timer)
{
(void)timer;
return 0;
}
#if !CONFIG_LIBRARY
uint64_t WEAK arch_timer_get_system(struct timer *timer)
{
(void)timer;
return 0;
}
#endif
#if CONFIG_LIBRARY
void WEAK arch_dump_regs_a(void *dump_buf);
#endif
void WEAK arch_dump_regs_a(void *dump_buf)
{
(void)dump_buf;
}
void WEAK heap_trace_all(int force)
{
(void)force;
}
void WEAK ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
{
(void)msg;
(void)data;
(void)high_priority;
}
int WEAK platform_ipc_init(struct ipc *ipc)
{
return 0;
}
enum task_state WEAK ipc_platform_do_cmd(struct ipc *ipc)
{
return 0;
}
void WEAK ipc_platform_complete_cmd(struct ipc *ipc)
{
}
#if !CONFIG_LIBRARY
int WEAK ipc_platform_send_msg(const struct ipc_msg *msg)
{
return 0;
}
void WEAK wait_delay(uint64_t number_of_clks)
{
}
void WEAK wait_delay_ms(uint64_t ms)
{
}
void WEAK wait_delay_us(uint64_t us)
{
}
void WEAK xthal_icache_region_invalidate(void *addr, unsigned size)
{
}
void WEAK xthal_dcache_region_invalidate(void *addr, unsigned size)
{
}
void WEAK xthal_dcache_region_writeback(void *addr, unsigned size)
{
}
void WEAK xthal_dcache_region_writeback_inv(void *addr, unsigned size)
{
}
#endif
struct sof * WEAK sof_get(void)
{
return &sof;
}
struct schedulers ** WEAK arch_schedulers_get(void)
{
return &schedulers;
}
int WEAK schedule_task_init(struct task *task,
const struct sof_uuid_entry *uid, uint16_t type,
uint16_t priority, enum task_state (*run)(void *data),
void *data, uint16_t core, uint32_t flags)
{
(void)task;
(void)uid;
(void)type;
(void)priority;
(void)run;
(void)data;
(void)core;
(void)flags;
return 0;
}
int WEAK schedule_task_init_ll(struct task *task,
const struct sof_uuid_entry *uid, uint16_t type,
uint16_t priority, enum task_state (*run)(void *data),
void *data, uint16_t core, uint32_t flags)
{
return 0;
}
void WEAK platform_host_timestamp(struct comp_dev *host,
struct sof_ipc_stream_posn *posn)
{
(void)host;
(void)posn;
}
void WEAK platform_dai_timestamp(struct comp_dev *dai,
struct sof_ipc_stream_posn *posn)
{
(void)dai;
(void)posn;
}
struct ipc_comp_dev *WEAK ipc_get_comp_dev(struct ipc *ipc, uint16_t type, uint32_t id)
{
(void)ipc;
(void)type;
(void)id;
return NULL;
}
struct ipc_comp_dev *WEAK ipc_get_comp_by_ppl_id(struct ipc *ipc, uint16_t type,
uint32_t ppl_id, uint32_t ignore_remote)
{
(void)ipc;
(void)type;
(void)ppl_id;
(void)ignore_remote;
return NULL;
}
uint32_t WEAK crc32(uint32_t base, const void *data, uint32_t bytes)
{
return 0;
}
int WEAK comp_set_state(struct comp_dev *dev, int cmd)
{
return 0;
}
#ifndef __ZEPHYR__
uint64_t WEAK clock_ms_to_ticks(int clock, uint64_t ms)
{
(void)clock;
(void)ms;
return 0;
}
uint64_t WEAK clock_us_to_ticks(int clock, uint64_t us)
{
(void)clock;
(void)us;
return 0;
}
uint64_t WEAK clock_ns_to_ticks(int clock, uint64_t us)
{
(void)clock;
(void)us;
return 0;
}
#endif /* __ZEPHYR__ */
#if CONFIG_MULTICORE && !CONFIG_LIBRARY
int WEAK idc_send_msg(struct idc_msg *msg, uint32_t mode)
{
(void)msg;
(void)mode;
return 0;
}
int WEAK arch_cpu_is_core_enabled(int id)
{
return 0;
}
#endif
#if CONFIG_LIBRARY
/* enable trace by default in testbench */
int WEAK test_bench_trace = 1;
int WEAK debug;
/* ... but not always in unit tests */
#if CONFIG_TRACE
/* look up subsystem class name from table */
char * WEAK get_trace_class(uint32_t trace_class)
{
(void)trace_class;
/* todo: trace class is deprecated,
* uuid should be used only
*/
return "unknown";
}
#endif
uint8_t * WEAK get_library_mailbox(void)
{
return NULL;
}
#endif
/*
* GCC xtensa requires us to fake some of the standard C library calls
* as this is "bare metal" support (i.e. with no host OS implementation
* methods for these calls).
*
* None of these IO calls are used in the Mocks for testing.
*/
#if !CONFIG_LIBRARY && !__XCC__
void _exit(int status);
unsigned int _getpid_r(void);
int _kill_r(int id, int sig);
void _sbrk_r(int id);
int _fstat_r(int fd, void *buf);
int _open_r(const char *pathname, int flags);
int _write_r(int fd, char *buf, int count);
int _read_r(int fd, char *buf, int count);
int _lseek_r(int fd, int count);
int _close_r(int fd);
int _isatty(int fd);
void _exit(int status)
{
while (1);
}
unsigned int _getpid_r(void)
{
return 0;
}
int _kill_r(int id, int sig)
{
return 0;
}
void _sbrk_r(int id)
{
}
int _fstat_r(int fd, void *buf)
{
return 0;
}
int _open_r(const char *pathname, int flags)
{
return 0;
}
int _write_r(int fd, char *buf, int count)
{
return 0;
}
int _read_r(int fd, char *buf, int count)
{
return 0;
}
int _lseek_r(int fd, int count)
{
return 0;
}
int _close_r(int fd)
{
return 0;
}
int _isatty(int fd)
{
return 0;
}
/* TODO: work around some linker warnings. Both will need fixed for qemu. */
int _start = 0;
int *__errno _PARAMS ((void));
/*
* TODO: Math support for GCC xtensa requires a little more work to use the
* newlib versions. This is just to build test only today !
*/
double __floatsidf(int i);
double __divdf3(double a, double b);
int __ledf2(double a, double b);
int __eqdf2(double a, double b);
double __floatsidf(int i)
{
return i;
}
double __divdf3(double a, double b)
{
return a / b;
}
int WEAK __ledf2(double a, double b)
{
return a <= b ? 0 : 1;
}
int WEAK __eqdf2(double a, double b)
{
return a == b ? 0 : 1;
}
#endif