From: Zhiyong Yang <zhiyong.yang@intel.com>
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 <zhiyong.yang@intel.com>
Subject: [dpdk-dev] [PATCH v2 2/4] app/test: add functional autotest for rte_memset
Date: Tue, 27 Dec 2016 18:04:56 +0800 [thread overview]
Message-ID: <1482833098-38096-3-git-send-email-zhiyong.yang@intel.com> (raw)
In-Reply-To: <1482833098-38096-1-git-send-email-zhiyong.yang@intel.com>
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 <zhiyong.yang@intel.com>
---
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 <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <rte_common.h>
+#include <rte_random.h>
+#include <rte_memset.h>
+#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
next prev parent reply other threads:[~2016-12-27 10:05 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-05 8:26 [dpdk-dev] [PATCH 0/4] eal/common: introduce rte_memset and related test Zhiyong Yang
2016-12-02 10:00 ` Maxime Coquelin
2016-12-06 6:33 ` Yang, Zhiyong
2016-12-06 8:29 ` Maxime Coquelin
2016-12-07 9:28 ` Yang, Zhiyong
2016-12-07 9:37 ` Yuanhan Liu
2016-12-07 9:43 ` Yang, Zhiyong
2016-12-07 9:48 ` Yuanhan Liu
2016-12-05 8:26 ` [dpdk-dev] [PATCH 1/4] eal/common: introduce rte_memset on IA platform Zhiyong Yang
2016-12-02 10:25 ` Thomas Monjalon
2016-12-08 7:41 ` Yang, Zhiyong
2016-12-08 9:26 ` Ananyev, Konstantin
2016-12-08 9:53 ` Yang, Zhiyong
2016-12-08 10:27 ` Bruce Richardson
2016-12-08 10:30 ` Ananyev, Konstantin
2016-12-11 12:32 ` Yang, Zhiyong
2016-12-15 6:51 ` Yang, Zhiyong
2016-12-15 10:12 ` Bruce Richardson
2016-12-16 10:19 ` Yang, Zhiyong
2016-12-19 6:27 ` Yuanhan Liu
2016-12-20 2:41 ` Yao, Lei A
2016-12-15 10:53 ` Ananyev, Konstantin
2016-12-16 2:15 ` Yang, Zhiyong
2016-12-16 11:47 ` Ananyev, Konstantin
2016-12-20 9:31 ` Yang, Zhiyong
2016-12-08 15:09 ` Thomas Monjalon
2016-12-11 12:04 ` Yang, Zhiyong
2016-12-27 10:04 ` [dpdk-dev] [PATCH v2 0/4] eal/common: introduce rte_memset and related test Zhiyong Yang
2016-12-27 10:04 ` [dpdk-dev] [PATCH v2 1/4] eal/common: introduce rte_memset on IA platform Zhiyong Yang
2016-12-27 10:04 ` Zhiyong Yang [this message]
2016-12-27 10:04 ` [dpdk-dev] [PATCH v2 3/4] app/test: add performance autotest for rte_memset Zhiyong Yang
2016-12-27 10:04 ` [dpdk-dev] [PATCH v2 4/4] lib/librte_vhost: improve vhost perf using rte_memset Zhiyong Yang
2017-01-09 9:48 ` [dpdk-dev] [PATCH v2 0/4] eal/common: introduce rte_memset and related test Yang, Zhiyong
2017-01-17 6:24 ` Yang, Zhiyong
2017-01-17 20:14 ` Thomas Monjalon
2017-01-18 0:15 ` Vincent JARDIN
2017-01-18 2:42 ` Yang, Zhiyong
2017-01-18 7:42 ` Thomas Monjalon
2017-01-19 1:36 ` Yang, Zhiyong
2016-12-05 8:26 ` [dpdk-dev] [PATCH 2/4] app/test: add functional autotest for rte_memset Zhiyong Yang
2016-12-05 8:26 ` [dpdk-dev] [PATCH 3/4] app/test: add performance " Zhiyong Yang
2016-12-05 8:26 ` [dpdk-dev] [PATCH 4/4] lib/librte_vhost: improve vhost perf using rte_memset Zhiyong Yang
2016-12-02 9:46 ` Thomas Monjalon
2016-12-06 8:04 ` Yang, Zhiyong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1482833098-38096-3-git-send-email-zhiyong.yang@intel.com \
--to=zhiyong.yang@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=konstantin.ananyev@intel.com \
--cc=pablo.de.lara.guarch@intel.com \
--cc=thomas.monjalon@6wind.com \
--cc=yuanhan.liu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).