xref: /OK3568_Linux_fs/external/security/librkcrypto/test/test_crypto_mem.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
3  */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include "rkcrypto_common.h"
8 #include "rkcrypto_core.h"
9 #include "rkcrypto_mem.h"
10 
11 #define BLOCK_SIZE	512 * 1024
12 #define MAX_COUNT	1024
13 
test_crypto_mem(void)14 int test_crypto_mem(void)
15 {
16 	int32_t count;
17 	rk_crypto_mem *mem[MAX_COUNT];
18 
19 	if (rk_crypto_init()) {
20 		printf("rk_crypto_init error!\n");
21 		return -1;
22 	}
23 
24 	for (count = 0; count < MAX_COUNT; count ++) {
25 		mem[count] = rk_crypto_mem_alloc(BLOCK_SIZE);
26 		if (!mem[count]) {
27 			usleep(300); // wait for kernel log print to avoid confusion
28 			printf("Crypto mem alloc: maximum size is [%d KB * %d].\n",
29 			       (BLOCK_SIZE / 1024), count);
30 			break;
31 		}
32 	}
33 
34 	if (count == MAX_COUNT) {
35 		printf("Crypto mem alloc: successfully alloc [%d KB * %d] size.\n",
36 		       (BLOCK_SIZE / 1024), count);
37 		printf("You and can alloc for more. Change '#define MAX_COUNT' to test larger size.\n");
38 	}
39 
40 	for (count = count - 1; count >= 0; count --) {
41 		rk_crypto_mem_free(mem[count]);
42 	}
43 
44 	rk_crypto_deinit();
45 
46 	return 0;
47 }
48