From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 6A1664CC5 for ; Tue, 27 Dec 2016 11:05:41 +0100 (CET) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 27 Dec 2016 02:05:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,415,1477983600"; d="scan'208";a="43603065" Received: from unknown (HELO dpdk5.bj.intel.com) ([172.16.182.188]) by orsmga004.jf.intel.com with ESMTP; 27 Dec 2016 02:05:39 -0800 From: Zhiyong Yang To: dev@dpdk.org Cc: yuanhan.liu@linux.intel.com, thomas.monjalon@6wind.com, bruce.richardson@intel.com, konstantin.ananyev@intel.com, pablo.de.lara.guarch@intel.com, Zhiyong Yang Date: Tue, 27 Dec 2016 18:04:56 +0800 Message-Id: <1482833098-38096-3-git-send-email-zhiyong.yang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482833098-38096-1-git-send-email-zhiyong.yang@intel.com> References: <1480926387-63838-2-git-send-email-zhiyong.yang@intel.com> <1482833098-38096-1-git-send-email-zhiyong.yang@intel.com> Subject: [dpdk-dev] [PATCH v2 2/4] app/test: add functional autotest for rte_memset X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2016 10:05:42 -0000 The file implements the functional autotest for rte_memset, which validates the new function rte_memset whether to work in a right way. The implementation of test_memcpy.c is used as a reference. Usage: step 1: run ./x86_64-native-linuxapp-gcc/app/test step 2: run command memset_autotest at the run time. Signed-off-by: Zhiyong Yang --- app/test/Makefile | 2 + app/test/test_memset.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 app/test/test_memset.c diff --git a/app/test/Makefile b/app/test/Makefile index 5be023a..82da3f3 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -123,6 +123,8 @@ SRCS-y += test_logs.c SRCS-y += test_memcpy.c SRCS-y += test_memcpy_perf.c +SRCS-y += test_memset.c + SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_thash.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c diff --git a/app/test/test_memset.c b/app/test/test_memset.c new file mode 100644 index 0000000..c9020bf --- /dev/null +++ b/app/test/test_memset.c @@ -0,0 +1,158 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +/* + * Set this to the maximum buffer size you want to test. If it is 0, then the + * values in the buf_sizes[] array below will be used. + */ +#define TEST_VALUE_RANGE 0 +#define MAX_INT8 127 +#define MIN_INT8 -128 +/* List of buffer sizes to test */ +#if TEST_VALUE_RANGE == 0 +static size_t buf_sizes[] = { + 0, 1, 7, 8, 9, 15, 16, 17, 31, 32, 33, 63, 64, 65, 127, 128, 129, + 255, 256, 257, 320, 384, 511, 512, 513, 1023, 1024, 1025, 1518, + 1522, 1600, 2048, 3072, 4096, 5120, 6144, 7168, 8192 +}; +/* MUST be as large as largest packet size above */ +#define BUFFER_SIZE 8192 +#else /* TEST_VALUE_RANGE != 0 */ +static size_t buf_sizes[TEST_VALUE_RANGE]; +#define BUFFER_SIZE TEST_VALUE_RANGE +#endif /* TEST_VALUE_RANGE == 0 */ + +/* Data is aligned on this many bytes (power of 2) */ +#define ALIGNMENT_UNIT 32 + +/* + * Create two buffers, and initialize the one as the reference buffer with + * random values. Another(dest_buff) is assigned by the reference buffer. + * Set some memory area of dest_buff by using ch and then compare to see + * if the rte_memset is successful. The bytes outside the setted area are + * also checked to make sure they are not changed. + */ +static int +test_single_memset(unsigned int off_dst, int ch, size_t size) +{ + unsigned int i; + uint8_t dest_buff[BUFFER_SIZE + ALIGNMENT_UNIT]; + uint8_t ref_buff[BUFFER_SIZE + ALIGNMENT_UNIT]; + void *ret; + + /* Setup buffers */ + for (i = 0; i < BUFFER_SIZE + ALIGNMENT_UNIT; i++) { + ref_buff[i] = (uint8_t) rte_rand(); + dest_buff[i] = ref_buff[i]; + } + /* Do the rte_memset */ + ret = rte_memset(dest_buff + off_dst, ch, size); + if (ret != (dest_buff + off_dst)) { + printf("rte_memset() returned %p, not %p\n", + ret, dest_buff + off_dst); + } + /* Check nothing before offset was affected */ + for (i = 0; i < off_dst; i++) { + if (dest_buff[i] != ref_buff[i]) { + printf("rte_memset() failed for %u bytes (offsets=%u): \ + [modified before start of dst].\n", + (unsigned int)size, off_dst); + return -1; + } + } + /* Check every byte was setted */ + for (i = 0; i < size; i++) { + if (dest_buff[i + off_dst] != (uint8_t)ch) { + printf("rte_memset() failed for %u bytes (offsets=%u): \ + [didn't memset byte %u].\n", + (unsigned int)size, off_dst, i); + return -1; + } + } + /* Check nothing after memset was affected */ + for (i = off_dst + size; i < BUFFER_SIZE + ALIGNMENT_UNIT; i++) { + if (dest_buff[i] != ref_buff[i]) { + printf("rte_memset() failed for %u bytes (offsets=%u): \ + [memset too many].\n", + (unsigned int)size, off_dst); + return -1; + } + } + return 0; +} + +/* + * Check functionality for various buffer sizes and data offsets/alignments. + */ +static int +func_test(void) +{ + unsigned int off_dst, i; + unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]); + int ret; + int j; + + for (j = MIN_INT8; j <= MAX_INT8; j++) { + for (off_dst = 0; off_dst < ALIGNMENT_UNIT; off_dst++) { + for (i = 0; i < num_buf_sizes; i++) { + ret = test_single_memset(off_dst, j, + buf_sizes[i]); + if (ret != 0) + return -1; + } + } + } + return 0; +} + +static int +test_memset(void) +{ + int ret; + + ret = func_test(); + if (ret != 0) + return -1; + return 0; +} + +REGISTER_TEST_COMMAND(memset_autotest, test_memset); -- 2.7.4