From patchwork Sat Nov 29 07:59:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 774 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=1764403272; bh=eQmJzYgm/QK5/qh6w6MHVEP3cwbuxAKkLgdnqxZ//iQ=; 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=WkKjxGNTdNngHhv7MhhWeuW6PBWmQ3Xjkh8kkoSwzUzruqyeAc2ga1AdpPpN5Xu9s qpImE3voDXUFHJWT/HkkMavyCCx+gulDyaTMmUfT4UQ2Hqj/Fd1V+T6peYjXiD/2WT +4cOsu6+CFQTv9QFG8UIrhY9IJ9jBZnqR2C4N+yh1nOIGxaMKnbaMOmLWcl11ntabg 9gKD1zQ44M3+PFXMB4JybL6VJX5N4EJLKrxR9I64X3W5LfeRZvULNvs4krSVa0jTZd UShTsSiwow3Fz3AL59F7PCWzruiguWJxR4l+p3AuB/Tfgj7t7Ol0HzS+PfT/dfBTdr Xds/Cz7+vpUXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DEBC4687CC for ; Sat, 29 Nov 2025 01:01:12 -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 cwGObkaSCzVd for ; Sat, 29 Nov 2025 01:01:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403272; bh=eQmJzYgm/QK5/qh6w6MHVEP3cwbuxAKkLgdnqxZ//iQ=; 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=WkKjxGNTdNngHhv7MhhWeuW6PBWmQ3Xjkh8kkoSwzUzruqyeAc2ga1AdpPpN5Xu9s qpImE3voDXUFHJWT/HkkMavyCCx+gulDyaTMmUfT4UQ2Hqj/Fd1V+T6peYjXiD/2WT +4cOsu6+CFQTv9QFG8UIrhY9IJ9jBZnqR2C4N+yh1nOIGxaMKnbaMOmLWcl11ntabg 9gKD1zQ44M3+PFXMB4JybL6VJX5N4EJLKrxR9I64X3W5LfeRZvULNvs4krSVa0jTZd UShTsSiwow3Fz3AL59F7PCWzruiguWJxR4l+p3AuB/Tfgj7t7Ol0HzS+PfT/dfBTdr Xds/Cz7+vpUXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CDDF2687B5 for ; Sat, 29 Nov 2025 01:01:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403270; bh=TOjlvL0SbR/I4E38YWQEyxadoJ+Nf6ZwbWiR9Iwybd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQawj8Ala5C77o13iTNORFbDVhL/ZkcCt3HgeLOlNmvVxkRdpl7mWw/bQG88ag7Ac Gd7ZIAwn+unYOzr9Mm7K69rWz1rGYlXaxvLggIPJ5LQJXDQ7HpYtKHNjH3EOlH/thL 657Uy14z5tVQL31rR37nOtrjol9R7enaou8s6wDxefvY3S/i41b1eWIPJyfMWh9ekn v5IQsXh+k5wYf6Rwadhp6aGX2Zw1KF5VV3YOVS3Xr/IUj/+cGDcqd1sJMuSibtBn7T GLg3BFG11Z+Fy0TfCOyitauvDF9IC/pe61rKZYy7ixKj57nKOLQ0mDU5ATRVu/6rUO cuJnbgpnHoYTA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 71A3E6875D; Sat, 29 Nov 2025 01:01: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 1dCrIR9Ts6Xs; Sat, 29 Nov 2025 01:01:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403266; bh=qb1Mc0kajM3W6R+kWvs50F8tYOHLURgYxRe94HlJzV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qOw+YObPLOg0eZMUM1nDuWzTIWuzyxHVW8WPBY/WDvOyPNWrrgehcEJ4KfbAl7j0m 9JKvZo7r9f+8zMlsFY3cMoEjf5fNDMn8Yh606GH3E5wngpDAw35d/BJyxqe9WzkmiD 2Ghis3DtVEd/nE+QTNSnLMhYrmnAkoHHjf7dHcz32oXy3ukZ9JI6vGvPRmNd12wOno +k1G0ZdZXPSSLlWKlZNkcK1/QAIuWrtFxhiEKM9V9jLBsUS+Ghy+x8tm7RTHUs/kM6 flEZ0ZFo5gAik+Cs4nJDfWvsJkhZl7urWppLdA1D+AS5q9hbb1WJ+jY3fLc35V4HMY ZPidXIvMmsWUg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0EEB56876F; Sat, 29 Nov 2025 01:01:05 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:52 -0700 Message-ID: <20251129080014.758001-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7F3H3EMXCJCPDLWIRPVIG6FWHODF46RL X-Message-ID-Hash: 7F3H3EMXCJCPDLWIRPVIG6FWHODF46RL 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 07/10] backtrace: Add a test 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 a simple test for the backtrace library. Co-developed-by: Claude Signed-off-by: Simon Glass --- test/lib/Makefile | 1 + test/lib/backtrace.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/lib/backtrace.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 1d94d6604d5..8b322df3b45 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_$(PHASE_)UT_COMPRESSION) += compression.o ifeq ($(CONFIG_XPL_BUILD),) obj-y += abuf.o obj-y += alist.o +obj-$(CONFIG_BACKTRACE) += backtrace.o obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-$(CONFIG_EFI_LOG) += efi_log.o diff --git a/test/lib/backtrace.c b/test/lib/backtrace.c new file mode 100644 index 00000000000..d9c36bbd495 --- /dev/null +++ b/test/lib/backtrace.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for backtrace functions + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include + +/* Test backtrace_init() and backtrace_get_syms() */ +static int lib_test_backtrace(struct unit_test_state *uts) +{ + char buf[BACKTRACE_BUFSZ]; + struct backtrace_ctx ctx; + bool found_self = false; + bool found_ut_run_list = false; + uint i; + + ut_assert(backtrace_init(&ctx, 0) > 2); + ut_assertok(backtrace_get_syms(&ctx, buf, sizeof(buf))); + + /* + * Check for known functions in the call stack. With libbacktrace + * we can find static functions too, so check for this test function. + */ + for (i = 0; i < ctx.count; i++) { + if (ctx.syms[i]) { + if (strstr(ctx.syms[i], "lib_test_backtrace")) + found_self = true; + if (strstr(ctx.syms[i], "ut_run_list")) + found_ut_run_list = true; + } + } + + ut_assert(found_self); + ut_assert(found_ut_run_list); + + backtrace_uninit(&ctx); + + return 0; +} +LIB_TEST(lib_test_backtrace, 0);