1 /*
2 * Copyright (c) 2024, Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8
9 #define STACK_SIZE 1024
10 #define NUM_THREADS (CONFIG_MP_MAX_NUM_CPUS * 2)
11
12 K_THREAD_STACK_ARRAY_DEFINE(thread_stack, NUM_THREADS, STACK_SIZE);
13
14 struct k_thread thread[NUM_THREADS];
15
thread_entry(void * p1,void * p2,void * p3)16 static void thread_entry(void *p1, void *p2, void *p3)
17 {
18 uint32_t i;
19 uint32_t j;
20 uint32_t index = (uint32_t)(uintptr_t)p1;
21 uint8_t init_regs[8 * 16] __aligned(16) = {0};
22 uint8_t value_regs[8 * 16] __aligned(16) = {0};
23
24 if (index < (NUM_THREADS - 1)) {
25 k_thread_start(&thread[index + 1]);
26 }
27
28 /* Initialize the AE regs with known values */
29
30 for (i = 0; i < sizeof(init_regs); i++) {
31 init_regs[i] = (index & 0xff);
32 }
33
34 extern void hifi_set(uint8_t *aed_buffer);
35 extern void hifi_get(uint8_t *aed_buffer);
36
37 hifi_set(init_regs);
38
39 for (i = 0; i < 10; i++) {
40 k_yield(); /* Switch to a new thread */
41
42 /*
43 * Verify that the HiFi AE regs have not been corrupted
44 * by another thread.
45 */
46
47 hifi_get(value_regs);
48
49 for (j = 0; j < sizeof(value_regs); j++) {
50 zassert_equal(value_regs[j], init_regs[j],
51 "Expected %u, got %u\n",
52 init_regs[j], value_regs[j]);
53 }
54 }
55 }
56
ZTEST(hifi,test_register_sanity)57 ZTEST(hifi, test_register_sanity)
58 {
59 int priority;
60 uint32_t i;
61
62 priority = k_thread_priority_get(k_current_get());
63
64 /* Create twice as many threads as there are CPUs */
65
66 for (i = 0; i < NUM_THREADS; i++) {
67 k_thread_create(&thread[i], thread_stack[i], STACK_SIZE,
68 thread_entry, (void *)(uintptr_t)i, NULL, NULL,
69 priority - 1, 0, K_FOREVER);
70
71
72 }
73
74 k_thread_start(&thread[0]);
75 }
76
77 ZTEST_SUITE(hifi, NULL, NULL, NULL, NULL, NULL);
78