From patchwork Mon Apr 27 11:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1277561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=fiKezj5t; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499jbk15DLz9sSK for ; Mon, 27 Apr 2020 21:44:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EA3233C285E for ; Mon, 27 Apr 2020 13:43:56 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id BFB3D3C226E for ; Mon, 27 Apr 2020 13:43:54 +0200 (CEST) Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 1D8CB600055 for ; Mon, 27 Apr 2020 13:43:48 +0200 (CEST) Received: by mail-pl1-x643.google.com with SMTP id d24so6901855pll.8 for ; Mon, 27 Apr 2020 04:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r6RK2zcqDPbliDyVIr+ebj/39AkPWV8aT3yNFgZOwgs=; b=fiKezj5tnll1ilxYgOsiaR4lVXui6H4IiH6vaGlhUEnaCpzTWDxEcpVmqZublgojvn Pv79/oOULaghrsQOTUdR9EEueI/urvSZyr+9F2qfD0d4eTbeP5mVNs5hZ9qRTwwxk+C4 kQLTQ/daqZ/BSp1JSN3yZYM4eOoVimEjaR50YZW4oXgdm/I8FesTKQT55BLCbda9KZQi Xbrf3QfZtDVNMKGng5KuSn4R1Yr63V8b7Xc9+FgngWNxP2QtjpWuGwW4h4j+GcaOP1Jx jB3lbYMSCINJFD9gyKnsdvvuB1l2s6Az159IzcwM4b2HY0BMEQvhecg9ViFdrdEk5KFY WVew== 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:mime-version :content-transfer-encoding; bh=r6RK2zcqDPbliDyVIr+ebj/39AkPWV8aT3yNFgZOwgs=; b=LshAvShx7kVCDPTx/7EJu6Qe2eyrDcUY58nkdNtjvmwemZmjsaWo4yDMdJZCjsD1jb XXMQ/32Muw1wA9GwzpQ2yAZEd2anjLPDan1QWvaw5nFDRkiVt1gnzau0Y5wIQTHdj5er Q2SuxZdFkY8xVSLu+DzSg7eHtaxKnkcKTLgOv4dp3ir4Utd/SaNmi4xVSn8Rul6/7bVe y2c91hqslXornbqyIkY3PQptdhMNlBT/LwaJvaCjp45kt8CBbkFOH4IhkIakCkMqb+ym foWywB/NTTG+MgVQW7y+NtAIpnU+wfDzleh0GJaiq7+uBIPEkaRxGTjpg/lODlympZfN EM2Q== X-Gm-Message-State: AGi0PuZVe60wZ6MSmTxfQEnV1bCQ5eTOYGw5GDD/tQUySlPVSJ7x1SYN 1k524VFzZga19ntZBelVXUJaCgNzYfY= X-Google-Smtp-Source: APiQypInoDHBF+Zj6scENZcfZSA1ahm9rTotnk4iTo8y/W/lkMIcT1Rsagm7I4Ehx1j85dhqz+4U4Q== X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr22358471plr.223.1587987832060; Mon, 27 Apr 2020 04:43:52 -0700 (PDT) Received: from localhost ([122.171.118.46]) by smtp.gmail.com with ESMTPSA id mn1sm10911016pjb.24.2020.04.27.04.43.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2020 04:43:51 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Mon, 27 Apr 2020 17:13:44 +0530 Message-Id: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 1/4] syscalls/timer_gettime: Add support for time64 tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , arnd@arndb.de, Viresh Kumar Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This adds support for time64 tests to the existing timer_gettime() syscall tests. Signed-off-by: Viresh Kumar --- include/tst_timer.h | 40 +++++++ .../syscalls/timer_gettime/timer_gettime01.c | 112 +++++++++--------- 2 files changed, 98 insertions(+), 54 deletions(-) diff --git a/include/tst_timer.h b/include/tst_timer.h index 256e1d71e1bc..601f934da670 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -15,6 +15,7 @@ #include #include #include "tst_test.h" +#include "lapi/common_timers.h" #include "lapi/syscalls.h" /* @@ -112,6 +113,11 @@ struct __kernel_timespec { __kernel_time64_t tv_sec; /* seconds */ long long tv_nsec; /* nanoseconds */ }; + +struct __kernel_itimerspec { + struct __kernel_timespec it_interval; /* timer period */ + struct __kernel_timespec it_value; /* timer expiration */ +}; #endif enum tst_ts_type { @@ -129,6 +135,14 @@ struct tst_ts { } ts; }; +struct tst_its { + enum tst_ts_type type; + union { + struct itimerspec libc_its; + struct __kernel_itimerspec kern_its; + } ts; +}; + static inline void *tst_ts_get(struct tst_ts *t) { if (!t) @@ -147,6 +161,22 @@ static inline void *tst_ts_get(struct tst_ts *t) } } +static inline void *tst_its_get(struct tst_its *t) +{ + if (!t) + return NULL; + + switch (t->type) { + case TST_LIBC_TIMESPEC: + return &t->ts.libc_its; + case TST_KERN_TIMESPEC: + return &t->ts.kern_its; + default: + tst_brk(TBROK, "Invalid type: %d", t->type); + return NULL; + } +} + static inline int libc_clock_getres(clockid_t clk_id, void *ts) { return clock_getres(clk_id, ts); @@ -212,6 +242,16 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags, request, remain); } +static inline int sys_timer_gettime(kernel_timer_t timerid, void *its) +{ + return tst_syscall(__NR_timer_gettime, timerid, its); +} + +static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its) +{ + return tst_syscall(__NR_timer_gettime64, timerid, its); +} + /* * Returns tst_ts seconds. */ diff --git a/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c b/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c index 1c75f1cf0e45..bd8a8e4763a1 100644 --- a/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c +++ b/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c @@ -26,71 +26,75 @@ #include #include -#include "test.h" -#include "lapi/syscalls.h" +#include "tst_timer.h" +#include "lapi/abisize.h" -char *TCID = "timer_gettime01"; -int TST_TOTAL = 3; +static struct test_variants { + int (*func)(kernel_timer_t timer, void *its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .func = sys_timer_gettime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif -static void cleanup(void) -{ - tst_rmdir(); -} +#if defined(TST_ABI64) + { .func = sys_timer_gettime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif -static void setup(void) -{ - TEST_PAUSE; - tst_tmpdir(); -} +#if (__NR_timer_gettime64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_gettime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; -int main(int ac, char **av) -{ - int lc; +static kernel_timer_t timer; +static void setup(void) +{ struct sigevent ev; - struct itimerspec spec; - int timer; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); ev.sigev_value = (union sigval) 0; ev.sigev_signo = SIGALRM; ev.sigev_notify = SIGEV_SIGNAL; - TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); - - if (TEST_RETURN != 0) - tst_brkm(TBROK | TERRNO, cleanup, "Failed to create timer"); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - TEST(ltp_syscall(__NR_timer_gettime, timer, &spec)); - if (TEST_RETURN == 0) { - tst_resm(TPASS, "timer_gettime(CLOCK_REALTIME) Passed"); - } else { - tst_resm(TFAIL | TERRNO, - "timer_gettime(CLOCK_REALTIME) Failed"); - } - - TEST(ltp_syscall(__NR_timer_gettime, -1, &spec)); - if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) { - tst_resm(TPASS, "timer_gettime(-1) Failed: EINVAL"); - } else { - tst_resm(TFAIL | TERRNO, - "timer_gettime(-1) = %li", TEST_RETURN); - } - - TEST(ltp_syscall(__NR_timer_gettime, timer, NULL)); - if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT) { - tst_resm(TPASS, "timer_gettime(NULL) Failed: EFAULT"); - } else { - tst_resm(TFAIL | TERRNO, - "timer_gettime(-1) = %li", TEST_RETURN); - } + + TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); + + if (TST_RET) { + tst_res(TFAIL | TTERRNO, "timer_create() failed"); + return; + } +} + +static void verify(void) +{ + struct test_variants *tv = &variants[tst_variant]; + struct tst_its spec = {.type = tv->type, }; + + TEST(tv->func(timer, tst_its_get(&spec))); + if (TST_RET == 0) { + tst_res(TPASS, "timer_gettime() Passed"); + } else { + tst_res(TFAIL | TTERRNO, "timer_gettime() Failed"); } - cleanup(); - tst_exit(); + TEST(tv->func((kernel_timer_t)-1, tst_its_get(&spec))); + if (TST_RET == -1 && TST_ERR == EINVAL) + tst_res(TPASS, "timer_gettime(-1) Failed: EINVAL"); + else + tst_res(TFAIL | TTERRNO, "timer_gettime(-1) = %li", TST_RET); + + TEST(tv->func(timer, NULL)); + if (TST_RET == -1 && TST_ERR == EFAULT) + tst_res(TPASS, "timer_gettime(NULL) Failed: EFAULT"); + else + tst_res(TFAIL | TTERRNO, "timer_gettime(-1) = %li", TST_RET); } + +static struct tst_test test = { + .test_all = verify, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .needs_tmpdir = 1, +}; From patchwork Mon Apr 27 11:43:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1277562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=FokTD4gc; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499jbv2L9pz9sSK for ; Mon, 27 Apr 2020 21:44:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 80CCF3C2874 for ; Mon, 27 Apr 2020 13:44:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id A385C3C2865 for ; Mon, 27 Apr 2020 13:43:57 +0200 (CEST) Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id D5FB21400352 for ; Mon, 27 Apr 2020 13:43:56 +0200 (CEST) Received: by mail-pj1-x1042.google.com with SMTP id h12so4620652pjz.1 for ; Mon, 27 Apr 2020 04:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MBvp4rNZq4zequSo6tD1QjtomwCkQXCO11ChIwKnGaw=; b=FokTD4gckciIH5enoCGvqUOJlAdMxb9kEr/OBJ1Zqv3BYyI6E03zkHHhXb9bXx60wH sGoAFxMJfvAS7QvZsP4tpqI+9LoF6RslTNqDqdLrPRKUXGLNpF2VviwZSz5RTObklfyS celH+4Fa8GQoAvaMUkwYgBeSBbPqFsOrK9gl+QmEeKx2dXxizmtqEeyAXC2D/mG9tI3e P3KoRRCB0EUf4C5hp2g4N0HKvBRAKh6Fbdy6FlqHmpEFJoR1ycaXmq/2gdUftRMD20xC pDpSps4CESJhYE/nGNJErZ3rXnCgspTj7IiFa9V6bkAg3cnnuwRmglSz50STZPzEPY4i dieg== 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:mime-version:content-transfer-encoding; bh=MBvp4rNZq4zequSo6tD1QjtomwCkQXCO11ChIwKnGaw=; b=m9O4YX20Hc2woDQ6PyyFUvOcIBEsMRiF//G35cBZu4rUc95CKk+tNbfvZayOdWyBor OO2w4GWEK/201IyP5/QJrIfkIlTO9A8AwjZINgAZToclDtDonnvv7DJbP40IisZy2Fqf WYmhbW3Vw8coOLsLVRsIJWitaruXi3qOEEAOZ29flVfyQEHJg0DRj7UVXZOX6i0yiN4s llspdgt5TLoNP71zjb3c8d0uqci+uTIWvjAokn6CyizZpgWmEnbtuPqIoqusTpdESEXN BxezkrAQq+dJ51eYe8kyOtmyohdsoyQ2GqhyjHRKILny7fZsIIYSeyEf1ZvBVbg+rP9e js3A== X-Gm-Message-State: AGi0PuYYL1iDRyaT6Ku/MDLYZQdCQCTyAWaprJcXFsTcDO+QVlSpuBwT 4XE2Vb/eBLqS02XB6jEgTzLJiqiP/Bg= X-Google-Smtp-Source: APiQypIyj9PlQ6+sOG6X87pVyLlCKRXhQGawUNG5PDnH0pxVyPJWBrMxxMBxyRNP7Nq8cJ6LmholBQ== X-Received: by 2002:a17:90a:d17:: with SMTP id t23mr24112728pja.77.1587987834762; Mon, 27 Apr 2020 04:43:54 -0700 (PDT) Received: from localhost ([122.171.118.46]) by smtp.gmail.com with ESMTPSA id b15sm12308304pfd.139.2020.04.27.04.43.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2020 04:43:54 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Mon, 27 Apr 2020 17:13:45 +0530 Message-Id: <4be02b8b3fed66adf3e165dc92d5d5b779799fd6.1587987802.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> References: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 2/4] syscalls/timer_settime: Add support for time64 tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , arnd@arndb.de, Viresh Kumar Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This adds support for time64 tests to the existing timer_settime() syscall tests. Signed-off-by: Viresh Kumar --- include/tst_timer.h | 34 ++++++++++ .../syscalls/timer_settime/timer_settime01.c | 51 +++++++++++---- .../syscalls/timer_settime/timer_settime02.c | 65 ++++++++++++++----- 3 files changed, 122 insertions(+), 28 deletions(-) diff --git a/include/tst_timer.h b/include/tst_timer.h index 601f934da670..94d03cecdabe 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -252,6 +252,40 @@ static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its) return tst_syscall(__NR_timer_gettime64, timerid, its); } +static inline int sys_timer_settime(kernel_timer_t timerid, int flags, + void *its, void *old_its) +{ + return tst_syscall(__NR_timer_settime, timerid, flags, its, old_its); +} + +static inline int sys_timer_settime64(kernel_timer_t timerid, int flags, + void *its, void *old_its) +{ + return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its); +} + +static inline void tst_its_set_time(struct tst_its *its, long long value_sec, + long long value_nsec, long long interval_sec, + long long interval_nsec) +{ + switch (its->type) { + case TST_LIBC_TIMESPEC: + its->ts.libc_its.it_value.tv_sec = value_sec; + its->ts.libc_its.it_value.tv_nsec = value_nsec; + its->ts.libc_its.it_interval.tv_sec = interval_sec; + its->ts.libc_its.it_interval.tv_nsec = interval_nsec; + break; + case TST_KERN_TIMESPEC: + its->ts.kern_its.it_value.tv_sec = value_sec; + its->ts.kern_its.it_value.tv_nsec = value_nsec; + its->ts.kern_its.it_interval.tv_sec = interval_sec; + its->ts.kern_its.it_interval.tv_nsec = interval_nsec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", its->type); + } +} + /* * Returns tst_ts seconds. */ diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime01.c b/testcases/kernel/syscalls/timer_settime/timer_settime01.c index da365d221086..8c00718eedaf 100644 --- a/testcases/kernel/syscalls/timer_settime/timer_settime01.c +++ b/testcases/kernel/syscalls/timer_settime/timer_settime01.c @@ -25,15 +25,15 @@ #include #include #include -#include "tst_test.h" -#include "lapi/common_timers.h" +#include "tst_timer.h" +#include "lapi/abisize.h" -static struct timespec timenow; -static struct itimerspec new_set, old_set; +static struct tst_ts timenow; +static struct tst_its new_set, old_set; static kernel_timer_t timer; static struct testcase { - struct itimerspec *old_ptr; + struct tst_its *old_ptr; int it_value_tv_sec; int it_interval_tv_sec; int flag; @@ -45,10 +45,32 @@ static struct testcase { {&old_set, 5, 0, TIMER_ABSTIME, "using absolute time"}, }; +static struct test_variants { + int (*gettime)(clockid_t clk_id, void *ts); + int (*func)(kernel_timer_t timerid, int flags, void *its, + void *old_its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .gettime = sys_clock_gettime, .func = sys_timer_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .gettime = sys_clock_gettime, .func = sys_timer_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timer_settime64 != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime64, .func = sys_timer_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + static void run(unsigned int n) { - unsigned int i; + struct test_variants *tv = &variants[tst_variant]; struct testcase *tc = &tcases[n]; + long long val; + unsigned int i; tst_res(TINFO, "Testing for %s:", tc->description); @@ -78,21 +100,24 @@ static void run(unsigned int n) memset(&new_set, 0, sizeof(new_set)); memset(&old_set, 0, sizeof(old_set)); - new_set.it_value.tv_sec = tc->it_value_tv_sec; - new_set.it_interval.tv_sec = tc->it_interval_tv_sec; + new_set.type = old_set.type = tv->type; + + val = tc->it_value_tv_sec; if (tc->flag & TIMER_ABSTIME) { - if (clock_gettime(clock, &timenow) < 0) { + timenow.type = tv->type; + if (tv->gettime(clock, tst_ts_get(&timenow)) < 0) { tst_res(TFAIL, "clock_gettime(%s) failed - skipping the test", get_clock_str(clock)); continue; } - new_set.it_value.tv_sec += timenow.tv_sec; + val += tst_ts_get_sec(timenow); } - TEST(tst_syscall(__NR_timer_settime, timer, - tc->flag, &new_set, tc->old_ptr)); + tst_its_set_time(&new_set, val, 0, tc->it_interval_tv_sec, 0); + + TEST(tv->func(timer, tc->flag, tst_its_get(&new_set), tst_its_get(tc->old_ptr))); if (TST_RET != 0) { tst_res(TFAIL | TTERRNO, "%s failed", @@ -116,6 +141,7 @@ static void sighandler(int sig) static void setup(void) { + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); SAFE_SIGNAL(SIGALRM, sighandler); } @@ -123,6 +149,7 @@ static struct tst_test test = { .test = run, .needs_root = 1, .tcnt = ARRAY_SIZE(tcases), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .tags = (const struct tst_tag[]) { {"linux-git", "f18ddc13af98"}, diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime02.c b/testcases/kernel/syscalls/timer_settime/timer_settime02.c index bcabb76956f8..9ca62e15b690 100644 --- a/testcases/kernel/syscalls/timer_settime/timer_settime02.c +++ b/testcases/kernel/syscalls/timer_settime/timer_settime02.c @@ -25,10 +25,12 @@ #include #include -#include "tst_test.h" -#include "lapi/common_timers.h" +#include "tst_timer.h" +#include "lapi/abisize.h" -static struct itimerspec new_set, old_set; +static struct tst_its new_set, old_set; +static struct tst_its *pnew_set = &new_set, *pold_set = &old_set, *null_set = NULL; +static void *faulty_set; static kernel_timer_t timer; static kernel_timer_t timer_inval = -1; @@ -44,23 +46,50 @@ static const char * const descriptions[] = { static struct testcase { kernel_timer_t *timer_id; - struct itimerspec *new_ptr; - struct itimerspec *old_ptr; + struct tst_its **new_ptr; + struct tst_its **old_ptr; int it_value_tv_nsec; int error; } tcases[] = { - {&timer, NULL, &old_set, 0, EINVAL}, - {&timer, &new_set, &old_set, -1, EINVAL}, - {&timer, &new_set, &old_set, NSEC_PER_SEC + 1, EINVAL}, - {&timer_inval, &new_set, &old_set, 0, EINVAL}, - {&timer, (struct itimerspec *) -1, &old_set, 0, EFAULT}, - {&timer, &new_set, (struct itimerspec *) -1, 0, EFAULT}, + {&timer, &null_set, &pold_set, 0, EINVAL}, + {&timer, &pnew_set, &pold_set, -1, EINVAL}, + {&timer, &pnew_set, &pold_set, NSEC_PER_SEC + 1, EINVAL}, + {&timer_inval, &pnew_set, &pold_set, 0, EINVAL}, + {&timer, (struct tst_its **)&faulty_set, &pold_set, 0, EFAULT}, + {&timer, &pnew_set, (struct tst_its **)&faulty_set, 0, EFAULT}, }; +static struct test_variants { + int (*func)(kernel_timer_t timerid, int flags, void *its, + void *old_its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .func = sys_timer_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .func = sys_timer_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timer_settime64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + +static void setup(void) +{ + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); + faulty_set = tst_get_bad_addr(NULL); +} + static void run(unsigned int n) { - unsigned int i; + struct test_variants *tv = &variants[tst_variant]; struct testcase *tc = &tcases[n]; + void *new, *old; + unsigned int i; tst_res(TINFO, "Testing for %s:", descriptions[n]); @@ -91,11 +120,13 @@ static void run(unsigned int n) memset(&new_set, 0, sizeof(new_set)); memset(&old_set, 0, sizeof(old_set)); - new_set.it_value.tv_sec = 5; - new_set.it_value.tv_nsec = tc->it_value_tv_nsec; + new_set.type = old_set.type = tv->type; + tst_its_set_time(&new_set, 5, tc->it_value_tv_nsec, 0, 0); + + new = (tc->new_ptr == (struct tst_its **)&faulty_set) ? faulty_set : tst_its_get(*tc->new_ptr); + old = (tc->old_ptr == (struct tst_its **)&faulty_set) ? faulty_set : tst_its_get(*tc->old_ptr); - TEST(tst_syscall(__NR_timer_settime, *tc->timer_id, - 0, tc->new_ptr, tc->old_ptr)); + TEST(tv->func(*tc->timer_id, 0, new, old)); if (tc->error != TST_ERR) { tst_res(TFAIL | TTERRNO, @@ -119,6 +150,8 @@ static struct tst_test test = { .test = run, .needs_root = 1, .tcnt = ARRAY_SIZE(tcases), + .test_variants = ARRAY_SIZE(variants), + .setup = setup, .tags = (const struct tst_tag[]) { {"linux-git", "f18ddc13af98"}, {} From patchwork Mon Apr 27 11:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1277563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=rnfQRQb2; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499jc41DhXz9sSK for ; Mon, 27 Apr 2020 21:44:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 855963C2864 for ; Mon, 27 Apr 2020 13:44:17 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 470B53C285B for ; Mon, 27 Apr 2020 13:44:01 +0200 (CEST) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id C59C71400522 for ; Mon, 27 Apr 2020 13:43:59 +0200 (CEST) Received: by mail-pg1-x541.google.com with SMTP id o15so8587029pgi.1 for ; Mon, 27 Apr 2020 04:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=grTMZnI76pgCsDNzqpAgsBeMx3Z2SsdeDosDcZjkN9I=; b=rnfQRQb2a6t37L6fK0lm30PSAh+DuWf/Uhy6d9Jq0MWWNwf2KHJpNIgCGXcIZRaItf ypEK3gklNvf0gOayZUUDmMRBtCVwYIPzfMXE9bq3cGgZL36dvUq8I3G5hYDLM4zHwQZY CR5AJ8PO38idxUELqr5q9yZF7QPZ9VHIEiIejYnqcgJcFiMpXbdK+SlpcXFN/6NFTGZh EqAqjCrwtl+3kZSZqqDMWvJ5SAk9yIhzyYjQTwsSNM/3ofM/YMGHQconC18QsxpdWQJB UGbMOLmTAoeAqQ2pmJlGWkL5JqKheB2xIyd2uoDQ57VGnKbaV9e9do5Vx9HVi/mJMX3U Ke2Q== 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:mime-version:content-transfer-encoding; bh=grTMZnI76pgCsDNzqpAgsBeMx3Z2SsdeDosDcZjkN9I=; b=PsVsdFs0mwT47t4heYdvhiqUJzm2sgaHxC+OxnQNGn7yVkCj8l2NV1ResNoPVjhvF4 6noN2Bej04htOfuhtQ54DUjuld+Qy3ngjWThI7+W1dpyQ74XL14NzLJ8dU/o+hZlO6Fy kX2kmDoKkC9ERtTIT9Lme5Y3u2GXQsheDh+WNAUW7e4Ru3FuaS9iDP0BvwDQWVIOdHB3 Io+14fKvgDcf4zBCQXj8hdvxZqPAJR7vP9xdhHob7wMCcQySOVhetixywh03W0vJhrsc TOYJ9z8aNWH8t6aGROo46oL+Ic9AeYXqW+eIqKGqqoZZT7Emtt+W35Jmwe8lovaALYH7 2RXQ== X-Gm-Message-State: AGi0Puaf3hsvrcEoKFQM9N/o05HAy4iHZtiTBus6qOkClmb71j3/Lv84 233TmnOzpdj4vOgCQixh7SaFaVT16P8= X-Google-Smtp-Source: APiQypJnCth0Dcwnr6j3tkNamWgsR71z/yRLwHuaWVRFVrMZvNTclOZx3qequp2Cq+ZJUu5iDw+rnA== X-Received: by 2002:a62:a113:: with SMTP id b19mr6359951pff.249.1587987837611; Mon, 27 Apr 2020 04:43:57 -0700 (PDT) Received: from localhost ([122.171.118.46]) by smtp.gmail.com with ESMTPSA id nu10sm12181753pjb.9.2020.04.27.04.43.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2020 04:43:57 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Mon, 27 Apr 2020 17:13:46 +0530 Message-Id: <4205044404347cee7b88ef5d7d2377f502397b92.1587987802.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> References: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 3/4] syscalls/timerfd: Add support for time64 tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , arnd@arndb.de, Viresh Kumar Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This adds support for time64 tests to the existing timerfd_gettime() and timerfd_settime() syscall tests. Signed-off-by: Viresh Kumar --- include/tst_timer.h | 48 +++++++ testcases/kernel/syscalls/timerfd/timerfd01.c | 58 ++++++-- testcases/kernel/syscalls/timerfd/timerfd04.c | 56 ++++++-- .../syscalls/timerfd/timerfd_gettime01.c | 124 ++++++++--------- .../syscalls/timerfd/timerfd_settime01.c | 125 +++++++++--------- .../syscalls/timerfd/timerfd_settime02.c | 33 ++++- 6 files changed, 301 insertions(+), 143 deletions(-) diff --git a/include/tst_timer.h b/include/tst_timer.h index 94d03cecdabe..a728d78d7def 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -264,6 +264,54 @@ static inline int sys_timer_settime64(kernel_timer_t timerid, int flags, return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its); } +static inline int sys_timerfd_gettime(int fd, void *its) +{ + return tst_syscall(__NR_timerfd_gettime, fd, its); +} + +static inline int sys_timerfd_gettime64(int fd, void *its) +{ + return tst_syscall(__NR_timerfd_gettime64, fd, its); +} + +static inline int sys_timerfd_settime(int fd, int flags, void *its, + void *old_its) +{ + return tst_syscall(__NR_timerfd_settime, fd, flags, its, old_its); +} + +static inline int sys_timerfd_settime64(int fd, int flags, void *its, + void *old_its) +{ + return tst_syscall(__NR_timerfd_settime64, fd, flags, its, old_its); +} + +static inline long long tst_its_get_val_sec(struct tst_its its) +{ + switch (its.type) { + case TST_LIBC_TIMESPEC: + return its.ts.libc_its.it_value.tv_sec; + case TST_KERN_TIMESPEC: + return its.ts.kern_its.it_value.tv_sec; + default: + tst_brk(TBROK, "Invalid type: %d", its.type); + return -1; + } +} + +static inline long long tst_its_get_val_nsec(struct tst_its its) +{ + switch (its.type) { + case TST_LIBC_TIMESPEC: + return its.ts.libc_its.it_value.tv_nsec; + case TST_KERN_TIMESPEC: + return its.ts.kern_its.it_value.tv_nsec; + default: + tst_brk(TBROK, "Invalid type: %d", its.type); + return -1; + } +} + static inline void tst_its_set_time(struct tst_its *its, long long value_sec, long long value_nsec, long long interval_sec, long long interval_nsec) diff --git a/testcases/kernel/syscalls/timerfd/timerfd01.c b/testcases/kernel/syscalls/timerfd/timerfd01.c index 45d4c5d5ea0d..99882bfc9782 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd01.c @@ -17,8 +17,8 @@ #define _GNU_SOURCE #include -#include "tst_test.h" #include "tst_timer.h" +#include "lapi/abisize.h" #include "tst_safe_timerfd.h" static struct tcase { @@ -29,25 +29,50 @@ static struct tcase { {CLOCK_REALTIME, "CLOCK REALTIME"}, }; +static struct test_variants { + int (*cgettime)(clockid_t clk_id, void *ts); + int (*tfd_gettime)(int fd, void *its); + int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .cgettime = sys_clock_gettime, .tfd_gettime = sys_timerfd_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .cgettime = sys_clock_gettime, .tfd_gettime = sys_timerfd_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timerfd_gettime64 != __LTP__NR_INVALID_SYSCALL) + { .cgettime = sys_clock_gettime64, .tfd_gettime = sys_timerfd_gettime64, .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + static unsigned long long getustime(int clockid) { - struct timespec tp; + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts tp = {.type = tv->type, }; - if (clock_gettime((clockid_t) clockid, &tp)) { + if (tv->cgettime((clockid_t) clockid, tst_ts_get(&tp))) { tst_res(TFAIL | TERRNO, "clock_gettime() failed"); return 0; } - return 1000000ULL * tp.tv_sec + tp.tv_nsec / 1000; + return 1000000ULL * tst_ts_get_sec(tp) + tst_ts_get_nsec(tp) / 1000; } -static void settime(int tfd, struct itimerspec *tmr, int tflags, +static void settime(int tfd, struct tst_its *tmr, int tflags, unsigned long long tvalue, int tinterval) { - tmr->it_value = tst_timespec_from_us(tvalue); - tmr->it_interval = tst_timespec_from_us(tinterval); + struct test_variants *tv = &variants[tst_variant]; + struct timespec value = tst_timespec_from_us(tvalue); + struct timespec interval = tst_timespec_from_us(tinterval); - SAFE_TIMERFD_SETTIME(tfd, tflags, tmr, NULL); + tst_its_set_time(tmr, value.tv_sec, value.tv_nsec, interval.tv_sec, interval.tv_nsec); + + if (tv->tfd_settime(tfd, tflags, tst_its_get(tmr), NULL)) + tst_res(TFAIL, "timerfd_settime() failed"); } static void waittmr(int tfd, unsigned int exp_ticks) @@ -78,10 +103,11 @@ static void waittmr(int tfd, unsigned int exp_ticks) static void run(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; int tfd; unsigned long long tnow; uint64_t uticks; - struct itimerspec tmr; + struct tst_its tmr = {.type = tv->type, }; struct tcase *clks = &tcases[n]; tst_res(TINFO, "testing %s", clks->name); @@ -102,11 +128,12 @@ static void run(unsigned int n) settime(tfd, &tmr, TFD_TIMER_ABSTIME, tnow + 50 * 1000, 50 * 1000); memset(&tmr, 0, sizeof(tmr)); - if (timerfd_gettime(tfd, &tmr)) - tst_res(TFAIL | TERRNO, "timerfd_gettime() failed"); + tmr.type = tv->type; + if (tv->tfd_gettime(tfd, tst_its_get(&tmr))) + tst_res(TFAIL | TERRNO, "timerfd_gettime() failed"); - if (tmr.it_value.tv_sec != 0 || tmr.it_value.tv_nsec > 50 * 1000000) + if (tst_its_get_val_sec(tmr) != 0 || tst_its_get_val_nsec(tmr) > 50 * 1000000) tst_res(TFAIL, "Timer read back value not relative"); else tst_res(TPASS, "Timer read back value is relative"); @@ -132,8 +159,15 @@ static void run(unsigned int n) SAFE_CLOSE(tfd); } +static void setup(void) +{ + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); +} + static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tcases), + .test_variants = ARRAY_SIZE(variants), + .setup = setup, .min_kver = "2.6.25", }; diff --git a/testcases/kernel/syscalls/timerfd/timerfd04.c b/testcases/kernel/syscalls/timerfd/timerfd04.c index 7197fc67ed47..75fa7882539a 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd04.c +++ b/testcases/kernel/syscalls/timerfd/timerfd04.c @@ -18,8 +18,8 @@ #include "tst_safe_clocks.h" #include "tst_safe_timerfd.h" #include "tst_timer.h" +#include "lapi/abisize.h" #include "lapi/namespaces_constants.h" -#include "tst_test.h" #define SLEEP_US 40000 @@ -35,26 +35,60 @@ static struct tcase { {CLOCK_BOOTTIME, CLOCK_BOOTTIME, -10}, }; +static struct test_variants { + int (*cgettime)(clockid_t clk_id, void *ts); + int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .cgettime = sys_clock_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .cgettime = sys_clock_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL) + { .cgettime = sys_clock_gettime64, .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + +static void setup(void) +{ + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); +} + static void verify_timerfd(unsigned int n) { - struct timespec start, end; - struct itimerspec it = {}; + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts start, end; + struct tst_its it; struct tcase *tc = &tcases[n]; + start.type = end.type = it.type = tv->type; SAFE_UNSHARE(CLONE_NEWTIME); SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0", tc->clk_off, tc->off); - SAFE_CLOCK_GETTIME(tc->clk_id, &start); + if (tv->cgettime(tc->clk_id, tst_ts_get(&start))) { + tst_res(TFAIL | TTERRNO, "clock_gettime(2) failed for clock %s", + tst_clock_name(tc->clk_id)); + return; + } - it.it_value = tst_timespec_add_us(start, 1000000 * tc->off + SLEEP_US); + end = tst_ts_add_us(start, 1000000 * tc->off + SLEEP_US); + tst_its_set_time(&it, tst_ts_get_sec(end), tst_ts_get_nsec(end), 0, 0); if (!SAFE_FORK()) { uint64_t exp; int fd = SAFE_TIMERFD_CREATE(tc->clk_id, 0); - SAFE_TIMERFD_SETTIME(fd, TFD_TIMER_ABSTIME, &it, NULL); + if (tv->tfd_settime(fd, TFD_TIMER_ABSTIME, tst_its_get(&it), NULL)) { + tst_res(TFAIL, "timerfd_settime() failed"); + return; + } SAFE_READ(1, fd, &exp, sizeof(exp)); @@ -67,9 +101,13 @@ static void verify_timerfd(unsigned int n) SAFE_WAIT(NULL); - SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &end); + if (tv->cgettime(CLOCK_MONOTONIC, tst_ts_get(&end))) { + tst_res(TFAIL | TTERRNO, "clock_gettime(2) failed for clock %s", + tst_clock_name(CLOCK_MONOTONIC)); + return; + } - long long diff = tst_timespec_diff_us(end, start); + long long diff = tst_ts_diff_us(end, start); if (diff > 5 * SLEEP_US) { tst_res(TFAIL, "timerfd %s slept too long %lli", @@ -90,6 +128,8 @@ static void verify_timerfd(unsigned int n) static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = verify_timerfd, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, .needs_root = 1, .forks_child = 1, .needs_kconfigs = (const char *[]) { diff --git a/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c b/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c index 5f3240bdc7d7..670481b634f6 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c @@ -24,99 +24,101 @@ #define _GNU_SOURCE -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" -#include "lapi/timerfd.h" +#include "tst_timer.h" +#include "lapi/abisize.h" +#include "tst_safe_timerfd.h" char *TCID = "timerfd_gettime01"; static int bad_clockfd = -1; static int clockfd; static int fd; +static void *bad_addr; static struct test_case_t { int *fd; - struct itimerspec *curr_value; + struct tst_its *curr_value; int exp_errno; } test_cases[] = { {&bad_clockfd, NULL, EBADF}, - {&clockfd, (struct itimerspec *)-1, EFAULT}, + {&clockfd, NULL, EFAULT}, {&fd, NULL, EINVAL}, }; -int TST_TOTAL = ARRAY_SIZE(test_cases); -static void setup(void); -static void timerfd_gettime_verify(const struct test_case_t *); -static void cleanup(void); +static struct test_variants { + int (*tfd_gettime)(int fd, void *its); + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .tfd_gettime = sys_timerfd_gettime, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .tfd_gettime = sys_timerfd_gettime, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timerfd_gettime64 != __LTP__NR_INVALID_SYSCALL) + { .tfd_gettime = sys_timerfd_gettime64, .desc = "syscall time64 with kernel spec64"}, +#endif +}; -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - int i; - - tst_parse_opts(argc, argv, NULL, NULL); + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); + bad_addr = tst_get_bad_addr(NULL); - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - timerfd_gettime_verify(&test_cases[i]); + clockfd = timerfd_create(CLOCK_REALTIME, 0); + if (clockfd == -1) { + tst_brk(TFAIL | TERRNO, "timerfd_create() fail"); + return; } - cleanup(); - tst_exit(); + fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0644); } -static void setup(void) +static void cleanup(void) { - if ((tst_kvercmp(2, 6, 25)) < 0) - tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer"); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - clockfd = timerfd_create(CLOCK_REALTIME, 0); - if (clockfd == -1) - tst_brkm(TBROK | TERRNO, cleanup, "timerfd_create() fail"); + if (clockfd > 0) + close(clockfd); - fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0644); + if (fd > 0) + close(fd); } -static void timerfd_gettime_verify(const struct test_case_t *test) +static void run(unsigned int n) { - TEST(timerfd_gettime(*test->fd, test->curr_value)); + struct test_variants *tv = &variants[tst_variant]; + struct test_case_t *test = &test_cases[n]; + struct itimerspec *its; + + if (test->exp_errno == EFAULT) + its = bad_addr; + else + its = tst_its_get(test->curr_value); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "timerfd_gettime() succeeded unexpectedly"); + TEST(tv->tfd_gettime(*test->fd, its)); + + if (TST_RET != -1) { + tst_res(TFAIL, "timerfd_gettime() succeeded unexpectedly"); return; } - if (TEST_ERRNO == test->exp_errno) { - tst_resm(TPASS | TTERRNO, - "timerfd_gettime() failed as expected"); + if (TST_ERR == test->exp_errno) { + tst_res(TPASS | TTERRNO, + "timerfd_gettime() failed as expected"); } else { - tst_resm(TFAIL | TTERRNO, - "timerfd_gettime() failed unexpectedly; expected: " - "%d - %s", test->exp_errno, strerror(test->exp_errno)); + tst_res(TFAIL | TTERRNO, + "timerfd_gettime() failed unexpectedly; expected: " + "%d - %s", test->exp_errno, strerror(test->exp_errno)); } } -static void cleanup(void) -{ - if (clockfd > 0) - close(clockfd); - - if (fd > 0) - close(fd); - - tst_rmdir(); -} +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(test_cases), + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .min_kver = "2.6.25", +}; diff --git a/testcases/kernel/syscalls/timerfd/timerfd_settime01.c b/testcases/kernel/syscalls/timerfd/timerfd_settime01.c index 2e65d23ae825..13317016b792 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_settime01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_settime01.c @@ -25,13 +25,8 @@ #define _GNU_SOURCE -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" +#include "tst_timer.h" +#include "lapi/abisize.h" #include "lapi/timerfd.h" char *TCID = "timerfd_settime01"; @@ -39,80 +34,55 @@ char *TCID = "timerfd_settime01"; static int bad_clockfd = -1; static int clockfd; static int fd; +static void *bad_addr; static struct test_case_t { int *fd; int flags; - struct itimerspec *old_value; + struct tst_its *old_value; int exp_errno; } test_cases[] = { {&bad_clockfd, 0, NULL, EBADF}, - {&clockfd, 0, (struct itimerspec *)-1, EFAULT}, + {&clockfd, 0, NULL, EFAULT}, {&fd, 0, NULL, EINVAL}, {&clockfd, -1, NULL, EINVAL}, }; -int TST_TOTAL = ARRAY_SIZE(test_cases); -static void setup(void); -static void timerfd_settime_verify(const struct test_case_t *); -static void cleanup(void); -static struct itimerspec new_value; - -int main(int argc, char *argv[]) -{ - int lc; - int i; +static struct tst_its new_value; - tst_parse_opts(argc, argv, NULL, NULL); +static struct test_variants { + int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif - setup(); +#if defined(TST_ABI64) + { .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - timerfd_settime_verify(&test_cases[i]); - } - - cleanup(); - tst_exit(); -} +#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL) + { .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; static void setup(void) { - if ((tst_kvercmp(2, 6, 25)) < 0) - tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer"); + struct test_variants *tv = &variants[tst_variant]; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + bad_addr = tst_get_bad_addr(NULL); + new_value.type = tv->type; clockfd = timerfd_create(CLOCK_REALTIME, 0); - if (clockfd == -1) - tst_brkm(TBROK | TERRNO, cleanup, "timerfd_create() fail"); - - fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0644); -} - -static void timerfd_settime_verify(const struct test_case_t *test) -{ - TEST(timerfd_settime(*test->fd, test->flags, &new_value, - test->old_value)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "timerfd_settime() succeeded unexpectedly"); + if (clockfd == -1) { + tst_brk(TFAIL | TERRNO, "timerfd_create() fail"); return; } - if (TEST_ERRNO == test->exp_errno) { - tst_resm(TPASS | TTERRNO, - "timerfd_settime() failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "timerfd_settime() failed unexpectedly; expected: " - "%d - %s", test->exp_errno, strerror(test->exp_errno)); - } + fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0644); } static void cleanup(void) @@ -122,6 +92,43 @@ static void cleanup(void) if (fd > 0) close(fd); +} + +static void run(unsigned int n) +{ + struct test_variants *tv = &variants[tst_variant]; + struct test_case_t *test = &test_cases[n]; + struct itimerspec *its; + + if (test->exp_errno == EFAULT) + its = bad_addr; + else + its = tst_its_get(test->old_value); + + TEST(tv->tfd_settime(*test->fd, test->flags, tst_its_get(&new_value), + its)); - tst_rmdir(); + if (TST_RET != -1) { + tst_res(TFAIL, "timerfd_settime() succeeded unexpectedly"); + return; + } + + if (TST_ERR == test->exp_errno) { + tst_res(TPASS | TTERRNO, + "timerfd_settime() failed as expected"); + } else { + tst_res(TFAIL | TTERRNO, + "timerfd_settime() failed unexpectedly; expected: " + "%d - %s", test->exp_errno, strerror(test->exp_errno)); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(test_cases), + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .min_kver = "2.6.25", +}; diff --git a/testcases/kernel/syscalls/timerfd/timerfd_settime02.c b/testcases/kernel/syscalls/timerfd/timerfd_settime02.c index 0565802f4288..b6444a6db7ba 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_settime02.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_settime02.c @@ -15,8 +15,9 @@ * timerfd: Protect the might cancel mechanism proper */ #include +#include "tst_timer.h" +#include "lapi/abisize.h" #include "tst_safe_timerfd.h" -#include "tst_test.h" #include "tst_fuzzy_sync.h" #include "tst_taint.h" @@ -27,11 +28,34 @@ #endif static int fd = -1; -static struct itimerspec its; +static struct tst_its its; static struct tst_fzsync_pair fzsync_pair; +static struct test_variants { + int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, +#endif + +#if defined(TST_ABI64) + { .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL) + { .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + its.type = tv->type; + tst_taint_init(TST_TAINT_W | TST_TAINT_D); fd = SAFE_TIMERFD_CREATE(CLOCK_REALTIME, 0); @@ -48,7 +72,9 @@ static void cleanup(void) static int punch_clock(int flags) { - return timerfd_settime(fd, flags, &its, NULL); + return variants[tst_variant].tfd_settime(fd, flags, tst_its_get(&its), + NULL); + } static void *thread_run(void *arg) @@ -91,6 +117,7 @@ static void run(void) static struct tst_test test = { .test_all = run, + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .min_kver = "2.6.25", From patchwork Mon Apr 27 11:43:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1277564 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=JbZPIne7; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499jcL043jz9sSc for ; Mon, 27 Apr 2020 21:44:33 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 750783C286B for ; Mon, 27 Apr 2020 13:44:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 81E7A3C2861 for ; Mon, 27 Apr 2020 13:44:03 +0200 (CEST) Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 767CA1A005E6 for ; Mon, 27 Apr 2020 13:44:02 +0200 (CEST) Received: by mail-pj1-x1044.google.com with SMTP id a32so7417334pje.5 for ; Mon, 27 Apr 2020 04:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uWrYp2uU+2Oeq0Dsvfe736xwL/qnKb3dJSG8lZqTBdw=; b=JbZPIne7VMyD+LjiqCzh8Lgc1hdA8TNQMkLb8hI7F1jTRTUR29YLX6xVks/px55EID iAAiqxVR0ELvjrq731wQqYRXP2j0dfcc+ANIwg6vXl3zMMz0oOUXBS4nP+O/K4UAulEm 8mC7JGtbDdfyuCVLoho6AUju05SlCfDKIpte+Fdk2gVRCPO1I0Iyf+VhWZd7vpsA9947 ApwCpI51lPySOJZIG9SZ+7uBXVDKG3F4pVQLnPsXVeAWkhfQ4dU56prTo9nLtkxfyi4o kvndTZLsukFmJ/Mo7ZI3APxGSl2Fiqxdc8vklgoWBbH1mwtc2SgiFE6K4A3vxL3wdDwQ wMuA== 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:mime-version:content-transfer-encoding; bh=uWrYp2uU+2Oeq0Dsvfe736xwL/qnKb3dJSG8lZqTBdw=; b=eMS2WLghp6RVtQ/FkEZU27xB/j7xTs6a0Bf/x9vSYlTgxkrD3r+nbDtqseB5qu4+l7 9HD+CY8kbX4JzMQnQFhh6dJzbbA+Jg/woixoEBPi6p4mNR32TfPPcrBH5J7E/MbFxlMZ gtIyS2eihfTh/tv37FgMPbZVKZlGG2LKB3rZX/nItu2r8xxNvJxkZVOIcYKQ3F3ONRTC VsnnZlxow0oGP1FuaKXu8UmOKH357ulJ81lwDNl/Ja5FFw9np5nmcH8ybjQMpZGvkUJD u58WRE9WhGG6sF0SvCpWwtoURbQckaS5aoctgJXrsOVkJ9p3MPV5NzO0pnPDg9kuAqcu Ic0A== X-Gm-Message-State: AGi0PuYXZKnLU+N51SwGXF110FjlNBKY61uI111O9WCZX9O8kbbUlVnv Ez/Jsg2NLhJf14XS7w2TDu9OlkE+Buc= X-Google-Smtp-Source: APiQypKMrjzhfKyZU/ANKdWjP4iyqQiC346XR1QFLzy13AsiLDrp0UBhQiLfN55cuFfd9CHU9Kl/MA== X-Received: by 2002:a17:90a:d504:: with SMTP id t4mr23435615pju.123.1587987840501; Mon, 27 Apr 2020 04:44:00 -0700 (PDT) Received: from localhost ([122.171.118.46]) by smtp.gmail.com with ESMTPSA id j22sm4844049pgh.67.2020.04.27.04.43.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2020 04:43:59 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Mon, 27 Apr 2020 17:13:47 +0530 Message-Id: <2bab832039bfc76266a5882507a8f4c593a0a637.1587987802.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> References: <41a72155effacaf3b58e6e50bfadddbd4dca188b.1587987802.git.viresh.kumar@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 4/4] syscalls/sched_rr_get_interval: Add support for time64 tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , arnd@arndb.de, Viresh Kumar Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This adds support for time64 tests to the existing sched_rr_get_interval() syscall tests. Signed-off-by: Viresh Kumar --- include/tst_timer.h | 16 +++ .../sched_rr_get_interval01.c | 113 +++++++-------- .../sched_rr_get_interval02.c | 119 ++++++++-------- .../sched_rr_get_interval03.c | 133 +++++++++--------- 4 files changed, 192 insertions(+), 189 deletions(-) diff --git a/include/tst_timer.h b/include/tst_timer.h index a728d78d7def..a726298b407d 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -12,6 +12,7 @@ #ifndef TST_TIMER #define TST_TIMER +#include #include #include #include "tst_test.h" @@ -242,6 +243,21 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags, request, remain); } +static inline int libc_sched_rr_get_interval(pid_t pid, void *ts) +{ + return sched_rr_get_interval(pid, ts); +} + +static inline int sys_sched_rr_get_interval(pid_t pid, void *ts) +{ + return tst_syscall(__NR_sched_rr_get_interval, pid, ts); +} + +static inline int sys_sched_rr_get_interval64(pid_t pid, void *ts) +{ + return tst_syscall(__NR_sched_rr_get_interval_time64, pid, ts); +} + static inline int sys_timer_gettime(kernel_timer_t timerid, void *its) { return tst_syscall(__NR_timer_gettime, timerid, its); diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c index b6084f673ca7..c3171c8c8fb8 100644 --- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c +++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c @@ -64,79 +64,72 @@ * ****************************************************************/ -#include #include -#include "test.h" - -static void setup(); -static void cleanup(); - -char *TCID = "sched_rr_get_interval01"; -int TST_TOTAL = 1; - -struct timespec tp; - -int main(int ac, char **av) +#include "tst_timer.h" +#include "lapi/abisize.h" + +struct tst_ts tp; + +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"}, +#endif + +#if defined(TST_ABI64) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + +static void setup(void) { - - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call sched_rr_get_interval(2) with pid=0 so that it will - * write into the timespec structure pointed to by tp, the - * round robin time quantum for the current process. - */ - TEST(sched_rr_get_interval(0, &tp)); - - if (TEST_RETURN == 0) { - tst_resm(TPASS, "sched_rr_get_interval() returned %ld", - TEST_RETURN); - } else { - tst_resm(TFAIL | TTERRNO, - "Test Failed, sched_rr_get_interval()" - "returned %ld", TEST_RETURN); - } - } - - /* cleanup and exit */ - cleanup(); - tst_exit(); - -} - -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) -{ - tst_require_root(); + struct test_variants *tv = &variants[tst_variant]; /* * Initialize scheduling parameter structure to use with * sched_setscheduler() */ struct sched_param p = { 1 }; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + tst_res(TINFO, "Testing variant: %s", tv->desc); - TEST_PAUSE; + tp.type = tv->type; /* Change scheduling policy to SCHED_RR */ - if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) { - tst_brkm(TBROK, cleanup, "sched_setscheduler() failed"); - } + if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) + tst_res(TFAIL | TTERRNO, "sched_setscheduler() failed"); } -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void run(void) { + struct test_variants *tv = &variants[tst_variant]; + + /* + * Call sched_rr_get_interval(2) with pid=0 so that it will + * write into the timespec structure pointed to by tp, the + * round robin time quantum for the current process. + */ + TEST(tv->func(0, tst_ts_get(&tp))); + if (!TST_RET) { + tst_res(TPASS, "sched_rr_get_interval() passed"); + } else { + tst_res(TFAIL | TTERRNO, "Test Failed, sched_rr_get_interval() returned %ld", + TST_RET); + } } + +static struct tst_test test = { + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c index 6bf743f78c5e..d5c020ff4e3b 100644 --- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c +++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c @@ -65,82 +65,75 @@ * ****************************************************************/ -#include #include -#include "test.h" - -static void setup(); -static void cleanup(); - -char *TCID = "sched_rr_get_interval02"; -int TST_TOTAL = 1; - -struct timespec tp; - -int main(int ac, char **av) -{ - - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - tp.tv_sec = 99; - tp.tv_nsec = 99; - /* - * Call sched_rr_get_interval(2) with pid=0 sothat it will - * write into the timespec structure pointed to by tp the - * round robin time quantum for the current process. - */ - TEST(sched_rr_get_interval(0, &tp)); - - if ((TEST_RETURN == 0) && (tp.tv_sec == 0) && (tp.tv_nsec == 0)) { - tst_resm(TPASS, "Test passed"); - } else { - tst_resm(TFAIL, "Test Failed, sched_rr_get_interval()" - "returned %ld, errno = %d : %s, tp.tv_sec = %d," - " tp.tv_nsec = %ld", TEST_RETURN, TEST_ERRNO, - strerror(TEST_ERRNO), (int)tp.tv_sec, - tp.tv_nsec); - } - } - - /* cleanup and exit */ - cleanup(); - tst_exit(); - -} - -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) +#include "tst_timer.h" +#include "lapi/abisize.h" + +struct tst_ts tp; + +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"}, +#endif + +#if defined(TST_ABI64) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif + +#if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; + +static void setup(void) { - tst_require_root(); + struct test_variants *tv = &variants[tst_variant]; /* * Initialize scheduling parameter structure to use with * sched_setscheduler() */ struct sched_param p = { 1 }; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + tst_res(TINFO, "Testing variant: %s", tv->desc); - TEST_PAUSE; + tp.type = tv->type; /* Change scheduling policy to SCHED_FIFO */ - if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1) { - tst_brkm(TBROK, cleanup, "sched_setscheduler() failed"); - } + if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1) + tst_res(TFAIL | TTERRNO, "sched_setscheduler() failed"); } -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void run(void) { + struct test_variants *tv = &variants[tst_variant]; + tst_ts_set_sec(&tp, 99); + tst_ts_set_nsec(&tp, 99); + + /* + * Call sched_rr_get_interval(2) with pid=0 so that it will + * write into the timespec structure pointed to by tp the + * round robin time quantum for the current process. + */ + TEST(tv->func(0, tst_ts_get(&tp))); + + if (!TST_RET && tst_ts_valid(&tp) == -1) { + tst_res(TPASS, "sched_rr_get_interval() passed"); + } else { + tst_res(TFAIL | TTERRNO, "Test Failed, sched_rr_get_interval() returned %ld, tp.tv_sec = %lld, tp.tv_nsec = %lld", + TST_RET, tst_ts_get_sec(tp), tst_ts_get_nsec(tp)); + } } + +static struct tst_test test = { + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c index 56f2fcf28269..3cd4dafd089e 100644 --- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c @@ -70,102 +70,103 @@ * ****************************************************************/ -#include #include -#include "test.h" - -static void setup(); -static void cleanup(); - -char *TCID = "sched_rr_get_interval03"; -struct timespec tp; +#include "tst_timer.h" +#include "lapi/abisize.h" static pid_t unused_pid; static pid_t inval_pid = -1; static pid_t zero_pid; +struct tst_ts tp; +static void *bad_addr; + struct test_cases_t { pid_t *pid; - struct timespec *tp; + struct tst_ts *tp; int exp_errno; } test_cases[] = { - { - &inval_pid, &tp, EINVAL}, { - &unused_pid, &tp, ESRCH}, + { &inval_pid, &tp, EINVAL}, + { &unused_pid, &tp, ESRCH}, #ifndef UCLINUX - /* Skip since uClinux does not implement memory protection */ - { - &zero_pid, (struct timespec *)-1, EFAULT} + /* Skip since uClinux does not implement memory protection */ + { &zero_pid, NULL, EFAULT} #endif }; -int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); - -int main(int ac, char **av) -{ - - int lc, i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; ++i) { - /* - * Call sched_rr_get_interval(2) - */ - TEST(sched_rr_get_interval(*(test_cases[i].pid), - test_cases[i].tp)); - - if ((TEST_RETURN == -1) && - (TEST_ERRNO == test_cases[i].exp_errno)) { - tst_resm(TPASS, "Test Passed"); - } else { - tst_resm(TFAIL | TTERRNO, "Test Failed," - " sched_rr_get_interval() returned %ld", - TEST_RETURN); - } - } - } - - /* cleanup and exit */ - cleanup(); +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if defined(TST_ABI32) + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"}, +#endif - tst_exit(); +#if defined(TST_ABI64) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"}, +#endif -} +#if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"}, +#endif +}; -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) +static void setup(void) { - tst_require_root(); + struct test_variants *tv = &variants[tst_variant]; /* * Initialize scheduling parameter structure to use with * sched_setscheduler() */ struct sched_param p = { 1 }; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + tst_res(TINFO, "Testing variant: %s", tv->desc); - TEST_PAUSE; + bad_addr = tst_get_bad_addr(NULL); + tp.type = tv->type; /* Change scheduling policy to SCHED_RR */ - if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) { - tst_brkm(TBROK, cleanup, "sched_setscheduler() failed"); - } + if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) + tst_res(TFAIL | TTERRNO, "sched_setscheduler() failed"); - unused_pid = tst_get_unused_pid(cleanup); + unused_pid = tst_get_unused_pid(); } -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; + struct test_cases_t *tc = &test_cases[i]; + struct timerspec *ts; + + if (tc->exp_errno == EFAULT) + ts = bad_addr; + else + ts = tst_ts_get(tc->tp); + /* + * Call sched_rr_get_interval(2) + */ + TEST(tv->func(*tc->pid, ts)); + + if (TST_RET != -1) { + tst_res(TFAIL, "sched_rr_get_interval() passed unexcpectedly"); + return; + } + + if (tc->exp_errno == TST_ERR) + tst_res(TPASS | TTERRNO, "sched_rr_get_interval() failed as excpected"); + else + tst_res(TFAIL | TTERRNO, "sched_rr_get_interval() failed unexcpectedly: %s", + tst_strerrno(tc->exp_errno)); } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(test_cases), + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .needs_root = 1, +};