From patchwork Fri Jan 9 01:53:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1372 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923661; bh=dmgDb3ryLAz5zuOJdUQblEs1XvaCy5VbeYNVNnbqW/M=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ltSHi6FwJ3he1V8dSBHsB6GGM0pNfRfJhgLrE2nxtexiIVe6KY7+yWFMfCxZac3Sg NrSy2nYHoO/8O0zK5VzhPria3L/QFNfUV0ZNWnN+9wBR1KIJb5rSq1BhLgME7KN0SF oMgMJVByko6R05uiclbKdvzsexpC0wwCJrt5zodORLaRwFMhNjeokWYWMG+chPEVgQ zCRtLfR2JaYn+5/K5pVa8eq+1xAZFLkFWH37r4ioEXmNE/w4ttNjE8kWWLn+ZVsqEc Q1MGJkXg8dGaXce9HupCKm0zEOqkUV6P230wPg1JlFwXWUF1csWggbrZ3QNWnBWWfx FGJCfrCU7PVwA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 52E63691E6 for ; Thu, 8 Jan 2026 18:54:21 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id zn9PhKWp1lgi for ; Thu, 8 Jan 2026 18:54:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923661; bh=dmgDb3ryLAz5zuOJdUQblEs1XvaCy5VbeYNVNnbqW/M=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ltSHi6FwJ3he1V8dSBHsB6GGM0pNfRfJhgLrE2nxtexiIVe6KY7+yWFMfCxZac3Sg NrSy2nYHoO/8O0zK5VzhPria3L/QFNfUV0ZNWnN+9wBR1KIJb5rSq1BhLgME7KN0SF oMgMJVByko6R05uiclbKdvzsexpC0wwCJrt5zodORLaRwFMhNjeokWYWMG+chPEVgQ zCRtLfR2JaYn+5/K5pVa8eq+1xAZFLkFWH37r4ioEXmNE/w4ttNjE8kWWLn+ZVsqEc Q1MGJkXg8dGaXce9HupCKm0zEOqkUV6P230wPg1JlFwXWUF1csWggbrZ3QNWnBWWfx FGJCfrCU7PVwA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 411AB691E7 for ; Thu, 8 Jan 2026 18:54:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923659; bh=IrkPD4s8siJgkd8WOs7cRb/PxmC9X7tG07YAx81dssQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vKO/6lNhQkwYX98fPaZJK4reB30+64GBNg0Ilp/0LduRmc+IlMPbdXeE72/ueWeGH gcxngwFEAjstmDYNN75fXpSgpporgj2TxGqRkBl0IMW7PaTsPTlCjTbNYczjHbncBa 2W6jKS8JK7poOVv+VtP9RZbfL23ahmUW4ON4j4bvt2H+EUfi2FxEyeBcdjzXpqwSqL 2u+lHpokGpKq97oBq2lS/2MvbvX4Sp/2UZGJ8uWFnN8U8LDY7Dt14bevQEUPxo7xm1 7jnHwTIE7xx1FPtdxbFTCOIaJpwej9+hGuQvn1vGDCY3n0dN7A6m5SO4TIqVecNBfA vEX8ShsLh4PrQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 88EA069130; Thu, 8 Jan 2026 18:54:19 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id ZB6s8SU0NxOq; Thu, 8 Jan 2026 18:54:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923659; bh=LcMQFL5lOlaN60lXYjT+NIpfXKQVx7rjGRVXbIGQ+U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JD5Rkcw56Xz5wZkQkCgfmh/Vd1OotRrYv7dhWI+iHos2srCX1P3Ri9ge/1+fmXnwo koZ+d5p6IFP6J1xicseznRRAWWdEVKSHBNPDYsalO07o9IaXOX5uEwA94R2X/HRbme SSArRZzhnv6r2tQ3FOHdX9e21FwaAKphJnhtwge/1AbTpuS1faOb0FDk5b7NyY9gaK dSbFo6zFN35zGV7wlJ8XRyhK2FT7rhFHnLCN682b47Eb5exgws5F3aJzAf7WetLyc3 2BEsu+r/Edgwx2f6tYG1XXwHJTUeB1V+nWM55iYGnJjRHgC6PHkcfBGLBdU/DS/rpx G30buny7Wpvwg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E429D6912D; Thu, 8 Jan 2026 18:54:18 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 8 Jan 2026 18:53:11 -0700 Message-ID: <20260109015323.3411528-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109015323.3411528-1-sjg@u-boot.org> References: <20260109015323.3411528-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: X4VMEZWFUX3AISQJQZK42LGE3RDJDFKY X-Message-ID-Hash: X4VMEZWFUX3AISQJQZK42LGE3RDJDFKY X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/16] test: pxe: Add a few tests for pxe functions List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add some tests for: - pxe_get_file_size(): missing env var, valid hex values, invalid format - format_mac_pxe(): buffer too small, valid MAC format verification - get_pxelinux_path(): path too long error Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- test/boot/pxe.c | 107 ++++++++++++++++++++++++++++++- test/py/tests/test_pxe_parser.py | 7 ++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/test/boot/pxe.c b/test/boot/pxe.c index 3ccb0c977e9..e6d95d07d41 100644 --- a/test/boot/pxe.c +++ b/test/boot/pxe.c @@ -13,11 +13,14 @@ #include #include #include +#include #include #include #include -/* Define test macro for pxe suite - no init function needed */ +/* Define test macros for pxe suite */ +#define PXE_TEST(_name, _flags) \ + UNIT_TEST(_name, _flags, pxe) #define PXE_TEST_ARGS(_name, _flags, ...) \ UNIT_TEST_ARGS(_name, _flags, pxe, __VA_ARGS__) @@ -483,3 +486,105 @@ static int pxe_test_errors_norun(struct unit_test_state *uts) PXE_TEST_ARGS(pxe_test_errors_norun, UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }, { "cfg_path", UT_ARG_STR }); + +/** + * Test pxe_get_file_size() function + * + * This tests reading the filesize from the environment variable. + */ +static int pxe_test_get_file_size(struct unit_test_state *uts) +{ + ulong size; + + /* Test with no filesize set - should return -ENOENT */ + env_set("filesize", NULL); + ut_asserteq(-ENOENT, pxe_get_file_size(&size)); + + /* Test with valid hex filesize */ + env_set("filesize", "1234"); + ut_assertok(pxe_get_file_size(&size)); + ut_asserteq(0x1234, size); + + /* Test with larger value */ + env_set("filesize", "abcdef"); + ut_assertok(pxe_get_file_size(&size)); + ut_asserteq(0xabcdef, size); + + /* Test with invalid (non-hex) value */ + env_set("filesize", "not_hex"); + ut_asserteq(-EINVAL, pxe_get_file_size(&size)); + + /* Clean up */ + env_set("filesize", NULL); + + return 0; +} +PXE_TEST(pxe_test_get_file_size, 0); + +/** + * Test format_mac_pxe() function + * + * This tests MAC address formatting for PXE boot paths. + */ +static int pxe_test_format_mac(struct unit_test_state *uts) +{ + char buf[21]; + + /* Test with buffer too small */ + ut_asserteq(-ENOSPC, format_mac_pxe(buf, 20)); + ut_asserteq(-ENOSPC, format_mac_pxe(buf, 1)); + + /* Test with valid buffer - sandbox has an ethernet device */ + ut_asserteq(1, format_mac_pxe(buf, sizeof(buf))); + + /* Verify format: 01-xx-xx-xx-xx-xx-xx */ + ut_asserteq(20, strlen(buf)); + ut_asserteq('0', buf[0]); + ut_asserteq('1', buf[1]); + ut_asserteq('-', buf[2]); + ut_asserteq('-', buf[5]); + ut_asserteq('-', buf[8]); + ut_asserteq('-', buf[11]); + ut_asserteq('-', buf[14]); + ut_asserteq('-', buf[17]); + + return 0; +} +PXE_TEST(pxe_test_format_mac, UTF_ETH_BOOTDEV); + +/** + * Test get_pxelinux_path() with path too long + * + * This tests the path length check in get_pxelinux_path(). + */ +static int pxe_test_pxelinux_path_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(PXE_ARG_FS_IMAGE); + struct pxe_test_info info; + struct pxe_context ctx; + char path[600]; + + ut_assertnonnull(fs_image); + info.uts = uts; + + /* Bind the filesystem image */ + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + + /* Set up the PXE context */ + ut_assertok(pxe_setup_ctx(&ctx, pxe_test_getfile, &info, false, "/", + false, false, NULL)); + + /* Create a path that's too long (> 512 - 13 for "pxelinux.cfg/") */ + memset(path, 'a', sizeof(path) - 1); + path[sizeof(path) - 1] = '\0'; + + /* Should fail with -ENAMETOOLONG */ + ut_asserteq(-ENAMETOOLONG, get_pxelinux_path(&ctx, path, + PXE_LOAD_ADDR)); + + pxe_destroy_ctx(&ctx); + + return 0; +} +PXE_TEST_ARGS(pxe_test_pxelinux_path_norun, UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_pxe_parser.py b/test/py/tests/test_pxe_parser.py index 2afe3a93b86..0d957c08219 100644 --- a/test/py/tests/test_pxe_parser.py +++ b/test/py/tests/test_pxe_parser.py @@ -420,3 +420,10 @@ class TestPxeParser: with ubman.log.section('Test PXE errors'): ubman.run_ut('pxe', 'pxe_test_errors', fs_image=fs_img, cfg_path=cfg_path) + + def test_pxe_pxelinux_path(self, ubman, pxe_image): + """Test get_pxelinux_path() path length checking""" + fs_img, cfg_path = pxe_image + with ubman.log.section('Test PXE pxelinux path'): + ubman.run_ut('pxe', 'pxe_test_pxelinux_path', + fs_image=fs_img)