[dpdk-dev,v3] app/test: add crc32 algorithms equivalence check
Commit Message
New function test_crc32_hash_alg_equiv() checks whether software,
4-byte operand and 8-byte operand versions of CRC32 hash function
implementations return the same result value.
Signed-off-by: Yerden Zhumabekov <e_zhumabekov@sts.kz>
---
app/test/test_hash.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
Comments
On Wed, Feb 25, 2015 at 06:34:06PM +0600, Yerden Zhumabekov wrote:
> New function test_crc32_hash_alg_equiv() checks whether software,
> 4-byte operand and 8-byte operand versions of CRC32 hash function
> implementations return the same result value.
>
> Signed-off-by: Yerden Zhumabekov <e_zhumabekov@sts.kz>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> app/test/test_hash.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
>
> diff --git a/app/test/test_hash.c b/app/test/test_hash.c
> index 76b1b8f..653dd86 100644
> --- a/app/test/test_hash.c
> +++ b/app/test/test_hash.c
> @@ -177,6 +177,63 @@ static struct rte_hash_parameters ut_params = {
> .socket_id = 0,
> };
>
> +#define CRC32_ITERATIONS (1U << 20)
> +#define CRC32_DWORDS (1U << 6)
> +/*
> + * Test if all CRC32 implementations yield the same hash value
> + */
> +static int
> +test_crc32_hash_alg_equiv(void)
> +{
> + uint32_t hash_val;
> + uint32_t init_val;
> + uint64_t data64[CRC32_DWORDS];
> + unsigned i, j;
> + size_t data_len;
> +
> + printf("# CRC32 implementations equivalence test\n");
> + for (i = 0; i < CRC32_ITERATIONS; i++) {
> + /* Randomizing data_len of data set */
> + data_len = (size_t) ((rte_rand() % sizeof(data64)) + 1);
> + init_val = (uint32_t) rte_rand();
> +
> + /* Fill the data set */
> + for (j = 0; j < CRC32_DWORDS; j++)
> + data64[j] = rte_rand();
> +
> + /* Calculate software CRC32 */
> + rte_hash_crc_set_alg(CRC32_SW);
> + hash_val = rte_hash_crc(data64, data_len, init_val);
> +
> + /* Check against 4-byte-operand sse4.2 CRC32 if available */
> + rte_hash_crc_set_alg(CRC32_SSE42);
> + if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
> + printf("Failed checking CRC32_SW against CRC32_SSE42\n");
> + break;
> + }
> +
> + /* Check against 8-byte-operand sse4.2 CRC32 if available */
> + rte_hash_crc_set_alg(CRC32_SSE42_x64);
> + if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
> + printf("Failed checking CRC32_SW against CRC32_SSE42_x64\n");
> + break;
> + }
> + }
> +
> + /* Resetting to best available algorithm */
> + rte_hash_crc_set_alg(CRC32_SSE42_x64);
> +
> + if (i == CRC32_ITERATIONS)
> + return 0;
> +
> + printf("Failed test data (hex, %lu bytes total):\n", data_len);
> + for (j = 0; j < data_len; j++)
> + printf("%02X%c", ((uint8_t *)data64)[j],
> + ((j+1) % 16 == 0 || j == data_len - 1) ? '\n' : ' ');
> +
> + return -1;
> +}
> +
> /*
> * Test a hash function.
> */
> @@ -1356,6 +1413,9 @@ test_hash(void)
>
> run_hash_func_tests();
>
> + if (test_crc32_hash_alg_equiv() < 0)
> + return -1;
> +
> return 0;
> }
>
> --
> 1.7.9.5
>
> > New function test_crc32_hash_alg_equiv() checks whether software,
> > 4-byte operand and 8-byte operand versions of CRC32 hash function
> > implementations return the same result value.
> >
> > Signed-off-by: Yerden Zhumabekov <e_zhumabekov@sts.kz>
>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied, thanks
@@ -177,6 +177,63 @@ static struct rte_hash_parameters ut_params = {
.socket_id = 0,
};
+#define CRC32_ITERATIONS (1U << 20)
+#define CRC32_DWORDS (1U << 6)
+/*
+ * Test if all CRC32 implementations yield the same hash value
+ */
+static int
+test_crc32_hash_alg_equiv(void)
+{
+ uint32_t hash_val;
+ uint32_t init_val;
+ uint64_t data64[CRC32_DWORDS];
+ unsigned i, j;
+ size_t data_len;
+
+ printf("# CRC32 implementations equivalence test\n");
+ for (i = 0; i < CRC32_ITERATIONS; i++) {
+ /* Randomizing data_len of data set */
+ data_len = (size_t) ((rte_rand() % sizeof(data64)) + 1);
+ init_val = (uint32_t) rte_rand();
+
+ /* Fill the data set */
+ for (j = 0; j < CRC32_DWORDS; j++)
+ data64[j] = rte_rand();
+
+ /* Calculate software CRC32 */
+ rte_hash_crc_set_alg(CRC32_SW);
+ hash_val = rte_hash_crc(data64, data_len, init_val);
+
+ /* Check against 4-byte-operand sse4.2 CRC32 if available */
+ rte_hash_crc_set_alg(CRC32_SSE42);
+ if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
+ printf("Failed checking CRC32_SW against CRC32_SSE42\n");
+ break;
+ }
+
+ /* Check against 8-byte-operand sse4.2 CRC32 if available */
+ rte_hash_crc_set_alg(CRC32_SSE42_x64);
+ if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
+ printf("Failed checking CRC32_SW against CRC32_SSE42_x64\n");
+ break;
+ }
+ }
+
+ /* Resetting to best available algorithm */
+ rte_hash_crc_set_alg(CRC32_SSE42_x64);
+
+ if (i == CRC32_ITERATIONS)
+ return 0;
+
+ printf("Failed test data (hex, %lu bytes total):\n", data_len);
+ for (j = 0; j < data_len; j++)
+ printf("%02X%c", ((uint8_t *)data64)[j],
+ ((j+1) % 16 == 0 || j == data_len - 1) ? '\n' : ' ');
+
+ return -1;
+}
+
/*
* Test a hash function.
*/
@@ -1356,6 +1413,9 @@ test_hash(void)
run_hash_func_tests();
+ if (test_crc32_hash_alg_equiv() < 0)
+ return -1;
+
return 0;
}