From patchwork Wed Jun 21 18:32:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71505 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03B563858C5E for ; Wed, 21 Jun 2023 18:33:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03B563858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687372411; bh=/ly/sy1zfsWZTr4kWjrACeeWlr+L8OiXrpb2+IKiF0s=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=q5jHbcoxb1ws23PVtNkoER0GyMfgKq8HHdM2LZZ1MB7nNp9rZoWOs58gzP69Z++Xv h0EfG0c3lTf0hgPzgA5Juu4AYsFZ/rR8P1/lZ8W9yGD8NCVLsngKb6oAzULTBbmdIw S0y+IQ9DS0h6FqOb8ENuvBbkpBYgKVQeSLtRcdBw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id B97433858D37 for ; Wed, 21 Jun 2023 18:32:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B97433858D37 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b539102474so25931325ad.1 for ; Wed, 21 Jun 2023 11:32:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687372344; x=1689964344; 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=/ly/sy1zfsWZTr4kWjrACeeWlr+L8OiXrpb2+IKiF0s=; b=BkowoVzUt8PmAZrr7xJkDAOo29dk4Nu03j+BzH3WHCQW3gW8cY1gaQvZ3AV0PNX9Bo 5Qsjs/3bGupohYUYFnOfXAHxdQkvab17+tB9MVbH2Ajm6hdWGFsjYu9p4qe9IsaSKrtc o2XjufUbWCGAlZm1RVG/AaTa2toLHbopV14LKMu6cmKIM99VmaQfX40xOURG4M17VYDq I85cLkGdxUPjtrmjgrPzdLcMl46mJknlAnMVEfoyUgDvhL/5pMXYkGOoc7+wrKzPZ9On BbT6mA06gPbFIRg+nZu5CDOlzU8vAcCcsIAVVHVT5yVwLCIrMuh1+7twayWUu8afoLqr z+Hg== X-Gm-Message-State: AC+VfDyQgHslBsM9lsi6qzJK5tTsK/lZT9txpG7kYTrxOpf+qCnJ3eAG HK+w6riS65ZukMtYqp4RWtzj6JoMb0YGkT32 X-Google-Smtp-Source: ACHHUZ6NPAv0J1DVsd8JCTBpoOmSWtXDiV5oosWm0ALF0irndkTUDqiKtlIC5QTjwLFBmtNIqQC/0g== X-Received: by 2002:a17:903:26c1:b0:1b2:46ab:a9e1 with SMTP id jg1-20020a17090326c100b001b246aba9e1mr10160440plb.28.1687372343510; Wed, 21 Jun 2023 11:32:23 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id x3-20020a1709027c0300b001ac2c3e54adsm3817323pll.118.2023.06.21.11.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 11:32:23 -0700 (PDT) To: Joseph Myers , libc-alpha@sourceware.org Cc: Yonggang Luo Subject: [PATCH 1/2] time: Implement newly add timebase defines for c2x timespec_get and timespec_getres Date: Thu, 22 Jun 2023 02:32:05 +0800 Message-Id: <20230621183206.260-2-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230621183206.260-1-luoyonggang@gmail.com> References: <20230621183206.260-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The following timebase defines are implemented # define TIME_MONOTONIC 2 # define TIME_ACTIVE 3 # define TIME_THREAD_ACTIVE 4 And a private function named clock_from_timebase is added, this is used to map c11 timebase to posix clockid_t in a common place Maybe it's can be prompted into a POSIX function in future to resolve issue that from https://www.openwall.com/lists/libc-coord/2023/04/25/1 Signed-off-by: Yonggang Luo --- NEWS | 5 +++ include/time.h | 26 ++++++++++++++++ sysdeps/unix/sysv/linux/timespec_get.c | 7 +++-- sysdeps/unix/sysv/linux/timespec_getres.c | 5 +-- time/time.h | 7 ++++- time/timespec_get.c | 7 +++-- time/timespec_getres.c | 7 +++-- time/tst-timespec_get.c | 17 ++++++++--- time/tst-timespec_getres.c | 37 ++++++++++++++--------- 9 files changed, 88 insertions(+), 30 deletions(-) diff --git a/NEWS b/NEWS index 709ee40e50..375e15c5e1 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,11 @@ Version 2.38 Major new features: +* C2x timebase macro defines are supported, these are: + TIME_MONOTONIC + TIME_ACTIVE + TIME_THREAD_ACTIVE + * When C2X features are enabled and the base argument is 0 or 2, the following functions support binary integers prefixed by 0b or 0B as input: strtol, strtoll, strtoul, strtoull, strtol_l, strtoll_l, diff --git a/include/time.h b/include/time.h index f599eeed4e..77ca52ecbf 100644 --- a/include/time.h +++ b/include/time.h @@ -361,6 +361,32 @@ in_time_t_range (__time64_t t) return s == t; } +/* Helper that convert from c11 timebase to posix clockid_t, + when the mapping not exist, return -1 */ +static inline clockid_t +clock_from_timebase (int timebase) +{ + clockid_t clockid = -1; + switch (timebase) + { + case TIME_UTC: + clockid = CLOCK_REALTIME; + break; + case TIME_MONOTONIC: + clockid = CLOCK_MONOTONIC; + break; + case TIME_ACTIVE: + clockid = CLOCK_PROCESS_CPUTIME_ID; + break; + case TIME_THREAD_ACTIVE: + clockid = CLOCK_THREAD_CPUTIME_ID; + break; + default: + break; + } + return clockid; +} + /* Convert a known valid struct timeval into a struct __timespec64. */ static inline struct __timespec64 valid_timeval_to_timespec64 (const struct timeval tv) diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c index 3c852be99b..40d3ae3f0d 100644 --- a/sysdeps/unix/sysv/linux/timespec_get.c +++ b/sysdeps/unix/sysv/linux/timespec_get.c @@ -23,10 +23,11 @@ int __timespec_get64 (struct __timespec64 *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = clock_from_timebase (base); + if (clockid >= 0) { - __clock_gettime64 (CLOCK_REALTIME, ts); - return base; + if (__clock_gettime (clockid, ts) >= 0) + return base; } return 0; } diff --git a/sysdeps/unix/sysv/linux/timespec_getres.c b/sysdeps/unix/sysv/linux/timespec_getres.c index 7e61d78a77..e73c73cf74 100644 --- a/sysdeps/unix/sysv/linux/timespec_getres.c +++ b/sysdeps/unix/sysv/linux/timespec_getres.c @@ -22,9 +22,10 @@ int __timespec_getres64 (struct __timespec64 *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = clock_from_timebase (base); + if (clockid >= 0) { - __clock_getres64 (CLOCK_REALTIME, ts); + __clock_getres64 (clockid, ts); return base; } return 0; diff --git a/time/time.h b/time/time.h index 368f4dc588..d01c90e229 100644 --- a/time/time.h +++ b/time/time.h @@ -62,7 +62,12 @@ typedef __pid_t pid_t; #ifdef __USE_ISOC11 /* Time base values for timespec_get. */ -# define TIME_UTC 1 +# define TIME_UTC 1 +#endif +#if __GLIBC_USE_ISOC2X +# define TIME_MONOTONIC 2 +# define TIME_ACTIVE 3 +# define TIME_THREAD_ACTIVE 4 #endif __BEGIN_DECLS diff --git a/time/timespec_get.c b/time/timespec_get.c index 9b1d4f22ed..93aa442ca0 100644 --- a/time/timespec_get.c +++ b/time/timespec_get.c @@ -22,10 +22,11 @@ int timespec_get (struct timespec *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = clock_from_timebase (base); + if (clockid >= 0) { - __clock_gettime (CLOCK_REALTIME, ts); - return base; + if (__clock_gettime (clockid, ts) >= 0) + return base; } return 0; } diff --git a/time/timespec_getres.c b/time/timespec_getres.c index fd64dc7a47..3cc7a4b3bb 100644 --- a/time/timespec_getres.c +++ b/time/timespec_getres.c @@ -23,10 +23,11 @@ int timespec_getres (struct timespec *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = clock_from_timebase (base); + if (clockid >= 0) { - __clock_getres (CLOCK_REALTIME, ts); - return base; + if (__clock_getres (clockid, ts) >= 0) + return base; } return 0; } diff --git a/time/tst-timespec_get.c b/time/tst-timespec_get.c index d735160394..f97327666c 100644 --- a/time/tst-timespec_get.c +++ b/time/tst-timespec_get.c @@ -19,6 +19,15 @@ #include #include +static void +test_timespec_get (int timebase) +{ + struct timespec ts; + TEST_COMPARE (timespec_get (&ts, timebase), timebase); + TEST_VERIFY (ts.tv_nsec >= 0); + TEST_VERIFY (ts.tv_nsec < 1000000000); +} + static int do_test (void) { @@ -28,10 +37,10 @@ do_test (void) } { - struct timespec ts; - TEST_COMPARE (timespec_get (&ts, TIME_UTC), TIME_UTC); - TEST_VERIFY (ts.tv_nsec >= 0); - TEST_VERIFY (ts.tv_nsec < 1000000000); + test_timespec_get (TIME_UTC); + test_timespec_get (TIME_MONOTONIC); + test_timespec_get (TIME_ACTIVE); + test_timespec_get (TIME_THREAD_ACTIVE); } return 0; diff --git a/time/tst-timespec_getres.c b/time/tst-timespec_getres.c index b400a70138..960f7c3298 100644 --- a/time/tst-timespec_getres.c +++ b/time/tst-timespec_getres.c @@ -19,6 +19,25 @@ #include #include +static void +test_timespec_getres (clockid_t clock, int timebase) +{ + struct timespec ts; + TEST_COMPARE (timespec_getres (&ts, timebase), timebase); + /* Expect all supported systems to support timebase with + resolution better than one second. */ + TEST_VERIFY (ts.tv_sec == 0); + TEST_VERIFY (ts.tv_nsec > 0); + TEST_VERIFY (ts.tv_nsec < 1000000000); + TEST_COMPARE (timespec_getres (NULL, timebase), timebase); + /* Expect the resolution to be the same as that reported for + clock with clock_getres. */ + struct timespec cts; + TEST_COMPARE (clock_getres (clock, &cts), 0); + TEST_COMPARE (ts.tv_sec, cts.tv_sec); + TEST_COMPARE (ts.tv_nsec, cts.tv_nsec); +} + static int do_test (void) { @@ -29,20 +48,10 @@ do_test (void) } { - struct timespec ts; - TEST_COMPARE (timespec_getres (&ts, TIME_UTC), TIME_UTC); - /* Expect all supported systems to support TIME_UTC with - resolution better than one second. */ - TEST_VERIFY (ts.tv_sec == 0); - TEST_VERIFY (ts.tv_nsec > 0); - TEST_VERIFY (ts.tv_nsec < 1000000000); - TEST_COMPARE (timespec_getres (NULL, TIME_UTC), TIME_UTC); - /* Expect the resolution to be the same as that reported for - CLOCK_REALTIME with clock_getres. */ - struct timespec cts; - TEST_COMPARE (clock_getres (CLOCK_REALTIME, &cts), 0); - TEST_COMPARE (ts.tv_sec, cts.tv_sec); - TEST_COMPARE (ts.tv_nsec, cts.tv_nsec); + test_timespec_getres (CLOCK_REALTIME, TIME_UTC); + test_timespec_getres (CLOCK_MONOTONIC, TIME_MONOTONIC); + test_timespec_getres (CLOCK_PROCESS_CPUTIME_ID, TIME_ACTIVE); + test_timespec_getres (CLOCK_THREAD_CPUTIME_ID, TIME_THREAD_ACTIVE); } return 0; From patchwork Wed Jun 21 18:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71504 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBFD73858032 for ; Wed, 21 Jun 2023 18:32:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBFD73858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687372370; bh=Y7qDLZhrq9LE2+vGe25BGPNi9thIthcPfg4W+mHDLE4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=a82lqqXy1PkD+w/zkUCWKYouwETsnDwKJT8D6i7xcdWePZivvjzV3U+G9EN7uPkzZ Jy4a/yYAuw/iXz6DdqK5W2I6wfwZzC5ayrrotcmQ2ZjP4JkqUuMWvlAdrBZaxrqx7T 2baWP0G/rBc2b/kZ3/Vy7sY5of3U+AqnIaB0PpbI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 9BD623858CDA for ; Wed, 21 Jun 2023 18:32:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BD623858CDA Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b53b8465daso29128425ad.0 for ; Wed, 21 Jun 2023 11:32:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687372346; x=1689964346; 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=Y7qDLZhrq9LE2+vGe25BGPNi9thIthcPfg4W+mHDLE4=; b=IXSnimsIt6T3uhZkj/rQWvQaZEPTW2Rd0beDyeewA2gqWatltLqKRD5/ATFTimy3oo z9sITQh4o55fRjPJETJlZYI7XSdFmTvho43l6nRn984LmpJmZCvUW4ElqOynHU6zoUA+ adPojedQerUJVmLy6eYB7XyZrYnIvgc491buUc27BDzLrhLK+A8JFel9YHeuoCgLRmLt Txe9ZKTIGpEtm0T4tzOVLEks2Q8owSVulWy2d8/YzUqkgSdv7Cj82H9xdIAviESh2nA1 KB2dLPCNaz5SV1sdFF0hxRlfoxJ4eLGJ1hsI/k6TIosr8oBrDbNRE1jjUdBuFY/wGoMv nSLQ== X-Gm-Message-State: AC+VfDzoZXHk9n7S0WTVnBkxvi+t2Y7EZEccUnVR6Ga0Um0SK7AXRxzI 5MqRNxRm+0GvbhES1ES1KsXK7q3tfWAXYGyC X-Google-Smtp-Source: ACHHUZ4k77C3CQV/cvDzTZbuIDygWLAdR45a8neT1NSjn8k3Txhe7fwCabwI/I2RhwOJm2L6sPuoxA== X-Received: by 2002:a17:903:245:b0:1ae:10bc:4ae8 with SMTP id j5-20020a170903024500b001ae10bc4ae8mr13379016plh.26.1687372345528; Wed, 21 Jun 2023 11:32:25 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id x3-20020a1709027c0300b001ac2c3e54adsm3817323pll.118.2023.06.21.11.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 11:32:25 -0700 (PDT) To: Joseph Myers , libc-alpha@sourceware.org Cc: Yonggang Luo Subject: [PATCH 2/2] time: Implement extra timebase defines for timespec_get and timespec_getres Date: Thu, 22 Jun 2023 02:32:06 +0800 Message-Id: <20230621183206.260-3-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230621183206.260-1-luoyonggang@gmail.com> References: <20230621183206.260-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" these are: TIME_MONOTONIC_RAW TIME_UTC_COARSE TIME_MONOTONIC_COARSE TIME_BOOTTIME TIME_UTC_ALARM TIME_BOOTTIME_ALARM TIME_SGI_CYCLE TIME_TAI according to https://gustedt.gitlabpages.inria.fr/c23-library/#time_monotonic-time_active-time_thread_active Signed-off-by: Yonggang Luo --- NEWS | 10 ++++++++++ include/time.h | 34 +++++++++++++++++++++++++++++++ time/time.h | 10 ++++++++++ time/tst-timespec_get.c | 41 ++++++++++++++++++++++++++++++++++++++ time/tst-timespec_getres.c | 35 ++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) diff --git a/NEWS b/NEWS index 375e15c5e1..2889e4b6c4 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,16 @@ Version 2.38 Major new features: +* Extra timebase defines are supported, these are: + TIME_MONOTONIC_RAW + TIME_UTC_COARSE + TIME_MONOTONIC_COARSE + TIME_BOOTTIME + TIME_UTC_ALARM + TIME_BOOTTIME_ALARM + TIME_SGI_CYCLE + TIME_TAI + * C2x timebase macro defines are supported, these are: TIME_MONOTONIC TIME_ACTIVE diff --git a/include/time.h b/include/time.h index 77ca52ecbf..19db10ffc6 100644 --- a/include/time.h +++ b/include/time.h @@ -381,6 +381,40 @@ clock_from_timebase (int timebase) case TIME_THREAD_ACTIVE: clockid = CLOCK_THREAD_CPUTIME_ID; break; + case TIME_MONOTONIC_RAW: + clockid = CLOCK_MONOTONIC_RAW; + break; + case TIME_UTC_COARSE: + clockid = CLOCK_REALTIME_COARSE; + break; + case TIME_MONOTONIC_COARSE: + clockid = CLOCK_MONOTONIC_COARSE; + break; +# ifdef CLOCK_BOOTTIME + case TIME_BOOTTIME: + clockid = CLOCK_BOOTTIME; + break; +# endif +# ifdef CLOCK_REALTIME_ALARM + case TIME_UTC_ALARM: + clockid = CLOCK_REALTIME_ALARM; + break; +# endif +# ifdef CLOCK_BOOTTIME_ALARM + case TIME_BOOTTIME_ALARM: + clockid = CLOCK_BOOTTIME_ALARM; + break; +# endif +# ifdef CLOCK_SGI_CYCLE + case TIME_SGI_CYCLE: + clockid = CLOCK_SGI_CYCLE; + break; +# endif +# ifdef CLOCK_TAI + case TIME_TAI: + clockid = CLOCK_TAI; + break; +# endif default: break; } diff --git a/time/time.h b/time/time.h index d01c90e229..10dfabbd3f 100644 --- a/time/time.h +++ b/time/time.h @@ -69,6 +69,16 @@ typedef __pid_t pid_t; # define TIME_ACTIVE 3 # define TIME_THREAD_ACTIVE 4 #endif +#ifdef __USE_GNU +# define TIME_MONOTONIC_RAW 5 +# define TIME_UTC_COARSE 6 +# define TIME_MONOTONIC_COARSE 7 +# define TIME_BOOTTIME 8 +# define TIME_UTC_ALARM 9 +# define TIME_BOOTTIME_ALARM 10 +# define TIME_SGI_CYCLE 11 +# define TIME_TAI 12 +#endif __BEGIN_DECLS diff --git a/time/tst-timespec_get.c b/time/tst-timespec_get.c index f97327666c..99a08279fc 100644 --- a/time/tst-timespec_get.c +++ b/time/tst-timespec_get.c @@ -28,6 +28,13 @@ test_timespec_get (int timebase) TEST_VERIFY (ts.tv_nsec < 1000000000); } +static void +test_timespec_get_not_support(int timebase) +{ + struct timespec ts; + TEST_COMPARE (timespec_get (&ts, timebase), 0); +} + static int do_test (void) { @@ -43,6 +50,40 @@ do_test (void) test_timespec_get (TIME_THREAD_ACTIVE); } + { + test_timespec_get (TIME_MONOTONIC_RAW); + test_timespec_get (TIME_UTC_COARSE); + test_timespec_get (TIME_MONOTONIC_COARSE); + } + + { +#ifdef CLOCK_BOOTTIME + test_timespec_get (TIME_BOOTTIME); +#else + test_timespec_get_not_support (TIME_BOOTTIME); +#endif +#ifdef CLOCK_REALTIME_ALARM + test_timespec_get (TIME_UTC_ALARM); +#else + test_timespec_get_not_support (TIME_UTC_ALARM); +#endif +#ifdef CLOCK_BOOTTIME_ALARM + test_timespec_get (TIME_BOOTTIME_ALARM); +#else + test_timespec_get_not_support (TIME_BOOTTIME_ALARM); +#endif +#ifdef CLOCK_SGI_CYCLE + test_timespec_get (TIME_SGI_CYCLE); +#else + test_timespec_get_not_support (TIME_SGI_CYCLE); +#endif +#ifdef CLOCK_TAI + test_timespec_get (TIME_TAI); +#else + test_timespec_get_not_support (TIME_TAI); +#endif + } + return 0; } diff --git a/time/tst-timespec_getres.c b/time/tst-timespec_getres.c index 960f7c3298..623a1d841c 100644 --- a/time/tst-timespec_getres.c +++ b/time/tst-timespec_getres.c @@ -54,6 +54,41 @@ do_test (void) test_timespec_getres (CLOCK_THREAD_CPUTIME_ID, TIME_THREAD_ACTIVE); } + { + test_timespec_getres (CLOCK_MONOTONIC_RAW, TIME_MONOTONIC_RAW); + test_timespec_getres (CLOCK_REALTIME_COARSE, TIME_UTC_COARSE); + test_timespec_getres (CLOCK_MONOTONIC_COARSE, TIME_MONOTONIC_COARSE); + } + + { + struct timespec ts; +#ifdef CLOCK_BOOTTIME + test_timespec_getres (CLOCK_BOOTTIME, TIME_BOOTTIME); +#else + TEST_COMPARE (timespec_getres (&ts, TIME_BOOTTIME), 0); +#endif +#ifdef CLOCK_REALTIME_ALARM + test_timespec_getres (CLOCK_REALTIME_ALARM, TIME_UTC_ALARM); +#else + TEST_COMPARE (timespec_getres (&ts, TIME_UTC_ALARM), 0); +#endif +#ifdef CLOCK_BOOTTIME_ALARM + test_timespec_getres (CLOCK_BOOTTIME_ALARM, TIME_BOOTTIME_ALARM); +#else + TEST_COMPARE (timespec_getres (&ts, TIME_BOOTTIME_ALARM), 0); +#endif +#ifdef CLOCK_SGI_CYCLE + test_timespec_getres (CLOCK_SGI_CYCLE, TIME_SGI_CYCLE); +#else + TEST_COMPARE (timespec_getres (&ts, TIME_SGI_CYCLE), 0); +#endif +#ifdef CLOCK_TAI + test_timespec_getres (CLOCK_TAI, TIME_TAI); +#else + TEST_COMPARE (timespec_getres (&ts, TIME_TAI), 0); +#endif + } + return 0; }