1 /*
2  * Copyright (c) 2025 BayLibre SAS
3  *   *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "syskernel.h"
8 
9 static void *malloc_array[NUMBER_OF_LOOPS];
10 
do_malloc(int loops)11 static void do_malloc(int loops)
12 {
13 	int i;
14 
15 	for (i = 0; i < loops; i++) {
16 		malloc_array[i] = k_malloc(1);
17 	}
18 }
19 
do_free(int loops)20 static void do_free(int loops)
21 {
22 	int i;
23 
24 	for (i = 0; i < loops; i++) {
25 		k_free(malloc_array[i]);
26 	}
27 }
28 
malloc_test(void)29 int malloc_test(void)
30 {
31 	uint32_t t;
32 	int return_value = 0;
33 
34 	fprintf(output_file, sz_test_case_fmt,
35 		"malloc #1");
36 	fprintf(output_file, sz_description,
37 		"\n\tk_malloc");
38 	printf(sz_test_start_fmt);
39 
40 	t = BENCH_START();
41 	do_malloc(number_of_loops);
42 	t = TIME_STAMP_DELTA_GET(t);
43 
44 	return_value += check_result(number_of_loops, t);
45 
46 	fprintf(output_file, sz_test_case_fmt,
47 		"malloc #2");
48 	fprintf(output_file, sz_description,
49 		"\n\tk_free");
50 	printf(sz_test_start_fmt);
51 
52 	t = BENCH_START();
53 	do_free(number_of_loops);
54 	t = TIME_STAMP_DELTA_GET(t);
55 
56 	return_value += check_result(number_of_loops, t);
57 
58 	return return_value;
59 }
60