From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C13DFC00144 for ; Mon, 1 Aug 2022 13:59:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1654784500; Mon, 1 Aug 2022 15:59:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dQ8OVfx8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 141AA844A4; Mon, 1 Aug 2022 15:59:06 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0: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 B163E8449C for ; Mon, 1 Aug 2022 15:59:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x331.google.com with SMTP id cb12-20020a056830618c00b00616b871cef3so8248120otb.5 for ; Mon, 01 Aug 2022 06:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KvfcVluRQJ71CwFvP8VXioEstxHX0e+IHYaM8DW28a4=; b=dQ8OVfx8chh1yioo7vQryEu/K2NJaJYAkvu+eCQjTEetgzwYady3QDkZ1d1vplzsuL Aplk3+or8WNLFveBtruQvorf9a94qmkdATKE1z8+Cjh0TB/0tPwMOoIO7E7qe1PFjVyQ vw/VI9LO6y/1R2/sKSUlbGJGpJI6wYpgq6pTg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KvfcVluRQJ71CwFvP8VXioEstxHX0e+IHYaM8DW28a4=; b=ylIzrVLMGji12sg4SQZu0wEru9kgiHnQy/MNeM4rz+BE6Z6BbpcgZiyr5C5Wa4A/OB SzLqsc0dz7Kh7+0NftzMslJ525NnwT3v0hXGzJZrBlkPYxFA63yQCggN4xRgttK0+iYe l+IOvG0TEZuDdx98ns9O3s5n7dRl2BhEjo2D3X59egBovm49FqH7Ux+nWrCvAhfglVLR oJm3GK8nTSl9K4ibY5ne2QIGf98VgG2Ox4V+TSVgNWN8LBTfM8/4dWfZgAvWuVlRmv62 dzlDWx+hYraczeVefCAECC55QXfQ7Pr+blltoiEU5CBKNkMDAeykEhtXxuo37N1SEfHQ U1mQ== X-Gm-Message-State: AJIora+ASGkEoBjcAJomQja2PjVSQr2JJj7ZDHGUW8KtWB5qP50gpaS0 n9OSY+8FWjTzraLErG8ZaEFHiV7H/wdzSg== X-Google-Smtp-Source: AGRyM1vsbX/W1A2IIpc8ALK84HGzjiZxfCCuWnO3wLXnvivXKmbezthtqpGJhM9CQCeX+1H6nM+45w== X-Received: by 2002:a9d:3cc:0:b0:61c:7d1d:2056 with SMTP id f70-20020a9d03cc000000b0061c7d1d2056mr6094749otf.247.1659362339167; Mon, 01 Aug 2022 06:58:59 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id a14-20020a9d3e0e000000b0061cf85b2a0csm2743161otd.5.2022.08.01.06.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 06:58:58 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH 4/5] dm: rtc: Try to avoid a race in rtc_set_get test Date: Mon, 1 Aug 2022 07:58:47 -0600 Message-Id: <20220801135848.992449-5-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog In-Reply-To: <20220801135848.992449-1-sjg@chromium.org> References: <20220801135848.992449-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean It seems that the time can change in between getting it and reading the offset. Check for this and try again if this happens. Signed-off-by: Simon Glass --- test/dm/rtc.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/dm/rtc.c b/test/dm/rtc.c index e23905b3e2e..50086ffcf36 100644 --- a/test/dm/rtc.c +++ b/test/dm/rtc.c @@ -60,16 +60,27 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts) { struct rtc_time now, time, cmp; struct udevice *dev, *emul; - long offset, old_offset, old_base_time; + long offset, check_offset, old_offset, old_base_time; + int i; ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev)); - ut_assertok(dm_rtc_get(dev, &now)); ut_assertok(i2c_emul_find(dev, &emul)); ut_assertnonnull(emul); - /* Tell the RTC to go into manual mode */ - old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + /* Get the offset, putting the RTC into manual mode */ + i = 0; + do { + check_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + ut_assertok(dm_rtc_get(dev, &now)); + + /* Tell the RTC to go into manual mode */ + old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + + /* If the times changed in that period, read it again */ + } while (++i < 2 && check_offset != old_offset); + ut_asserteq(check_offset, old_offset); + old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1); memset(&time, '\0', sizeof(time)); @@ -127,7 +138,8 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts) ut_asserteq(now.tm_sec + 1, cmp.tm_sec); } - old_offset = sandbox_i2c_rtc_set_offset(emul, true, 0); + /* return RTC to normal mode */ + sandbox_i2c_rtc_set_offset(emul, true, 0); return 0; } -- 2.37.1.455.g008518b4e5-goog