From patchwork Mon Mar 31 12:31:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 877293 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp1726625wrs; Mon, 31 Mar 2025 05:33:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX6nMq1EHTujij/uhEFzPeR4VJxPgwVX22H8u12iIeHpVg7iErvjrDu42HC2s/Xa++OhV+Zig==@linaro.org X-Google-Smtp-Source: AGHT+IGV9oR5QltwGO4Sm8KnLOyS54dWqwHsw7ezS+bxleOF11JVZ2KlZwBsqsIDeUYLHK68RFBZ X-Received: by 2002:a05:6102:3e8a:b0:4c3:6ba1:3aac with SMTP id ada2fe7eead31-4c6d3837bcdmr5385589137.3.1743424400050; Mon, 31 Mar 2025 05:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743424400; cv=none; d=google.com; s=arc-20240605; b=lJq/k3F6OtpsjWKLG4HaolpmBO9zRB+n5hqksXsIHg7bU+cD41adIBA3ap9HWE9J3w 654vV6feVSHstuzBecSamk7FFTHnEdS8OI1zjna7MGZ7l06lbase3jHbjnslsHGM+rJo 6cFB89Q0P6jISBNOl2kCt6d470l2OQoWkb+4qWUHSAlefY5XnMj6JazWdWOy6o3F1do0 3vRVwBHGAeVCmfFNuNslBhEwG0knfCqjesN0pK6poQL12FhX1gzem/Gat35l248dzLvf ZIqLcwMHbjuvA4CIAYHsE5KrvmyifaZqOXk9s57aFJDECNlW/ulD2TS3Y+c2On0Ek5Ro BrXg== 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=vRaJm7848vfOJLHvrW3owiUGagnHG2yjnxN7am7SWEk=; fh=pwzqd1tcaoJvPaaF+Zz6jA22igjjbWCnYSzWt80XhHg=; b=ky+4mHAZ6aczelzoO/QhiF39N4HqZk47KxYnMbYvhHdiaMKB4TRhVAWpz+93VryrPx iRymAJSYWPnPkCM56ia8jR7ma2PD9VriRY1VqolGGV7ytWWw8Dp38lwl9y+UfeCwPNgC FIPI2DXOxbCltGylFFRWldKGw+te1dJ0MIS1iV48JiYjsAyay+/5nOtv/xN9kthT3/V4 LLcajl36npluNN9H2iIJrirdwcKUOkmCAbLzkYATvj7G4bCMHLKR8DXcE8C78dqpaBsX U+bf8l4aHRZlpBOA9kB5BkeiFNsa1OPKgrN5EOZLLYIX8tWibHGaJWfG4gWmcbd+sSPS ELEw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TImoIXsq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id ada2fe7eead31-4c6bfea5805si1642204137.680.2025.03.31.05.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TImoIXsq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 EB34282033; 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="TImoIXsq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D8EE81703; Mon, 31 Mar 2025 14:31:51 +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-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 6186A81703 for ; Mon, 31 Mar 2025 14:31:49 +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-wr1-x433.google.com with SMTP id ffacd0b85a97d-38a25d4b9d4so2318604f8f.0 for ; Mon, 31 Mar 2025 05:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743424308; x=1744029108; 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=vRaJm7848vfOJLHvrW3owiUGagnHG2yjnxN7am7SWEk=; b=TImoIXsqeXXfOILouqXKqw5nU9DEAtJbvgTL/zrCs1djs6mgkOEWQglHNkCBwV+jM2 mZ5wC7pHEoG+VAAN293O5dvD9s8D8+Vk7k/iSB1dZPSKGL2lBXlLfkry5+5qG0Z82iY2 aYT4q6K5SVU3cmtrQvSr8clYn1+uMkJJ4cphpT8IA5aKHnGW9wQF13uIMzVc9nEpfVds cyRa/rXgDlACizi7z125/R1hw5+M3hGCFh122Gc9kxAKthoQGqqmvrNF8yeD1uhO4jCR 5tVH34ICXT/XStCTE+3SnVOS7m6yyCn0ax+uZuzGFqdupm/aCj5qSSNsbvHOtENlif9L meGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743424308; x=1744029108; 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=vRaJm7848vfOJLHvrW3owiUGagnHG2yjnxN7am7SWEk=; b=j+DjK7bjl2xYknhRMllOnliqhWPRf04h6KTZoZZro0kKefz4/1ZDfeiLIRrfb54Y5W 7f+cislwwUJ1oCfl3M9CD/fyjeIMlkheyqE7yRRFJhpQErPc3AoxXxfCUyGm9tfjJmC8 r0NyZOuJ+2z/CR+MLfd8SHHE/xSDqKsn5CVKE1/9s66f/lR2UCA4JrK4qfbvKcY431Hv gJpQnBDJsSaNen/8lDYtYUs/Y5WCXoHKdd0B2HVZtmDSlFWuVSy2XYDiRRFhpGHkXv85 fdW1yRtTarg3+0B8gFwvpwNH8n4K9HI/FoWwaFLT62/p49QiLYLhjKxZ5YEoNu1djELR SOiA== X-Gm-Message-State: AOJu0YxT/o/eFFW5e29jrWhURN0c7GdFQ1wbKUhk9YDQPE5GRwem4A9o Du9Ot20p1ybGEWR7QFWY8IKJ1h9jCXiusPIgfc8vVrxM4y5DmcuqM6pIMuCLxIQqcwfbe18i3yO y10TIbg== X-Gm-Gg: ASbGnctG1IzQXF34jbr+AQK+YDdZruKPuPr4+81ROuyk6pF/cNwztiAtK5KZaP/wf8z W8zwlJtEDn2681qJt8EvubpBxB/caTqtgqON66p/3RNsflLSwhjsi7MYHKk9ukuVV/sAygHeIVM fHfYRUrp4XlAC8Kw78IvuTJ3e957ZThKBDWYLh9HnEsRa/vOHEajRYkQw/HsrHhn6JEI9smrFwI 98aPSnUY3bSUMhMzQOUh+uA2LUcGKtjwwo/pNRytvDH3n1H6XS8gRcVNA1z2O8J/glat4wj/9Px 5orWhleD/DxVRzOQKUM5vgk/VFLBXFCvYmflgAz0nQ+3JkMEBn22 X-Received: by 2002:a05:6000:2910:b0:391:4889:503e with SMTP id ffacd0b85a97d-39c120f5923mr6319901f8f.33.1743424308596; Mon, 31 Mar 2025 05:31:48 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:31:48 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini Subject: [PATCH v5 11/16] test: lib: add uthread_mutex test Date: Mon, 31 Mar 2025 14:31:05 +0200 Message-ID: <20250331123120.2025062-12-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 test for uthread mutexes. Signed-off-by: Jerome Forissier --- test/lib/uthread.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/lib/uthread.c b/test/lib/uthread.c index 0c0540585e7..d33daa62f6c 100644 --- a/test/lib/uthread.c +++ b/test/lib/uthread.c @@ -78,3 +78,69 @@ static int lib_uthread(struct unit_test_state *uts) return 0; } LIB_TEST(lib_uthread, 0); + +struct mw_args { + struct unit_test_state *uts; + struct uthread_mutex *m; + int flag; +}; + +static int mutex_worker_ret; + +static int _mutex_worker(struct mw_args *args) +{ + struct unit_test_state *uts = args->uts; + + ut_asserteq(EBUSY, uthread_mutex_trylock(args->m)); + ut_assertok(uthread_mutex_lock(args->m)); + args->flag = 1; + ut_assertok(uthread_mutex_unlock(args->m)); + + return 0; +} + +static void mutex_worker(void *arg) +{ + mutex_worker_ret = _mutex_worker((struct mw_args *)arg); +} + +/* + * lib_uthread_mutex() - testing uthread mutex operations + * + */ +static int lib_uthread_mutex(struct unit_test_state *uts) +{ + struct uthread_mutex m = UTHREAD_MUTEX_INITIALIZER; + struct mw_args args = { .uts = uts, .m = &m, .flag = 0 }; + int id; + int i; + + id = uthread_grp_new_id(); + ut_assert(id != 0); + /* Take the mutex */ + ut_assertok(uthread_mutex_lock(&m)); + /* Start a thread */ + ut_assertok(uthread_create(NULL, mutex_worker, (void *)&args, 0, + id)); + /* Let the thread run for a bit */ + for (i = 0; i < 100; i++) + ut_assert(uthread_schedule()); + /* Thread should not have set the flag due to the mutex */ + ut_asserteq(0, args.flag); + /* Release the mutex */ + ut_assertok(uthread_mutex_unlock(&m)); + /* Schedule the thread until it is done */ + while (uthread_schedule()) + ; + /* Now the flag should be set */ + ut_asserteq(1, args.flag); + /* And the mutex should be available */ + ut_assertok(uthread_mutex_trylock(&m)); + ut_assertok(uthread_mutex_unlock(&m)); + + /* Of course no error are expected from the thread routine */ + ut_assertok(mutex_worker_ret); + + return 0; +} +LIB_TEST(lib_uthread_mutex, 0);