From nobody Tue Nov 4 21:57:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530815016745546.1845686154574; Thu, 5 Jul 2018 11:23:36 -0700 (PDT) Received: from localhost ([::1]:54280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb8ul-0006P1-Li for importer@patchew.org; Thu, 05 Jul 2018 14:23:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb8rn-0004Sa-O8 for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fb8rj-0006E9-2h for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:20:31 -0400 Received: from mail-pl0-x22d.google.com ([2607:f8b0:400e:c01::22d]:35137) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fb8ri-0006Do-Rl for qemu-devel@nongnu.org; Thu, 05 Jul 2018 14:20:26 -0400 Received: by mail-pl0-x22d.google.com with SMTP id k1-v6so1630862plt.2 for ; Thu, 05 Jul 2018 11:20:26 -0700 (PDT) Received: from localhost.localdomain (c-73-158-53-43.hsd1.ca.comcast.net. [73.158.53.43]) by smtp.gmail.com with ESMTPSA id g75-v6sm14170847pfg.145.2018.07.05.11.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 11:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vDTp3oeug8/fXwEh2tmR+OPN22ajYk+8qT0bohkAij8=; b=dStGBS/Kji/5CISuF6ivkysPyNwoM6SZ7h/Dbj47BdpayNHhECIkMaPzmxiDgRpBPU 3rkiMxWNdav69lyDiaSC2qx/8wI7WrkZIu3Mm710tT2w+8EmV7ffIv0pwfADKsPdkw6c 9Tujddc3o6mycugUMYVyQrzYA/kQru+XlnojsUptENmBIhCz2ecw69S7bKjxvMA1DTxt tFFYGOqYwLiQhEPobISpa+nxvZD07zGTOWUlgRV4bWZWCwOlsAxWmowiQN0bBaFJJC5v 7tpBflEnZWD5nBLkHOmpf0aV9rzvz+XCKWSgY6Jh2r+5JRlAcvkDtFbdHzFfUYAVoVl9 rwJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vDTp3oeug8/fXwEh2tmR+OPN22ajYk+8qT0bohkAij8=; b=MD0j5EalVgPTS8lMHZZUxLJN3h9yCU9D1/eWk/r73ppR6fyRQFYdISwdLmU18SeXMu 7lIHrp/0VveCjz+IzXxtmyw8Anh8zCqmZgd94CPfVLIjucFdEKbbmnrSYPrUhj21Cl5e yq1FS3G/6WveLeJWalgUmAFfg+WcZmV2exA0RgFNSrpMcDZa/aJqjnswLK2YClnVBIdd E/oIDfay6NoIVzDdjLSvILFGztSVBpCb4Bn0l5X+1rG5Yta1H6rHfJVmsjp7xIn3OhHQ IjiBecHmQfl78bPZZGgNUgQiYf24ydW4yK4sCgOTyvwZSFY03Ufr0MO36jcOwUt1SMDJ 3E/A== X-Gm-Message-State: APt69E2QyxugMZqRjJxaWHOpXtqpHCVkYHLXZ/qAMeAvXQ/eLbEZv8EQ MTETWElMMhNLHWRvCySlCj4oWQ== X-Google-Smtp-Source: AAOMgpdzzJEwd5un1ubQRGI6unPCrKew2PpzIXXBYt4QHCJmPs9fHvCohb4qQuYr9i3+nLUO6ORuFA== X-Received: by 2002:a17:902:aa87:: with SMTP id d7-v6mr7231867plr.215.1530814825942; Thu, 05 Jul 2018 11:20:25 -0700 (PDT) From: Michael Davidsaver To: Peter Maydell , Paolo Bonzini Date: Thu, 5 Jul 2018 11:19:54 -0700 Message-Id: <20180705182001.16537-8-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180705182001.16537-1-mdavidsaver@gmail.com> References: <20180705182001.16537-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::22d Subject: [Qemu-devel] [PATCH 07/14] tests: ds-rtc test wday offset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antoine Mathys , Thomas Huth , Michael Davidsaver , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Davidsaver --- tests/ds-rtc-common.h | 10 +++++++--- tests/ds-rtc-current-test.c | 9 ++++++++- tests/ds-rtc-set-test.c | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/ds-rtc-common.h b/tests/ds-rtc-common.h index c8e6c2bc5b..633131c55f 100644 --- a/tests/ds-rtc-common.h +++ b/tests/ds-rtc-common.h @@ -20,7 +20,7 @@ static uint8_t addr; static bool use_century; =20 /* input buffer must have at least 7 elements */ -static inline time_t rtc_parse(const uint8_t *buf) +static inline time_t rtc_parse(const uint8_t *buf, unsigned *wday) { struct tm parts; =20 @@ -48,10 +48,14 @@ static inline time_t rtc_parse(const uint8_t *buf) parts.tm_year +=3D 100u; } =20 + if (wday) { + *wday =3D parts.tm_wday; + } + return mktimegm(&parts); } =20 -static time_t rtc_gettime(void) +static time_t rtc_gettime(unsigned *wday) { uint8_t buf[7]; =20 @@ -61,7 +65,7 @@ static time_t rtc_gettime(void) /* read back current time registers */ i2c_recv(i2c, addr, buf, 7); =20 - return rtc_parse(buf); + return rtc_parse(buf, wday); } =20 #endif /* DSRTCCOMMON_H */ diff --git a/tests/ds-rtc-current-test.c b/tests/ds-rtc-current-test.c index 6acbbed9a6..7dc3202261 100644 --- a/tests/ds-rtc-current-test.c +++ b/tests/ds-rtc-current-test.c @@ -20,17 +20,24 @@ static void test_rtc_current(void) { + struct tm tm_actual; time_t expected, actual; /* relax test to limit false positives when host may be overloaded. * Allow larger delta when running "-m quick" */ time_t max_delta =3D g_test_slow() ? 1 : 30; =20 + unsigned wday_expect; + actual =3D time(NULL); /* new second may start here */ - expected =3D rtc_gettime(); + expected =3D rtc_gettime(&wday_expect); + + gmtime_r(&actual, &tm_actual); + g_assert_cmpuint(expected, <=3D, actual + max_delta); g_assert_cmpuint(expected, >=3D, actual); + g_assert_cmpuint(wday_expect, =3D=3D, tm_actual.tm_wday); } =20 int main(int argc, char *argv[]) diff --git a/tests/ds-rtc-set-test.c b/tests/ds-rtc-set-test.c index c48406ee2c..12aeb2580a 100644 --- a/tests/ds-rtc-set-test.c +++ b/tests/ds-rtc-set-test.c @@ -124,16 +124,18 @@ void test_rtc_set(const void *raw) =20 const uint8_t *testtime =3D raw; time_t expected, actual; + unsigned wday_expect, wday_actual; =20 /* skip address pointer and parse remainder */ - expected =3D rtc_parse(&testtime[1]); + expected =3D rtc_parse(&testtime[1], &wday_expect); =20 i2c_send(i2c, addr, testtime, 8); /* host may start new second here */ - actual =3D rtc_gettime(); + actual =3D rtc_gettime(&wday_actual); =20 g_assert_cmpuint(expected, <=3D, actual); g_assert_cmpuint(expected + max_delta, >=3D, actual); + g_assert_cmpuint(wday_expect, =3D=3D, wday_actual); } =20 int main(int argc, char *argv[]) --=20 2.11.0