From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8947745A81; Tue, 1 Oct 2024 21:27:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0384540659; Tue, 1 Oct 2024 21:27:03 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by mails.dpdk.org (Postfix) with ESMTP id 0D183402BD for ; Tue, 1 Oct 2024 21:27:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727810821; x=1759346821; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hT/ezhOhwezZb9X6RtbKSciKR5BJXWvPD1jJuqwnjJ4=; b=KlJ7kADpKg362lFMSmsXXIb50T2+pTR+OpmPUKrYyuo9HB32AOGJCEnM iFO//RizDzB7tXz5UsvPH4Z45jP/rRg0ylHfEYLxMxjQNC1YZhJRojTO4 F5bn7PZE0kqO9mCarXRboneCjoS3w30AXMyAPJW8fW+7ddJDeeoOFiKvW GSCUg7iy1boxA8BmMXirPCyaiM9wfomrGI8eD1hgyM51xazvjitDOzyMh xmr7AbYmbt5ouB2ouiUfRsDt+e+QkB92ePhlJhBkm+Zb+0mdjHOz1v8u9 LRchC9T4J+INz7r2WDChse92SNy8k/qnjTgEjfKD2xYe6N2KPYCjs8DIF g==; X-CSE-ConnectionGUID: cc4sKZocSsK1F6TnXAKB6g== X-CSE-MsgGUID: LHGeVDEJRvqYZvdYT/fkbw== X-IronPort-AV: E=McAfee;i="6700,10204,11212"; a="27139766" X-IronPort-AV: E=Sophos;i="6.11,169,1725346800"; d="scan'208";a="27139766" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 12:27:00 -0700 X-CSE-ConnectionGUID: U+ylDZOqQ2C41rFrzgWLGQ== X-CSE-MsgGUID: RGySKhybRu+3zwthBiKb6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,169,1725346800"; d="scan'208";a="78521931" Received: from silpixa00399302.ir.intel.com ([10.237.214.22]) by orviesa005.jf.intel.com with ESMTP; 01 Oct 2024 12:26:59 -0700 From: Arkadiusz Kusztal To: dev@dpdk.org Cc: ferruh.yigit@amd.com, kai.ji@intel.com, brian.dooley@intel.com, Arkadiusz Kusztal Subject: [PATCH v2 3/3] test/crc: replace thread-unsafe api functions Date: Tue, 1 Oct 2024 19:11:50 +0100 Message-Id: <20241001181150.43506-4-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20241001181150.43506-1-arkadiuszx.kusztal@intel.com> References: <20241001181150.43506-1-arkadiuszx.kusztal@intel.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch replaces thread-unsafe CRC functions with the safe ones. Signed-off-by: Arkadiusz Kusztal --- app/test/test_crc.c | 168 +++++++++++++++++++++------------------------------- 1 file changed, 67 insertions(+), 101 deletions(-) diff --git a/app/test/test_crc.c b/app/test/test_crc.c index b85fca35fe..d7afec20b3 100644 --- a/app/test/test_crc.c +++ b/app/test/test_crc.c @@ -2,13 +2,13 @@ * Copyright(c) 2017-2020 Intel Corporation */ -#include "test.h" - #include #include #include #include +#include "test.h" + #define CRC_VEC_LEN 32 #define CRC32_VEC_LEN1 1512 #define CRC32_VEC_LEN2 348 @@ -44,131 +44,97 @@ static const uint32_t crc32_vec_res = 0xb491aab4; static const uint32_t crc32_vec1_res = 0xac54d294; static const uint32_t crc32_vec2_res = 0xefaae02f; static const uint32_t crc16_vec_res = 0x6bec; -static const uint16_t crc16_vec1_res = 0x8cdd; -static const uint16_t crc16_vec2_res = 0xec5b; +static const uint32_t crc16_vec1_res = 0x8cdd; +static const uint32_t crc16_vec2_res = 0xec5b; static int -crc_calc(const uint8_t *vec, - uint32_t vec_len, - enum rte_net_crc_type type) +crc_all_algs(const char *desc, enum rte_net_crc_type type, + const uint8_t *data, int data_len, uint32_t res) { - /* compute CRC */ - uint32_t ret = rte_net_crc_calc(vec, vec_len, type); + struct rte_net_crc ctx; + uint32_t crc; + int ret = TEST_SUCCESS; + + ctx = rte_net_crc_set(RTE_NET_CRC_SCALAR, type); + crc = rte_net_crc(&ctx, data, data_len); + if (crc != res) { + RTE_LOG(ERR, USER1, "TEST FAILED: %s SCALAR\n", desc); + debug_hexdump(stdout, "SCALAR", &crc, 4); + ret = TEST_FAILED; + } - /* dump data on console */ - debug_hexdump(stdout, NULL, vec, vec_len); + ctx = rte_net_crc_set(RTE_NET_CRC_SSE42, type); + if (ctx.alg == RTE_NET_CRC_SSE42) { + crc = rte_net_crc(&ctx, data, data_len); + if (crc != res) { + RTE_LOG(ERR, USER1, "TEST FAILED: %s SSE42\n", desc); + debug_hexdump(stdout, "SSE", &crc, 4); + ret = TEST_FAILED; + } + } + + ctx = rte_net_crc_set(RTE_NET_CRC_AVX512, type); + if (ctx.alg == RTE_NET_CRC_AVX512) { + crc = rte_net_crc(&ctx, data, data_len); + if (crc != res) { + RTE_LOG(ERR, USER1, "TEST FAILED: %s AVX512\n", desc); + debug_hexdump(stdout, "AVX512", &crc, 4); + ret = TEST_FAILED; + } + } + + ctx = rte_net_crc_set(RTE_NET_CRC_NEON, type); + if (ctx.alg == RTE_NET_CRC_NEON) { + crc = rte_net_crc(&ctx, data, data_len); + if (crc != res) { + RTE_LOG(ERR, USER1, "TEST FAILED: %s NEON\n", desc); + debug_hexdump(stdout, "NEON", &crc, 4); + ret = TEST_FAILED; + } + } - return ret; + return ret; } static int -test_crc_calc(void) -{ +crc_autotest(void) +{ uint8_t *test_data; uint32_t i; - enum rte_net_crc_type type; - uint8_t *test_data; - uint32_t result; - int error; + int ret = TEST_SUCCESS; /* 32-bit ethernet CRC: Test 1 */ - type = RTE_NET_CRC32_ETH; - - result = crc_calc(crc_vec, CRC_VEC_LEN, type); - if (result != crc32_vec_res) - return -1; + ret = crc_all_algs("32-bit ethernet CRC: Test 1", RTE_NET_CRC32_ETH, crc_vec, + sizeof(crc_vec), crc32_vec_res); /* 32-bit ethernet CRC: Test 2 */ test_data = rte_zmalloc(NULL, CRC32_VEC_LEN1, 0); if (test_data == NULL) return -7; - for (i = 0; i < CRC32_VEC_LEN1; i += 12) rte_memcpy(&test_data[i], crc32_vec1, 12); - - result = crc_calc(test_data, CRC32_VEC_LEN1, type); - if (result != crc32_vec1_res) { - error = -2; - goto fail; - } + ret |= crc_all_algs("32-bit ethernet CRC: Test 2", RTE_NET_CRC32_ETH, test_data, + CRC32_VEC_LEN1, crc32_vec1_res); /* 32-bit ethernet CRC: Test 3 */ + memset(test_data, 0, CRC32_VEC_LEN1); for (i = 0; i < CRC32_VEC_LEN2; i += 12) rte_memcpy(&test_data[i], crc32_vec1, 12); - - result = crc_calc(test_data, CRC32_VEC_LEN2, type); - if (result != crc32_vec2_res) { - error = -3; - goto fail; - } + ret |= crc_all_algs("32-bit ethernet CRC: Test 3", RTE_NET_CRC32_ETH, test_data, + CRC32_VEC_LEN2, crc32_vec2_res); /* 16-bit CCITT CRC: Test 4 */ - type = RTE_NET_CRC16_CCITT; - result = crc_calc(crc_vec, CRC_VEC_LEN, type); - if (result != crc16_vec_res) { - error = -4; - goto fail; - } - /* 16-bit CCITT CRC: Test 5 */ - result = crc_calc(crc16_vec1, CRC16_VEC_LEN1, type); - if (result != crc16_vec1_res) { - error = -5; - goto fail; - } - /* 16-bit CCITT CRC: Test 6 */ - result = crc_calc(crc16_vec2, CRC16_VEC_LEN2, type); - if (result != crc16_vec2_res) { - error = -6; - goto fail; - } - - rte_free(test_data); - return 0; - -fail: - rte_free(test_data); - return error; -} - -static int -test_crc(void) -{ - int ret; - /* set CRC scalar mode */ - rte_net_crc_set_alg(RTE_NET_CRC_SCALAR); - - ret = test_crc_calc(); - if (ret < 0) { - printf("test_crc (scalar): failed (%d)\n", ret); - return ret; - } - /* set CRC sse4.2 mode */ - rte_net_crc_set_alg(RTE_NET_CRC_SSE42); - - ret = test_crc_calc(); - if (ret < 0) { - printf("test_crc (x86_64_SSE4.2): failed (%d)\n", ret); - return ret; - } + crc_all_algs("16-bit CCITT CRC: Test 4", RTE_NET_CRC16_CCITT, crc_vec, + sizeof(crc_vec), crc16_vec_res); - /* set CRC avx512 mode */ - rte_net_crc_set_alg(RTE_NET_CRC_AVX512); - - ret = test_crc_calc(); - if (ret < 0) { - printf("test crc (x86_64 AVX512): failed (%d)\n", ret); - return ret; - } - - /* set CRC neon mode */ - rte_net_crc_set_alg(RTE_NET_CRC_NEON); + /* 16-bit CCITT CRC: Test 5 */ + ret |= crc_all_algs("16-bit CCITT CRC: Test 5", RTE_NET_CRC16_CCITT, crc16_vec1, + CRC16_VEC_LEN1, crc16_vec1_res); - ret = test_crc_calc(); - if (ret < 0) { - printf("test crc (arm64 neon pmull): failed (%d)\n", ret); - return ret; - } + /* 16-bit CCITT CRC: Test 6 */ + ret |= crc_all_algs("16-bit CCITT CRC: Test 6", RTE_NET_CRC16_CCITT, crc16_vec2, + CRC16_VEC_LEN2, crc16_vec2_res); - return 0; + return ret; } -REGISTER_FAST_TEST(crc_autotest, true, true, test_crc); +REGISTER_FAST_TEST(crc_autotest, true, true, crc_autotest); -- 2.13.6