From: Paul Eggert <eggert@cs.ucla.edu> To: Eli Zaretskii <eliz@gnu.org> Cc: manikulin@gmail.com, emacs-orgmode@gnu.org, 54764@debbugs.gnu.org Subject: Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones Date: Tue, 19 Apr 2022 15:22:29 -0700 [thread overview] Message-ID: <6efc5d24-34a2-fd30-cd20-fe4ac3e48310@cs.ucla.edu> (raw) In-Reply-To: <83tuapvcxs.fsf@gnu.org> [-- Attachment #1: Type: text/plain, Size: 847 bytes --] On 4/18/22 22:50, Eli Zaretskii wrote: >> * admin/merge-gnulib (GNULIB_MODULES): Add gettime-res. >> * lib/gettime-res.c: New file, copied from Gnulib. >> * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. > Is this known to support MS-Windows correctly? I haven't tested it on that platform, though I expect it to work since it relies only on current_timespec and Emacs already uses that. I just now added some test cases to Gnulib for it; see the patch in the first attachment. You can try these tests in your environment by running './gnulib-tool --test gettime-res' in the Gnulib source directory. Or you can save time by running './configure; make check' in the directory represented by the second attachment, which is a compressed tarball containing the output of './gnulib-tool --create-testdir --dir test-gettime-res gettime-res'. [-- Attachment #2: 0001-gettime-res-add-tests.patch --] [-- Type: text/x-patch, Size: 4055 bytes --] From f67c0cfb02c920bd89f490c7790f991db45a0bc5 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Tue, 19 Apr 2022 15:13:09 -0700 Subject: [PATCH] gettime-res: add tests * modules/gettime-res-tests, tests/test-gettime-res.c: New files. --- ChangeLog | 5 +++ modules/gettime-res-tests | 12 ++++++ tests/test-gettime-res.c | 89 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 modules/gettime-res-tests create mode 100644 tests/test-gettime-res.c diff --git a/ChangeLog b/ChangeLog index 1e238d14e9..9bab736be4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-04-19 Paul Eggert <eggert@cs.ucla.edu> + + gettime-res: add tests + * modules/gettime-res-tests, tests/test-gettime-res.c: New files. + 2022-04-16 Paul Eggert <eggert@cs.ucla.edu> verify: port to Mac OS 10.7.5 diff --git a/modules/gettime-res-tests b/modules/gettime-res-tests new file mode 100644 index 0000000000..b169f1c187 --- /dev/null +++ b/modules/gettime-res-tests @@ -0,0 +1,12 @@ +Files: +tests/signature.h +tests/test-gettime-res.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-gettime-res +check_PROGRAMS += test-gettime-res +test_gettime_res_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) diff --git a/tests/test-gettime-res.c b/tests/test-gettime-res.c new file mode 100644 index 0000000000..0b13f93ec6 --- /dev/null +++ b/tests/test-gettime-res.c @@ -0,0 +1,89 @@ +/* + * Copyright 2022 Free Software Foundation, Inc. + * Written by Paul Eggert. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include <timespec.h> + +#include <stdio.h> + +int +main (void) +{ + long int res = gettime_res (); + printf ("gettime_res returned %ld ns\n", res); + + if (res <= 0) + { + fprintf (stderr, "gettime_res value %ld not positive\n", res); + return 1; + } + + if (res < TIMESPEC_HZ) + { + if (TIMESPEC_HZ % res != 0) + { + fprintf (stderr, + ("gettime_res value %ld ns is smaller than %d" + " but does not divide it\n"), + res, TIMESPEC_HZ); + return 1; + } + } + else + { + if (res % TIMESPEC_HZ != 0) + { + fprintf (stderr, + ("gettime_res value %ld ns is larger than %d" + " but is not a multiple of it\n"), + res, TIMESPEC_HZ); + return 1; + } + } + + int saw_res = 0; + + for (int i = 0; i < 100000; i++) + { + struct timespec t = current_timespec (); + if (res < TIMESPEC_HZ + ? t.tv_nsec % res != 0 + : t.tv_nsec != 0 || t.tv_sec % (res / TIMESPEC_HZ) != 0) + { + fprintf (stderr, + ("current_timespec returned %lld.%09ld which is not" + " a multiple of the resolution, %ld ns\n"), + (long long) t.tv_sec, t.tv_nsec, res); + return 1; + } + if (res < TIMESPEC_HZ + ? (t.tv_nsec / res % 2 != 0 + || t.tv_nsec / res % 5 != 0) + : (t.tv_sec / (res / TIMESPEC_HZ) % 2 != 0 + || t.tv_sec / (res / TIMESPEC_HZ) % 5 != 0)) + saw_res = 1; + } + + if (saw_res == 0) + fprintf (stderr, + ("warning: all timestamps had coarser" + " resolution than %ld ns\n"), + res); + + return 0; +} -- 2.35.1 [-- Attachment #3: test-gettime-res.tgz --] [-- Type: application/x-compressed-tar, Size: 438013 bytes --]
next prev parent reply other threads:[~2022-04-19 22:24 UTC|newest] Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-07 12:37 Max Nikulin 2022-04-09 7:52 ` Paul Eggert 2022-04-10 3:57 ` Max Nikulin 2022-04-13 14:40 ` Max Nikulin 2022-04-13 18:35 ` Paul Eggert 2022-04-14 13:19 ` Max Nikulin 2022-04-14 22:46 ` Paul Eggert 2022-04-15 2:14 ` Tim Cross 2022-04-15 17:23 ` Max Nikulin 2022-04-16 19:23 ` Paul Eggert 2022-04-21 16:59 ` Max Nikulin 2022-04-19 2:02 ` Paul Eggert 2022-04-19 5:50 ` Eli Zaretskii 2022-04-19 22:22 ` Paul Eggert [this message] 2022-04-20 7:23 ` Eli Zaretskii 2022-04-20 18:19 ` Paul Eggert 2022-04-20 18:41 ` Eli Zaretskii 2022-04-20 19:01 ` Paul Eggert 2022-04-20 19:14 ` Eli Zaretskii 2022-04-20 19:23 ` Paul Eggert 2022-04-20 19:30 ` Eli Zaretskii 2022-04-21 0:11 ` Paul Eggert 2022-04-21 6:44 ` Eli Zaretskii 2022-04-21 23:56 ` Paul Eggert 2022-04-22 5:01 ` Eli Zaretskii 2022-04-23 14:35 ` Bernhard Voelker 2022-04-20 15:07 ` Max Nikulin 2022-04-20 18:29 ` Paul Eggert 2022-04-25 15:30 ` Max Nikulin 2022-04-25 15:37 ` Paul Eggert 2022-04-25 19:49 ` Paul Eggert 2022-04-30 11:22 ` Max Nikulin 2022-05-01 2:32 ` Paul Eggert 2022-05-01 17:15 ` Max Nikulin 2022-04-13 15:12 ` Max Nikulin 2022-04-16 16:26 ` Max Nikulin 2022-04-17 1:58 ` Paul Eggert 2022-04-20 16:56 ` Max Nikulin 2022-04-20 19:17 ` Paul Eggert
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=6efc5d24-34a2-fd30-cd20-fe4ac3e48310@cs.ucla.edu \ --to=eggert@cs.ucla.edu \ --cc=54764@debbugs.gnu.org \ --cc=eliz@gnu.org \ --cc=emacs-orgmode@gnu.org \ --cc=manikulin@gmail.com \ --subject='Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).