DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jan Viktorin <viktorin@rehivetech.com>
To: dev@dpdk.org
Cc: Thomas Monjalon <thomas.monjalon@6wind.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Keith Wiles <keith.wiles@intel.com>,
	david.marchand@6wind.com, jianbo.liu@linaro.org,
	jerin.jacob@caviumnetworks.com, bruce.richardson@intel.com,
	Jan Viktorin <viktorin@rehivetech.com>
Subject: [dpdk-dev] [RFC 3/6] eal/fdt: test FDT API
Date: Sat, 26 Mar 2016 02:12:35 +0100	[thread overview]
Message-ID: <1458954760-2333-4-git-send-email-viktorin@rehivetech.com> (raw)
In-Reply-To: <1458954760-2333-1-git-send-email-viktorin@rehivetech.com>

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
 app/test/Makefile   |   1 +
 app/test/test_fdt.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 271 insertions(+)
 create mode 100644 app/test/test_fdt.c

diff --git a/app/test/Makefile b/app/test/Makefile
index a4907d5..ce4ec263 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -103,6 +103,7 @@ SRCS-y += test_alarm.c
 SRCS-y += test_interrupts.c
 SRCS-y += test_version.c
 SRCS-y += test_func_reentrancy.c
+SRCS-y += test_fdt.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c
diff --git a/app/test/test_fdt.c b/app/test/test_fdt.c
new file mode 100644
index 0000000..7e6d331
--- /dev/null
+++ b/app/test/test_fdt.c
@@ -0,0 +1,270 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 RehiveTech. 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 RehiveTech 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 <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "test.h"
+
+#include <rte_fdt.h>
+
+static int test_fdt_path_is_valid(void)
+{
+	TEST_ASSERT(rte_fdt_path_is_valid("name"), "'name' must be valid");
+	TEST_ASSERT(rte_fdt_path_is_valid("comp@00ffabcd"),
+			"'comp@00ffabcd' must be valid");
+	TEST_ASSERT(rte_fdt_path_is_valid("#address-cells"),
+			"'#address-cells' must be valid");
+	TEST_ASSERT(rte_fdt_path_is_valid("#size-cells"),
+			"'#size-cells' must be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid(NULL), "NULL must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid("."), "'.' must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid(".."), "'..' must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid("/"), "'/' must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid("/name"),
+			"'/name' must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid("base/name"),
+			"'base/name' must not be valid");
+	TEST_ASSERT(!rte_fdt_path_is_valid("base/"),
+			"'base/' must not be valid");
+	return 0;
+}
+
+static int test_fdt_path_push_pop(void)
+{
+	struct rte_fdt_path *path = NULL;
+
+	path = rte_fdt_path_pushs(path, "amba");
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "amba"), "name must be 'amba'");
+	TEST_ASSERT_NULL(path->base, "base must be NULL");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+
+	path = rte_fdt_path_pushs(path, "ethernet@ffc00000");
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "ethernet@ffc00000"),
+			"name must be 'ethernet@ffc00000'");
+	TEST_ASSERT_NOT_NULL(path->base, "base must not be NULL");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+	TEST_ASSERT_EQUAL(path->base->top, path,
+			"base must point to current top");
+
+	path = rte_fdt_path_pushs(path, "name");
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "name"),
+			"name must be 'name'");
+	TEST_ASSERT_NOT_NULL(path->base, "base must not be NULL");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+	TEST_ASSERT_EQUAL(path->base->top, path,
+			"base must point to current top");
+
+	path = rte_fdt_path_pop(path);
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "ethernet@ffc00000"),
+			"name must be 'ethernet@ffc00000'");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+
+	path = rte_fdt_path_pushs(path, "compatible");
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "compatible"),
+			"name must be 'compatible'");
+	TEST_ASSERT_NOT_NULL(path->base, "base must not be NULL");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+	TEST_ASSERT_EQUAL(path->base->top, path,
+			"base must point to current top");
+
+	path = rte_fdt_path_pop(path);
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "ethernet@ffc00000"),
+			"name must be 'ethernet@ffc00000'");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+
+	path = rte_fdt_path_pop(path);
+	TEST_ASSERT_NOT_NULL(path, "path must not be NULL");
+	TEST_ASSERT(!strcmp(path->name, "amba"),
+			"name must be 'amba'");
+	TEST_ASSERT_NULL(path->top, "top must be NULL");
+
+	path = rte_fdt_path_pop(path);
+	TEST_ASSERT_NULL(path, "path must be NULL");
+
+	return 0;
+}
+
+static int fdt_path_equal(const struct rte_fdt_path *a,
+		const struct rte_fdt_path *b)
+{
+	while (a != NULL && b != NULL) {
+		if (strcmp(a->name, b->name))
+			return 0;
+
+		a = a->base;
+		b = b->base;
+	}
+
+	if (a != b) /* both must be NULL */
+		return 0;
+
+	return 1;
+}
+
+static int test_fdt_path_parse(void)
+{
+	const char *p0  = "/";
+	const char *p1  = "/amba";
+	const char *p2  = "/amba/ethernet@ffc00000";
+	const char *p3  = "/amba/ethernet@ffc00000/compatible";
+	const char *p4  = "/amba/./xxx";
+	const char *p5  = "/amba/./xxx/.";
+	const char *p6  = "/amba/../xxx/..";
+	const char *p7  = "..";
+	const char *p8  = "/..";
+	const char *p9  = "";
+	const char *p10 = NULL;
+
+	struct rte_fdt_path *test = NULL;
+	struct rte_fdt_path *tmp;
+
+	// parse p0
+
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p0), 0,
+			"failed to parse p0");
+	TEST_ASSERT_NULL(tmp, "tmp must be NULL");
+
+	// parse p1
+
+	test = rte_fdt_path_pushs(test, "amba");
+	TEST_ASSERT_NOT_NULL(test, "push failed for 'amba'");
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p1), 0,
+			"failed to parse p1");
+	TEST_ASSERT_NOT_NULL(tmp, "tmp must not be NULL");
+	TEST_ASSERT(fdt_path_equal(test, tmp),
+			"parsed p1 does not match the constructed path");
+	tmp = rte_fdt_path_free(tmp);
+
+	// parse p2
+
+	test = rte_fdt_path_pushs(test, "ethernet@ffc00000");
+	TEST_ASSERT_NOT_NULL(test, "push failed for 'ethernet@ffc00000'");
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p2), 0,
+			"failed to parse p2");
+	TEST_ASSERT_NOT_NULL(tmp, "tmp must not be NULL");
+	TEST_ASSERT(fdt_path_equal(test, tmp),
+			"parsed p2 does not match the constructed path");
+	tmp = rte_fdt_path_free(tmp);
+
+	// parse p3
+
+	test = rte_fdt_path_pushs(test, "compatible");
+	TEST_ASSERT_NOT_NULL(test, "push failed for 'compatible'");
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p3), 0,
+			"failed to parse p3");
+	TEST_ASSERT_NOT_NULL(tmp, "tmp must not be NULL");
+	TEST_ASSERT(fdt_path_equal(test, tmp),
+			"parsed p3 does not match the constructed path");
+	tmp = rte_fdt_path_free(tmp);
+
+	// parse p4
+
+	test = rte_fdt_path_pop(test); /* pop compatible */
+	test = rte_fdt_path_pop(test); /* pop ethernet@ffc00000 */
+
+	test = rte_fdt_path_pushs(test, "xxx");
+	TEST_ASSERT_NOT_NULL(test, "push failed for 'xxx'");
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p4), 0,
+			"failed to parse p4");
+	TEST_ASSERT_NOT_NULL(tmp, "tmp must not be NULL");
+	TEST_ASSERT(fdt_path_equal(test, tmp),
+			"parsed p4 does not match the constructed path");
+	tmp = rte_fdt_path_free(tmp);
+
+	// parse p5
+
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p5), 0,
+			"failed to parse p5");
+	TEST_ASSERT_NOT_NULL(tmp, "tmp must not be NULL");
+	TEST_ASSERT(fdt_path_equal(test, tmp),
+			"parsed p5 does not match the constructed path");
+	tmp = rte_fdt_path_free(tmp);
+
+	// parse p6
+
+	test = rte_fdt_path_free(test);
+
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p6), 0,
+			"failed to parse p6");
+	TEST_ASSERT_NULL(tmp, "tmp must be NULL");
+
+	// parse p7
+
+	TEST_ASSERT_NOT_EQUAL(rte_fdt_path_parse(&tmp, p7), 0,
+			"parse p7 must fail");
+	// parse p8
+
+	TEST_ASSERT_EQUAL(rte_fdt_path_parse(&tmp, p8), 0,
+			"failed to parse p8");
+	TEST_ASSERT_NULL(tmp, "tmp must be NULL");
+
+	// parse p9
+
+	TEST_ASSERT_NOT_EQUAL(rte_fdt_path_parse(&tmp, p9), 0,
+			"parse p9 must fail");
+
+	// parse p10
+
+	TEST_ASSERT_NOT_EQUAL(rte_fdt_path_parse(&tmp, p10), 0,
+			"parse p10 must fail");
+
+	return 0;
+}
+
+static int test_fdt(void)
+{
+	if (test_fdt_path_is_valid())
+		return -1;
+
+	if (test_fdt_path_push_pop())
+		return -1;
+
+	if (test_fdt_path_parse())
+		return -1;
+
+	return 0;
+}
+
+static struct test_command fdt_cmd = {
+	.command = "fdt_autotest",
+	.callback = test_fdt,
+};
+REGISTER_TEST_COMMAND(fdt_cmd);
-- 
2.7.0

  parent reply	other threads:[~2016-03-26  1:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-26  1:12 [dpdk-dev] [RFC 0/6] Flattened Device Tree access from DPDK Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 1/6] eal/fdt: introduce Flattened Device Tree API Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 2/6] eal/fdt: implement FDT API for Linux Jan Viktorin
2016-03-26  1:12 ` Jan Viktorin [this message]
2016-03-26  1:12 ` [dpdk-dev] [RFC 4/6] eal/fdt: add testing FDT of xgene-1 got from Linux runtime Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 5/6] eal/fdt: test FDT for Linux on real data source Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 5/6] eal/fdt: test Linux implementation on xgene-1 FDT Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 6/6] eal/fdt: export for dpdk 16.07 Jan Viktorin
2016-03-26  1:12 ` [dpdk-dev] [RFC 0/6] Flattened Device Tree access from DPDK Jan Viktorin
2016-03-28  2:43 ` Jianbo Liu
2016-03-29 10:34   ` Jan Viktorin

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=1458954760-2333-4-git-send-email-viktorin@rehivetech.com \
    --to=viktorin@rehivetech.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=jianbo.liu@linaro.org \
    --cc=keith.wiles@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas.monjalon@6wind.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).