From patchwork Tue Nov 11 12:41:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 676 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=1762864933; bh=6JkATnVqJiBuvns3Evigq127aPxZx/NwUu4iZ1it9Ns=; 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=LkfegNLFMT9h0PKaOYcH9/OsWn0qE+TsUQGNNwLSM5KxxKjFxMp8GnKJMsefSeyVq pv8e5MudpK4am5vnku5vTFJRMMuKf1SxMHhUeCne5hYb0CWvWXVfwsFwEo4+Sfp+74 MudYZVY3T5VaPy8rdRfP2qi44LENN2NxLrj5xRWN2hWXK+6E0kOr5KMTmhocwOd9zz eM1zKNCw+8C41GThbthgKR6U/aooaI6K6GAFhWC/mTNRULJPOLbIXruAQpMhblmPFZ fKPe26ShhcmCOEnVinNBcKVzVhlPNfzsF3eEVFZGM2BHBiVKVaE00uTGlI4V6X1u9f aFsX2sEGSyI7A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5764268484 for ; Tue, 11 Nov 2025 05:42:13 -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 JkWjvxTieduA for ; Tue, 11 Nov 2025 05:42:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1762864933; bh=6JkATnVqJiBuvns3Evigq127aPxZx/NwUu4iZ1it9Ns=; 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=LkfegNLFMT9h0PKaOYcH9/OsWn0qE+TsUQGNNwLSM5KxxKjFxMp8GnKJMsefSeyVq pv8e5MudpK4am5vnku5vTFJRMMuKf1SxMHhUeCne5hYb0CWvWXVfwsFwEo4+Sfp+74 MudYZVY3T5VaPy8rdRfP2qi44LENN2NxLrj5xRWN2hWXK+6E0kOr5KMTmhocwOd9zz eM1zKNCw+8C41GThbthgKR6U/aooaI6K6GAFhWC/mTNRULJPOLbIXruAQpMhblmPFZ fKPe26ShhcmCOEnVinNBcKVzVhlPNfzsF3eEVFZGM2BHBiVKVaE00uTGlI4V6X1u9f aFsX2sEGSyI7A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 40E31684B7 for ; Tue, 11 Nov 2025 05:42:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1762864930; bh=atD/6K74sevk69fkxsPvFMRd26pl+fcPG2j5QWjuIMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqT779DbzR5tEO5mSWVs9TAMaFZKfAexJ/PUOmTy4p7zKFK6xkNQIZLyzf2J5h1zA fXFjrufeAjUhXYSu4UaPEBZ1SKLdAkR8Jh02naYLyzQBg907yF1isAPMotk7dZ3h8F LrtVrfX7x4SUsoqiPPn4fAcQ+hKVHGJ73ZqVDxWmgMbQLZTZc3Gm1k0Y7zanwmxpQe JUiRDLpOyNS1KJUVrnOoQ531BPgz/zEALhqwilVGVzWAoW577O7VBlBehvl8NnPEWi N1rAEqIYqJJqtfFV4TNyV+g9+SVvbah8kXKFnbgFprqutErH7THzvzYHdEw2igPjFH EAd6JbcB/q8Ew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D4277684B7; Tue, 11 Nov 2025 05:42:10 -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 iZScerVXa1iD; Tue, 11 Nov 2025 05:42:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1762864929; bh=zPk1MTNqzbnlzkgt4RQyVsoz3SI5CR+aVr0G9FXL0ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ma+S7G/cx/vTCyipq5p5QEKoGETCekfJI5Ik3I/Kgk7yBlRQVU+iKF3ABOBuIjywV uYYQyMH6GCHviz4jb51NorvS70wkD1TNyP4RuXMF0sYrpU+4BDty1y9+9AGlqiWptp +lmEIEArpRwAlfzY96ceDA7QhwMZN+53HzNFI31vszQSmfBIkxwZVPDFEh6uEXUdAw UMrs2h163Qsjn5DMyq2xv9ml4qHexTfR7hTmAcO8xWKdGzZ6ZuqXmX/gKymZ3/yIBk 2xkrc8PsZr/Q6lgo0fmnTZ2XSOo2UXdmigRHV2EqfmJtIXQhz6KH3v6eSlru6/d1Fh Gnuk0kdOE01DQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A75B068518; Tue, 11 Nov 2025 05:42:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 11 Nov 2025 05:41:09 -0700 Message-ID: <20251111124131.1198930-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251111124131.1198930-1-sjg@u-boot.org> References: <20251111124131.1198930-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 3YFCDPCJ2HZXMQ6YDA7N6FXS4MLSM7Y5 X-Message-ID-Hash: 3YFCDPCJ2HZXMQ6YDA7N6FXS4MLSM7Y5 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/15] test: Check for null string in assert 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 Update ut_asserteq_str() and ut_asserteq_strn() to check for NULL. This allows tests to avoid doing this. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/test/ut.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/include/test/ut.h b/include/test/ut.h index 6731b43dba9..70eaaea5e0e 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -206,7 +206,15 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); const char *_val1 = (expr1), *_val2 = (expr2); \ int __ret = 0; \ \ - if (strcmp(_val1, _val2)) { \ + if (!_val1 || !_val2) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + #expr1 " = " #expr2, \ + "Expected \"%s\", got \"%s\"", \ + _val1 ? _val1 : "(null)", \ + _val2 ? _val2 : "(null)"); \ + if (!uts->soft_fail) \ + return CMD_RET_FAILURE; \ + } else if (strcmp(_val1, _val2)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ "Expected \"%s\", got \"%s\"", _val1, _val2); \ @@ -222,16 +230,26 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); */ #define ut_asserteq_strn(expr1, expr2) ({ \ const char *_val1 = (expr1), *_val2 = (expr2); \ - int _len = strlen(_val1); \ int __ret = 0; \ \ - if (memcmp(_val1, _val2, _len)) { \ + if (!_val1 || !_val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected \"%.*s\", got \"%.*s\"", \ - _len, _val1, _len, _val2); \ + "Expected \"%s\", got \"%s\"", \ + _val1 ? _val1 : "(null)", \ + _val2 ? _val2 : "(null)"); \ if (!uts->soft_fail) \ return CMD_RET_FAILURE; \ + } else { \ + int _len = strlen(_val1); \ + if (memcmp(_val1, _val2, _len)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + #expr1 " = " #expr2, \ + "Expected \"%.*s\", got \"%.*s\"", \ + _len, _val1, _len, _val2); \ + if (!uts->soft_fail) \ + return CMD_RET_FAILURE; \ + } \ } \ __ret; \ })