From patchwork Tue Sep 6 15:09:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vyacheslav V. Mitrofanov" X-Patchwork-Id: 1674911 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.a=rsa-sha256 header.s=mta-01 header.b=oKdGNCIn; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMTRQ5mWYz1yhR for ; Wed, 7 Sep 2022 01:13:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4192E84A9C; Tue, 6 Sep 2022 17:11:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=yadro.com 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=yadro.com header.i=@yadro.com header.b="oKdGNCIn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4421F84A92; Tue, 6 Sep 2022 17:11:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 10DE884A6F for ; Tue, 6 Sep 2022 17:10:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=v.v.mitrofanov@yadro.com Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 939424465A; Tue, 6 Sep 2022 15:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received:received; s= mta-01; t=1662477052; x=1664291453; bh=h8+mIO9lYUfUnqUBIt1J81rN3 Tw02kiT3y9FAgvuqo4=; b=oKdGNCInNA0D2UI9kvS25qS+oPIjR7zaqvY2g6/Zy 36BHyuXGJB4NoGb0bUPVB+vS0wmcRJ3zmpRSK/SLlfxfyYeshE/+Xg938XlJHp+e glIvczDdR1WpTt+/q8YFiR+uTKHvOhV7F8QUjl73GwpJzsb2KDOZcn5ExQPYD6wM Nc= Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iWAJBB3VpNri; Tue, 6 Sep 2022 18:10:52 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (T-EXCH-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 440A045869; Tue, 6 Sep 2022 18:10:29 +0300 (MSK) Received: from T-EXCH-06.corp.yadro.com (172.17.10.110) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Tue, 6 Sep 2022 18:10:29 +0300 Received: from v.yadro.com (10.199.17.194) by T-EXCH-06.corp.yadro.com (172.17.10.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.9; Tue, 6 Sep 2022 18:10:28 +0300 From: Viacheslav Mitrofanov To: CC: , , , , , , , Subject: [PATCH 12/17] test: dm: eth: Add string_to_ip6 test Date: Tue, 6 Sep 2022 18:09:50 +0300 Message-ID: <20220906150955.505100-13-v.v.mitrofanov@yadro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906150955.505100-1-v.v.mitrofanov@yadro.com> References: <20220906150955.505100-1-v.v.mitrofanov@yadro.com> MIME-Version: 1.0 X-Originating-IP: [10.199.17.194] X-ClientProxiedBy: T-EXCH-02.corp.yadro.com (172.17.10.102) To T-EXCH-06.corp.yadro.com (172.17.10.110) 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 Add a test to check convertation from char* to struct in6_addr. Use in sandbox Signed-off-by: Viacheslav Mitrofanov --- test/dm/eth.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/dm/eth.c b/test/dm/eth.c index 5437f9ea4a..f5c55099ef 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,59 @@ #define DM_TEST_ETH_NUM 4 +static int dm_test_string_to_ip6(struct unit_test_state *uts) +{ + char *str; + struct test_ip6_pair + { + char *string_addr; + struct in6_addr ip6_addr; + }; + + struct in6_addr ip6 = {0}; + + /* Correct statements */ + struct test_ip6_pair test_suite[] = { + {"2001:db8::0:1234:1", {.s6_addr32[0] = 0xb80d0120, + .s6_addr32[1] = 0x00000000, + .s6_addr32[2] = 0x00000000, + .s6_addr32[3] = 0x01003412}}, + {"2001:0db8:0000:0000:0000:0000:1234:0001", + {.s6_addr32[0] = 0xb80d0120, + .s6_addr32[1] = 0x00000000, + .s6_addr32[2] = 0x00000000, + .s6_addr32[3] = 0x01003412}}, + {"::1", {.s6_addr32[0] = 0x00000000, + .s6_addr32[1] = 0x00000000, + .s6_addr32[2] = 0x00000000, + .s6_addr32[3] = 0x01000000}}, + {"::ffff:192.168.1.1", {.s6_addr32[0] = 0x00000000, + .s6_addr32[1] = 0x00000000, + .s6_addr32[2] = 0xffff0000, + .s6_addr32[3] = 0x0101a8c0}}, + }; + + for (int i = 0; i < ARRAY_SIZE(test_suite); ++i) { + ut_assertok(string_to_ip6(test_suite[i].string_addr, + strlen(test_suite[i].string_addr), &ip6)); + ut_asserteq_mem(&ip6, &test_suite[i].ip6_addr, + sizeof(struct in6_addr)); + } + + /* Incorrect statements */ + str = "hello:world"; + ut_assertok(!string_to_ip6(str, strlen(str), &ip6)); + str = "2001:db8::0::0"; + ut_assertok(!string_to_ip6(str, strlen(str), &ip6)); + str = "2001:db8:192.168.1.1::1"; + ut_assertok(!string_to_ip6(str, strlen(str), &ip6)); + str = "192.168.1.1"; + ut_assertok(!string_to_ip6(str, strlen(str), &ip6)); + + return 0; +} +DM_TEST(dm_test_string_to_ip6, 0); + static int dm_test_eth(struct unit_test_state *uts) { net_ping_ip = string_to_ip("1.1.2.2");