From patchwork Fri Feb 14 14:00:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865105 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170640wrz; Fri, 14 Feb 2025 06:02:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUhi1c74dRPHL5NoReCTB3CgJ89CLYh45RKvOOroPCuzcInNqhcQDImwTMYC6WbVAQpXXCX0Q==@linaro.org X-Google-Smtp-Source: AGHT+IFgBduo3DM+SY6n+2WimlFVIyR7gNcDHpkm86zTg0eySuQWHTs/HQguUDfL9W6ji6jKVhTY X-Received: by 2002:a05:6000:1ac8:b0:38e:ae25:6d66 with SMTP id ffacd0b85a97d-38f244e4874mr9316472f8f.19.1739541769829; Fri, 14 Feb 2025 06:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541769; cv=none; d=google.com; s=arc-20240605; b=XlZJi82XmJCL7mCDfSgdF1bLlCMmTOcy+aSuQ5FlCNudSHrS/6jUxDxYF6T7CTcOhr sh/McVoooNJmyX9j7kLVEUFk0fM3g7adNIcpyftTib/H6t78zaBgKY+ntMrw2aMF5nLR Q9NRYtKJAtQI/XKLp3hq/DjgfYeEjk7X/z0l8UE0IhpX/hPE90Si1IdsfOdvFAOYXayD pKDYaJaBfJZkS1KSMNFOqhU++Njke8gDkXqS7fvd7nl3xp9VkNRbQ+3L7xXp9WexpF8v YH6lnBaLO9WAHnG/UUXMP62YsysjItH/RPjbUPuYBPa5XdB+f1/+ab3ffIygajou62LB 3gTg== 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=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=PGPzJlceHqu3JT9tLguwP6lj981hJHHuOygVwj/8fElGimnFzT9FG7H02Fu1a6GZbT lUCFrckBsXdK2FCO4B9y8Ts5/DxdF62W6PNE87B039XwFi0DCN3rJGDnsZp0jxW1G+k7 e3OROHqP7iChzDeJdwTvtk7YxKRfdiFS0zld2jyU3Js8Yr5gVG5ZvvUutFXDMU9ouxn7 H9pJml4/G5bfcHPDWSRCCGxuhwX8lHSJYL0HUOyLif7kls3c8S23/xiV0Mf8roOE0hc2 xY8KqwoDQ4QHSUXnsLcm4NuREqJ61u46RM7t+KcDEZekqcbViW87f3kGaZsmON/9V0M6 XUgA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R7l5uCgC; 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 ffacd0b85a97d-38f25a1024esi4588975f8f.629.2025.02.14.06.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:49 -0800 (PST) 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=R7l5uCgC; 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 E7EAB80F4E; Fri, 14 Feb 2025 15:01:14 +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="R7l5uCgC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 41B2E80F30; Fri, 14 Feb 2025 15:01:12 +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-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 21ADB80F42 for ; Fri, 14 Feb 2025 15:01:10 +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-wr1-x42c.google.com with SMTP id ffacd0b85a97d-38de17a5fc9so1119847f8f.3 for ; Fri, 14 Feb 2025 06:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541669; x=1740146469; 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=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; b=R7l5uCgCzIaStf8A5dmtSr8Y4RY2cCVVQ5wzy7GsXAzODZv7UrPCvqSyC5Hg+vW03W iARmZhQ9uhAxLcguOSKp15Rrfd5zJUZqZwT+Aj7k9e0U3Es3OKSb00pgB5cVluV+r/LM 6CqzAm4dTv/+Mk1A2cjd9cu/rLssvvYMaLMaW/baqj+CKMcWRs7NhAV3vf1R4A3diUxX JZpLHwYpaisS00a1nqrxNwVu0wOT+93uJuyTU4fd7+GSEFglVyOTHGto//tSdVh4/4r/ G9KYQW0nmOiYkmWB3FEwklnRx56Yg1kpFed7bnXXiqATeJ9Br1WY25+fgAUWq4f+031W M5Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541669; x=1740146469; 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=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; b=A++W8PJ4urZudVmv0uU5isgYw+R8VWUyTokHX7/E47JDUfiWhkCD8Gv1n1ZzJZlVL3 0pLx2dJ7JeXh6guG77Phrz/0sRGqsVmMJiqvpj/Pgh7QrihcG2YfrSvCvMPms2u8P314 ZbbPCoOiHPanNoSlowVpqRdCw6Y/4jOnDCMNaKpBto9tGE8s3zUlc6bNLdxoz9WRsTRJ GavpjDXckRtU9Zpl2CdV3zALiXC6Ah7lKktwVALovhYrb+9UGczPMaS+ZmX8Z3+kCrSv j8aGi3PrmValYJQ1VnO7AooCODyoBTepDyi85p9zkQyxe+p1PQ4fGNNBy/aNydQNfOdm tvAg== X-Gm-Message-State: AOJu0Yz9ZGZwrvUUjmyP7Z5WJ+NOnE7s5kfqF5xVeXTeZqezBLZUAeiE ptCQ+5CumoPEdzdpQEBxcoD8VAEBcuXyT5Lc5Jc4FQBlm9Ph3lywScWso1C0rR2MnI9KAF16amr xQ2p9IQ== X-Gm-Gg: ASbGncucxZIn1bHj86QNbf8rhmeDNajmvWrZGlyEitxPunhV9pvNLhGfHNp6dDzQpT2 ap1VVaMKAXixxt2PIykpL4fqshhCQSQfG/tAWCpdURL1z54xiJT+Jg+f3anchEVRMFgMl/XyPcl 9KrjokMgxu6Z8Gi/sBr/WcI+5Vp5M7WU2X4opddz/t9bdZD83/6SCCATciQdEDBia9az/dog3j8 7iQ+rCr4dvXsalQaQhfstF6WDK9P1n4fUdTqKVubLbmuAuYlAshr9MsNVZPQzWQ7Dh1BTnXouF7 6y+gjyjtqh2X9TBPf5r1JJKJ X-Received: by 2002:a05:6000:1f81:b0:38a:8ed1:c5c7 with SMTP id ffacd0b85a97d-38f24528db4mr8934108f8f.46.1739541669158; Fri, 14 Feb 2025 06:01:09 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:08 -0800 (PST) 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: [RFC PATCH 10/10] test: lib: add uthread test Date: Fri, 14 Feb 2025 15:00:25 +0100 Message-ID: <20250214140031.484344-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-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 uthread scheduling. Signed-off-by: Jerome Forissier --- lib/uthread.c | 3 ++- test/lib/Makefile | 1 + test/lib/uthread.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/lib/uthread.c diff --git a/lib/uthread.c b/lib/uthread.c index bb132001fb6..1f8e6d0fa80 100644 --- a/lib/uthread.c +++ b/lib/uthread.c @@ -76,10 +76,11 @@ err: void uthread_free_all(void) { + struct uthread *main = &main_thread; struct uthread *next; struct uthread *tmp; - list_for_each_entry_safe(next, tmp, ¤t->list, list) { + list_for_each_entry_safe(next, tmp, &main->list, list) { list_del(&next->list); uthread_free(next); } diff --git a/test/lib/Makefile b/test/lib/Makefile index bf04685dae1..c991dff1c63 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(XPL_)UT_UNICODE) += unicode.o +obj-$(CONFIG_UTHREAD) += uthread.o obj-$(CONFIG_LIB_UUID) += uuid.o else obj-$(CONFIG_SANDBOX) += kconfig_spl.o diff --git a/test/lib/uthread.c b/test/lib/uthread.c new file mode 100644 index 00000000000..c9d030dc778 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for uthread + */ + +#include +#include +#include +#include + +static int count; + +static void worker(void *arg) +{ + int loops = (int)(unsigned long)arg; + int i; + + for (i = 0; i < loops; i++) { + count++; + uthread_schedule(); + } +} + +static int lib_uthread(struct unit_test_state *uts) +{ + int i; + + count = 0; + ut_assertok(uthread_create(worker, (void *)5, 0)); + ut_assertok(uthread_create(worker, (void *)10, 0)); + /* + * The first call is expected to schedule the first worker, which will + * schedule the second one, which will schedule back to the main thread + * (here). Therefore count should be 2. + */ + ut_assert(uthread_schedule()); + ut_asserteq(2, count); + /* Four more calls should bring the count to 10 */ + for (i = 0; i < 4; i++) + ut_assert(uthread_schedule()); + ut_asserteq(10, count); + /* This one allows the first worker to exit */ + ut_assert(uthread_schedule()); + /* Five more calls for the second worker to finish incrementing */ + for (i = 0; i < 5; i++) + ut_assert(uthread_schedule()); + ut_asserteq(15, count); + /* Plus one call to let the second worker return from its entry point */ + ut_assert(uthread_schedule()); + /* Now both tasks should be done, schedule should return false */ + ut_assert(!uthread_schedule()); + uthread_free_all(); + + return 0; +} +LIB_TEST(lib_uthread, 0);