From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgw.gov.kz (mgw.gov.kz [89.218.88.242]) by dpdk.org (Postfix) with ESMTP id 88943AD8A for ; Tue, 24 Feb 2015 13:36:01 +0100 (CET) Received: from mgw.gov.kz (mx.ctsat.kz [178.89.4.95]) by mgw.gov.kz with ESMTP id t1OCZwcU007844-t1OCZwcV007844; Tue, 24 Feb 2015 18:35:58 +0600 Received: from EXCASHUB2.rgp.local (192.168.40.53) by EdgeForefront.rgp.local (192.168.40.59) with Microsoft SMTP Server (TLS) id 14.2.247.3; Tue, 24 Feb 2015 18:34:24 +0600 Received: from r220.rgp.local (192.168.59.10) by excashub2.rgp.local (192.168.40.48) with Microsoft SMTP Server (TLS) id 14.2.247.3; Tue, 24 Feb 2015 18:35:57 +0600 From: Yerden Zhumabekov To: Date: Tue, 24 Feb 2015 18:36:28 +0600 Message-ID: <1424781388-7485-1-git-send-email-e_zhumabekov@sts.kz> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.59.10] X-FEAS-SYSTEM-WL: e_zhumabekov@sts.kz Subject: [dpdk-dev] [PATCH] app/test: add crc32 algorithms equivalence check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Feb 2015 12:36:01 -0000 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 --- 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