DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check
@ 2015-02-24 12:36 Yerden Zhumabekov
  2015-02-24 14:57 ` Bruce Richardson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Yerden Zhumabekov @ 2015-02-24 12:36 UTC (permalink / raw)
  To: dev

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 |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 76b1b8f..941dc69 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -177,6 +177,56 @@ static struct rte_hash_parameters ut_params = {
 	.socket_id = 0,
 };
 
+#define CRC32_ITERATIONS (1U << 16)
+#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;
+	int res = 0;
+
+	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)) {
+			res = -1;
+			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)) {
+			res = -1;
+			break;
+		}
+	}
+
+	/* Resetting to best available algorithm */
+	rte_hash_crc_set_alg(CRC32_SSE42_x64);
+	return res;
+}
+
 /*
  * Test a hash function.
  */
@@ -1356,6 +1406,9 @@ test_hash(void)
 
 	run_hash_func_tests();
 
+	if (test_crc32_hash_alg_equiv() < 0)
+		return -1;
+
 	return 0;
 }
 
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check
  2015-02-24 12:36 [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check Yerden Zhumabekov
@ 2015-02-24 14:57 ` Bruce Richardson
  2015-02-25  3:14   ` Yerden Zhumabekov
  2015-02-25  4:08 ` [dpdk-dev] [PATCH v2] " Yerden Zhumabekov
  2015-02-25 12:34 ` [dpdk-dev] [PATCH v3] " Yerden Zhumabekov
  2 siblings, 1 reply; 9+ messages in thread
From: Bruce Richardson @ 2015-02-24 14:57 UTC (permalink / raw)
  To: Yerden Zhumabekov; +Cc: dev

On Tue, Feb 24, 2015 at 06:36:28PM +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>

Looks like what we want for this.
In 2.1 we should perhaps look at splitting off unit tests for the hash algorithms
from the tests for the hash tables themselves, since they are all in one file.
However, I don't think such rework is feasible in 2.0 timeframe.

Some comments inline.

/Bruce

> ---
>  app/test/test_hash.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/app/test/test_hash.c b/app/test/test_hash.c
> index 76b1b8f..941dc69 100644
> --- a/app/test/test_hash.c
> +++ b/app/test/test_hash.c
> @@ -177,6 +177,56 @@ static struct rte_hash_parameters ut_params = {
>  	.socket_id = 0,
>  };
>  
> +#define CRC32_ITERATIONS (1U << 16)
This test takes almost no time at all, so maybe we want to do a few more
iterations e.g. 2^18 - 2^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;
> +	int res = 0;
> +
> +	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);
I suggest parenthesis around the % operation for clarity.

> +		init_val = (uint32_t) rte_rand();
> +
> +		/* Fill the data set */
> +		for (j = 0; j < CRC32_DWORDS; j++) {
> +			data64[j] = rte_rand();
> +		}
As a matter of style, we generally omit braces for single-statement loop bodies.

> +
> +		/* 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)) {
> +			res = -1;
I think you need a print statement here, stating that the test failed, and
why exactly it failed.
Also, rather than setting res to -1, you can just do a print and break, and
change "return res" below to "return i == CRC32_ITERATIONS ? 0 : -1", making
use of the fact that you can check i to detect early termination on error.

> +			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)) {
> +			res = -1;
> +			break;
> +		}
> +	}
> +
> +	/* Resetting to best available algorithm */
> +	rte_hash_crc_set_alg(CRC32_SSE42_x64);
> +	return res;
> +}
> +
>  /*
>   * Test a hash function.
>   */
> @@ -1356,6 +1406,9 @@ test_hash(void)
>  
>  	run_hash_func_tests();
>  
> +	if (test_crc32_hash_alg_equiv() < 0)
> +		return -1;
> +
>  	return 0;
>  }
>  
> -- 
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check
  2015-02-24 14:57 ` Bruce Richardson
@ 2015-02-25  3:14   ` Yerden Zhumabekov
  0 siblings, 0 replies; 9+ messages in thread
From: Yerden Zhumabekov @ 2015-02-25  3:14 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev


24.02.2015 20:57, Bruce Richardson пишет:
> +#define CRC32_ITERATIONS (1U << 16)
> This test takes almost no time at all, so maybe we want to do a few more
> iterations e.g. 2^18 - 2^20. 
Noted, I'll put (1U << 20).
>> +	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);
> I suggest parenthesis around the % operation for clarity.
Noted.
>> +		init_val = (uint32_t) rte_rand();
>> +
>> +		/* Fill the data set */
>> +		for (j = 0; j < CRC32_DWORDS; j++) {
>> +			data64[j] = rte_rand();
>> +		}
> As a matter of style, we generally omit braces for single-statement loop bodies.
Noted.
>> +
>> +		/* 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)) {
>> +			res = -1;
> I think you need a print statement here, stating that the test failed, and
> why exactly it failed.
> Also, rather than setting res to -1, you can just do a print and break, and
> change "return res" below to "return i == CRC32_ITERATIONS ? 0 : -1", making
> use of the fact that you can check i to detect early termination on error.

Noted; then I suggest I'll print out test data which caused the break as
well. It might be handy for further investigation.

-- 
Sincerely,

Yerden Zhumabekov
State Technical Service
Astana, KZ

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2] app/test: add crc32 algorithms equivalence check
  2015-02-24 12:36 [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check Yerden Zhumabekov
  2015-02-24 14:57 ` Bruce Richardson
@ 2015-02-25  4:08 ` Yerden Zhumabekov
  2015-02-25 11:34   ` Bruce Richardson
  2015-02-25 12:34 ` [dpdk-dev] [PATCH v3] " Yerden Zhumabekov
  2 siblings, 1 reply; 9+ messages in thread
From: Yerden Zhumabekov @ 2015-02-25  4:08 UTC (permalink / raw)
  To: dev

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 |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 76b1b8f..3e94af1 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -177,6 +177,66 @@ 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):\n");
+
+	for (j = 0; j < data_len; j++) {
+		printf("%02X", ((uint8_t *)data64)[j]);
+		if ((j+1) % 16 == 0 || j == data_len - 1)
+			printf("\n");
+	}
+
+	return -1;
+}
+
 /*
  * Test a hash function.
  */
@@ -1356,6 +1416,9 @@ test_hash(void)
 
 	run_hash_func_tests();
 
+	if (test_crc32_hash_alg_equiv() < 0)
+		return -1;
+
 	return 0;
 }
 
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2] app/test: add crc32 algorithms equivalence check
  2015-02-25  4:08 ` [dpdk-dev] [PATCH v2] " Yerden Zhumabekov
@ 2015-02-25 11:34   ` Bruce Richardson
  2015-02-25 12:36     ` Yerden Zhumabekov
  0 siblings, 1 reply; 9+ messages in thread
From: Bruce Richardson @ 2015-02-25 11:34 UTC (permalink / raw)
  To: Yerden Zhumabekov; +Cc: dev

On Wed, Feb 25, 2015 at 10:08:32AM +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>

Two small notes below for improving output on error.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> ---
>  app/test/test_hash.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 63 insertions(+)
> 
> diff --git a/app/test/test_hash.c b/app/test/test_hash.c
> index 76b1b8f..3e94af1 100644
> --- a/app/test/test_hash.c
> +++ b/app/test/test_hash.c
> @@ -177,6 +177,66 @@ 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):\n");
> +
> +	for (j = 0; j < data_len; j++) {
> +		printf("%02X", ((uint8_t *)data64)[j]);
Put in a space after each hex character, otherwise it comes out like:

Failed test data (hex):
AAD292776348010C7A18D3080DB3A300
FD
Test Failed

[I forced a failure by changing a != to == to test it, don't worry, the
hash calculations are fine! :-)]

> +		if ((j+1) % 16 == 0 || j == data_len - 1)
> +			printf("\n");
> +	}
Maybe also print out here, or before the hex digits, the length of the data
that was tested. e.g. "printf("%u bytes total\n", data_len);" or similar.
> +
> +	return -1;
> +}
> +
>  /*
>   * Test a hash function.
>   */
> @@ -1356,6 +1416,9 @@ test_hash(void)
>  
>  	run_hash_func_tests();
>  
> +	if (test_crc32_hash_alg_equiv() < 0)
> +		return -1;
> +
>  	return 0;
>  }
>  
> -- 
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v3] app/test: add crc32 algorithms equivalence check
  2015-02-24 12:36 [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check Yerden Zhumabekov
  2015-02-24 14:57 ` Bruce Richardson
  2015-02-25  4:08 ` [dpdk-dev] [PATCH v2] " Yerden Zhumabekov
@ 2015-02-25 12:34 ` Yerden Zhumabekov
  2015-02-25 13:14   ` Bruce Richardson
  2 siblings, 1 reply; 9+ messages in thread
From: Yerden Zhumabekov @ 2015-02-25 12:34 UTC (permalink / raw)
  To: dev

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(+)

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2] app/test: add crc32 algorithms equivalence check
  2015-02-25 11:34   ` Bruce Richardson
@ 2015-02-25 12:36     ` Yerden Zhumabekov
  0 siblings, 0 replies; 9+ messages in thread
From: Yerden Zhumabekov @ 2015-02-25 12:36 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

All notes taken into account. v3 posted.

25.02.2015 17:34, Bruce Richardson пишет:
> On Wed, Feb 25, 2015 at 10:08:32AM +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>
> Two small notes below for improving output on error.
>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
>
>> ---
>>  app/test/test_hash.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 63 insertions(+)
>>
>> diff --git a/app/test/test_hash.c b/app/test/test_hash.c
>> index 76b1b8f..3e94af1 100644
>> --- a/app/test/test_hash.c
>> +++ b/app/test/test_hash.c
>> @@ -177,6 +177,66 @@ 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):\n");
>> +
>> +	for (j = 0; j < data_len; j++) {
>> +		printf("%02X", ((uint8_t *)data64)[j]);
> Put in a space after each hex character, otherwise it comes out like:
>
> Failed test data (hex):
> AAD292776348010C7A18D3080DB3A300
> FD
> Test Failed
>
> [I forced a failure by changing a != to == to test it, don't worry, the
> hash calculations are fine! :-)]
>
>> +		if ((j+1) % 16 == 0 || j == data_len - 1)
>> +			printf("\n");
>> +	}
> Maybe also print out here, or before the hex digits, the length of the data
> that was tested. e.g. "printf("%u bytes total\n", data_len);" or similar.
>> +
>> +	return -1;
>> +}
>> +
>>  /*
>>   * Test a hash function.
>>   */
>> @@ -1356,6 +1416,9 @@ test_hash(void)
>>  
>>  	run_hash_func_tests();
>>  
>> +	if (test_crc32_hash_alg_equiv() < 0)
>> +		return -1;
>> +
>>  	return 0;
>>  }
>>  
>> -- 
>> 1.7.9.5
>>

-- 
Sincerely,

Yerden Zhumabekov
State Technical Service
Astana, KZ

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] app/test: add crc32 algorithms equivalence check
  2015-02-25 12:34 ` [dpdk-dev] [PATCH v3] " Yerden Zhumabekov
@ 2015-02-25 13:14   ` Bruce Richardson
  2015-02-25 15:19     ` Thomas Monjalon
  0 siblings, 1 reply; 9+ messages in thread
From: Bruce Richardson @ 2015-02-25 13:14 UTC (permalink / raw)
  To: Yerden Zhumabekov; +Cc: dev

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
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] app/test: add crc32 algorithms equivalence check
  2015-02-25 13:14   ` Bruce Richardson
@ 2015-02-25 15:19     ` Thomas Monjalon
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2015-02-25 15:19 UTC (permalink / raw)
  To: Yerden Zhumabekov; +Cc: dev

> > 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-02-25 15:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-24 12:36 [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check Yerden Zhumabekov
2015-02-24 14:57 ` Bruce Richardson
2015-02-25  3:14   ` Yerden Zhumabekov
2015-02-25  4:08 ` [dpdk-dev] [PATCH v2] " Yerden Zhumabekov
2015-02-25 11:34   ` Bruce Richardson
2015-02-25 12:36     ` Yerden Zhumabekov
2015-02-25 12:34 ` [dpdk-dev] [PATCH v3] " Yerden Zhumabekov
2015-02-25 13:14   ` Bruce Richardson
2015-02-25 15:19     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).