66// generative artificial intelligence solutions.
77
88#include <zephyr/ztest.h>
9+ #include <sof/common.h>
910#include <sof/lib/fast-get.h>
1011#include <stdlib.h>
1112
@@ -71,20 +72,33 @@ void *__wrap_rzalloc(uint32_t flags, size_t bytes)
7172 return ret ;
7273}
7374
74- void * __wrap_rmalloc (uint32_t flags , size_t bytes )
75+ void __wrap_rfree (void * ptr )
76+ {
77+ free (ptr );
78+ }
79+
80+ struct k_heap ;
81+ void * __wrap_sof_heap_alloc (struct k_heap * heap , uint32_t flags , size_t bytes , size_t alignment )
7582{
7683 void * ret ;
84+
7785 (void )flags ;
86+ (void )heap ;
7887
79- ret = malloc (bytes );
88+ if (alignment )
89+ ret = aligned_alloc (alignment , ALIGN_UP (bytes , alignment ));
90+ else
91+ ret = malloc (bytes );
8092
8193 zassert_not_null (ret , "Memory allocation should not fail" );
8294
8395 return ret ;
8496}
8597
86- void __wrap_rfree ( void * ptr )
98+ void __wrap_sof_heap_free ( struct k_heap * heap , void * ptr )
8799{
100+ (void )heap ;
101+
88102 free (ptr );
89103}
90104
@@ -98,13 +112,13 @@ ZTEST(fast_get_suite, test_simple_fast_get_put)
98112{
99113 const void * ret ;
100114
101- ret = fast_get (testdata [0 ], sizeof (testdata [0 ]));
115+ ret = fast_get (NULL , testdata [0 ], sizeof (testdata [0 ]));
102116
103117 zassert_not_null (ret , "fast_get should return valid pointer" );
104118 zassert_mem_equal (ret , testdata [0 ], sizeof (testdata [0 ]),
105119 "Returned data should match original data" );
106120
107- fast_put (ret );
121+ fast_put (NULL , ret );
108122}
109123
110124/**
@@ -117,16 +131,16 @@ ZTEST(fast_get_suite, test_fast_get_size_missmatch_test)
117131{
118132 const void * ret [2 ];
119133
120- ret [0 ] = fast_get (testdata [0 ], sizeof (testdata [0 ]));
134+ ret [0 ] = fast_get (NULL , testdata [0 ], sizeof (testdata [0 ]));
121135
122136 zassert_not_null (ret [0 ], "First fast_get should succeed" );
123137 zassert_mem_equal (ret [0 ], testdata [0 ], sizeof (testdata [0 ]),
124138 "Returned data should match original data" );
125139
126- ret [1 ] = fast_get (testdata [0 ], sizeof (testdata [0 ]) + 1 );
140+ ret [1 ] = fast_get (NULL , testdata [0 ], sizeof (testdata [0 ]) + 1 );
127141 zassert_is_null (ret [1 ], "fast_get with different size should return NULL" );
128142
129- fast_put (ret [0 ]);
143+ fast_put (NULL , ret [0 ]);
130144}
131145
132146/**
@@ -141,14 +155,14 @@ ZTEST(fast_get_suite, test_over_32_fast_gets_and_puts)
141155 int i ;
142156
143157 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
144- copy [i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
158+ copy [i ] = fast_get (NULL , testdata [i ], sizeof (testdata [0 ]));
145159
146160 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
147161 zassert_mem_equal (copy [i ], testdata [i ], sizeof (testdata [0 ]),
148162 "Data at index %d should match original" , i );
149163
150164 for (i = 0 ; i < ARRAY_SIZE (copy ); i ++ )
151- fast_put (copy [i ]);
165+ fast_put (NULL , copy [i ]);
152166}
153167
154168/**
@@ -164,10 +178,10 @@ ZTEST(fast_get_suite, test_fast_get_refcounting)
164178 int i ;
165179
166180 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
167- copy [0 ][i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
181+ copy [0 ][i ] = fast_get (NULL , testdata [i ], sizeof (testdata [0 ]));
168182
169183 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
170- copy [1 ][i ] = fast_get (testdata [i ], sizeof (testdata [0 ]));
184+ copy [1 ][i ] = fast_get (NULL , testdata [i ], sizeof (testdata [0 ]));
171185
172186 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
173187 zassert_equal_ptr (copy [0 ][i ], copy [1 ][i ],
@@ -179,7 +193,7 @@ ZTEST(fast_get_suite, test_fast_get_refcounting)
179193
180194 /* Release first set of references */
181195 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
182- fast_put (copy [0 ][i ]);
196+ fast_put (NULL , copy [0 ][i ]);
183197
184198 /* Data should still be valid through second set of references */
185199 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
@@ -188,7 +202,7 @@ ZTEST(fast_get_suite, test_fast_get_refcounting)
188202
189203 /* Release second set of references */
190204 for (i = 0 ; i < ARRAY_SIZE (copy [0 ]); i ++ )
191- fast_put (copy [1 ][i ]);
205+ fast_put (NULL , copy [1 ][i ]);
192206}
193207
194208/**
0 commit comments