From patchwork Tue Feb 25 16:34:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 868122 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389140wrb; Tue, 25 Feb 2025 08:36:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVsDctE8f34LNgrwh/vVlzEB994p+/oQ4HZuL5aMxLuuGfn5pUBYhtf6oiJiJmWc6+hB0qacg==@linaro.org X-Google-Smtp-Source: AGHT+IHSBZEuDVns9VEhQiPOB650MV9kDGDyLQn8h89NuoAVMZX70KJcMtLw3iVDdDxY1vWqffN6 X-Received: by 2002:a5d:47a6:0:b0:38f:3a89:fdae with SMTP id ffacd0b85a97d-38f70859ee3mr13622636f8f.46.1740501395441; Tue, 25 Feb 2025 08:36:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501395; cv=none; d=google.com; s=arc-20240605; b=Wbi/42hww4AjG2V8N7wpVn8xtSwfgndlLhrCQRZZzTKRQzKubnFV/S5Q+xY74usiib 03mhkUgMaHTpbBdUhB1YUTPqMFpmkGU3V7Uz02sCfmI4jvL9ynjskim8CZ7KsvkTao0H eYyI6abUnEjC8jzHNZd+oBzfz7OLWatbSSYO9+wVlXgBD/IlmG6fAZu1Y6aeoqGg2k6j nPI5F0FHmwCZky9VHtFLOm8eBvC8NbslfTtmF7b4IPt067QVARSxD8O80yA9hgwyJIWD RwQRc+iUBNea9cQab57JuoHhc3mbrAl2h6otT1CyUe0d3QAmGbeynlzcPtln6lB15E6J DuiQ== 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=QYWoN9iTth0GmhEwCvvUxY91BaLJyfvZA4d6KKqMzmqQXTIwfyL56Ud5iy9XOaZ8E+ p8fQ7WHWoN25ZFt8yY5unGslEndkcH1ZGm/OvQwMkWZDiRXlbX5lz26Kb5Jp+8zpnAxt FsCFDaTXluRrEMs5e19I5WDi2Uhd3KqZTwYnlVDGTJNvA06emtJut+iOR7qMqSGhifa/ OyoKPeVG6Lq2Z8ZbRdzHDI4x0iG/gdvkDFepxRif+BHhK2oRrqFSk39dVGFkm7MPCgV+ puHKapPcpHLoCOaV8JFlw/yN0Gd/qe/lWGxS9tQLEIOJgUkt04r9bfeOiUfSSHv8dLzN T1yQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUBnXKQg; 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-390cd8e6521si1302593f8f.510.2025.02.25.08.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:35 -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=JUBnXKQg; 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 3A8698104B; Tue, 25 Feb 2025 17:35:27 +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="JUBnXKQg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D98FA810F1; Tue, 25 Feb 2025 17:35:24 +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 D8DA78104B for ; Tue, 25 Feb 2025 17:35:22 +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-439ac3216dcso34660075e9.1 for ; Tue, 25 Feb 2025 08:35:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501322; x=1741106122; 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; b=JUBnXKQgFO6E6wE2S5QBrGSEtwdEVCxPDY4m/xZzTnCZ4Ix4/2XDJKvp9V0E3p1dhR 3rPVLa2m/FVacw0p9o1/1T4/pIizJhMfSXtlBSIIGJ1pLDwP/HkGvyrP+sLsLOfXPLba czFRSN4YuTbIYT9vQwKQ79fZ3IuhNPzwqlzs2OGJEW6wbwSJY7H0I21KWsViFwVQro14 sQ/YM8kIZqwVtY09yvYAOLWOzkzN9tfWHaKNe9pFqYZatJ1oEAHzsVOCch9A06W+8SgC pR3aI8roXWQ6v8awtVmpIzr/DhOVSrVJOkp3wHG4rFjTLU1izaFWkd62boAlQo67FcK8 rjtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501322; x=1741106122; 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; b=rkAdu1WpcpAnrPLhTtu8BrPDo6+vTuLxrvjHKGVqktuyFyKBdLTMM6UpNTM6lz++Pa D8QdQL8k1xT9a3rWwhiinuN6pwDvKsjOqOxs//jgPPyW1Fj/jA3EMslnPIH5/TKMYT3Q 2l/QRZgIaAby1OUZOU6vz1P/79q2BoQaQ3K4bQMd1Im+r93ST+iPFmLR7/Z6BuWhq+RX cw6MO7w5tknPILvTot2QnUzGksNnTWPwe12kD51DdrlaHQBUs1AbOyhj1SjEKA+bHAmG WO7BghuiUnBheEVTm4ODZOfyQB+ylPygceViUes9Kb8cXesaaqTSD9NrOBS44nz6j4hA TWQw== X-Gm-Message-State: AOJu0Ywcw6/KfHcODZGXeWh4qmxXsXQPKKaLL1SGWdkYQb/VQke7HOy+ y7BZjkGg/XizVOlH+AsAlX4+6SK6bJTd7emhmOixCeS98OoXIFHtukH/FGElydCWPt7HaNxMZgk 6crCIqA== X-Gm-Gg: ASbGncv6i2+PL07hFw5lASxOG8rNYnFo/k0o3JNxbmJuDRNpeFazTVGgj5SP2W1Rqwk CCxbw2jIzwf1YdLioV445emcBFkEVd2ZrK1+9k53WRwqdQjpdVJdd0audkG2QSoPoR0WiGUNzGv HCbXVdwx12Z2hXEIKuGyF7B0I5SLBtqtAjYFlzCP1iNT9GGM4TSqWRcH7fSqKupefdboz/IGzt2 +aTyC5ZgvFaP53VfKWjBU2fpdtZx0Fe2PC5Y3rHuqAzAEvYvunJGSKyU2fI54m1lheQfk/4i9vi +5w+d7F03LfivcPf+iUif6A7oLmM+xnRm6g= X-Received: by 2002:a05:600c:1906:b0:439:9c0e:3709 with SMTP id 5b1f17b1804b1-439aeafab74mr127407795e9.8.1740501322187; Tue, 25 Feb 2025 08:35:22 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:21 -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: [PATCH v2 10/14] test: lib: add uthread test Date: Tue, 25 Feb 2025 17:34:36 +0100 Message-ID: <17ec7e3f553fa8c36c19d2cbf4cc0e6d03c7e443.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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 Add a uhread framework test to the lib tests. Signed-off-by: Jerome Forissier --- test/lib/Makefile | 1 + test/lib/uthread.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/lib/uthread.c 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..84c41d35875 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,68 @@ +// 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; + int id1, id2; + + count = 0; + id1 = uthread_grp_new_id(); + ut_assert(id1 != 0); + id2 = uthread_grp_new_id(); + ut_assert(id2 != 0); + ut_assert(id1 != id2); + ut_assertok(uthread_create(worker, (void *)5, 0, id1)); + ut_assertok(uthread_create(worker, (void *)10, 0, 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); + ut_assert(!uthread_grp_done(id1)); + /* Four more calls should bring the count to 10 */ + for (i = 0; i < 4; i++) { + ut_assert(!uthread_grp_done(id1)); + ut_assert(uthread_schedule()); + } + ut_asserteq(10, count); + /* This one allows the first worker to exit */ + ut_assert(uthread_schedule()); + /* At this point there should be no runnable thread in group 'id1' */ + ut_assert(uthread_grp_done(id1)); + /* 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()); + + return 0; +} +LIB_TEST(lib_uthread, 0);