44//
55// Author: Jyri Sarha <jyri.sarha@linux.intel.com>
66
7+ #include "../../util.h"
8+ #include "../../audio/module_adapter.h"
9+
10+ #include <sof/audio/module_adapter/module/generic.h>
11+ #include <sof/audio/component_ext.h>
12+ #include <sof/audio/format.h>
713#include <sof/lib/fast-get.h>
814#include <rtos/sof.h>
915#include <rtos/alloc.h>
1016#include <sof/lib/mm_heap.h>
1117#include <sof/lib/memory.h>
1218#include <sof/common.h>
19+ #include <volume/volume.h>
1320
1421#include <stdarg.h>
1522#include <stddef.h>
@@ -66,65 +73,116 @@ static const int testdata[33][100] = {
6673 { 33 },
6774};
6875
76+ struct test_data {
77+ struct comp_dev * dev ;
78+ struct processing_module * mod ;
79+ struct comp_data * cd ;
80+ struct processing_module_test_data * vol_state ;
81+ };
82+
83+ struct test_data _td ;
84+
85+ static int setup (void * * state )
86+ {
87+ struct test_data * td = & _td ;
88+ struct module_data * md ;
89+ struct vol_data * cd ;
90+
91+ /* allocate new state */
92+ td -> vol_state = test_malloc (sizeof (struct processing_module_test_data ));
93+ td -> vol_state -> num_sources = 1 ;
94+ td -> vol_state -> num_sinks = 1 ;
95+ module_adapter_test_setup (td -> vol_state );
96+
97+ /* allocate and set new data */
98+ cd = test_malloc (sizeof (* cd ));
99+ md = & td -> vol_state -> mod -> priv ;
100+ md -> private = cd ;
101+ cd -> is_passthrough = false;
102+ td -> dev = td -> vol_state -> mod -> dev ;
103+ td -> mod = td -> vol_state -> mod ;
104+
105+ /* malloc memory to store current volume 4 times to ensure the address
106+ * is 8-byte aligned for multi-way xtensa intrinsic operations.
107+ */
108+ const size_t vol_size = sizeof (int32_t ) * SOF_IPC_MAX_CHANNELS * 4 ;
109+
110+ cd -> vol = test_malloc (vol_size );
111+ cd -> ramp_type = SOF_VOLUME_LINEAR ;
112+ * state = td ;
113+
114+ return 0 ;
115+ }
116+
117+ static int teardown (void * * state )
118+ {
119+ struct test_data * td = & _td ;
120+ struct vol_data * cd = module_get_private_data (td -> vol_state -> mod );
121+
122+ test_free (cd -> vol );
123+ test_free (cd );
124+ module_adapter_test_free (td -> vol_state );
125+ test_free (td -> vol_state );
126+
127+ return 0 ;
128+ }
129+
69130static void test_simple_fast_get_put (void * * state )
70131{
132+ struct test_data * td = * ((struct test_data * * )state );
71133 const void * ret ;
72134
73- (void )state ; /* unused */
74-
75- ret = fast_get (testdata [0 ], sizeof (testdata [0 ]));
135+ ret = fast_get (td -> mod , testdata [0 ], sizeof (testdata [0 ]));
76136
77137 assert (ret );
78138 assert (!memcmp (ret , testdata [0 ], sizeof (testdata [0 ])));
79139
80- fast_put (ret );
140+ fast_put (td -> mod , ret );
81141}
82142
83143static void test_fast_get_size_missmatch_test (void * * state )
84144{
145+ struct test_data * td = * ((struct test_data * * )state );
85146 const void * ret [2 ];
86147
87- (void )state ; /* unused */
88-
89- ret [0 ] = fast_get (testdata [0 ], sizeof (testdata [0 ]));
148+ ret [0 ] = fast_get (td -> mod , testdata [0 ], sizeof (testdata [0 ]));
90149
91150 assert (ret [0 ]);
92151 assert (!memcmp (ret [0 ], testdata [0 ], sizeof (testdata [0 ])));
93152
94- ret [1 ] = fast_get (testdata [0 ], sizeof (testdata [0 ]) + 1 );
153+ /* this test is designed to test size mismatch handling */
154+ ret [1 ] = fast_get (td -> mod , testdata [0 ], sizeof (testdata [0 ]) + 1 );
95155 assert (!ret [1 ]);
96-
97- fast_put (ret );
156+ fast_put (td -> mod , ret );
98157}
99158
100159static void test_over_32_fast_gets_and_puts (void * * state )
101160{
161+ struct test_data * td = * ((struct test_data * * )state );
102162 const void * copy [ARRAY_SIZE (testdata )];
103163 int i ;
104164
105- (void )state ; /* unused */
106-
107165 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
108- copy [i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
166+ copy [i ] = fast_get (td -> mod , testdata [i ], sizeof (testdata [i ]));
109167
110168 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
111- assert (!memcmp (copy [i ], testdata [i ], sizeof (testdata [0 ])));
169+ assert (!memcmp (copy [i ], testdata [i ], sizeof (testdata [i ])));
112170
113171 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
114- fast_put (copy [i ]);
172+ fast_put (td -> mod , copy [i ]);
115173}
116174
117175static void test_fast_get_refcounting (void * * state )
118176{
177+ struct test_data * td = * ((struct test_data * * )state );
119178 const void * copy [2 ][ARRAY_SIZE (testdata )];
120179 int i ;
121- (void )state ; /* unused */
122180
123181 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
124- copy [0 ][i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
182+ copy [0 ][i ] = fast_get (td -> mod , testdata [i ], sizeof (testdata [0 ]));
125183
126184 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
127- copy [1 ][i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
185+ copy [1 ][i ] = fast_get (td -> mod , testdata [i ], sizeof (testdata [0 ]));
128186
129187 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
130188 assert (copy [0 ][i ] == copy [1 ][i ]);
@@ -133,18 +191,18 @@ static void test_fast_get_refcounting(void **state)
133191 assert (!memcmp (copy [0 ][i ], testdata [i ], sizeof (testdata [0 ])));
134192
135193 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
136- fast_put (copy [0 ][i ]);
194+ fast_put (td -> mod , copy [0 ][i ]);
137195
138196 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
139197 assert (!memcmp (copy [1 ][i ], testdata [i ], sizeof (testdata [0 ])));
140198
141199 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
142- fast_put (copy [1 ][i ]);
200+ fast_put (td -> mod , copy [1 ][i ]);
143201}
144202
145203int main (void )
146204{
147- const struct CMUnitTest tests [] = {
205+ struct CMUnitTest tests [] = {
148206 cmocka_unit_test (test_simple_fast_get_put ),
149207 cmocka_unit_test (test_fast_get_size_missmatch_test ),
150208 cmocka_unit_test (test_over_32_fast_gets_and_puts ),
@@ -153,7 +211,7 @@ int main(void)
153211
154212 cmocka_set_message_output (CM_OUTPUT_TAP );
155213
156- return cmocka_run_group_tests (tests , NULL , NULL );
214+ return cmocka_run_group_tests (tests , setup , teardown );
157215}
158216
159217void * __wrap_rzalloc (uint32_t flags , size_t bytes );
0 commit comments