From patchwork Tue Mar 18 10:46:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874399 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442953wrq; Tue, 18 Mar 2025 03:48:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXywfwuqSLM2LXQgI8KLOcMhFM/gehlmm4eS/qlGLcEl5uv1WJhSYua+6bogSp7AUiDv7z/GQ==@linaro.org X-Google-Smtp-Source: AGHT+IGM371aIuoV/b8KYQV7XNA/L/ExRG1/RUXtbYe3s/fg6t9SKCzNIC8ZzPYz9rrPUh+SXImp X-Received: by 2002:a05:690c:4b93:b0:6fd:42ed:c90 with SMTP id 00721157ae682-6ffd74abce8mr43937857b3.16.1742294895836; Tue, 18 Mar 2025 03:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294895; cv=none; d=google.com; s=arc-20240605; b=Cu3dmds3tAuBQIF8IB5opCENIr5atwGs0zfJOCs9wGmOEhpJZDpUX/l+sRDfxjpQY0 du7bGKg8VkMgrS9Pb2MBul8Ee+leffgi5qAApsKcXm0mO4iXGT0LhS40Uoz+n4+FP7PT N1OtIbiozK7H1CVF+UcStDFlw9uvnU+ao74rfjLZiOXUk5qQoI8eX93kyeFeuGRZR4Or QT+AZ2l2cT2feP3ysbCxx6WrgVhqoRcev1eOarA5g3LAb18NLpQLJRScJaZnsuR9xcgB j/gOKXZ9xvkML6fv51yr9BP16rifu7WNxZ0t16zui5rJ96iNori+XtCrwHQUkZvTZR5k cltA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=e1wD7GfNW67qZRdMfvieu4JK/iNnI8/jZA7k7W3GA4R6qRc2AwDNmydhMQk9FWUvrr BXw6Mh0nfllXuEG/3mGjJ4xzYRGoS/fhWjP6bssfjx3QV2LchEDKb6XtK1xPXTO8eQ8B xHpRA+b/tPf5ve+wKpo/JXVQGYlFF+5F2qGk9d6SB4KzA3AjnISKP/TfpLsfDg7nUR+u Umk67rBZvxc329YkoK3Bkg+Fyf7TAMU2jEebOX6I2GOsTLLWS+CsDNE9NZ7g2vx+A5um pzeDlwlK0MODxjasIpYFP6K4MNhyrXBzFGEB/qfPp9Aur80b7If92POebeqM6fHZElaR gPwQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fhPxw+e7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 00721157ae682-6ff32b46219si100837117b3.295.2025.03.18.03.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:15 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fhPxw+e7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4D72181B42; Tue, 18 Mar 2025 11:47:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fhPxw+e7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF1AA80F70; Tue, 18 Mar 2025 11:47:27 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 CF34180107 for ; Tue, 18 Mar 2025 11:47:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43948f77f1aso22251905e9.0 for ; Tue, 18 Mar 2025 03:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294845; x=1742899645; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; b=fhPxw+e7TOmpH8m4wzpKcMAkQIuMKmk31km8J9qGgbKmjkp75XKPbxBTwjBuP1IMPM AuQSeDrz36rgbWNS/YdqZJzHT5u6gZ1YlUq9r9MBUZJ2dZYbVXWunLcKfhAdS3S7mC89 Vjbi+1WyGFxnJgJg6xUIsH8TzW0XzhXygVF90Quwa4syxD/17t65ekOqRVydesu+nToR 8OblGiyyOXKt4X6XAQsU/8rI6DhtNwr/5w11kHaCNkiYVdW4WbryX+QYiSEE1+deo3dI 4DmKJfAGo4EeOy3G4NRwRMX6dNEaQS5sxpEBxiHee9fZZY2f6mYJ7QnYIdmyRzggIqR5 1lKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294845; x=1742899645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; b=LUE8cyUUqC9YpTeRFp/z7i5EWgruVkJXVb2qJrGDdO8OU5RRXZUTlGbkIzFV9sDv6i DIxl9m/jjANPxoPji+/RhBt0VqIYn4kXCj2qn0YdlXodv+sVDse+Lwes4m4SWDbMLfKt z9cgy2UJUkUaL1KioQ59Kc2exdXbIeRVkQj8QKliyPha8da4Ua0IFw9S0nGNampm3HjS rGB+vbPZfHMig/v+EztY9dTBFdr00Zd78aXmrpKy5y6MN+9+i5osSk/T6Ag9Zc3OjzOk nFy445WVV84t5htCNecCvq1K/O0CP/B4LZx1Xx8pLrOkpSSieSEjo9eR6lj1B1gzhm+W jTvA== X-Gm-Message-State: AOJu0YwMItV7ZFidYTAH7TnG8igqNKC3Uv97lrrQ0YmcTatZuqUpxZzm zgoc5bcerJR/xCQaJ2X+ffPKwfl1jPapaAjcJmqcCQftq6Lyn/AkCEJ+vaBshhDTwVSNus7nUGp SyJg= X-Gm-Gg: ASbGncvhOlWJMGFrx1x4OzAt5ZlcP9aaSltT9LSbKy9tjwMYKq/+fNXioYZsdaijGLJ iXbrxP/DlQ0ht/qYi9FG/jhaK0J2CBzW6FfxFHtO8gGq+es7GjVNmleBw1+S5+ntf2GE5tNRe1b vfNHPoh7IwfG5002s5dFLUJm4mXBPWx6mtkNY0ng3EszCh4VRFT1MOXtnIf1fSf3Wia3LF0xok4 E6u23FHpvB5tFbypb2Ob1jyWW2cm700jPx3xolQemzYq74dx1ClTTYzPAUSrbTMcKnlQ5qMntJ+ +QyhehdE7dm8j4H1gPDGSQjHUEPYdw8l2T5ISG0+H/uAyuSL9KZhAg== X-Received: by 2002:a05:600c:1c2a:b0:43b:ca39:6c7d with SMTP id 5b1f17b1804b1-43d3b95013amr13736045e9.3.1742294845108; Tue, 18 Mar 2025 03:47:25 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:24 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Raymond Mao , Philippe Reynes Subject: [PATCH v4 05/14] test: lib: add initjmp() test Date: Tue, 18 Mar 2025 11:46:41 +0100 Message-ID: <20250318104659.1114340-6-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean Test the initjmp() function when HAVE_INITJMP is set. Use the test as an example in the API documentation. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- doc/api/setjmp.rst | 10 +++++++ test/lib/Makefile | 1 + test/lib/initjmp.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 test/lib/initjmp.c diff --git a/doc/api/setjmp.rst b/doc/api/setjmp.rst index 7718047085c..c48b2e3e096 100644 --- a/doc/api/setjmp.rst +++ b/doc/api/setjmp.rst @@ -8,3 +8,13 @@ Long jump API .. kernel-doc:: include/setjmp.h :internal: + +Example +------- + +Here is an example showing how to use the a long jump functions and +initjmp() in particular: + +.. literalinclude:: ../../test/lib/initjmp.c + :language: c + :linenos: diff --git a/test/lib/Makefile b/test/lib/Makefile index 0e4cb8e3dfd..bf04685dae1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -14,6 +14,7 @@ obj-y += hexdump.o obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-$(CONFIG_HAVE_SETJMP) += longjmp.o +obj-$(CONFIG_HAVE_INITJMP) += initjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-$(CONFIG_$(PHASE_)STRTO) += str.o diff --git a/test/lib/initjmp.c b/test/lib/initjmp.c new file mode 100644 index 00000000000..5b4b50b3f0f --- /dev/null +++ b/test/lib/initjmp.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2025 Linaro Limited + * + * Unit test for initjmp() + */ + +#include +#include +#include +#include +#include +#include + +static bool ep_entered; +static jmp_buf return_buf; + +static void __noreturn entrypoint(void) +{ + ep_entered = true; + + /* Jump back to the main routine */ + longjmp(return_buf, 1); + + /* Not reached */ + panic("longjmp failed\n"); +} + +static int lib_initjmp(struct unit_test_state *uts) +{ + int ret; + void *stack; + jmp_buf buf; + /* Arbitrary but smaller values (< page size?) fail on SANDBOX */ + size_t stack_sz = 8192; + + (void)entrypoint; + + ep_entered = false; + + stack = malloc(stack_sz); + ut_assertnonnull(stack); + + /* + * Prepare return_buf so that entrypoint may jump back just after the + * if() + */ + if (!setjmp(return_buf)) { + /* return_buf initialized, entrypoint not yet called */ + + /* + * Prepare another jump buffer to jump into entrypoint with the + * given stack + */ + ret = initjmp(buf, entrypoint, stack, stack_sz); + ut_assertok(ret); + + /* Jump into entrypoint */ + longjmp(buf, 1); + /* + * Not reached since entrypoint is expected to branch after + * the if() + */ + ut_assert(false); + } + + ut_assert(ep_entered); + + free(stack); + + return 0; +} +LIB_TEST(lib_initjmp, 0);