summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch')
-rw-r--r--recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch439
1 files changed, 0 insertions, 439 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch b/recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch
deleted file mode 100644
index f54286ae..00000000
--- a/recipes-kernel/cryptodev/sdk_patches/0050-add-basic-optargs-support-for-async_speed-test.patch
+++ /dev/null
@@ -1,439 +0,0 @@
1From 13cb1f2dcf8865b076a7e8290d8f864d91a2d7c7 Mon Sep 17 00:00:00 2001
2From: Cristian Stoica <cristian.stoica@nxp.com>
3Date: Mon, 24 Oct 2016 16:33:55 +0300
4Subject: [PATCH 050/104] add basic optargs support for async_speed test
5
6Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
7---
8 tests/async_speed.c | 302 +++++++++++++++++++++++++++++++++++-----------------
9 1 file changed, 202 insertions(+), 100 deletions(-)
10
11diff --git a/tests/async_speed.c b/tests/async_speed.c
12index 15ab80c..fff3414 100644
13--- a/tests/async_speed.c
14+++ b/tests/async_speed.c
15@@ -27,9 +27,45 @@
16 #include <sys/types.h>
17 #include <signal.h>
18 #include <crypto/cryptodev.h>
19+#include <stdbool.h>
20+#include <unistd.h>
21
22 #ifdef ENABLE_ASYNC
23
24+struct test_params {
25+ bool tflag;
26+ bool nflag;
27+ int tvalue;
28+ int nvalue;
29+};
30+
31+const char usage_str[] = "Usage: %s [OPTION]... <cipher>|<hash>\n"
32+ "Run benchmark test for cipher or hash\n\n"
33+ " -t <secs>\t" "time to run each test (default 10 secs)\n"
34+ " -n <bytes>\t" "size of the test buffer\n"
35+ " -h\t\t" "show this help\n"
36+;
37+
38+int run_null(int fdc, struct test_params tp);
39+int run_aes_cbc(int fdc, struct test_params tp);
40+int run_aes_xts(int fdc, struct test_params tp);
41+int run_crc32c(int fdc, struct test_params tp);
42+int run_sha1(int fdc, struct test_params tp);
43+int run_sha256(int fdc, struct test_params tp);
44+
45+#define ALG_COUNT 6
46+struct {
47+ char *name;
48+ int (*func)(int, struct test_params);
49+} ciphers[ALG_COUNT] = {
50+ {"null", run_null},
51+ {"aes-cbc", run_aes_cbc},
52+ {"aes-xts", run_aes_xts},
53+ {"crc32c", run_crc32c},
54+ {"sha1", run_sha1},
55+ {"sha256", run_sha256},
56+};
57+
58 static double udifftimeval(struct timeval start, struct timeval end)
59 {
60 return (double)(end.tv_usec - start.tv_usec) +
61@@ -61,7 +97,7 @@ static void value2human(double bytes, double time, double* data, double* speed,c
62 }
63
64
65-int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
66+int encrypt_data(int fdc, struct test_params tp, struct session_op *sess)
67 {
68 struct crypt_op cop;
69 char *buffer[64], iv[32];
70@@ -72,31 +108,33 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
71 double secs, ddata, dspeed;
72 char metric[16];
73 int rc, wqueue = 0, bufidx = 0;
74+ int alignmask;
75
76 memset(iv, 0x23, 32);
77
78- printf("\tEncrypting in chunks of %d bytes: ", chunksize);
79+ printf("\tEncrypting in chunks of %d bytes: ", tp.nvalue);
80 fflush(stdout);
81
82+ alignmask = get_alignmask(fdc, sess);
83 for (rc = 0; rc < 64; rc++) {
84 if (alignmask) {
85- if (posix_memalign((void **)(buffer + rc), alignmask + 1, chunksize)) {
86+ if (posix_memalign((void **)(buffer + rc), alignmask + 1, tp.nvalue)) {
87 printf("posix_memalign() failed!\n");
88 return 1;
89 }
90 } else {
91- if (!(buffer[rc] = malloc(chunksize))) {
92+ if (!(buffer[rc] = malloc(tp.nvalue))) {
93 perror("malloc()");
94 return 1;
95 }
96 }
97- memset(buffer[rc], val++, chunksize);
98+ memset(buffer[rc], val++, tp.nvalue);
99 }
100 pfd.fd = fdc;
101 pfd.events = POLLOUT | POLLIN;
102
103 must_finish = 0;
104- alarm(5);
105+ alarm(tp.tvalue);
106
107 gettimeofday(&start, NULL);
108 do {
109@@ -111,7 +149,7 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
110 if (pfd.revents & POLLOUT) {
111 memset(&cop, 0, sizeof(cop));
112 cop.ses = sess->ses;
113- cop.len = chunksize;
114+ cop.len = tp.nvalue;
115 cop.iv = (unsigned char *)iv;
116 cop.op = COP_ENCRYPT;
117 cop.src = cop.dst = (unsigned char *)buffer[bufidx];
118@@ -146,25 +184,75 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
119 return 0;
120 }
121
122-int main(void)
123+void usage(char *cmd_name)
124 {
125- int fd, i, fdc = -1, alignmask = 0;
126- struct session_op sess;
127-#ifdef CIOCGSESSINFO
128- struct session_info_op siop;
129-#endif
130- char keybuf[32];
131+ printf(usage_str, cmd_name);
132+}
133
134- signal(SIGALRM, alarm_handler);
135+int run_test(int id, struct test_params tp)
136+{
137+ int fd;
138+ int fdc;
139
140- if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
141+ fd = open("/dev/crypto", O_RDWR, 0);
142+ if (fd < 0) {
143 perror("open()");
144- return 1;
145+ return fd;
146 }
147 if (ioctl(fd, CRIOGET, &fdc)) {
148 perror("ioctl(CRIOGET)");
149- return 1;
150+ return -EINVAL;
151+ }
152+
153+ ciphers[id].func(fdc, tp);
154+
155+ close(fdc);
156+ close(fd);
157+}
158+
159+int get_alignmask(int fdc, struct session_op *sess)
160+{
161+ int alignmask;
162+
163+#ifdef CIOCGSESSINFO
164+ struct session_info_op siop;
165+
166+ siop.ses = sess->ses;
167+ if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
168+ perror("ioctl(CIOCGSESSINFO)");
169+ return -EINVAL;
170+ }
171+ alignmask = siop.alignmask;
172+#else
173+ alignmask = 0;
174+#endif
175+
176+ return alignmask;
177+}
178+
179+void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
180+{
181+ int i;
182+
183+ if (tp.nflag) {
184+ encrypt_data(fdc, tp, sess);
185+ } else {
186+ for (i = 256; i <= (64 * 1024); i *= 2) {
187+ tp.nvalue = i;
188+ if (encrypt_data(fdc, tp, sess)) {
189+ break;
190+ }
191+ }
192 }
193+}
194+
195+
196+int run_null(int fdc, struct test_params tp)
197+{
198+ struct session_op sess;
199+ char keybuf[32];
200+ int alignmask;
201+ int i;
202
203 fprintf(stderr, "Testing NULL cipher: \n");
204 memset(&sess, 0, sizeof(sess));
205@@ -173,21 +261,19 @@ int main(void)
206 sess.key = (unsigned char *)keybuf;
207 if (ioctl(fdc, CIOCGSESSION, &sess)) {
208 perror("ioctl(CIOCGSESSION)");
209- return 1;
210- }
211-#ifdef CIOCGSESSINFO
212- siop.ses = sess.ses;
213- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
214- perror("ioctl(CIOCGSESSINFO)");
215- return 1;
216+ return -EINVAL;
217 }
218- alignmask = siop.alignmask;
219-#endif
220
221- for (i = 256; i <= (64 * 4096); i *= 2) {
222- if (encrypt_data(&sess, fdc, i, alignmask))
223- break;
224- }
225+ do_test_vectors(fdc, tp, &sess);
226+ return 0;
227+}
228+
229+int run_aes_cbc(int fdc, struct test_params tp)
230+{
231+ struct session_op sess;
232+ char keybuf[32];
233+ int alignmask;
234+ int i;
235
236 fprintf(stderr, "\nTesting AES-128-CBC cipher: \n");
237 memset(&sess, 0, sizeof(sess));
238@@ -197,21 +283,17 @@ int main(void)
239 sess.key = (unsigned char *)keybuf;
240 if (ioctl(fdc, CIOCGSESSION, &sess)) {
241 perror("ioctl(CIOCGSESSION)");
242- return 1;
243- }
244-#ifdef CIOCGSESSINFO
245- siop.ses = sess.ses;
246- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
247- perror("ioctl(CIOCGSESSINFO)");
248- return 1;
249+ return -EINVAL;
250 }
251- alignmask = siop.alignmask;
252-#endif
253
254- for (i = 256; i <= (64 * 1024); i *= 2) {
255- if (encrypt_data(&sess, fdc, i, alignmask))
256- break;
257- }
258+ do_test_vectors(fdc, tp, &sess);
259+ return 0;
260+}
261+
262+int run_aes_xts(int fdc, struct test_params tp)
263+{
264+ struct session_op sess;
265+ char keybuf[32];
266
267 fprintf(stderr, "\nTesting AES-256-XTS cipher: \n");
268 memset(&sess, 0, sizeof(sess));
269@@ -221,21 +303,16 @@ int main(void)
270 sess.key = (unsigned char *)keybuf;
271 if (ioctl(fdc, CIOCGSESSION, &sess)) {
272 perror("ioctl(CIOCGSESSION)");
273- return 1;
274+ return -EINVAL;
275 }
276-#ifdef CIOCGSESSINFO
277- siop.ses = sess.ses;
278- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
279- perror("ioctl(CIOCGSESSION)");
280- return 1;
281- }
282- alignmask = siop.alignmask;
283-#endif
284
285- for (i = 256; i <= (64 * 1024); i *= 2) {
286- if (encrypt_data(&sess, fdc, i, alignmask))
287- break;
288- }
289+ do_test_vectors(fdc, tp, &sess);
290+ return 0;
291+}
292+
293+int run_crc32c(int fdc, struct test_params tp)
294+{
295+ struct session_op sess;
296
297 fprintf(stderr, "\nTesting CRC32C hash: \n");
298 memset(&sess, 0, sizeof(sess));
299@@ -244,21 +321,14 @@ int main(void)
300 perror("ioctl(CIOCGSESSION)");
301 return 1;
302 }
303-#ifdef CIOCGSESSINFO
304- siop.ses = sess.ses;
305- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
306- perror("ioctl(CIOCGSESSION)");
307- return 1;
308- }
309- printf("requested hash CRYPTO_CRC32C, got %s with driver %s\n",
310- siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
311- alignmask = siop.alignmask;
312-#endif
313
314- for (i = 256; i <= (64 * 1024); i *= 2) {
315- if (encrypt_data(&sess, fdc, i, alignmask))
316- break;
317- }
318+ do_test_vectors(fdc, tp, &sess);
319+ return 0;
320+}
321+
322+int run_sha1(int fdc, struct test_params tp)
323+{
324+ struct session_op sess;
325
326 fprintf(stderr, "\nTesting SHA-1 hash: \n");
327 memset(&sess, 0, sizeof(sess));
328@@ -267,21 +337,14 @@ int main(void)
329 perror("ioctl(CIOCGSESSION)");
330 return 1;
331 }
332-#ifdef CIOCGSESSINFO
333- siop.ses = sess.ses;
334- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
335- perror("ioctl(CIOCGSESSION)");
336- return 1;
337- }
338- printf("requested hash CRYPTO_SHA1, got %s with driver %s\n",
339- siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
340- alignmask = siop.alignmask;
341-#endif
342
343- for (i = 256; i <= (64 * 1024); i *= 2) {
344- if (encrypt_data(&sess, fdc, i, alignmask))
345- break;
346- }
347+ do_test_vectors(fdc, tp, &sess);
348+ return 0;
349+}
350+
351+int run_sha256(int fdc, struct test_params tp)
352+{
353+ struct session_op sess;
354
355 fprintf(stderr, "\nTesting SHA2-256 hash: \n");
356 memset(&sess, 0, sizeof(sess));
357@@ -290,25 +353,64 @@ int main(void)
358 perror("ioctl(CIOCGSESSION)");
359 return 1;
360 }
361-#ifdef CIOCGSESSINFO
362- siop.ses = sess.ses;
363- if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
364- perror("ioctl(CIOCGSESSION)");
365- return 1;
366- }
367- printf("requested hash CRYPTO_SHA2_256, got %s with driver %s\n",
368- siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
369- alignmask = siop.alignmask;
370-#endif
371
372- for (i = 256; i <= (64 * 1024); i *= 2) {
373- if (encrypt_data(&sess, fdc, i, alignmask))
374+ do_test_vectors(fdc, tp, &sess);
375+ return 0;
376+}
377+
378+int main(int argc, char **argv)
379+{
380+ int i;
381+ int c;
382+ int index;
383+ bool alg_flag;
384+ char *alg_name;
385+ struct test_params tp;
386+
387+ tp.tflag = false;
388+ tp.nflag = false;
389+ alg_flag = false;
390+ opterr = 0;
391+ while ((c = getopt(argc, argv, "hn:t:")) != -1) {
392+ switch (c) {
393+ case 'n':
394+ tp.nvalue = atoi(optarg);
395+ tp.nflag = true;
396+ break;
397+ case 't':
398+ tp.tvalue = atoi(optarg);
399+ tp.tflag = true;
400 break;
401+ case 'h': /* no break */
402+ default:
403+ usage(argv[0]);
404+ exit(1);
405+ }
406+ }
407+
408+ /* the name of a specific test asked on the command line */
409+ if (optind < argc) {
410+ alg_name = argv[optind];
411+ alg_flag = true;
412+ }
413+
414+ /* default test time */
415+ if (!tp.tflag) {
416+ tp.tvalue = 5;
417+ }
418+
419+ signal(SIGALRM, alarm_handler);
420+
421+ for (i = 0; i < ALG_COUNT; i++) {
422+ if (alg_flag) {
423+ if (strcmp(alg_name, ciphers[i].name) == 0) {
424+ run_test(i, tp);
425+ }
426+ } else {
427+ run_test(i, tp);
428+ }
429 }
430
431-end:
432- close(fdc);
433- close(fd);
434 return 0;
435 }
436
437--
4382.10.2
439