Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3FC2C433FE for ; Fri, 30 Sep 2022 00:01:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B49B884CE6; Fri, 30 Sep 2022 02:01:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gabBwAL1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7D5EC84CE6; Fri, 30 Sep 2022 02:01:45 +0200 (CEST) Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BA23984CF2 for ; Fri, 30 Sep 2022 02:01:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd34.google.com with SMTP id v128so2138679ioe.12 for ; Thu, 29 Sep 2022 17:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=fnffboa6VUXN1iHXgUKYPG8WFeU3qoG/XK7U7ASNI34=; b=gabBwAL1rC2+UXnKX/KHU7f5eIjL1JphjrXpbnoBD9bsM6j+QAoenJP6Qqi2qK2BZy EwAl9ceViWH3WpC7LJRYMWVu94yvf6EH9OZ4FegniUTHF5WoNEjZlr+9g0IIsOoeGQYt XmKsCBPItxxSF99cv7AzEI3Wfb2nbpjGQO20Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=fnffboa6VUXN1iHXgUKYPG8WFeU3qoG/XK7U7ASNI34=; b=wm+IIKAQK7pFUYVmigVPtVaWl259rtUbSHDXg2fw/fN60mMwAz/yIAb5w6jspu+PpH gBMLsFhHwdPaThpfLCyebZRuogbKuQtEBYKd2vwnAiCGg0sS5rtv2cSprZ2w70J4VGUI GEo1uG5NtHZGlBfcbiFebfyDEk2rLfCW191py8hSDK2DTvTmdBzd7QqnblLWnDiq7OA8 OHpemoDdE5EgQEhzT2jDCpiQN6sfU+8MvB2MOlnYpexr0UK0TosVfQt4mBZNc24qh3nz gpA1ysZhuW3DamyJMf1hxMofrYbor/juNCtRL+5zP9Vn2ObPjoUzIPe1nCQT73z3bpLC lgmQ== X-Gm-Message-State: ACrzQf0idx0WeoNJyEpkXBV08fMwyFgHsVOfz9USTidmZ39xlT6juu5b Q0WKsC8YMBMpW5iY71mzDVW2Fhs5HjReHg== X-Google-Smtp-Source: AMsMyM4vXhD3d22eWfp10c3z8cZUNB7ohbfMyKgO8A2zRAw/KhYwE5EM8WMfuKIRSm4apTsusZ8oVQ== X-Received: by 2002:a02:ccca:0:b0:35a:d680:7a0f with SMTP id k10-20020a02ccca000000b0035ad6807a0fmr3484686jaq.110.1664496097695; Thu, 29 Sep 2022 17:01:37 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id p15-20020a056e0206cf00b002f611806ae9sm386186ils.60.2022.09.29.17.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 17:01:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= , Michal Simek , Tom Rini , Kishon Vijay Abraham I , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH v3 30/45] dm: core: Expand integer-reading tests Date: Thu, 29 Sep 2022 18:00:48 -0600 Message-Id: <20220930000103.2801372-31-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The current tests do not cover all the behaviour. Add some more. Tidy up a few inconsistencies between livetree and flattree which come to light with these tests. Also drop the -ENODATA error since it is never actually returned. Signed-off-by: Simon Glass --- Changes in v3: - Avoid code-size increase in SPL where error codes matter less drivers/core/of_access.c | 5 +- drivers/core/ofnode.c | 17 +++++-- include/dm/of_access.h | 10 ++-- include/dm/ofnode.h | 8 +-- test/dm/ofnode.c | 102 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 17 deletions(-) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 8631e1c286b..85f7da5a499 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -471,8 +471,7 @@ struct device_node *of_find_node_by_phandle(struct device_node *root, * @len: requested length of property value * * Return: the property value on success, -EINVAL if the property does not - * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the - * property data isn't large enough. + * exist and -EOVERFLOW if the property data isn't large enough. */ static void *of_find_property_value_of_size(const struct device_node *np, const char *propname, u32 len) @@ -481,8 +480,6 @@ static void *of_find_property_value_of_size(const struct device_node *np, if (!prop) return ERR_PTR(-EINVAL); - if (!prop->value) - return ERR_PTR(-ENODATA); if (len > prop->length) return ERR_PTR(-EOVERFLOW); diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 4dd2aee11ce..e4b4b352e46 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -296,9 +296,20 @@ int ofnode_read_u32_array(ofnode node, const char *propname, return of_read_u32_array(ofnode_to_np(node), propname, out_values, sz); } else { - return fdtdec_get_int_array(gd->fdt_blob, - ofnode_to_offset(node), propname, - out_values, sz); + int ret; + + ret = fdtdec_get_int_array(gd->fdt_blob, + ofnode_to_offset(node), propname, + out_values, sz); + + /* get the error right, but space is more important in SPL */ + if (!IS_ENABLED(CONFIG_SPL_BUILD)) { + if (ret == -FDT_ERR_NOTFOUND) + return -EINVAL; + else if (ret == -FDT_ERR_BADLAYOUT) + return -EOVERFLOW; + } + return ret; } } diff --git a/include/dm/of_access.h b/include/dm/of_access.h index dd70b44344d..c556a18f7d9 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -327,8 +327,7 @@ int of_read_u32(const struct device_node *np, const char *propname, u32 *outp); * @outp: pointer to return value, modified only if return value is 0. * * Return: - * 0 on success, -EINVAL if the property does not exist, - * -ENODATA if property does not have a value, and -EOVERFLOW if the + * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the * property data isn't large enough. */ int of_read_u32_index(const struct device_node *np, const char *propname, @@ -345,8 +344,7 @@ int of_read_u32_index(const struct device_node *np, const char *propname, * @outp: pointer to return value, modified only if return value is 0. * * Return: - * 0 on success, -EINVAL if the property does not exist, - * -ENODATA if property does not have a value, and -EOVERFLOW if the + * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the * property data isn't large enough. */ int of_read_u64(const struct device_node *np, const char *propname, u64 *outp); @@ -362,8 +360,8 @@ int of_read_u64(const struct device_node *np, const char *propname, u64 *outp); * @out_values: pointer to return value, modified only if return value is 0. * @sz: number of array elements to read * Return: - * 0 on success, -EINVAL if the property does not exist, -ENODATA - * if property does not have a value, and -EOVERFLOW is longer than sz. + * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if + * longer than sz. */ int of_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index a674d7d8fd6..8b0a1087062 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -373,12 +373,12 @@ const char *ofnode_read_string(ofnode node, const char *propname); * @propname: name of the property to read * @out_values: pointer to return value, modified only if return value is 0 * @sz: number of array elements to read - * Return: 0 if OK, -ve on error + * Return: 0 on success, -EINVAL if the property does not exist, + * -ENODATA if property does not have a value, and -EOVERFLOW if the + * property data isn't large enough * * Search for a property in a device node and read 32-bit value(s) from - * it. Returns 0 on success, -EINVAL if the property does not exist, - * -ENODATA if property does not have a value, and -EOVERFLOW if the - * property data isn't large enough. + * it. * * The out_values is modified only if a valid u32 value can be decoded. */ diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 5ddfd0298a6..eac0c50364a 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -320,6 +320,9 @@ static int dm_test_ofnode_get_path(struct unit_test_state *uts) res = ofnode_get_path(node, buf, 32); ut_asserteq(-ENOSPC, res); + res = ofnode_get_path(ofnode_root(), buf, 32); + ut_asserteq_str("/", buf); + return 0; } DM_TEST(dm_test_ofnode_get_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); @@ -589,6 +592,7 @@ DM_TEST(dm_test_ofnode_livetree_writing, static int dm_test_ofnode_u32(struct unit_test_state *uts) { ofnode node; + u32 val; node = ofnode_path("/lcd"); ut_assert(ofnode_valid(node)); @@ -597,10 +601,62 @@ static int dm_test_ofnode_u32(struct unit_test_state *uts) ut_asserteq(1367, ofnode_read_u32_default(node, "xres", 123)); ut_assertok(ofnode_write_u32(node, "xres", 1366)); + node = ofnode_path("/backlight"); + ut_assertok(ofnode_read_u32_index(node, "brightness-levels", 0, &val)); + ut_asserteq(0, val); + ut_assertok(ofnode_read_u32_index(node, "brightness-levels", 1, &val)); + ut_asserteq(16, val); + ut_assertok(ofnode_read_u32_index(node, "brightness-levels", 8, &val)); + ut_asserteq(255, val); + ut_asserteq(-EOVERFLOW, + ofnode_read_u32_index(node, "brightness-levels", 9, &val)); + ut_asserteq(-EINVAL, ofnode_read_u32_index(node, "missing", 0, &val)); + return 0; } DM_TEST(dm_test_ofnode_u32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +static int dm_test_ofnode_u32_array(struct unit_test_state *uts) +{ + ofnode node; + u32 val[10]; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_read_u32_array(node, "int-value", val, 1)); + ut_asserteq(-EINVAL, ofnode_read_u32_array(node, "missing", val, 1)); + ut_asserteq(-EOVERFLOW, ofnode_read_u32_array(node, "bool-value", val, + 1)); + + memset(val, '\0', sizeof(val)); + ut_assertok(ofnode_read_u32_array(node, "int-array", val + 1, 3)); + ut_asserteq(0, val[0]); + ut_asserteq(5678, val[1]); + ut_asserteq(9123, val[2]); + ut_asserteq(4567, val[3]); + ut_asserteq(0, val[4]); + ut_asserteq(-EOVERFLOW, ofnode_read_u32_array(node, "int-array", val, + 4)); + + return 0; +} +DM_TEST(dm_test_ofnode_u32_array, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +static int dm_test_ofnode_u64(struct unit_test_state *uts) +{ + ofnode node; + u64 val; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_read_u64(node, "int64-value", &val)); + ut_asserteq_64(0x1111222233334444, val); + ut_asserteq(-EINVAL, ofnode_read_u64(node, "missing", &val)); + + return 0; +} +DM_TEST(dm_test_ofnode_u64, UT_TESTF_SCAN_FDT); + static int dm_test_ofnode_add_subnode(struct unit_test_state *uts) { ofnode node, check, subnode; @@ -693,3 +749,49 @@ static int dm_test_ofnode_for_each_prop(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_for_each_prop, UT_TESTF_SCAN_FDT); + +static int dm_test_ofnode_by_compatible(struct unit_test_state *uts) +{ + const char *compat = "denx,u-boot-fdt-test"; + ofnode node; + int count; + + count = 0; + for (node = ofnode_null(); + node = ofnode_by_compatible(node, compat), ofnode_valid(node);) + count++; + ut_asserteq(11, count); + + return 0; +} +DM_TEST(dm_test_ofnode_by_compatible, UT_TESTF_SCAN_FDT); + +static int dm_test_ofnode_find_subnode(struct unit_test_state *uts) +{ + ofnode node, subnode; + + node = ofnode_path("/buttons"); + + subnode = ofnode_find_subnode(node, "btn1"); + ut_assert(ofnode_valid(subnode)); + ut_asserteq_str("btn1", ofnode_get_name(subnode)); + + subnode = ofnode_find_subnode(node, "btn"); + ut_assert(!ofnode_valid(subnode)); + + return 0; +} +DM_TEST(dm_test_ofnode_find_subnode, UT_TESTF_SCAN_FDT); + +static int dm_test_ofnode_get_name(struct unit_test_state *uts) +{ + ofnode node; + + node = ofnode_path("/buttons"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("buttons", ofnode_get_name(node)); + ut_asserteq_str("", ofnode_get_name(ofnode_root())); + + return 0; +} +DM_TEST(dm_test_ofnode_get_name, UT_TESTF_SCAN_FDT); -- 2.38.0.rc1.362.ged0d419d3c-goog