1 /*
2 * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include "rkcrypto_random.h"
8 #include "test_cipher.h"
9 #include "test_hash.h"
10 #include "test_rsa.h"
11 #include "test_stress.h"
12 #include "test_utils.h"
13
14 typedef RK_RES (*test_func)(int verbose);
15
16 struct test_stress_item {
17 test_func func;
18 const char *name;
19 };
20
21 #define DEFINE_STRESS_ITEM(_func) {\
22 .func = _func, \
23 .name = #_func, \
24 }
25
26 struct test_stress_item test_stress_tbl[] = {
27 DEFINE_STRESS_ITEM(test_cipher),
28 DEFINE_STRESS_ITEM(test_hash),
29 DEFINE_STRESS_ITEM(test_hmac),
30 DEFINE_STRESS_ITEM(test_rsa),
31 };
32
stress_test(int test_cnt)33 void stress_test(int test_cnt)
34 {
35 int i;
36 uint32_t j;
37 int verbose = 0;
38 RK_RES res;
39 uint32_t tbl_len = ARRAY_SIZE(test_stress_tbl);
40 uint8_t rand_buf[ARRAY_SIZE(test_stress_tbl)];
41
42 printf("===================== stress test begin =====================\n");
43 for (i = 0; i < test_cnt; i++) {
44 printf("stress test %d/%d...\n", i + 1, test_cnt);
45
46 res = rk_get_random(rand_buf, tbl_len);
47 if (res) {
48 printf("rk_get_random failed %x\n",res);
49 goto exit;
50 }
51
52 for (j = 0; j < tbl_len; j++) {
53 uint32_t index = rand_buf[j] % tbl_len;
54
55 res = test_stress_tbl[index].func(verbose);
56 if (res) {
57 printf("%s error[%x]\n", test_stress_tbl[index].name, res);
58 goto exit;
59 }
60 }
61 }
62
63 printf("===================== stress test finish =====================\n");
64 exit:
65 return;
66 }
67
68