From nobody Wed May 1 07:53:03 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VTq735Wrnz5JPjh; Wed, 1 May 2024 07:53:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VTq734x9Gz4W03; Wed, 1 May 2024 07:53:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714549983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sAuwb0MHvUwBRJxxQv4twwczVm84A0jZ5Bu+ogHR8a4=; b=JuDn2/Rc6cB95wu6ajtLCCihplR+ISXIava0MsEpF18bbR/eBILRawCBzqwdzERB94Jz+V uTQ2Hj7raWTimqopYNCl212I1KO4fqrC1W6okgw4m+U5GBW/ZSqPcwDKy6HPTq5SW97EvQ h01+dPnFQ6+k0eDnyiL4QIPaypXHQxJ7l5LEeZJRJVeFVBX8U2lFxlrhte2COIy3J23+Co yWnBFGhEFDmFwkUozkcmQ0N1QuutNXlEJlACywWqv5DAirhUSwtD9Ma0c2bArpPJPCudSi HgK9pjkoVh5Hig/LvFxCf4HK3Ji712AK9xuE+y1FuMsSdr0ViUovg3loY+wIjw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714549983; a=rsa-sha256; cv=none; b=jBvPdDuwG05zdp3zZqDdEzvGlbX95z43Z4sODYoWSH+J1t5EpRWWX0A6VrTSYMDGF3hhXa MjmyAm48E8dE7qnJiA0A2hpy2k54KuOH9Bi4Bsz6WZQEF2tR7ZIwIFnXLuS04nu521wZyb GIvxfzmBm55kzMiurgx924o/Z7YmPKMlPmHVRJJyivOx1RVGyil8Z5pxrFt3Htdh1k4df3 7ukVQGXevimGDQXlH8suyEycjAa9UhNwS7TOwXc4R43buXVCZmHRtJB7D4dIma0gSSK8vh C9utlfRDw7Sc8Ar7Z+h6irAib+qlWRuIsuYao3iEgwC8LSRNiWXzZZIc/UIVnw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714549983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sAuwb0MHvUwBRJxxQv4twwczVm84A0jZ5Bu+ogHR8a4=; b=o5p+OXEIP2kdcFHbnY3F8lmxUgx8ttuLQxGqp8y4oQ8/ipcF/x9fqSDFM9wzooU4B/qwqv ZJlAbZyD6KaTygXZtIIUIfmxsiYBug3OzG6doLiiZg4bzD40X3YKoiJGUkE2hug8iySYZT LmrJ7WadQ0Oo5O5DVXrAMpfMOJNJ8qcffksEKzjdlQa/WyRW7vb1YgC9mkwcwTZQehP98Q nHIM0nlUB1wBzSWWWB2LlkocY8T2TmuZi7UfHWfwxMam9d3OP+Xzh5FyxQblJLqcU2J5oV 8Ju8OXT5lu2YcW3KfHfF9etwKZAbs4CGvsZR2991w1fMrAZutG/WsRxTR78mFQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VTq734WWNz19F5; Wed, 1 May 2024 07:53:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4417r39E080945; Wed, 1 May 2024 07:53:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4417r3bX080942; Wed, 1 May 2024 07:53:03 GMT (envelope-from git) Date: Wed, 1 May 2024 07:53:03 GMT Message-Id: <202405010753.4417r3bX080942@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: 9d1396c34611 - main - fattime: make the test code check beyond 32-bit time_t limits List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9d1396c34611a2ed1e93c3cfb04db7a6148458bd Auto-Submitted: auto-generated The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=9d1396c34611a2ed1e93c3cfb04db7a6148458bd commit 9d1396c34611a2ed1e93c3cfb04db7a6148458bd Author: Josef 'Jeff' Sipek AuthorDate: 2024-04-29 13:40:30 +0000 Commit: Toomas Soome CommitDate: 2024-05-01 04:56:41 +0000 fattime: make the test code check beyond 32-bit time_t limits On systems that have a 64-bit time_t, the test code now exercises the whole range of fattime. To do this, this commit... 1. replaces the call to random() with two calls to arc4random() to generate a 33-bit number of seconds in order to cover the entire range of fattime [1970,2107]. (32-bits stops just short - in January 2106.) On systems with 32-bit time_t, the extra bits are discarded and only the time_t expressible range is tested. 2. casts time_t values passed to printf as longs and changes the format string to match. Now, the test code builds, runs, and exercises what it can (i.e., the whole fattime range or the 32-bit time_t subset of it) on both 32-bit and 64-bit time_t systems. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44754 --- sys/kern/subr_fattime.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/kern/subr_fattime.c b/sys/kern/subr_fattime.c index bdbc4e11827a..7b41b551eeef 100644 --- a/sys/kern/subr_fattime.c +++ b/sys/kern/subr_fattime.c @@ -84,6 +84,7 @@ #define YEAR 365 /* Length of normal year */ #define LYC (4 * YEAR + 1) /* Length of 4 year leap-year cycle */ #define T1980 (10 * 365 + 2) /* Days from 1970 to 1980 */ +#define T2108 (138 * 365 + 33) /* Days from 1970 to 2108 */ /* End of month is N days from start of (normal) year */ #define JAN 31 @@ -275,11 +276,17 @@ main(int argc __unused, char **argv __unused) for (i = 0; i < 10000; i++) { do { - ts.tv_sec = random(); - } while (ts.tv_sec < T1980 * 86400); + /* + * 32-bits gets us to 2106-02-07 06:28:15, but we + * need to get to the end of 2107. So, we generate + * a 36-bit second count to get us way past 2106. + */ + ts.tv_sec = ((time_t) arc4random() << 4) ^ arc4random(); + } while ((ts.tv_sec < T1980 * 86400) || (ts.tv_sec >= T2108 * 86400ull)); + ts.tv_nsec = random() % 1000000000; - printf("%10d.%03ld -- ", ts.tv_sec, ts.tv_nsec / 1000000); + printf("%10jd.%03ld -- ", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); gmtime_r(&ts.tv_sec, &tm); strftime(buf, sizeof buf, "%Y %m %d %H %M %S", &tm); @@ -299,7 +306,7 @@ main(int argc __unused, char **argv __unused) ts.tv_sec = ts.tv_nsec = 0; fattime2timespec(d, t, p, 1, &ts); - printf("%10d.%03ld == ", ts.tv_sec, ts.tv_nsec / 1000000); + printf("%10jd.%03ld == ", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); gmtime_r(&ts.tv_sec, &tm); strftime(buf, sizeof buf, "%Y %m %d %H %M %S", &tm); printf("%s -- ", buf);