From patchwork Mon Mar 31 12:31:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 877292 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp1726543wrs; Mon, 31 Mar 2025 05:33:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX204fyztD3fJ3ShyC66Jx9WxJGIu+7V3LG1zF4sc6KY7G32YbomsmceKwWgR6XzLAUXvUZoQ==@linaro.org X-Google-Smtp-Source: AGHT+IERj4Foq0Ft7C6cwLOoRPZ65SYwDj2nGbPW37U9rFCa5Rb/nvfZszD8GyUNTBWoEhwRIBPB X-Received: by 2002:a67:e713:0:b0:4c1:76a4:aee4 with SMTP id ada2fe7eead31-4c6d39516f8mr5162657137.19.1743424391790; Mon, 31 Mar 2025 05:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743424391; cv=none; d=google.com; s=arc-20240605; b=C/GRwts2dFc+C/fF9EJebehxRgTZ9DCx+dZ3TsNhwNlM2Gmwjr5PZ3AA4xTw1smnRW Fu29+Mh1gO+QHxJQGbZ9WJc7OcMXTaBkRtnNjU7/yHMj2GJnNiNGCDGSgMl1gikrgto1 m8eJAD+D86dJwvsNy7GUsPDUH0YkRTK/YsEbY5RT9Md1Oog5fEHrcNZbih/fak4ufWgb NMpEMXOTur+ci4+2zZ1SxHwnEeAPlw9gU5wblXrUTEMe5ToFSH6nXe1Ny2cTwODfTAL5 gXGGFeEQEshNfxY6inCAm1q3M2HxtaAwVZrcgaTSnaNRJ9MX3M681sWlzVAisxRtPbfK cw+g== 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; fh=pxkeymicbWSzax63Za9jHWp/6CzGxVjGkJodzxw4Txs=; b=einNj5gU5nD2hgdFrUxncfe6nlH2kQOOcBNa1QIQn2fYLniGgzcgwNL/fjVQ0eTFOP DDzH01JsLVoXe+9kRPirJN+Hj1fRFrg6FlHwHXtNBLwbuOIwsb0T0B3fLPaZsfA5XH5/ nvhufhPQaEWFtSdAT+FolmPx1N0SttEJjGmjUmE+3EzKh7qqGAdM1L59qJEpNlXxLVKz 7jXk2mVQiHDxLR8JxzPiUM2WmRFZoWBiDFJaQV/iHqeyaeFgdPWp7rKh3qotihN8Z77b DTysKdA8RtKbBJHKL/ug0SYDiiRyLC/rOQTEKCs6qWr7aSKE5Plj7XhWjAZkAHMCdFTh wntw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zuf17zPN; 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 ada2fe7eead31-4c6bfe83f3csi1595845137.568.2025.03.31.05.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:33:11 -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=zuf17zPN; 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 9E9D082027; Mon, 31 Mar 2025 14:31:53 +0200 (CEST) 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="zuf17zPN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5094782027; Mon, 31 Mar 2025 14:31:50 +0200 (CEST) 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 2DD5981F0D for ; Mon, 31 Mar 2025 14:31:48 +0200 (CEST) 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-43ea40a6e98so2975835e9.1 for ; Mon, 31 Mar 2025 05:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743424307; x=1744029107; 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; b=zuf17zPNMxy6NUYGMq5b8e81v/T/9zjIzasA3hfQRG6HS4KNyiuIrOOsvWfiHLgeId zoMPQBpNquuTLZFTLdhp3muggAPDyLt4RSMG9LNzNgN2ZuQvjCVrbX9X5IiC2Tp3BFdt 7UTlE4TaILvxxiwSWAaAjANyf9XuhpU5CFEWVS6ZhhdgwMYfs7HpalSkvVSPgjqU4bfD kw25RynHITm2kP38/nepDUUWLB9yckNT/Zg2CQpyytg7DlR8cW5Lbj9KKN9FJUusq4nH hhAXwMFiLHvJF0ljy42uKjbCM+IgCJ22/sTwLxK0uKu6WHtgcftQbu6g/m33cAP06d7L TgQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743424307; x=1744029107; 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; b=UP7DUzBHLsXWkCFZMobJR3j6EQM6xikQOPXLqisXqSVwkHMhooDan/Xl94DkFw8H2k tYBZSOYo+SDD4kVNx/dVZhqO8X2uVjEF7K2+9ovP0BmGAbmMeRCNdBO3mSSvxFQnwmko cDo+XoMTyYJv+nykJ/dYHuTzVO3dNr4otsByklj+Vc/I+Gbxpws5SUqieoNRDHEvVFuN 5lkk9JM6GxMmD+0cmK/BmAA/F1yyGgwgZ5/ZCK6GxRfebBsGwJL7X9Ao+wlT5yxxiEmh kdiMl1Qx42sttfMyrvT9RNb6fDD1AHkpKXrwI9eVDG4Zna2VrasaTHkTClzpjoh/hx/K iTaA== X-Gm-Message-State: AOJu0YzIhyMORYRnMcdpE8zs9/iwBk18r4KLKl/Lt0h1h7M8/JUoeMz7 lLYz/wsfGdsES86yFEliGmZgStQAY0Bny04OFopNW9sfQKhdJ0q4VMDpfUcKGAbLzq9io81iUeG 7R83Mwg== X-Gm-Gg: ASbGncsx+BRKGsYugLQYeUjwTnUpyvZbm2rQDs8/1T4L3SbA7ryAt0QkW5Jc739MYx0 jtdtF3pdj+7TCLPgDqlbQsJShJPBScVB6APQB+BW0UHUxYcqr0to81KMZIXAFPyoxG9LZ99DJQe PdPw6fF4r7od9h8cRg+p3VriZdPhEH3psE+xH/a6I6rIYhX2tl/QPEcx/uME28JVNE86Ul/5QSY Ytr62NMC25xkjMUYP6EJInVW6hbA9BnXbVvhm8QKMnPX523xNxk3iWcieoofrsDJXIfRAagsVSw TGVjmlKNuOpOHBQayr7PjjkIRvcuxwxgdjEOwDhsWNGYNb6Zq8Ah X-Received: by 2002:a05:6000:420a:b0:391:487f:2828 with SMTP id ffacd0b85a97d-39c120cd1d0mr7340258f8f.10.1743424307373; Mon, 31 Mar 2025 05:31:47 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:f23c:25c9:dc74:be1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c0b6589e4sm11337029f8f.10.2025.03.31.05.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:31:46 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Heinrich Schuchardt , Simon Glass , Raymond Mao , Philippe Reynes Subject: [PATCH v5 10/16] test: lib: add uthread test Date: Mon, 31 Mar 2025 14:31:04 +0200 Message-ID: <20250331123120.2025062-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250331123120.2025062-1-jerome.forissier@linaro.org> References: <20250331123120.2025062-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 Add a thread framework test to the lib tests. Update the API documentation to use the test as an example. Signed-off-by: Jerome Forissier Acked-by: Ilias Apalodimas --- doc/api/uthread.rst | 12 +++++++ test/lib/Makefile | 1 + test/lib/uthread.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 test/lib/uthread.c diff --git a/doc/api/uthread.rst b/doc/api/uthread.rst index 21233ff6b22..8b25cc1ff80 100644 --- a/doc/api/uthread.rst +++ b/doc/api/uthread.rst @@ -3,5 +3,17 @@ Uthread API =========== +.. kernel-doc:: include/uthread.h + :doc: Overview + .. kernel-doc:: include/uthread.h :internal: + +Example +------- + +Here is an example of how to use this API: + +.. literalinclude:: ../../test/lib/uthread.c + :language: c + :linenos: 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..0c0540585e7 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for uthread + */ + +#include +#include +#include +#include + +static int count; + +/* A thread entry point */ +static void worker(void *arg) +{ + int loops = (int)(unsigned long)arg; + int i; + + for (i = 0; i < loops; i++) { + count++; + uthread_schedule(); + } +} + +/* + * lib_uthread() - testing the uthread API + * + * This function creates two threads with the same entry point. The first one + * receives 5 as an argument, the second one receives 10. The number indicates + * the number of time the worker thread should loop on uthread_schedule() + * before returning. The workers increment a global counter each time they loop. + * As a result the main thread knows how many times it should call + * uthread_schedule() to let the two threads proceed, and it also knows which + * value the counter should have at any moment. + */ +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(NULL, worker, (void *)5, 0, id1)); + ut_assertok(uthread_create(NULL ,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);