From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 42B6C3858D29 for ; Mon, 22 Mar 2021 20:22:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 42B6C3858D29 Received: by mail-qk1-x730.google.com with SMTP id q26so6764898qkm.6 for ; Mon, 22 Mar 2021 13:22:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aU/6+modoAsTBhr5f/J/f0yx1Lf76ugoKLsc8RTvmyI=; b=FWqP/GW9gqz0y47JVOldqkgUaub59rl0SCV+S+ctotwmIcEV9Z+bSU96cy8WEk491U SEOlgts9dWlUUEQqd5eOD06xbfAMv/NIWLVh624Xc22AKDzaJ3/fTWn8HcmkDEucW4Cs VGXCmyphyvodhUnYC7BP8t/DlIkowEQxvE033pdbCkQrHVKJ6bjaukO7st1KsOFGDSrO fyiEHlgecO8uCPlQT4KZKinAfQX8KPdRnZq2y/qnOXxMuGsCM9fIB/2AiLQKl9UDmpL1 YtZTfGu2us0A05MxmKc3ncg8MHNPmT2SOtkeEbmj0e44SkCkANRjPCD5jWeyXPLJCTFr Cm9Q== X-Gm-Message-State: AOAM532TEI1YRA7tCqLBERT/tJv+Pne8sXqUisBpmLUu8DH3FbZYUKZj mUWIdi/OyRvq6t5OFJDToEXaLw96XvVSow== X-Google-Smtp-Source: ABdhPJzGxW/X2sgiq65FSbNllbB/KeBQGlKm10IoTlW1GCSztt4YATUlPrXP8kZFlGdCOfIiE04xOw== X-Received: by 2002:a37:9f91:: with SMTP id i139mr1961262qke.72.1616444529539; Mon, 22 Mar 2021 13:22:09 -0700 (PDT) Received: from ?IPv6:2804:18:844:62ae:d820:43e4:85c0:4786? ([2804:18:844:62ae:d820:43e4:85c0:4786]) by smtp.gmail.com with ESMTPSA id d23sm11640994qka.125.2021.03.22.13.22.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Mar 2021 13:22:09 -0700 (PDT) Subject: Re: [PATCH v2 1/2] tst: Add test for ntp_gettime To: Lukasz Majewski Cc: GNU C Library References: <20210310130056.23926-1-lukma@denx.de> From: Adhemerval Zanella Message-ID: Date: Mon, 22 Mar 2021 17:22:06 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210310130056.23926-1-lukma@denx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 22 Mar 2021 20:22:11 -0000 On 10/03/2021 10:00, Lukasz Majewski wrote: > This code provides test to check if time on target machine is properly > read via ntp_gettime syscall. > > --- > Changes for v2: > - Check time before and after calling ntp_gettime{x} to avoid situation > when seconds rollover between call to ntp_gettime and wrapper providing > current time. LGTM with the format fixes below. Reviewed-by: Adhemerval Zanella > --- > sysdeps/unix/sysv/linux/Makefile | 2 +- > sysdeps/unix/sysv/linux/tst-ntp_gettime.c | 56 +++++++++++++++++++++++ > 2 files changed, 57 insertions(+), 1 deletion(-) > create mode 100644 sysdeps/unix/sysv/linux/tst-ntp_gettime.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index b8c1caa505..8a07870cb4 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -113,7 +113,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ > tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux \ > tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes \ > tst-clock_adjtime tst-adjtimex tst-ntp_adjtime tst-futimes \ > - tst-lutimes > + tst-lutimes tst-ntp_gettime > tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc > tests-time64 += \ > tst-futimes-time64\ Ok. > diff --git a/sysdeps/unix/sysv/linux/tst-ntp_gettime.c b/sysdeps/unix/sysv/linux/tst-ntp_gettime.c > new file mode 100644 > index 0000000000..6cd3a0ec2c > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-ntp_gettime.c > @@ -0,0 +1,56 @@ > +/* Test for ntp_gettime Missing period. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library 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 > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > + > +#ifndef NTP_GETTIME_SYSCALL > +# define NTP_GETTIME_SYSCALL ntp_gettime > +#endif > + > +#define STR(__s) #__s > + > +static int > +do_test (void) > +{ > + struct timespec tv_before_ntp, tv_after_ntp; > + struct ntptimeval ntv; > + > + /* To prevent seconds rollover (which is very unlikely though), > + loop until we do match seconds values before and after > + call to ntp_gettime. */ > + do { > + tv_before_ntp = xclock_now (CLOCK_REALTIME); > + > + int ret = NTP_GETTIME_SYSCALL (&ntv); > + if (ret == -1) > + FAIL_EXIT1 (STR(NTP_GETTIME_SYSCALL)" failed: %m\n"); > + > + tv_after_ntp = xclock_now (CLOCK_REALTIME); > + } while (tv_after_ntp.tv_sec != tv_before_ntp.tv_sec); The correct indentation is: do { } while (...) The test looks ok. > + > + if (tv_after_ntp.tv_sec != ntv.time.tv_sec) > + FAIL_EXIT1 (STR(NTP_GETTIME_SYSCALL)" provided wrong time!\n"); Use TEST_COMPARE. > + > + return 0; > +} > + > +#include >