@@ -288,3 +288,76 @@ test_mixed_obj_to_hmu(void **state)
288288
289289 mem_allocator_destroy (allocator );
290290}
291+
292+ /* Test: Many aligned allocations */
293+ static void
294+ test_aligned_alloc_many (void * * state )
295+ {
296+ mem_allocator_t allocator ;
297+ char heap_buf [512 * 1024 ];
298+ void * ptrs [100 ];
299+ int count = 0 ;
300+
301+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
302+ assert_non_null (allocator );
303+
304+ /* Allocate as many as possible */
305+ for (int i = 0 ; i < 100 ; i ++ ) {
306+ int align = (i % 4 == 0 ) ? 64 : 32 ;
307+ ptrs [i ] = mem_allocator_malloc_aligned (allocator , align * 2 , align );
308+ if (ptrs [i ]) {
309+ assert_true (is_aligned (ptrs [i ], align ));
310+ count ++ ;
311+ } else {
312+ break ;
313+ }
314+ }
315+
316+ assert_true (count > 10 ); /* At least some should succeed */
317+
318+ /* Free all */
319+ for (int i = 0 ; i < count ; i ++ ) {
320+ mem_allocator_free (allocator , ptrs [i ]);
321+ }
322+
323+ mem_allocator_destroy (allocator );
324+ }
325+
326+ /* Test: Many mixed allocations */
327+ static void
328+ test_mixed_alloc_many (void * * state )
329+ {
330+ mem_allocator_t allocator ;
331+ char heap_buf [512 * 1024 ];
332+ void * ptrs [200 ];
333+ int count = 0 ;
334+
335+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
336+ assert_non_null (allocator );
337+
338+ /* Alternate normal and aligned */
339+ for (int i = 0 ; i < 200 ; i ++ ) {
340+ if (i % 2 == 0 ) {
341+ /* Normal allocation */
342+ ptrs [i ] = mem_allocator_malloc (allocator , 64 );
343+ } else {
344+ /* Aligned allocation */
345+ ptrs [i ] = mem_allocator_malloc_aligned (allocator , 64 , 32 );
346+ }
347+
348+ if (ptrs [i ]) {
349+ count ++ ;
350+ } else {
351+ break ;
352+ }
353+ }
354+
355+ assert_true (count > 20 );
356+
357+ /* Free in reverse order */
358+ for (int i = count - 1 ; i >= 0 ; i -- ) {
359+ mem_allocator_free (allocator , ptrs [i ]);
360+ }
361+
362+ mem_allocator_destroy (allocator );
363+ }
0 commit comments