[Accel-config] [PATCH v1 03/11] accel-config/test: Add algorithm to generate random data for Zcompress16
Li Zhang <li4.zhang at intel.com> Tue, 17 May 2022 18:48:25 +0800
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
Add new file iaa_zcompress.c and iaa_zcompress.h with an algorithm
to generate random input data for operation Zcompress16, add new
files into Makefile for compiling.
Signed-off-by: Li Zhang <li4.zhang(a)intel.com>
---
test/Makefile.am | 2 +-
test/algorithms/iaa_zcompress.c | 37 +++++++++++++++++++++++++++++++++
test/algorithms/iaa_zcompress.h | 10 +++++++++
3 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 test/algorithms/iaa_zcompress.c
create mode 100644 test/algorithms/iaa_zcompress.h
diff --git a/test/Makefile.am b/test/Makefile.am
index 07f8d24..e9a7ddd 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -38,5 +38,5 @@ libaccfg_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS)
dsa_test_SOURCES = dsa_test.c dsa.c dsa_prep.c accel_test.c
dsa_test_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS)
-iaa_test_SOURCES = iaa_test.c iaa.c iaa_prep.c accel_test.c algorithms/iaa_crc64.c algorithms/iaa_crc64.h
+iaa_test_SOURCES = iaa_test.c iaa.c iaa_prep.c accel_test.c algorithms/iaa_crc64.c algorithms/iaa_zcompress.c
iaa_test_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS)
diff --git a/test/algorithms/iaa_zcompress.c b/test/algorithms/iaa_zcompress.c
new file mode 100644
index 0000000..5ee8ff7
--- /dev/null
+++ b/test/algorithms/iaa_zcompress.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2019 Intel Corporation. All rights reserved. */
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
+#include "algorithms/iaa_zcompress.h"
+
+static int iaa_zcompress_get_random_value(void)
+{
+ static int extra_seed;
+
+ srand(time(NULL) + (extra_seed++));
+ return rand();
+}
+
+static uint16_t iaa_zcompress16_get_word_pattern(uint64_t pattern)
+{
+ uint16_t word_pattern = 0;
+ int position = (iaa_zcompress_get_random_value() % 4);
+
+ word_pattern = (uint16_t)((pattern & (0xFFFF << (16 * position))) >> (16 * position));
+ return word_pattern;
+}
+
+void iaa_zcompress16_randomize_input(void *dst, uint64_t pattern, int len)
+{
+ int i;
+ int num_words = len / 2;
+
+ for (i = 0; i < num_words; i++) {
+ if (iaa_zcompress_get_random_value() % 2)
+ ((uint16_t *)dst)[i] = iaa_zcompress16_get_word_pattern(pattern);
+ else
+ ((uint16_t *)dst)[i] = 0;
+ }
+}
diff --git a/test/algorithms/iaa_zcompress.h b/test/algorithms/iaa_zcompress.h
new file mode 100644
index 0000000..b567ac0
--- /dev/null
+++ b/test/algorithms/iaa_zcompress.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2019 Intel Corporation. All rights reserved. */
+#ifndef _IAA_ZCOMPRESS_H_
+#define _IAA_ZCOMPRESS_H_
+
+#include <stdint.h>
+
+void iaa_zcompress16_randomize_input(void *dst, uint64_t pattern, int len);
+
+#endif
--
2.25.1