From patchwork Fri Jun 26 06:22:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317392 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=n9V/KdLH; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49tRdh3YQZz9sRR for ; Fri, 26 Jun 2020 16:23:04 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B10203C5864 for ; Fri, 26 Jun 2020 08:22:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id C77ED3C583B for ; Fri, 26 Jun 2020 08:22:43 +0200 (CEST) Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id C63172010B9 for ; Fri, 26 Jun 2020 08:22:42 +0200 (CEST) Received: by mail-pl1-x641.google.com with SMTP id g17so3887935plq.12 for ; Thu, 25 Jun 2020 23:22:42 -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=K0hjiLk7barxMgCDPXbNf5gcVlXTuL9HIcuMHvA1m/Y=; b=n9V/KdLHsDhJYpTXoAR621xbTRFMK3faW9msA4gJGpdrf+vEbAg8WQSPaQ2t3+rUxZ tZuEOdipv09F5BrXdIo4+zPZYCIpqJf5medK2WOvhvN7S4RGsF3YRLhicxhP6T69a/G3 Os+rnGF1BR5HsYT2NTwPuMluZ7kJ2DACitxrHDiohIydvi/OFqQksfk9rKHLI1sq7MN4 yHazgPm+9Z3pXN+l2gIIG5XFhmsk+H4YGN40dnTFmYliMPuRLwTs/5kZ3sDGw8D4pNs3 OhQoM1L/EeIWCjrDaljvkIk1jiiTxVThuG+vJJ8AXGAuBwJoAZrcQUHjieFekjnnAKN2 BmrQ== 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=K0hjiLk7barxMgCDPXbNf5gcVlXTuL9HIcuMHvA1m/Y=; b=nGRgnZUTKTe53SnbeSQlc96IW1IWpaBymiBPN7Hmh3C+9XTBr8EOs4lM7OjHkikpex ne+X3u8tZbBbZ9lqivKZz73EfSnRc7nPY8OZv9XLDpDzeNSmS8aMwPseluVcSDphiMzJ 7Tw1BszC8yFYe4gI94d+yx1eF0rFwRLTNUom03tj3etPTL0/d+pKjit7TbvF+TqVLBCX EuxCm3OHsMsqptKa0VO/SLQfaWYuoaJxx39XvNCKg7AHJdS/n2dZ327iSFGKIjebvb2l 5fgOgDmj/4hLbvt5H6IG7ErPLaDIvoaGxQbuYAa9anaQQANjt/07x20mnjGRszYFw1zm exzw== X-Gm-Message-State: AOAM532Dgry8Vggc1P2yu1oqcd0MCS0agArBZ/Jn3UZXCJ6f3AVuEnbU gGGZWlaEOARGcMbt6iCL5zMoA7q6gtg= X-Google-Smtp-Source: ABdhPJz5HuJVXus00upzmfsRdAyWcLCEs+dCNYdlwe8TD3RlgTaJ9aC3EGOwhgq0XjJk2Y97tNla6w== X-Received: by 2002:a17:90a:7c07:: with SMTP id v7mr1742810pjf.38.1593152560759; Thu, 25 Jun 2020 23:22:40 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id 4sm21557188pgk.68.2020.06.25.23.22.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:40 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:14 +0530 Message-Id: <6c96466165bb88f052676e6ce5c8eed41cbe628a.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Subject: [LTP] [PATCH V7 01/19] tst_timer: Add new definitions 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 patch adds new helpers for itimerspec and wrapper functions for multiple syscalls. These will be used by later patches. Signed-off-by: Viresh Kumar --- include/tst_timer.h | 326 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 305 insertions(+), 21 deletions(-) diff --git a/include/tst_timer.h b/include/tst_timer.h index 82e3e1e308f1..7fd4a7093960 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -12,9 +12,12 @@ #ifndef TST_TIMER #define TST_TIMER +#include #include +#include #include #include "tst_test.h" +#include "lapi/common_timers.h" #include "lapi/posix_types.h" #include "lapi/syscalls.h" @@ -112,6 +115,16 @@ struct __kernel_timespec { __kernel_time64_t tv_sec; /* seconds */ long long tv_nsec; /* nanoseconds */ }; + +struct __kernel_old_itimerspec { + struct __kernel_old_timespec it_interval; /* timer period */ + struct __kernel_old_timespec it_value; /* timer expiration */ +}; + +struct __kernel_itimerspec { + struct __kernel_timespec it_interval; /* timer period */ + struct __kernel_timespec it_value; /* timer expiration */ +}; #endif enum tst_ts_type { @@ -129,6 +142,14 @@ struct tst_ts { } ts; }; +struct tst_its { + enum tst_ts_type type; + union { + struct __kernel_old_itimerspec kern_old_its; + struct __kernel_itimerspec kern_its; + } ts; +}; + static inline void *tst_ts_get(struct tst_ts *t) { if (!t) @@ -147,6 +168,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_KERN_OLD_TIMESPEC: + return &t->ts.kern_old_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 +249,117 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags, request, remain); } +static inline int sys_futex(int *uaddr, int futex_op, int val, void *to, + int *uaddr2, int val3) +{ + return tst_syscall(__NR_futex, uaddr, futex_op, val, to, uaddr2, val3); +} + +static inline int sys_futex_time64(int *uaddr, int futex_op, int val, void *to, + int *uaddr2, int val3) +{ + return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to, uaddr2, val3); +} + +static inline int libc_mq_timedsend(mqd_t mqdes, const char *msg_ptr, + size_t msg_len, unsigned int msg_prio, void *abs_timeout) +{ + return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout); +} + +static inline int sys_mq_timedsend(mqd_t mqdes, const char *msg_ptr, + size_t msg_len, unsigned int msg_prio, void *abs_timeout) +{ + return tst_syscall(__NR_mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio, + abs_timeout); +} + +static inline int sys_mq_timedsend64(mqd_t mqdes, const char *msg_ptr, + size_t msg_len, unsigned int msg_prio, void *abs_timeout) +{ + return tst_syscall(__NR_mq_timedsend_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +} + +static inline ssize_t libc_mq_timedreceive(mqd_t mqdes, char *msg_ptr, + size_t msg_len, unsigned int *msg_prio, void *abs_timeout) +{ + return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout); +} + +static inline ssize_t sys_mq_timedreceive(mqd_t mqdes, char *msg_ptr, + size_t msg_len, unsigned int *msg_prio, void *abs_timeout) +{ + return tst_syscall(__NR_mq_timedreceive, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +} + +static inline ssize_t sys_mq_timedreceive64(mqd_t mqdes, char *msg_ptr, + size_t msg_len, unsigned int *msg_prio, void *abs_timeout) +{ + return tst_syscall(__NR_mq_timedreceive_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +} + +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(timer_t timerid, void *its) +{ + return tst_syscall(__NR_timer_gettime, timerid, its); +} + +static inline int sys_timer_gettime64(timer_t timerid, void *its) +{ + return tst_syscall(__NR_timer_gettime64, timerid, its); +} + +static inline int sys_timer_settime(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(timer_t timerid, int flags, void *its, + void *old_its) +{ + 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); +} + /* * Returns tst_ts seconds. */ @@ -248,27 +396,6 @@ static inline long long tst_ts_get_nsec(struct tst_ts ts) } } -/* - * Checks that timespec is valid, i.e. that the timestamp is not zero and that - * the nanoseconds are normalized i.e. in <0, 1s) interval. - * - * 0: On success, i.e. timespec updated correctly. - * -1: Error, timespec not updated. - * -2: Error, tv_nsec is corrupted. - */ -static inline int tst_ts_valid(struct tst_ts *t) -{ - long long nsec = tst_ts_get_nsec(*t); - - if (nsec < 0 || nsec >= 1000000000) - return -2; - - if (tst_ts_get_sec(*t) == 0 && tst_ts_get_nsec(*t) == 0) - return -1; - - return 0; -} - /* * Sets tst_ts seconds. */ @@ -309,6 +436,163 @@ static inline void tst_ts_set_nsec(struct tst_ts *ts, long long nsec) } } +/* + * Returns tst_its it_interval seconds. + */ +static inline long long tst_its_get_interval_sec(struct tst_its its) +{ + switch (its.type) { + case TST_KERN_OLD_TIMESPEC: + return its.ts.kern_old_its.it_interval.tv_sec; + case TST_KERN_TIMESPEC: + return its.ts.kern_its.it_interval.tv_sec; + default: + tst_brk(TBROK, "Invalid type: %d", its.type); + return -1; + } +} + +/* + * Returns tst_its it_interval nanoseconds. + */ +static inline long long tst_its_get_interval_nsec(struct tst_its its) +{ + switch (its.type) { + case TST_KERN_OLD_TIMESPEC: + return its.ts.kern_old_its.it_interval.tv_nsec; + case TST_KERN_TIMESPEC: + return its.ts.kern_its.it_interval.tv_nsec; + default: + tst_brk(TBROK, "Invalid type: %d", its.type); + return -1; + } +} + +/* + * Sets tst_its it_interval seconds. + */ +static inline void tst_its_set_interval_sec(struct tst_its *its, long long sec) +{ + switch (its->type) { + break; + case TST_KERN_OLD_TIMESPEC: + its->ts.kern_old_its.it_interval.tv_sec = sec; + break; + case TST_KERN_TIMESPEC: + its->ts.kern_its.it_interval.tv_sec = sec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", its->type); + } +} + +/* + * Sets tst_its it_interval nanoseconds. + */ +static inline void tst_its_set_interval_nsec(struct tst_its *its, long long nsec) +{ + switch (its->type) { + break; + case TST_KERN_OLD_TIMESPEC: + its->ts.kern_old_its.it_interval.tv_nsec = nsec; + break; + case TST_KERN_TIMESPEC: + its->ts.kern_its.it_interval.tv_nsec = nsec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", its->type); + } +} + +/* + * Returns tst_its it_value seconds. + */ +static inline long long tst_its_get_value_sec(struct tst_its its) +{ + switch (its.type) { + case TST_KERN_OLD_TIMESPEC: + return its.ts.kern_old_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; + } +} + +/* + * Returns tst_its it_value nanoseconds. + */ +static inline long long tst_its_get_value_nsec(struct tst_its its) +{ + switch (its.type) { + case TST_KERN_OLD_TIMESPEC: + return its.ts.kern_old_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; + } +} + +/* + * Sets tst_its it_value seconds. + */ +static inline void tst_its_set_value_sec(struct tst_its *its, long long sec) +{ + switch (its->type) { + break; + case TST_KERN_OLD_TIMESPEC: + its->ts.kern_old_its.it_value.tv_sec = sec; + break; + case TST_KERN_TIMESPEC: + its->ts.kern_its.it_value.tv_sec = sec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", its->type); + } +} + +/* + * Sets tst_its it_value nanoseconds. + */ +static inline void tst_its_set_value_nsec(struct tst_its *its, long long nsec) +{ + switch (its->type) { + break; + case TST_KERN_OLD_TIMESPEC: + its->ts.kern_old_its.it_value.tv_nsec = nsec; + break; + case TST_KERN_TIMESPEC: + its->ts.kern_its.it_value.tv_nsec = nsec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", its->type); + } +} + +/* + * Checks that timespec is valid, i.e. that the timestamp is not zero and that + * the nanoseconds are normalized i.e. in <0, 1s) interval. + * + * 0: On success, i.e. timespec updated correctly. + * -1: Error, timespec not updated. + * -2: Error, tv_nsec is corrupted. + */ +static inline int tst_ts_valid(struct tst_ts *t) +{ + long long nsec = tst_ts_get_nsec(*t); + + if (nsec < 0 || nsec >= 1000000000) + return -2; + + if (tst_ts_get_sec(*t) == 0 && tst_ts_get_nsec(*t) == 0) + return -1; + + return 0; +} + /* * Converts timespec to tst_ts. */ From patchwork Fri Jun 26 06:22:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317393 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=FuKdqzN2; 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 49tRdk3VwMz9sSc for ; Fri, 26 Jun 2020 16:23:06 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7523F3C2B5E for ; Fri, 26 Jun 2020 08:23:03 +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 C1F293C583C for ; Fri, 26 Jun 2020 08:22:46 +0200 (CEST) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 C3AEC1401184 for ; Fri, 26 Jun 2020 08:22:45 +0200 (CEST) Received: by mail-pg1-x544.google.com with SMTP id e9so4509413pgo.9 for ; Thu, 25 Jun 2020 23:22:45 -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=8QlfqIDyKeHblS8UuX3/4BCXqCBVSs/CzOzkVisJr1U=; b=FuKdqzN2u1Nv0ocACa9O95wgDViLwCYOXZTng0U0LuB3Z4PdB1dnfqdz4ghTaysKcD dZHmxd0l02NTU7AmGiE7Wb9BJCqTbdwhQudrzXGHfMfxSE6EYKQLNLpjlV6D+qU8fVJ4 GuSlKl80I0ulSlfNDSSQ21TDc1LCNbOWXUZyFLx7IF/UU012jYuatQNXDB3cfPIHRnW9 fivqREmILMjhGXsZubFoEA6w/5VRuA2YEMhyMDeGRa0Sa58TvVSDNMQ6zxwCsaYdFeHo oscNA9vRUthdUpR3/HgJZTKr04m0zRtR8j+ZSPpa/RtrxLSBNZj7uJxw0YBTKjoPETDv py2A== 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=8QlfqIDyKeHblS8UuX3/4BCXqCBVSs/CzOzkVisJr1U=; b=Rp6wpxiMhUNtzzZygQlQO3W2/NnzfJxOWpMx/GUsAyfjC2O1jR5QMbGOBmW6oVvqJD svLppw0tj8VdG2CxcoExHmpbGKlnh+rY2b6wo7F637fhOpA1TFMDnF3sMYEan51se4qO +vlmdglKc0U+Uzi+NcpHqldh2D2GwmcBcyVYVhvWxnW3a7moaSsgtu66LcrR+ljaSc3A U4oxTV3sNSqELF5FtZ1NYF373+Hmfd0OV4sLZJC40mz5i8DbB57JR3PIHDgsEIoS8SXz PYAliwEIvuhrcR9UwD/TPOhdgcAgGAiEaOqw3Rnp3N6Gkm9Xfz4upMA40S1KGDsFZoSh DufQ== X-Gm-Message-State: AOAM533fzAvT9fccbiYsC0DEAEZnt77VRb0YfSUziC4+P6l+VURRb0ED YvrHbzR8IIUUfUD3wGOib6/RnJmyMQk= X-Google-Smtp-Source: ABdhPJzAqJkvJBq1Nd8w4Yhf+2ufettICco2VycTH5CzfBRTpmDVu1LKcEPCH/t6hLTifU5qmm1u1g== X-Received: by 2002:a63:7d4e:: with SMTP id m14mr1403753pgn.391.1593152563553; Thu, 25 Jun 2020 23:22:43 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id o11sm9947317pjq.54.2020.06.25.23.22.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:43 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:15 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 02/19] 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 --- .../syscalls/timer_gettime/timer_gettime01.c | 135 ++++++++---------- 1 file changed, 63 insertions(+), 72 deletions(-) diff --git a/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c b/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c index 1c75f1cf0e45..f7083917317c 100644 --- a/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c +++ b/testcases/kernel/syscalls/timer_gettime/timer_gettime01.c @@ -1,24 +1,10 @@ -/****************************************************************************** - * Copyright (c) Crackerjack Project., 2007 * - * Porting from Crackerjack to LTP is done by: * - * Manas Kumar Nayak * - * Copyright (c) 2013 Cyril Hrubis * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * - * the GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation, * - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * * - ******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) Crackerjack Project., 2007 + * Porting from Crackerjack to LTP is done by: + * Manas Kumar Nayak + * Copyright (c) 2013 Cyril Hrubis + */ #include #include @@ -26,71 +12,76 @@ #include #include -#include "test.h" -#include "lapi/syscalls.h" +#include "tst_timer.h" -char *TCID = "timer_gettime01"; -int TST_TOTAL = 3; +static struct test_variants { + int (*func)(timer_t timer, void *its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_timer_gettime != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_gettime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif -static void cleanup(void) -{ - tst_rmdir(); -} +#if (__NR_timer_gettime64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_gettime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; -static void setup(void) -{ - TEST_PAUSE; - tst_tmpdir(); -} +static timer_t timer; -int main(int ac, char **av) +static void setup(void) { - int lc; - 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(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); - 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); - } + if (TST_RET) { + tst_res(TFAIL | TTERRNO, "timer_create() failed"); + 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); - } +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) { + if (tst_its_get_interval_sec(spec) || + tst_its_get_interval_nsec(spec) || + tst_its_get_value_sec(spec) || + tst_its_get_value_nsec(spec)) + tst_res(TFAIL, "timespec should have been zeroed"); + else + tst_res(TPASS, "timer_gettime() Passed"); + } else { + tst_res(TFAIL | TTERRNO, "timer_gettime() Failed"); } - cleanup(); - tst_exit(); + TEST(tv->func((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 Fri Jun 26 06:22:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317394 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=JaNdQehD; 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 49tRdx1gkXz9sRR for ; Fri, 26 Jun 2020 16:23:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7C9553C2B67 for ; Fri, 26 Jun 2020 08:23:14 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 0F6883C585A for ; Fri, 26 Jun 2020 08:22:48 +0200 (CEST) Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 DE2CA600B8E for ; Fri, 26 Jun 2020 08:21:52 +0200 (CEST) Received: by mail-pl1-x644.google.com with SMTP id d12so3914105ply.1 for ; Thu, 25 Jun 2020 23:22:48 -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=ERU/2N+jHtSJmjAASD07ZLHpWznQ7nOWmKAaoBHiLqY=; b=JaNdQehD89oVIuVRnlrVdw9BAVtAHoiYsE6CuJVHj5ICLLUX4OUp+MPRduLzERPbpl St6eOnrAItWds9hvTnPkGWuxs4Pze5wRWp8AijOESKbrayivy4trS2zYGc9qH17pxGdp uXy5Da1WU9b4QfF9/BJLpZOaMjFo12eo9cw0u4E/jOO4fkd1VLCpWPQj4KEtHvvwJQmU 9z/r7CxwNMjKrNv5mmjdFyrKy0GjDQ4Q/0eG5y1C1kb5qgl6n9ejxkBtEdWIHRiEVtol FNM0vaPoOwf9G6HKS4gvNiGvdxaE+esJlw2qH13oq0S2IrdXSFNuNL+MRaMZDbPow8d4 BSzA== 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=ERU/2N+jHtSJmjAASD07ZLHpWznQ7nOWmKAaoBHiLqY=; b=eZb7+mcQTAnVoRyafvrLWK+iCp7GaMFAzPsxgj2TkK5CJmDErs1ef0qH8SM4VM4lT6 2xayNnijv7DAMY/ybZ+aaFv9TYww91rfYRaloz9VmbK7HtWqGxwMrZSm0s0+vbqIvLlZ ya0rijtB856y2rIaxFfHEygmU18+/Snc58XGVGu4JBqCwNIReq18pxGilmCMUI17EyFR QGJwkPwAgwcMny0tHwSPlnEQJyFB2WSBFiQhkxaYNvIjbAyiTggZhjfumj2MawSzFWK9 i6fnpGdamAyEviELv6+Er0aJndwZDf0kJwRMZpo6HRIdvaDr0bXfokV3GeZSBTwLAPHf T0XA== X-Gm-Message-State: AOAM5320IO0r0K2OZZQnd+TdAkJkjMPI6tqqZHwGxdmh9oW5nTiWGvTj +LY3bSbHSisFgmnx1IbVhvdpYPxe8ms= X-Google-Smtp-Source: ABdhPJydiJ684fbELrToN5q5GhlwIUBJAz3xJhl4sM1DfKD+/KzeL6FENAy4BnIp7GuV6eCfQV+PxQ== X-Received: by 2002:a17:902:9a94:: with SMTP id w20mr1295355plp.177.1593152566291; Thu, 25 Jun 2020 23:22:46 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id v13sm10570909pjd.9.2020.06.25.23.22.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:45 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:16 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 03/19] 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 --- .../syscalls/timer_settime/timer_settime01.c | 51 ++++++++++---- .../syscalls/timer_settime/timer_settime02.c | 69 ++++++++++++++----- 2 files changed, 88 insertions(+), 32 deletions(-) diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime01.c b/testcases/kernel/syscalls/timer_settime/timer_settime01.c index da365d221086..08fb56e4943a 100644 --- a/testcases/kernel/syscalls/timer_settime/timer_settime01.c +++ b/testcases/kernel/syscalls/timer_settime/timer_settime01.c @@ -25,15 +25,14 @@ #include #include #include -#include "tst_test.h" -#include "lapi/common_timers.h" +#include "tst_timer.h" -static struct timespec timenow; -static struct itimerspec new_set, old_set; -static kernel_timer_t timer; +static struct tst_ts timenow; +static struct tst_its new_set, old_set; +static 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 +44,28 @@ 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)(timer_t timerid, int flags, void *its, + void *old_its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_timer_settime != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime, .func = sys_timer_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#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 spec"}, +#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 +95,27 @@ 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_interval_sec(&new_set, tc->it_interval_tv_sec); + tst_its_set_interval_nsec(&new_set, 0); + tst_its_set_value_sec(&new_set, val); + tst_its_set_value_nsec(&new_set, 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 +139,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 +147,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..e82adddc3189 100644 --- a/testcases/kernel/syscalls/timer_settime/timer_settime02.c +++ b/testcases/kernel/syscalls/timer_settime/timer_settime02.c @@ -25,12 +25,13 @@ #include #include -#include "tst_test.h" -#include "lapi/common_timers.h" +#include "tst_timer.h" -static struct itimerspec new_set, old_set; -static kernel_timer_t timer; -static kernel_timer_t timer_inval = -1; +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 timer_t timer; +static timer_t timer_inval = -1; /* separate description-array to (hopefully) improve readability */ static const char * const descriptions[] = { @@ -43,24 +44,47 @@ static const char * const descriptions[] = { }; static struct testcase { - kernel_timer_t *timer_id; - struct itimerspec *new_ptr; - struct itimerspec *old_ptr; + timer_t *timer_id; + 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)(timer_t timerid, int flags, void *its, + void *old_its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_timer_settime != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_timer_settime64 != __LTP__NR_INVALID_SYSCALL) + { .func = sys_timer_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#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 +115,16 @@ 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_interval_sec(&new_set, 0); + tst_its_set_interval_nsec(&new_set, 0); + tst_its_set_value_sec(&new_set, 5); + tst_its_set_value_nsec(&new_set, tc->it_value_tv_nsec); + + 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 +148,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 Fri Jun 26 06:22:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317395 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=u6simnIu; 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 49tRf829bYz9sSc for ; Fri, 26 Jun 2020 16:23:28 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 84CF93C2B5D for ; Fri, 26 Jun 2020 08:23:25 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id A31EB3C5842 for ; Fri, 26 Jun 2020 08:22:52 +0200 (CEST) Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 216051000D3D for ; Fri, 26 Jun 2020 08:22:51 +0200 (CEST) Received: by mail-pj1-x1041.google.com with SMTP id h22so4518946pjf.1 for ; Thu, 25 Jun 2020 23:22:51 -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=L26AYa8v9PFIrmiwzUT8ZbIxddQpG7cETWJHcQKV9Mc=; b=u6simnIubqTKZJUh/E1vTh72FNHHExh5jlzTDoxH2fbouFZbb7U+N7xGnJpXDXt9kW 9WtwAfQpFrpfTaG3DMYLtuBnbTDMiConvQVq/ZXp0iodz3FDKYQIq8Hzmt6YCKe26RTb er0c8zQFaR87gmiJraxqQOBibCcHGiHz7PKWsCYKi7jWQDjIbARwuzlxx0/lFc9xAu9s 7unxecXxt8ufgod4SMdGAt8OGGX38MlEtvR+MS5JF6+YmkyiECdmYE0krgKFSN2FS7hO oPA1T+3IjWHXbxEV+KKE0DrN9QV8ia2MWaFElLwj5cOQe1I5D8L4/dnzTacyDMv0d0Hu irUA== 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=L26AYa8v9PFIrmiwzUT8ZbIxddQpG7cETWJHcQKV9Mc=; b=IiXERm88JfIyggxe/iRtCeHoyqXb7cFkkN9OmnJP+4vt+JI06EKEIpoY34rMoQrfxZ pWIxh7KAXY2v/KigkLGOq3z5VyA0Gdh/OuHX1DM7i6N2TXskAlAVO8es+00foVZ7E5pH soR2hR7fIZAF9BDI14Un8ufvBPziEZHMD7wnL0n13has3hX7RW2P0Uo4h4SnDJAioI1d qZip+62zgR/MKurFLVX8ZZJtl73iLlyUiN9kirPYqw0shF84Y/j8oXO6LZdVeSqMMMST IrqPh15ZniiEhNDTCHhJOba/goUM3wxBIKzxX3XFBPCcATGMAHfRkvpLSn3HUAXhB4SG 6n5w== X-Gm-Message-State: AOAM5326B1gCzaWlI6261O4Z5Ys3TCQhLOmO6RWM3sYd0xGtz2FBmOJU 8B2AtclmNg/ZCz+JyHxZr0LwBE9el54= X-Google-Smtp-Source: ABdhPJyi+IegtKmioRQx/ZnbC3PfumyvPJSDHv6rc1BRCHQl8CMM7YGlZXnwox/V4x6RxT1iluu9yw== X-Received: by 2002:a17:902:8b8a:: with SMTP id ay10mr1385274plb.236.1593152568980; Thu, 25 Jun 2020 23:22:48 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id j23sm3676603pfn.3.2020.06.25.23.22.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:48 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:17 +0530 Message-Id: <657d473ec91c2d43e241ebc4a1ba20679fd4ef9a.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH V7 04/19] 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 --- testcases/kernel/syscalls/timerfd/timerfd01.c | 56 ++++++-- testcases/kernel/syscalls/timerfd/timerfd04.c | 54 +++++-- .../syscalls/timerfd/timerfd_gettime01.c | 133 ++++++++--------- .../syscalls/timerfd/timerfd_settime01.c | 136 ++++++++---------- .../syscalls/timerfd/timerfd_settime02.c | 28 +++- 5 files changed, 237 insertions(+), 170 deletions(-) diff --git a/testcases/kernel/syscalls/timerfd/timerfd01.c b/testcases/kernel/syscalls/timerfd/timerfd01.c index 45d4c5d5ea0d..90144b843e30 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd01.c @@ -17,7 +17,6 @@ #define _GNU_SOURCE #include -#include "tst_test.h" #include "tst_timer.h" #include "tst_safe_timerfd.h" @@ -29,25 +28,49 @@ 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 (__NR_timerfd_gettime != __LTP__NR_INVALID_SYSCALL) + { .cgettime = sys_clock_gettime, .tfd_gettime = sys_timerfd_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#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 spec"}, +#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_interval_sec(tmr, interval.tv_sec); + tst_its_set_interval_nsec(tmr, interval.tv_nsec); + tst_its_set_value_sec(tmr, value.tv_sec); + tst_its_set_value_nsec(tmr, value.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 +101,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 +126,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_value_sec(tmr) != 0 || tst_its_get_value_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 +157,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..49d50d00022a 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd04.c +++ b/testcases/kernel/syscalls/timerfd/timerfd04.c @@ -19,7 +19,6 @@ #include "tst_safe_timerfd.h" #include "tst_timer.h" #include "lapi/namespaces_constants.h" -#include "tst_test.h" #define SLEEP_US 40000 @@ -35,26 +34,59 @@ 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 (__NR_timerfd_settime != __LTP__NR_INVALID_SYSCALL) + { .cgettime = sys_clock_gettime, .tfd_settime = sys_timerfd_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#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 spec"}, +#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_interval_sec(&it, 0); + tst_its_set_interval_nsec(&it, 0); + tst_its_set_value_sec(&it, tst_ts_get_sec(end)); + tst_its_set_value_nsec(&it, tst_ts_get_nsec(end)); 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 +99,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 +126,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..49f5aa59a96b 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c @@ -1,20 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -/* * DESCRIPTION * Verify that, * 1. fd is not a valid file descriptor, EBADF would return. @@ -24,99 +12,96 @@ #define _GNU_SOURCE -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" -#include "lapi/timerfd.h" +#include "tst_timer.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 (__NR_timerfd_gettime != __LTP__NR_INVALID_SYSCALL) + { .tfd_gettime = sys_timerfd_gettime, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_timerfd_gettime64 != __LTP__NR_INVALID_SYSCALL) + { .tfd_gettime = sys_timerfd_gettime64, .desc = "syscall time64 with kernel spec"}, +#endif +}; -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - int i; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); + bad_addr = tst_get_bad_addr(NULL); - 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]; + void *its; - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "timerfd_gettime() succeeded unexpectedly"); + if (test->exp_errno == EFAULT) + its = bad_addr; + else + its = tst_its_get(test->curr_value); + + 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..2fd64c1c6a04 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_settime01.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_settime01.c @@ -1,20 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -/* * DESCRIPTION * Verify that, * 1. fd is not a valid file descriptor, EBADF would return. @@ -25,13 +13,7 @@ #define _GNU_SOURCE -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" +#include "tst_timer.h" #include "lapi/timerfd.h" char *TCID = "timerfd_settime01"; @@ -39,80 +21,51 @@ 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; +static struct tst_its new_value; -int main(int argc, char *argv[]) -{ - int lc; - int i; - - 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 (__NR_timerfd_settime != __LTP__NR_INVALID_SYSCALL) + { .tfd_settime = sys_timerfd_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif - setup(); - - 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 spec"}, +#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"); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + struct test_variants *tv = &variants[tst_variant]; - 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 +75,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]; + void *its; + + if (test->exp_errno == EFAULT) + its = bad_addr; + else + its = tst_its_get(test->old_value); - tst_rmdir(); + TEST(tv->tfd_settime(*test->fd, test->flags, tst_its_get(&new_value), + its)); + + 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..c15b69dca9ca 100644 --- a/testcases/kernel/syscalls/timerfd/timerfd_settime02.c +++ b/testcases/kernel/syscalls/timerfd/timerfd_settime02.c @@ -15,8 +15,8 @@ * timerfd: Protect the might cancel mechanism proper */ #include +#include "tst_timer.h" #include "tst_safe_timerfd.h" -#include "tst_test.h" #include "tst_fuzzy_sync.h" #include "tst_taint.h" @@ -27,11 +27,30 @@ #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 (__NR_timerfd_settime != __LTP__NR_INVALID_SYSCALL) + { .tfd_settime = sys_timerfd_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL) + { .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#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 +67,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 +112,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 Fri Jun 26 06:22:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317396 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=GCTCTlBe; 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 49tRfK3MY5z9sRR for ; Fri, 26 Jun 2020 16:23:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DFC903C2B7A for ; Fri, 26 Jun 2020 08:23:34 +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 CF0373C5837 for ; Fri, 26 Jun 2020 08:22:54 +0200 (CEST) Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 A1D511401184 for ; Fri, 26 Jun 2020 08:22:53 +0200 (CEST) Received: by mail-pf1-x444.google.com with SMTP id d66so4217619pfd.6 for ; Thu, 25 Jun 2020 23:22: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=iLslCRv9fhuSgCnJ1+XY4XFU8bJwq8ABR5V+maLwJXc=; b=GCTCTlBe8K4lgjKOhde8X7HmmS96gh8zb4n1Qco2O5WbB7jHPR0fN0IwwtjuwzzSZs LPR6u6inXRtsTcAcHEZxqUyLb0YHf8CiY1mDpXcY/87D/eHcf0GJ7faeCfzmq7cKlypV CBoKDaZmQdEH11tBxcG8QZ32ckyyVgJwcyJ17LnbuyTTdMM6y/RxUGYVEP20OufrGTqm GAjGS6187e7i47qHtsMvUcJvqgEpgRBZUY8L1qbk4yURzy6dbktsuK9ADttfNS6K6Lth utBwL8S9EDl5yFCAYGXo7m6cNPHdPvtVHz1pHFJ7QgpXXqZLg12NkiHuhJA5HBs59h1g yIfA== 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=iLslCRv9fhuSgCnJ1+XY4XFU8bJwq8ABR5V+maLwJXc=; b=EZSQrTqfGIL0IF0JQRTicXTbrQW8a9C4WASDRtrDuR1FREtqT6/MBEJMvy5ArHm5HN RabAOKj+Pj6FcHqF/Ab5GeQ3iN1tubnMUpG/swMHlFN+59Gmv0aRg5mPNas75E3bmFuB 0Qha58XjNp+LsOKZk2BIrG0/B5zfjDb0X5cjEkdkFT8j4bNao2aIpiY+bYM5pU6pI/n4 qAIARSAhXJIJ/P1e+wCV8+1b8WfGiOHTB6GP8lb2am69davGtYxS1QvcXcycy0BjwOz+ CXEf+RUuo71RhAurByPehBi1oKjXhbGoxrcxGEYOjGOFVzwng5rk766wgnNNqxObaWcz b4eA== X-Gm-Message-State: AOAM530UkH6kaIwqfkfClJrMpzVqpky5JSWV1NreJ9J0u4+QvaZNjssl IWZhBpf7kNSdfT4weiwVUH7yuduzAxc= X-Google-Smtp-Source: ABdhPJy6s8GEvB7mHwLQennT9c4OBbfq8ZRNgxw2bcjmR9YFsWOH36PBNDdBWKmGdmIAnOPxHqtg8Q== X-Received: by 2002:a63:2248:: with SMTP id t8mr1398246pgm.113.1593152571592; Thu, 25 Jun 2020 23:22:51 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id w17sm26084298pff.27.2020.06.25.23.22.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:51 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:18 +0530 Message-Id: <325a43a851acca8bb242011a1d62063c8154653c.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 05/19] 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 --- .../sched_rr_get_interval01.c | 116 ++++++-------- .../sched_rr_get_interval02.c | 122 ++++++--------- .../sched_rr_get_interval03.c | 146 ++++++++---------- 3 files changed, 157 insertions(+), 227 deletions(-) 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 6ebf873de798..9bad698aa6ec 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 @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -/********************************************************** * * TEST IDENTIFIER : sched_rr_get_interval01 * @@ -62,81 +48,69 @@ * -P x : Pause for x seconds between iterations. * -t : Turn on syscall timing. * - ****************************************************************/ + */ -#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) -{ - - int lc; - - tst_parse_opts(ac, av, NULL, NULL); +#include "tst_timer.h" - setup(); +struct tst_ts tp; - for (lc = 0; TEST_LOOPING(lc); lc++) { +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, - tst_count = 0; +#if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif - /* - * 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 (__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 spec"}, +#endif +}; - 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) +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_RR */ - if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) { - tst_brkm(TBROK|TERRNO, 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 367d9e3ff486..8da42e97404b 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 @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -/********************************************************** * * TEST IDENTIFIER : sched_rr_get_interval02 * @@ -63,84 +49,72 @@ * -P x : Pause for x seconds between iterations. * -t : Turn on syscall timing. * - ****************************************************************/ + */ -#include #include -#include "test.h" - -static void setup(); -static void cleanup(); +#include "tst_timer.h" -char *TCID = "sched_rr_get_interval02"; -int TST_TOTAL = 1; +struct tst_ts tp; -struct timespec tp; +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, -int main(int ac, char **av) -{ - - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); +#if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif - for (lc = 0; TEST_LOOPING(lc); lc++) { +#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 spec"}, +#endif +}; - 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) +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|TERRNO, 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 40b636b4dc65..0ccf47d2a561 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 @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -/********************************************************** * * TEST IDENTIFIER : sched_rr_get_interval03 * @@ -68,104 +54,100 @@ * -P x : Pause for x seconds between iterations. * -t : Turn on syscall timing. * - ****************************************************************/ + */ -#include #include -#include "test.h" - -static void setup(); -static void cleanup(); - -char *TCID = "sched_rr_get_interval03"; -struct timespec tp; +#include "tst_timer.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]); +static struct test_variants { + int (*func)(pid_t pid, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .func = libc_sched_rr_get_interval, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, -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(); - - tst_exit(); +#if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL) + { .func = sys_sched_rr_get_interval, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#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 spec"}, +#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|TERRNO, 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, +}; From patchwork Fri Jun 26 06:22:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317397 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=g+2NSPFv; 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 49tRfY3wBTz9sRR for ; Fri, 26 Jun 2020 16:23:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DD70A3C5843 for ; Fri, 26 Jun 2020 08:23:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 29C183C2B64 for ; Fri, 26 Jun 2020 08:22:57 +0200 (CEST) Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 1696820109F for ; Fri, 26 Jun 2020 08:22:56 +0200 (CEST) Received: by mail-pj1-x1041.google.com with SMTP id h22so4519036pjf.1 for ; Thu, 25 Jun 2020 23:22:55 -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=oH8G5rqomIPQnTCNPZaGaq4jGJMqNIwZj4/hWqHFEic=; b=g+2NSPFv7oZnPIkWDR1w6Sd1GHT1qWk0P9/7qB34YuNOy88mbtsBDceJVKg8PP4h/A mg7y5xyJ4T4NqlkPTThxZNoDnu5iSbp4zFVoWYwr/DHUnjjNODI6ilFw4at8IFVzEJHK 2n+yT9/MOp6jfU1kUBl5oQVKb2FJiVrSjj2pb/aWmjOUcmffVtl9tALqGe671bofNjvl F8aaS9x/d/FXdBCZ7XPaMRnGoAH9VYc14fbcnSaOH5Jd1brMLg71epe61OLmPFpizMTv fbhkyZArHX0JVzI3pc1GZq9roWngfd7dYKuqHeVXkL0RgIZdrMvKKgMf+oqxMNhad8Xg uuGg== 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=oH8G5rqomIPQnTCNPZaGaq4jGJMqNIwZj4/hWqHFEic=; b=lsT8migcnHBLt+qsCCbL+1Xh3OjODwTJTiAYbUNuISEP1nLmh2wFKFLIWB2HCGCKNg 7NmcPuDx4aaK1ff4qG4Hy0xcJpt9ViPl3K2sPbDUgPX91eQ9Ma6NtSyVJBm/+9nNNMjE abUPeU5n29366Jgucof6P4J4jghNEgSzPqdX/i7GRdpoHHjKF1LSeqKXHac/tapp/Teo pC0DGFNM7l3dB149X4r54fjjuIHAn/ASKz4mi58cDy+vjraKdQqpz78iXZ0QRAy5yY/Z aoCT39RqGgalTPykZVGRPCKspy8zT5S6lvsbJmw2I3vZKNoekXy6mGROR1k7t+pSLzSQ MPDQ== X-Gm-Message-State: AOAM531KR5Jj+osgLpXsSwKZ21pDPqwW2wXy8qnhudmC05rC19JehNBk TK29zRUlH2hD8Max7m+ZxUAixSHYeCo= X-Google-Smtp-Source: ABdhPJzk9vmYC7GxUX4UyX8HNYTtV2hCH2Um4U13owpXohYSGp+uuW1EFllPXqO/CDmmQPUL6Qc7vg== X-Received: by 2002:a17:902:694b:: with SMTP id k11mr1328774plt.285.1593152574152; Thu, 25 Jun 2020 23:22:54 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id g21sm24373171pfh.134.2020.06.25.23.22.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:53 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:19 +0530 Message-Id: <681915c7fbb224ffdd9acb5dba012cc7aadfbd46.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Subject: [LTP] [PATCH V7 06/19] syscalls/futex: Merge futex_wait_bitset 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" We can handle them easily in a single test, lets do it. Signed-off-by: Viresh Kumar Reviewed-by: Petr Vorel --- runtest/syscalls | 1 - testcases/kernel/syscalls/futex/.gitignore | 1 - testcases/kernel/syscalls/futex/Makefile | 1 - .../kernel/syscalls/futex/futex_wait_bitset.h | 75 ------------------- .../syscalls/futex/futex_wait_bitset01.c | 73 +++++++++++++++++- .../syscalls/futex/futex_wait_bitset02.c | 18 ----- 6 files changed, 71 insertions(+), 98 deletions(-) delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset.h delete mode 100644 testcases/kernel/syscalls/futex/futex_wait_bitset02.c diff --git a/runtest/syscalls b/runtest/syscalls index b4d523319924..5b3a0862faea 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1671,7 +1671,6 @@ futex_wake02 futex_wake02 futex_wake03 futex_wake03 futex_wake04 futex_wake04 futex_wait_bitset01 futex_wait_bitset01 -futex_wait_bitset02 futex_wait_bitset02 memfd_create01 memfd_create01 memfd_create02 memfd_create02 diff --git a/testcases/kernel/syscalls/futex/.gitignore b/testcases/kernel/syscalls/futex/.gitignore index 68bc2028e1b2..54cd02b0223f 100644 --- a/testcases/kernel/syscalls/futex/.gitignore +++ b/testcases/kernel/syscalls/futex/.gitignore @@ -6,7 +6,6 @@ /futex_wait04 /futex_wait05 /futex_wait_bitset01 -/futex_wait_bitset02 /futex_wake01 /futex_wake02 /futex_wake03 diff --git a/testcases/kernel/syscalls/futex/Makefile b/testcases/kernel/syscalls/futex/Makefile index 8dd239301e63..c88af7c9643b 100644 --- a/testcases/kernel/syscalls/futex/Makefile +++ b/testcases/kernel/syscalls/futex/Makefile @@ -12,7 +12,6 @@ futex_wake02: CFLAGS+=-pthread futex_wake04: CFLAGS+=-pthread futex_wait05: LDLIBS+=-lrt futex_wait_bitset01: LDLIBS+=-lrt -futex_wait_bitset02: LDLIBS+=-lrt include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset.h b/testcases/kernel/syscalls/futex/futex_wait_bitset.h deleted file mode 100644 index 84712816bfe8..000000000000 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset.h +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2015 Cyril Hrubis - */ - -#define THRESHOLD_US 100000 -#define DEFAULT_TIMEOUT_US 100010 - -static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) -{ - struct timespec start, to, end; - futex_t futex = FUTEX_INITIALIZER; - u_int32_t bitset = 0xffffffff; - int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0; - - tst_res(TINFO, "testing futex_wait_bitset() timeout with %s", - clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"); - - clock_gettime(clk_id, &start); - to = tst_timespec_add_us(start, wait_us); - - TEST(futex_wait_bitset(&futex, futex, &to, bitset, flags)); - - clock_gettime(clk_id, &end); - - if (TST_RET != -1) { - tst_res(TFAIL, "futex_wait_bitset() returned %li, expected -1", - TST_RET); - return; - } - - if (TST_ERR == ENOSYS) { - tst_res(TCONF, - "In this kernel, futex() does not support FUTEX_WAIT_BITSET operation"); - return; - } - - if (TST_ERR != ETIMEDOUT) { - tst_res(TFAIL | TTERRNO, "expected %s", - tst_strerrno(ETIMEDOUT)); - return; - } - - if (tst_timespec_lt(end, to)) { - tst_res(TFAIL, - "futex_wait_bitset() woken up prematurely %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); - return; - } - - if (tst_timespec_diff_us(end, to) > THRESHOLD_US) { - tst_res(TFAIL, - "futex_wait_bitset() waited too long %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); - return; - } - - tst_res(TPASS, "futex_wait_bitset() waited %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); -} - -static void setup(void) -{ - tst_timer_check(USE_CLOCK); -} - -static void run(void) -{ - verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, USE_CLOCK); -} - -static struct tst_test test = { - .setup = setup, - .test_all = run, -}; diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c index 1ae3253cfe13..b8546c3e640c 100644 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c +++ b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c @@ -13,7 +13,76 @@ #include "tst_timer.h" #include "futextest.h" -#define USE_CLOCK CLOCK_MONOTONIC +#define THRESHOLD_US 100000 +#define DEFAULT_TIMEOUT_US 100010 -#include "futex_wait_bitset.h" +static struct test_case_t { + clockid_t clk_id; +} tcases[] = { + { CLOCK_MONOTONIC }, + { CLOCK_REALTIME } +}; +static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) +{ + struct timespec start, to, end; + futex_t futex = FUTEX_INITIALIZER; + u_int32_t bitset = 0xffffffff; + int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0; + + tst_res(TINFO, "testing futex_wait_bitset() timeout with %s", + clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"); + + clock_gettime(clk_id, &start); + to = tst_timespec_add_us(start, wait_us); + + TEST(futex_wait_bitset(&futex, futex, &to, bitset, flags)); + + clock_gettime(clk_id, &end); + + if (TST_RET != -1) { + tst_res(TFAIL, "futex_wait_bitset() returned %li, expected -1", + TST_RET); + return; + } + + if (TST_ERR == ENOSYS) { + tst_res(TCONF, + "In this kernel, futex() does not support FUTEX_WAIT_BITSET operation"); + return; + } + + if (TST_ERR != ETIMEDOUT) { + tst_res(TFAIL | TTERRNO, "expected %s", + tst_strerrno(ETIMEDOUT)); + return; + } + + if (tst_timespec_lt(end, to)) { + tst_res(TFAIL, + "futex_wait_bitset() woken up prematurely %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); + return; + } + + if (tst_timespec_diff_us(end, to) > THRESHOLD_US) { + tst_res(TFAIL, + "futex_wait_bitset() waited too long %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); + return; + } + + tst_res(TPASS, "futex_wait_bitset() waited %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); +} + +static void run(unsigned int n) +{ + tst_timer_check(tcases[n].clk_id); + verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, tcases[n].clk_id); +} + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tcases), +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset02.c b/testcases/kernel/syscalls/futex/futex_wait_bitset02.c deleted file mode 100644 index 4d532fc07775..000000000000 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset02.c +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2015 Cyril Hrubis - * - * 1. Block on a bitset futex and wait for timeout, the difference between - * normal futex and bitset futex is that that the later have absolute timeout. - * 2. Check that the futex waited for expected time. - */ - -#include - -#include "tst_test.h" -#include "tst_timer.h" -#include "futextest.h" - -#define USE_CLOCK CLOCK_REALTIME - -#include "futex_wait_bitset.h" From patchwork Fri Jun 26 06:22:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317399 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=aNK/MzyG; 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 49tRfv0zRxz9sRR for ; Fri, 26 Jun 2020 16:24:07 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 999DB3C5839 for ; Fri, 26 Jun 2020 08:24:04 +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 B5DF83C584B for ; Fri, 26 Jun 2020 08:23:02 +0200 (CEST) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 E8F741401194 for ; Fri, 26 Jun 2020 08:22:59 +0200 (CEST) Received: by mail-pg1-x543.google.com with SMTP id z5so4520285pgb.6 for ; Thu, 25 Jun 2020 23:22: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=8QRsGWElYki4V9st6UhXV++4e47GRg3W5s1soqADkf0=; b=aNK/MzyGz5vT0nbSmPwpIQJMR5sZlOLl4NlDsssozgDjq+rSkuli+3KXAehQwXHW+P eoezgHTcBQ5W8ON4dv9wXAkyPOU+G1JUPOMP61+OSw40jhE2vTh+HbRApGR7DMdn6Gva MbSV5kpk5QKDGIi3IIHmUIW4xHzeTDtSJUEgOZdzMZwdxDgzleZbF3kA4x//ujwdDsZQ 7EvpJFOS9A4U8ADxnJWhozBfdv1jmU1egct3e279pIVCmWQMNMS03LvDHR8cUsruzGHH yuIlM1e8uwXP5YF6exukrlIoB7Cj3Nw9t+UH+kkBNN8aqIIeR4v/GutAP3cU8wD6VYvB 3qOw== 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=8QRsGWElYki4V9st6UhXV++4e47GRg3W5s1soqADkf0=; b=pvISzqbaE9VjJBPkjq3wjO1BaK03iT1GHPiBDLhUX9Q56JXeHepT3b1OYbkbBFxZXc s8w94Jm78mKBTrWuiV3mGrt+XwRm1PXZ5hno/sxyUuDURrjEKQ37qa5Zeh/PyyVpPJDR HeDWvjDnhBGThOa/eNJWC4Hsnt2LHTsfUolsSmeDwFjuToSlsgRe7XRddKcbNOQo07gh ZlALNxDTQS7Wqharzf6VlAfqOEnSmWmb9ikx9iBcwBYNCjyj8zBYBEJ+lcev+Xbt3pQF LWdlRvYvLquYdvKhKQBoBQZ78ciaEC0ZA0XJP0ziY8L+JTvke8yHBD3srHmfz2vxguer H52g== X-Gm-Message-State: AOAM530ohvGHKqv50t+F1CxuyUlVlUVXKnLMFc+R96eXYgMV+rLdDPhF iPsB2iBkkkFaYXDx7Xh4W36zd2rxdkw= X-Google-Smtp-Source: ABdhPJygwPyIEqNtn3riiT6Bhy0yz0BU25V++JiuJNjpCnSCPo/xwY6sndVRxtsW2svLFiPMYoZPrQ== X-Received: by 2002:a63:195a:: with SMTP id 26mr1263653pgz.402.1593152577067; Thu, 25 Jun 2020 23:22:57 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id h15sm22525344pgl.12.2020.06.25.23.22.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:56 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:20 +0530 Message-Id: <6030fa8c1deda3aab977c7d5745c117fda87708a.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 07/19] syscalls/futex: 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 futex() syscall tests. Signed-off-by: Viresh Kumar Reviewed-by: Petr Vorel Signed-off-by: Viresh Kumar --- .../syscalls/futex/futex_cmp_requeue01.c | 34 +++- .../syscalls/futex/futex_cmp_requeue02.c | 24 ++- testcases/kernel/syscalls/futex/futex_utils.h | 52 +++++-- .../kernel/syscalls/futex/futex_wait01.c | 79 +++++----- .../kernel/syscalls/futex/futex_wait02.c | 102 ++++++------ .../kernel/syscalls/futex/futex_wait03.c | 87 ++++++----- .../kernel/syscalls/futex/futex_wait04.c | 81 +++++----- .../kernel/syscalls/futex/futex_wait05.c | 2 +- .../syscalls/futex/futex_wait_bitset01.c | 48 ++++-- .../kernel/syscalls/futex/futex_wake01.c | 67 ++++---- .../kernel/syscalls/futex/futex_wake02.c | 95 ++++++------ .../kernel/syscalls/futex/futex_wake03.c | 109 +++++++------ .../kernel/syscalls/futex/futex_wake04.c | 145 +++++++++--------- testcases/kernel/syscalls/futex/futextest.h | 122 ++++++++++----- 14 files changed, 580 insertions(+), 467 deletions(-) diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c index c50fade9f969..537641766357 100644 --- a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c @@ -42,14 +42,29 @@ static struct tcase { {1000, 300, 500}, }; +static struct test_variants { + enum futex_fn_type fntype; + enum tst_ts_type tstype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void do_child(void) { + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts usec = tst_ts_from_ms(tv->tstype, max_sleep_ms); int slept_for_ms = 0; - struct timespec usec = tst_timespec_from_ms(max_sleep_ms); int pid = getpid(); int ret = 0; - if (futex_wait(&sd->futexes[0], sd->futexes[0], &usec, 0) == -1) { + if (futex_wait(tv->fntype, &sd->futexes[0], sd->futexes[0], &usec, 0) == -1) { if (errno == EAGAIN) { /* spurious wakeup or signal */ tst_atomic_inc(&sd->spurious); @@ -72,6 +87,7 @@ static void do_child(void) static void verify_futex_cmp_requeue(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; int num_requeues = 0, num_waits = 0, num_total = 0; int i, status, spurious, woken_up; struct tcase *tc = &tcases[n]; @@ -104,8 +120,8 @@ static void verify_futex_cmp_requeue(unsigned int n) * specifies an upper limit on the number of waiters that are requeued. * Returns the total number of waiters that were woken up or requeued. */ - TEST(futex_cmp_requeue(&sd->futexes[0], sd->futexes[0], &sd->futexes[1], - tc->set_wakes, tc->set_requeues, 0)); + TEST(futex_cmp_requeue(tv->fntype, &sd->futexes[0], sd->futexes[0], + &sd->futexes[1], tc->set_wakes, tc->set_requeues, 0)); /* Fail if more than requested wakes + requeues were returned */ if (TST_RET > exp_ret) { @@ -115,8 +131,8 @@ static void verify_futex_cmp_requeue(unsigned int n) tst_res(TINFO, "futex_cmp_requeue() returned %ld", TST_RET); } - num_requeues = futex_wake(&sd->futexes[1], tc->num_waiters, 0); - num_waits = futex_wake(&sd->futexes[0], tc->num_waiters, 0); + num_requeues = futex_wake(tv->fntype, &sd->futexes[1], tc->num_waiters, 0); + num_waits = futex_wake(tv->fntype, &sd->futexes[0], tc->num_waiters, 0); tst_atomic_store(1, &sd->test_done); for (i = 0; i < tc->num_waiters; i++) { @@ -178,6 +194,11 @@ static void verify_futex_cmp_requeue(unsigned int n) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); + max_sleep_ms = tst_multiply_timeout(5000); sd = SAFE_MMAP(NULL, sizeof(*sd), PROT_READ | PROT_WRITE, @@ -198,5 +219,6 @@ static struct tst_test test = { .cleanup = cleanup, .tcnt = ARRAY_SIZE(tcases), .test = verify_futex_cmp_requeue, + .test_variants = ARRAY_SIZE(variants), .forks_child = 1, }; diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c index 228d8cff6ea0..dd8fafb3ee38 100644 --- a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c +++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c @@ -32,12 +32,26 @@ static struct tcase { {1, 1, FUTEX_INITIALIZER + 1, EAGAIN}, }; +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void verify_futex_cmp_requeue(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; struct tcase *tc = &tcases[n]; - TEST(futex_cmp_requeue(&futexes[0], tc->exp_val, &futexes[1], - tc->set_wakes, tc->set_requeues, 0)); + TEST(futex_cmp_requeue(tv->fntype, &futexes[0], tc->exp_val, + &futexes[1], tc->set_wakes, tc->set_requeues, 0)); if (TST_RET != -1) { tst_res(TFAIL, "futex_cmp_requeue() succeeded unexpectedly"); return; @@ -55,6 +69,11 @@ static void verify_futex_cmp_requeue(unsigned int n) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); + futexes = SAFE_MMAP(NULL, sizeof(futex_t) * 2, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); @@ -73,6 +92,7 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_futex_cmp_requeue, .tcnt = ARRAY_SIZE(tcases), + .test_variants = ARRAY_SIZE(variants), .tags = (const struct tst_tag[]) { {"CVE", "2018-6927"}, {"linux-git", "fbe0e839d1e2"}, diff --git a/testcases/kernel/syscalls/futex/futex_utils.h b/testcases/kernel/syscalls/futex/futex_utils.h index 63b97c00b631..f77b9d6b3b8a 100644 --- a/testcases/kernel/syscalls/futex/futex_utils.h +++ b/testcases/kernel/syscalls/futex/futex_utils.h @@ -20,10 +20,13 @@ #ifndef FUTEX_UTILS_H__ #define FUTEX_UTILS_H__ +#include +#include + /* * Wait for nr_threads to be sleeping */ -static int wait_for_threads(unsigned int nr_threads) +static inline int wait_for_threads(unsigned int nr_threads) { char thread_state, name[1024]; DIR *dir; @@ -32,34 +35,63 @@ static int wait_for_threads(unsigned int nr_threads) snprintf(name, sizeof(name), "/proc/%i/task/", getpid()); - dir = SAFE_OPENDIR(NULL, name); + dir = SAFE_OPENDIR(name); - while ((dent = SAFE_READDIR(NULL, dir))) { + while ((dent = SAFE_READDIR(dir))) { /* skip ".", ".." and the main thread */ if (atoi(dent->d_name) == getpid() || atoi(dent->d_name) == 0) continue; snprintf(name, sizeof(name), "/proc/%i/task/%s/stat", - getpid(), dent->d_name); + getpid(), dent->d_name); - SAFE_FILE_SCANF(NULL, name, "%*i %*s %c", &thread_state); + SAFE_FILE_SCANF(name, "%*i %*s %c", &thread_state); if (thread_state != 'S') { - tst_resm(TINFO, "Thread %s not sleeping yet", dent->d_name); - SAFE_CLOSEDIR(NULL, dir); + tst_res(TINFO, "Thread %s not sleeping yet", dent->d_name); + SAFE_CLOSEDIR(dir); return 1; } cnt++; } - SAFE_CLOSEDIR(NULL, dir); + SAFE_CLOSEDIR(dir); if (cnt != nr_threads) { - tst_resm(TINFO, "%u threads sleeping, expected %u", - cnt, nr_threads); + tst_res(TINFO, "%u threads sleeping, expected %u", cnt, + nr_threads); } return 0; } +static inline int process_state_wait2(pid_t pid, const char state) +{ + char proc_path[128], cur_state; + + snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid); + + for (;;) { + FILE *f = fopen(proc_path, "r"); + if (!f) { + tst_res(TFAIL, "Failed to open '%s': %s\n", proc_path, + strerror(errno)); + return 1; + } + + if (fscanf(f, "%*i %*s %c", &cur_state) != 1) { + fclose(f); + tst_res(TFAIL, "Failed to read '%s': %s\n", proc_path, + strerror(errno)); + return 1; + } + fclose(f); + + if (state == cur_state) + return 0; + + usleep(10000); + } +} + #endif /* FUTEX_UTILS_H__ */ diff --git a/testcases/kernel/syscalls/futex/futex_wait01.c b/testcases/kernel/syscalls/futex/futex_wait01.c index 51a540d9e315..e884e696ef55 100644 --- a/testcases/kernel/syscalls/futex/futex_wait01.c +++ b/testcases/kernel/syscalls/futex/futex_wait01.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * @@ -5,34 +6,15 @@ * written by Darren Hart * Gowrishankar * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 1. Block on a futex and wait for timeout. + * 2. Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs + * from the expected one. */ - /* - * 1. Block on a futex and wait for timeout. - * 2. Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs - * from the expected one. - */ #include -#include "test.h" #include "futextest.h" -const char *TCID="futex_wait01"; - struct testcase { futex_t *f_addr; futex_t f_val; @@ -41,7 +23,6 @@ struct testcase { }; static futex_t futex = FUTEX_INITIALIZER; -static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000}; static struct testcase testcases[] = { {&futex, FUTEX_INITIALIZER, 0, ETIMEDOUT}, @@ -50,38 +31,58 @@ static struct testcase testcases[] = { {&futex, FUTEX_INITIALIZER+1, FUTEX_PRIVATE_FLAG, EWOULDBLOCK}, }; -const int TST_TOTAL=ARRAY_SIZE(testcases); +static struct test_variants { + enum futex_fn_type fntype; + enum tst_ts_type tstype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; -static void verify_futex_wait(struct testcase *tc) +static void run(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; + struct testcase *tc = &testcases[n]; + static struct tst_ts to; int res; - res = futex_wait(tc->f_addr, tc->f_val, &to, tc->opflags); + to.type = tv->tstype; + tst_ts_set_sec(&to, 0); + tst_ts_set_nsec(&to, 10000); + + res = futex_wait(tv->fntype, tc->f_addr, tc->f_val, &to, tc->opflags); if (res != -1) { - tst_resm(TFAIL, "futex_wait() returned %i, expected -1", res); + tst_res(TFAIL, "futex_wait() succeeded unexpectedly"); return; } if (errno != tc->exp_errno) { - tst_resm(TFAIL | TERRNO, "expected errno=%s", + tst_res(TFAIL | TTERRNO, "futex_wait() failed with incorrect error, expected errno=%s", tst_strerrno(tc->exp_errno)); return; } - tst_resm(TPASS | TERRNO, "futex_wait()"); + tst_res(TPASS | TERRNO, "futex_wait() passed"); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc, i; + struct test_variants *tv = &variants[tst_variant]; - tst_parse_opts(argc, argv, NULL, NULL); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - for (i = 0; i < TST_TOTAL; i++) - verify_futex_wait(testcases + i); - } - - tst_exit(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); } + +static struct tst_test test = { + .setup = setup, + .test = run, + .tcnt = ARRAY_SIZE(testcases), + .test_variants = ARRAY_SIZE(variants), +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait02.c b/testcases/kernel/syscalls/futex/futex_wait02.c index 1ca1df457b4a..34b78357f6e6 100644 --- a/testcases/kernel/syscalls/futex/futex_wait02.c +++ b/testcases/kernel/syscalls/futex/futex_wait02.c @@ -1,105 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Block on a futex and wait for wakeup. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This tests uses shared memory page to store the mutex variable. */ - /* - * Block on a futex and wait for wakeup. - * - * This tests uses shared memory page to store the mutex variable. - */ #include #include #include -#include "test.h" -#include "safe_macros.h" #include "futextest.h" - -const char *TCID="futex_wait02"; -const int TST_TOTAL=1; +#include "futex_utils.h" static futex_t *futex; +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void do_child(void) { + struct test_variants *tv = &variants[tst_variant]; int ret; - tst_process_state_wait2(getppid(), 'S'); + process_state_wait2(getppid(), 'S'); - ret = futex_wake(futex, 1, 0); + ret = futex_wake(tv->fntype, futex, 1, 0); if (ret != 1) - tst_brkm(TFAIL, NULL, "futex_wake() returned %i", ret); + tst_res(TFAIL | TTERRNO, "futex_wake() failed"); - exit(TPASS); + exit(0); } -static void verify_futex_wait(void) +static void run(void) { - int res; - int pid; + struct test_variants *tv = &variants[tst_variant]; + int res, pid; - pid = tst_fork(); + pid = SAFE_FORK(); switch (pid) { case 0: do_child(); - break; - case -1: - tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); - break; default: - break; + break; } - res = futex_wait(futex, *futex, NULL, 0); - + res = futex_wait(tv->fntype, futex, *futex, NULL, 0); if (res) { - tst_resm(TFAIL, "futex_wait() returned %i, errno %s", - res, tst_strerrno(errno)); + tst_res(TFAIL | TTERRNO, "futex_wait() failed"); + return; } - SAFE_WAIT(NULL, &res); + SAFE_WAIT(&res); if (WIFEXITED(res) && WEXITSTATUS(res) == TPASS) - tst_resm(TPASS, "futex_wait() woken up"); + tst_res(TPASS, "futex_wait() woken up"); else - tst_resm(TFAIL, "child failed"); + tst_res(TFAIL, "child failed"); } static void setup(void) { - futex = SAFE_MMAP(NULL, NULL, sizeof(*futex), PROT_READ | PROT_WRITE, + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); + + futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); *futex = FUTEX_INITIALIZER; } -int main(int argc, char *argv[]) -{ - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wait(); - - tst_exit(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .forks_child = 1, +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait03.c b/testcases/kernel/syscalls/futex/futex_wait03.c index 9683e76503c0..e436b238a165 100644 --- a/testcases/kernel/syscalls/futex/futex_wait03.c +++ b/testcases/kernel/syscalls/futex/futex_wait03.c @@ -1,87 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Block on a futex and wait for wakeup. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This tests uses private mutexes with threads. */ - /* - * Block on a futex and wait for wakeup. - * - * This tests uses private mutexes with threads. - */ #include #include -#include "test.h" #include "futextest.h" - -const char *TCID="futex_wait03"; -const int TST_TOTAL=1; +#include "futex_utils.h" static futex_t futex = FUTEX_INITIALIZER; +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void *threaded(void *arg LTP_ATTRIBUTE_UNUSED) { + struct test_variants *tv = &variants[tst_variant]; long ret; - tst_process_state_wait2(getpid(), 'S'); + process_state_wait2(getpid(), 'S'); - ret = futex_wake(&futex, 1, FUTEX_PRIVATE_FLAG); + ret = futex_wake(tv->fntype, &futex, 1, FUTEX_PRIVATE_FLAG); return (void*)ret; } -static void verify_futex_wait(void) +static void run(void) { - long ret; - int res; + struct test_variants *tv = &variants[tst_variant]; + long ret, res; pthread_t t; res = pthread_create(&t, NULL, threaded, NULL); if (res) { - tst_brkm(TBROK, NULL, "pthread_create(): %s", - tst_strerrno(res)); + tst_res(TFAIL | TTERRNO, "pthread_create() failed"); + return; } - res = futex_wait(&futex, futex, NULL, FUTEX_PRIVATE_FLAG); + res = futex_wait(tv->fntype, &futex, futex, NULL, FUTEX_PRIVATE_FLAG); if (res) { - tst_resm(TFAIL, "futex_wait() returned %i, errno %s", - res, tst_strerrno(errno)); + tst_res(TFAIL | TTERRNO, "futex_wait() failed"); pthread_join(t, NULL); return; } res = pthread_join(t, (void*)&ret); - if (res) - tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res)); + if (res) { + tst_res(TFAIL | TTERRNO, "pthread_join() failed"); + return; + } if (ret != 1) - tst_resm(TFAIL, "futex_wake() returned %li", ret); + tst_res(TFAIL, "futex_wake() returned %li", ret); else - tst_resm(TPASS, "futex_wait() woken up"); + tst_res(TPASS, "futex_wait() woken up"); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; + struct test_variants *tv = &variants[tst_variant]; - tst_parse_opts(argc, argv, NULL, NULL); - - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wait(); - - tst_exit(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); } + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait04.c b/testcases/kernel/syscalls/futex/futex_wait04.c index b8360ff80914..8de3c90b08d3 100644 --- a/testcases/kernel/syscalls/futex/futex_wait04.c +++ b/testcases/kernel/syscalls/futex/futex_wait04.c @@ -1,65 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * * Based on futextest (futext_wait_uninitialized_heap.c) * written by KOSAKI Motohiro * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Wait on uninitialized heap. It shold be zero and FUTEX_WAIT should return + * immediately. This test tests zero page handling in futex code. */ - /* - * Wait on uninitialized heap. It shold be zero and FUTEX_WAIT should return - * immediately. This test tests zero page handling in futex code. - */ #include -#include "test.h" -#include "safe_macros.h" #include "futextest.h" -const char *TCID="futex_wait04"; -const int TST_TOTAL=1; -static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000}; +static struct test_variants { + enum futex_fn_type fntype; + enum tst_ts_type tstype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; -static void verify_futex_wait(void) +static void run(void) { - int res; - void *buf; + struct test_variants *tv = &variants[tst_variant]; + static struct tst_ts to; size_t pagesize = getpagesize(); - buf = SAFE_MMAP(NULL, NULL, pagesize, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); + void *buf; + int res; + + buf = SAFE_MMAP(NULL, pagesize, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - res = futex_wait(buf, 1, &to, 0); + to.type = tv->tstype; + tst_ts_set_sec(&to, 0); + tst_ts_set_nsec(&to, 10000); + res = futex_wait(tv->fntype, buf, 1, &to, 0); if (res == -1 && errno == EWOULDBLOCK) - tst_resm(TPASS | TERRNO, "futex_wait() returned %i", res); + tst_res(TPASS | TERRNO, "futex_wait() returned %i", res); else - tst_resm(TFAIL | TERRNO, "futex_wait() returned %i", res); + tst_res(TFAIL | TERRNO, "futex_wait() returned %i", res); - SAFE_MUNMAP(NULL, buf, pagesize); + SAFE_MUNMAP(buf, pagesize); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); + struct test_variants *tv = &variants[tst_variant]; - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wait(); - - tst_exit(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); } + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait05.c b/testcases/kernel/syscalls/futex/futex_wait05.c index 2573ae177d5b..8fad5d858716 100644 --- a/testcases/kernel/syscalls/futex/futex_wait05.c +++ b/testcases/kernel/syscalls/futex/futex_wait05.c @@ -19,7 +19,7 @@ int sample_fn(int clk_id, long long usec) futex_t futex = FUTEX_INITIALIZER; tst_timer_start(clk_id); - TEST(futex_wait(&futex, futex, &to, 0)); + TEST(syscall(SYS_futex, &futex, FUTEX_WAIT, futex, &to, NULL, 0)); tst_timer_stop(); tst_timer_sample(); diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c index b8546c3e640c..a871af992572 100644 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c +++ b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c @@ -23,22 +23,40 @@ static struct test_case_t { { CLOCK_REALTIME } }; +static struct test_variants { + enum futex_fn_type fntype; + enum tst_ts_type tstype; + int (*gettime)(clockid_t clk_id, void *ts); + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .gettime = sys_clock_gettime, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .gettime = sys_clock_gettime64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) { - struct timespec start, to, end; + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts start, to, end; futex_t futex = FUTEX_INITIALIZER; u_int32_t bitset = 0xffffffff; int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0; + start.type = end.type = to.type = tv->tstype; + tst_res(TINFO, "testing futex_wait_bitset() timeout with %s", clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"); - clock_gettime(clk_id, &start); - to = tst_timespec_add_us(start, wait_us); + tv->gettime(clk_id, tst_ts_get(&start)); + to = tst_ts_add_us(start, wait_us); - TEST(futex_wait_bitset(&futex, futex, &to, bitset, flags)); + TEST(futex_wait_bitset(tv->fntype, &futex, futex, &to, bitset, flags)); - clock_gettime(clk_id, &end); + tv->gettime(clk_id, tst_ts_get(&end)); if (TST_RET != -1) { tst_res(TFAIL, "futex_wait_bitset() returned %li, expected -1", @@ -58,22 +76,22 @@ static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) return; } - if (tst_timespec_lt(end, to)) { + if (tst_ts_lt(end, to)) { tst_res(TFAIL, "futex_wait_bitset() woken up prematurely %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_ts_diff_us(end, start), wait_us); return; } - if (tst_timespec_diff_us(end, to) > THRESHOLD_US) { + if (tst_ts_diff_us(end, to) > THRESHOLD_US) { tst_res(TFAIL, "futex_wait_bitset() waited too long %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_ts_diff_us(end, start), wait_us); return; } tst_res(TPASS, "futex_wait_bitset() waited %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_ts_diff_us(end, start), wait_us); } static void run(unsigned int n) @@ -82,7 +100,17 @@ static void run(unsigned int n) verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, tcases[n].clk_id); } +static void setup(void) +{ + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); +} + static struct tst_test test = { + .setup = setup, .test = run, .tcnt = ARRAY_SIZE(tcases), + .test_variants = ARRAY_SIZE(variants), }; diff --git a/testcases/kernel/syscalls/futex/futex_wake01.c b/testcases/kernel/syscalls/futex/futex_wake01.c index 42ea6f6e6a75..2dbe8cc2f3aa 100644 --- a/testcases/kernel/syscalls/futex/futex_wake01.c +++ b/testcases/kernel/syscalls/futex/futex_wake01.c @@ -1,33 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * futex_wake() returns 0 (0 woken up processes) when no processes wait on the mutex. */ - /* - * futex_wake() returns 0 (0 woken up processes) when no processes wait on the mutex. - */ #include #include -#include "test.h" #include "futextest.h" -const char *TCID="futex_wake01"; - struct testcase { futex_t *f_addr; int nr_wake; @@ -46,32 +28,45 @@ static struct testcase testcases[] = { {&futex, INT_MAX, FUTEX_PRIVATE_FLAG}, }; -const int TST_TOTAL=ARRAY_SIZE(testcases); +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif -static void verify_futex_wake(struct testcase *tc) +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +static void run(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; + struct testcase *tc = &testcases[n]; int res; - res = futex_wake(tc->f_addr, tc->nr_wake, tc->opflags); - + res = futex_wake(tv->fntype, tc->f_addr, tc->nr_wake, tc->opflags); if (res != 0) { - tst_resm(TFAIL, "futex_wake() returned %i, expected 0", res); + tst_res(TFAIL | TTERRNO, "futex_wake() failed"); return; } - tst_resm(TPASS, "futex_wake() returned 0"); + tst_res(TPASS, "futex_wake() passed"); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc, i; + struct test_variants *tv = &variants[tst_variant]; - tst_parse_opts(argc, argv, NULL, NULL); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - for (i = 0; i < TST_TOTAL; i++) - verify_futex_wake(testcases + i); - } - - tst_exit(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); } + +static struct tst_test test = { + .setup = setup, + .test = run, + .tcnt = ARRAY_SIZE(testcases), + .test_variants = ARRAY_SIZE(variants), +}; diff --git a/testcases/kernel/syscalls/futex/futex_wake02.c b/testcases/kernel/syscalls/futex/futex_wake02.c index 8a4c2d58e4b9..3491839872ac 100644 --- a/testcases/kernel/syscalls/futex/futex_wake02.c +++ b/testcases/kernel/syscalls/futex/futex_wake02.c @@ -1,40 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Block several threads on a private mutex, then wake them up. */ - /* - * Block several threads on a private mutex, then wake them up. - */ #include #include +#include -#include "test.h" -#include "safe_macros.h" #include "futextest.h" #include "futex_utils.h" -const char *TCID="futex_wake02"; -const int TST_TOTAL=11; - static futex_t futex = FUTEX_INITIALIZER; static volatile int threads_flags[55]; +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static int threads_awake(void) { int ret = 0; @@ -58,9 +52,10 @@ static void clear_threads_awake(void) static void *threaded(void *arg) { + struct test_variants *tv = &variants[tst_variant]; long i = (long)arg; - futex_wait(&futex, futex, NULL, FUTEX_PRIVATE_FLAG); + futex_wait(tv->fntype, &futex, futex, NULL, FUTEX_PRIVATE_FLAG); threads_flags[i] = 1; @@ -69,14 +64,15 @@ static void *threaded(void *arg) static void do_child(void) { + struct test_variants *tv = &variants[tst_variant]; int res, i, j, awake; pthread_t t[55]; for (i = 0; i < (int)ARRAY_SIZE(t); i++) { res = pthread_create(&t[i], NULL, threaded, (void*)((long)i)); if (res) { - tst_brkm(TBROK, NULL, "pthread_create(): %s", - tst_strerrno(res)); + tst_res(TFAIL | TTERRNO, "pthread_create() failed"); + return; } } @@ -85,9 +81,9 @@ static void do_child(void) for (i = 1; i <= 10; i++) { clear_threads_awake(); - res = futex_wake(&futex, i, FUTEX_PRIVATE_FLAG); + res = futex_wake(tv->fntype, &futex, i, FUTEX_PRIVATE_FLAG); if (i != res) { - tst_resm(TFAIL, + tst_res(TFAIL | TTERRNO, "futex_wake() woken up %i threads, expected %i", res, i); } @@ -101,26 +97,26 @@ static void do_child(void) } if (awake == i) { - tst_resm(TPASS, "futex_wake() woken up %i threads", i); + tst_res(TPASS, "futex_wake() woken up %i threads", i); } else { - tst_resm(TFAIL, "Woken up %i threads, expected %i", - awake, i); + tst_res(TFAIL | TTERRNO, "Woken up %i threads, expected %i", + awake, i); } } - res = futex_wake(&futex, 1, FUTEX_PRIVATE_FLAG); + res = futex_wake(tv->fntype, &futex, 1, FUTEX_PRIVATE_FLAG); if (res) { - tst_resm(TFAIL, "futex_wake() woken up %i, none were waiting", - res); + tst_res(TFAIL | TTERRNO, "futex_wake() woken up %i, none were waiting", + res); } else { - tst_resm(TPASS, "futex_wake() woken up 0 threads"); + tst_res(TPASS, "futex_wake() woken up 0 threads"); } for (i = 0; i < (int)ARRAY_SIZE(t); i++) pthread_join(t[i], NULL); - tst_exit(); + exit(0); } /* @@ -135,30 +131,31 @@ static void do_child(void) * under /proc/$PID/tasks/, but the subsequent open() fails with ENOENT because * the thread was removed meanwhile. */ -static void verify_futex_wake(void) +static void run(void) { - int pid; + int status, pid; - pid = tst_fork(); + pid = SAFE_FORK(); switch (pid) { case 0: do_child(); - case -1: - tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); default: - tst_record_childstatus(NULL, pid); + SAFE_WAITPID(pid, &status, 0); } } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); + struct test_variants *tv = &variants[tst_variant]; - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wake(); - - tst_exit(); + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); } + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .forks_child = 1, +}; diff --git a/testcases/kernel/syscalls/futex/futex_wake03.c b/testcases/kernel/syscalls/futex/futex_wake03.c index d6e5e5422db9..29e586c40132 100644 --- a/testcases/kernel/syscalls/futex/futex_wake03.c +++ b/testcases/kernel/syscalls/futex/futex_wake03.c @@ -1,54 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Cyril Hrubis * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Block several processes on a mutex, then wake them up. */ - /* - * Block several processes on a mutex, then wake them up. - */ #include #include #include -#include "test.h" -#include "safe_macros.h" #include "futextest.h" - -const char *TCID="futex_wake03"; -const int TST_TOTAL=11; +#include "futex_utils.h" static futex_t *futex; +static struct test_variants { + enum futex_fn_type fntype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void do_child(void) { - futex_wait(futex, *futex, NULL, 0); + struct test_variants *tv = &variants[tst_variant]; + + futex_wait(tv->fntype, futex, *futex, NULL, 0); exit(0); } static void do_wake(int nr_children) { + struct test_variants *tv = &variants[tst_variant]; int res, i, cnt; - res = futex_wake(futex, nr_children, 0); + res = futex_wake(tv->fntype, futex, nr_children, 0); if (res != nr_children) { - tst_resm(TFAIL, - "futex_wake() woken up %i children, expected %i", - res, nr_children); + tst_res(TFAIL | TTERRNO, + "futex_wake() woken up %i children, expected %i", + res, nr_children); return; } @@ -63,65 +60,63 @@ static void do_wake(int nr_children) } if (cnt != nr_children) { - tst_resm(TFAIL, "reaped only %i childs, expected %i", - cnt, nr_children); + tst_res(TFAIL | TTERRNO, "reaped only %i childs, expected %i", + cnt, nr_children); } else { - tst_resm(TPASS, "futex_wake() woken up %i childs", cnt); + tst_res(TPASS, "futex_wake() woken up %i childs", cnt); } } -static void verify_futex_wake(void) +static void run(void) { - int i, res; + struct test_variants *tv = &variants[tst_variant]; pid_t pids[55]; + unsigned int i; + int res; - for (i = 0; i < (int)ARRAY_SIZE(pids); i++) { - pids[i] = tst_fork(); + for (i = 0; i < ARRAY_SIZE(pids); i++) { + pids[i] = SAFE_FORK(); switch (pids[i]) { - case -1: - tst_brkm(TBROK | TERRNO, NULL, "fork()"); case 0: do_child(); default: - break; + break; } } - for (i = 0; i < (int)ARRAY_SIZE(pids); i++) - tst_process_state_wait2(pids[i], 'S'); + for (i = 0; i < ARRAY_SIZE(pids); i++) + process_state_wait2(pids[i], 'S'); for (i = 1; i <= 10; i++) do_wake(i); - res = futex_wake(futex, 1, 0); + res = futex_wake(tv->fntype, futex, 1, 0); if (res) { - tst_resm(TFAIL, "futex_wake() woken up %u, none were waiting", - res); + tst_res(TFAIL | TTERRNO, "futex_wake() woken up %u, none were waiting", + res); } else { - tst_resm(TPASS, "futex_wake() woken up 0 children"); + tst_res(TPASS, "futex_wake() woken up 0 children"); } } static void setup(void) { - futex = SAFE_MMAP(NULL, NULL, sizeof(*futex), PROT_READ | PROT_WRITE, + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); + + futex = SAFE_MMAP(NULL, sizeof(*futex), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); *futex = FUTEX_INITIALIZER; } -int main(int argc, char *argv[]) -{ - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wake(); - - tst_exit(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .forks_child = 1, +}; diff --git a/testcases/kernel/syscalls/futex/futex_wake04.c b/testcases/kernel/syscalls/futex/futex_wake04.c index f92bda53f6c7..582ebc4b917a 100644 --- a/testcases/kernel/syscalls/futex/futex_wake04.c +++ b/testcases/kernel/syscalls/futex/futex_wake04.c @@ -1,23 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Yi Zhang * Li Wang * - * Licensed under the GNU GPLv2 or later. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - /* DESCRIPTION: + * DESCRIPTION: * * It is a regression test for commit: * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/ @@ -42,53 +28,59 @@ #include #include -#include "test.h" -#include "safe_macros.h" #include "futextest.h" #include "futex_utils.h" #include "lapi/mmap.h" +#include "tst_safe_stdio.h" #define PATH_MEMINFO "/proc/meminfo" #define PATH_NR_HUGEPAGES "/proc/sys/vm/nr_hugepages" #define PATH_HUGEPAGES "/sys/kernel/mm/hugepages/" -const char *TCID = "futex_wake04"; -const int TST_TOTAL = 1; - static futex_t *futex1, *futex2; -static struct timespec to = {.tv_sec = 30, .tv_nsec = 0}; +static struct tst_ts to; static long orig_hugepages; +static struct test_variants { + enum futex_fn_type fntype; + enum tst_ts_type tstype; + char *desc; +} variants[] = { +#if (__NR_futex != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX, .tstype = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL) + { .fntype = FUTEX_FN_FUTEX64, .tstype = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void setup(void) { - tst_require_root(); + struct test_variants *tv = &variants[tst_variant]; - if ((tst_kvercmp(2, 6, 32)) < 0) { - tst_brkm(TCONF, NULL, "This test can only run on kernels " - "that are 2.6.32 or higher"); - } + tst_res(TINFO, "Testing variant: %s", tv->desc); + futex_supported_by_kernel(tv->fntype); - if (access(PATH_HUGEPAGES, F_OK)) - tst_brkm(TCONF, NULL, "Huge page is not supported."); + to.type = tv->tstype; + tst_ts_set_sec(&to, 30); + tst_ts_set_nsec(&to, 0); - tst_tmpdir(); + if (access(PATH_HUGEPAGES, F_OK)) + tst_brk(TCONF, "Huge page is not supported."); - SAFE_FILE_SCANF(NULL, PATH_NR_HUGEPAGES, "%ld", &orig_hugepages); + SAFE_FILE_SCANF(PATH_NR_HUGEPAGES, "%ld", &orig_hugepages); if (orig_hugepages <= 0) - SAFE_FILE_PRINTF(NULL, PATH_NR_HUGEPAGES, "%d", 1); - - TEST_PAUSE; + SAFE_FILE_PRINTF(PATH_NR_HUGEPAGES, "%d", 1); } static void cleanup(void) { if (orig_hugepages <= 0) - SAFE_FILE_PRINTF(NULL, PATH_NR_HUGEPAGES, "%ld", orig_hugepages); - - tst_rmdir(); + SAFE_FILE_PRINTF(PATH_NR_HUGEPAGES, "%ld", orig_hugepages); } static int read_hugepagesize(void) @@ -97,60 +89,63 @@ static int read_hugepagesize(void) char line[BUFSIZ], buf[BUFSIZ]; int val; - fp = SAFE_FOPEN(cleanup, PATH_MEMINFO, "r"); + fp = SAFE_FOPEN(PATH_MEMINFO, "r"); while (fgets(line, BUFSIZ, fp) != NULL) { if (sscanf(line, "%64s %d", buf, &val) == 2) if (strcmp(buf, "Hugepagesize:") == 0) { - SAFE_FCLOSE(cleanup, fp); + SAFE_FCLOSE(fp); return 1024 * val; } } - SAFE_FCLOSE(cleanup, fp); - tst_brkm(TBROK, NULL, "can't find \"%s\" in %s", - "Hugepagesize:", PATH_MEMINFO); + SAFE_FCLOSE(fp); + tst_res(TFAIL, "can't find \"%s\" in %s", "Hugepagesize:", + PATH_MEMINFO); + return 0; } static void *wait_thread1(void *arg LTP_ATTRIBUTE_UNUSED) { - futex_wait(futex1, *futex1, &to, 0); + struct test_variants *tv = &variants[tst_variant]; + + futex_wait(tv->fntype, futex1, *futex1, &to, 0); return NULL; } static void *wait_thread2(void *arg LTP_ATTRIBUTE_UNUSED) { + struct test_variants *tv = &variants[tst_variant]; int res; - res = futex_wait(futex2, *futex2, &to, 0); + res = futex_wait(tv->fntype, futex2, *futex2, &to, 0); if (!res) - tst_resm(TPASS, "Hi hydra, thread2 awake!"); + tst_res(TPASS, "Hi hydra, thread2 awake!"); else - tst_resm(TFAIL, "Bug: wait_thread2 did not wake after 30 secs."); + tst_res(TFAIL | TTERRNO, "Bug: wait_thread2 did not wake after 30 secs."); return NULL; } static void wakeup_thread2(void) { + struct test_variants *tv = &variants[tst_variant]; void *addr; int hpsz, pgsz, res; pthread_t th1, th2; hpsz = read_hugepagesize(); - tst_resm(TINFO, "Hugepagesize %i", hpsz); + tst_res(TINFO, "Hugepagesize %i", hpsz); /*allocate some shared memory*/ addr = mmap(NULL, hpsz, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); if (addr == MAP_FAILED) { - if (errno == ENOMEM) { - tst_brkm(TCONF, NULL, - "Cannot allocate hugepage, memory too fragmented?"); - } + if (errno == ENOMEM) + tst_brk(TCONF, "Cannot allocate hugepage, memory too fragmented?"); - tst_brkm(TBROK | TERRNO, NULL, "Cannot allocate hugepage"); + tst_brk(TBROK | TERRNO, "Cannot allocate hugepage"); } pgsz = getpagesize(); @@ -165,45 +160,47 @@ static void wakeup_thread2(void) /*thread1 block on futex1 first,then thread2 block on futex2*/ res = pthread_create(&th1, NULL, wait_thread1, NULL); if (res) { - tst_brkm(TBROK, NULL, "pthread_create(): %s", - tst_strerrno(res)); + tst_res(TFAIL | TTERRNO, "pthread_create() failed"); + return; } res = pthread_create(&th2, NULL, wait_thread2, NULL); if (res) { - tst_brkm(TBROK, NULL, "pthread_create(): %s", - tst_strerrno(res)); + tst_res(TFAIL | TTERRNO, "pthread_create() failed"); + return; } while (wait_for_threads(2)) usleep(1000); - futex_wake(futex2, 1, 0); + futex_wake(tv->fntype, futex2, 1, 0); res = pthread_join(th2, NULL); - if (res) - tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res)); + if (res) { + tst_res(TFAIL | TTERRNO, "pthread_join() failed"); + return; + } - futex_wake(futex1, 1, 0); + futex_wake(tv->fntype, futex1, 1, 0); res = pthread_join(th1, NULL); if (res) - tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res)); + tst_res(TFAIL | TTERRNO, "pthread_join() failed"); - SAFE_MUNMAP(NULL, addr, hpsz); + SAFE_MUNMAP(addr, hpsz); } -int main(int argc, char *argv[]) +static void run(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - wakeup_thread2(); - - cleanup(); - tst_exit(); + wakeup_thread2(); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .needs_root = 1, + .min_kver = "2.6.32", + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/futex/futextest.h b/testcases/kernel/syscalls/futex/futextest.h index 5754d36dae51..b72d83bc711b 100644 --- a/testcases/kernel/syscalls/futex/futextest.h +++ b/testcases/kernel/syscalls/futex/futextest.h @@ -39,6 +39,7 @@ #include #include #include "lapi/futex.h" +#include "tst_timer.h" #define FUTEX_INITIALIZER 0 @@ -82,18 +83,35 @@ # define FUTEX_CLOCK_REALTIME 256 #endif +enum futex_fn_type { + FUTEX_FN_FUTEX, + FUTEX_FN_FUTEX64, +}; + +static inline void futex_supported_by_kernel(enum futex_fn_type fntype) +{ + if (fntype != FUTEX_FN_FUTEX64) + return; + + /* Check if the syscall is implemented on the platform */ + TEST(sys_futex_time64(NULL, 0, 0, NULL, NULL, 0)); + if (TST_RET == -1 && TST_ERR == ENOSYS) + tst_brk(TCONF, "Test not supported on kernel/platform"); +} + /** - * futex() - SYS_futex syscall wrapper + * futex_syscall() - futex syscall wrapper + * @fntype: Futex function type * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op - * @timeout: typically an absolute struct timespec (except where noted + * @timeout: typically an absolute struct tst_ts (except where noted * otherwise). Overloaded by some ops * @uaddr2: address of second futex for some ops\ * @val3: varies by op * @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG * - * futex() is used by all the following futex op wrappers. It can also be + * futex_syscall() is used by all the following futex op wrappers. It can also be * used for misuse and abuse testing. Generally, the specific op wrappers * should be used instead. It is a macro instead of an static inline function as * some of the types over overloaded (timeout is used for nr_requeue for @@ -102,17 +120,30 @@ * These argument descriptions are the defaults for all * like-named arguments in the following wrappers except where noted below. */ -#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \ - syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3) +static inline int futex_syscall(enum futex_fn_type fntype, futex_t *uaddr, + int futex_op, futex_t val, void *timeout, + futex_t *uaddr2, int val3, int opflags) +{ + int (*func)(int *uaddr, int futex_op, int val, void *to, int *uaddr2, int val3); + + if (fntype == FUTEX_FN_FUTEX) + func = sys_futex; + else + func = sys_futex_time64; + + return func((int *)uaddr, futex_op | opflags, val, timeout, (int *)uaddr2, val3); +} /** * futex_wait() - block on uaddr with optional timeout * @timeout: relative timeout */ static inline int -futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags) +futex_wait(enum futex_fn_type fntype, futex_t *uaddr, futex_t val, + struct tst_ts *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAIT, val, + tst_ts_get(timeout), NULL, 0, opflags); } /** @@ -120,9 +151,10 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags) * @nr_wake: wake up to this many tasks */ static inline int -futex_wake(futex_t *uaddr, int nr_wake, int opflags) +futex_wake(enum futex_fn_type fntype, futex_t *uaddr, int nr_wake, int opflags) { - return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, + opflags); } /** @@ -130,11 +162,11 @@ futex_wake(futex_t *uaddr, int nr_wake, int opflags) * @bitset: bitset to be used with futex_wake_bitset */ static inline int -futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, - u_int32_t bitset, int opflags) +futex_wait_bitset(enum futex_fn_type fntype, futex_t *uaddr, futex_t val, + struct tst_ts *timeout, u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAIT_BITSET, val, + tst_ts_get(timeout), NULL, bitset, opflags); } /** @@ -142,10 +174,11 @@ futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, * @bitset: bitset to compare with that used in futex_wait_bitset */ static inline int -futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opflags) +futex_wake_bitset(enum futex_fn_type fntype, futex_t *uaddr, int nr_wake, + u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, + NULL, bitset, opflags); } /** @@ -153,30 +186,32 @@ futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opflags) * @detect: whether (1) or not (0) to perform deadlock detection */ static inline int -futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, - int opflags) +futex_lock_pi(enum futex_fn_type fntype, futex_t *uaddr, struct tst_ts *timeout, + int detect, int opflags) { - return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); + return futex_syscall(fntype, uaddr, FUTEX_LOCK_PI, detect, + tst_ts_get(timeout), NULL, 0, opflags); } /** * futex_unlock_pi() - release uaddr as a PI mutex, waking the top waiter */ static inline int -futex_unlock_pi(futex_t *uaddr, int opflags) +futex_unlock_pi(enum futex_fn_type fntype, futex_t *uaddr, int opflags) { - return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); -} + return futex_syscall(fntype, uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, + opflags); } /** * futex_wake_op() - FIXME: COME UP WITH A GOOD ONE LINE DESCRIPTION */ static inline int -futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2, - int wake_op, int opflags) +futex_wake_op(enum futex_fn_type fntype, futex_t *uaddr, futex_t *uaddr2, + int nr_wake, int nr_wake2, int wake_op, int opflags) { - return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAKE_OP, nr_wake, + (void *)((unsigned long)nr_wake2), uaddr2, wake_op, + opflags); } /** @@ -188,11 +223,12 @@ futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2, * favor of futex_cmp_requeue(). */ static inline int -futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue, - int opflags) +futex_requeue(enum futex_fn_type fntype, futex_t *uaddr, futex_t *uaddr2, + int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_REQUEUE, nr_wake, + (void *)((unsigned long)nr_requeue), uaddr2, 0, + opflags); } /** @@ -201,11 +237,12 @@ futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue, * @nr_requeue: requeue up to this many tasks */ static inline int -futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, - int nr_requeue, int opflags) +futex_cmp_requeue(enum futex_fn_type fntype, futex_t *uaddr, futex_t val, + futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall(fntype, uaddr, FUTEX_CMP_REQUEUE, nr_wake, + (void *)((unsigned long)nr_requeue), uaddr2, val, + opflags); } /** @@ -217,11 +254,11 @@ futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, * paired with futex_cmp_requeue_pi(). */ static inline int -futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, - struct timespec *timeout, int opflags) +futex_wait_requeue_pi(enum futex_fn_type fntype, futex_t *uaddr, futex_t val, + futex_t *uaddr2, struct tst_ts *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_WAIT_REQUEUE_PI, val, + tst_ts_get(timeout), uaddr2, 0, opflags); } /** @@ -232,11 +269,12 @@ futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, * @nr_requeue: requeue up to this many tasks */ static inline int -futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, - int nr_requeue, int opflags) +futex_cmp_requeue_pi(enum futex_fn_type fntype, futex_t *uaddr, futex_t val, + futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, val, - opflags); + return futex_syscall(fntype, uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, + (void *)((unsigned long)nr_requeue), uaddr2, val, + opflags); } /** From patchwork Fri Jun 26 06:22:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317398 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=AsQLStK0; 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 49tRfk2Nphz9sRR for ; Fri, 26 Jun 2020 16:23:58 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B758C3C5853 for ; Fri, 26 Jun 2020 08:23:55 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 3997A3C5837 for ; Fri, 26 Jun 2020 08:23:02 +0200 (CEST) Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (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 4DCD7600BA3 for ; Fri, 26 Jun 2020 08:22:06 +0200 (CEST) Received: by mail-pj1-x1041.google.com with SMTP id u8so4274758pje.4 for ; Thu, 25 Jun 2020 23:23:01 -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=s0R7H3ESXy9BXi4x7K7Cc8ZDcyKc7QY2sKsGQcjvlo8=; b=AsQLStK0rg3ZJi9FAvMLa7Jfl76s1FAukJt4MrzLVmWJesOxOaD/Eev/jEbwjJQLOg hfkuqGCU/roANIRdg0SGMoXkh+4KpewQvuIqUEpB8S7rdeve2qv7tCK0yvJ4b20XPbId kYb51sqvMfvT44aYJzfjU3zRsYu+WLI0msAOYQupJGtszxAYakb9wsFWNvJx7cWyGXb3 gPqkDWTEus/Jvwpd2Zt6gg5uuW8+KzGk4Zp2xG7TMdskkU6y4E+Rp65/IqmPq3w3QTHW WeMR7izIqDXFwwMz02HmW6mol/QeCnCtFgRb3UW7o+SMccmlKPD/zdI2xtcPFmLDhg2k HSUA== 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=s0R7H3ESXy9BXi4x7K7Cc8ZDcyKc7QY2sKsGQcjvlo8=; b=WfVn7sHdShJmjfLkfgDMflKwNZGZxhERYCkp49b26gcmOTnboUQ/v5eZpGojyGcLHy OLT6th0wvinP+TRYIN/cNFvenJ5PvN8eyOOfLLqJPSRhvx7KLQO2CCiU2qrSOsHwHEgB pv+fK3U1A4dC69S1a9ITTwWP29j+c4bYaABgRuBQJNKO/ncQULqQW/4rzjY9aeunk7rq ac+3Mvc4wXnmvYzEH0DBIwCFeR9RP+4J7p95oSuXlA0AeK2MPyEwmNlWvttmFuCg08OG bnExm0C4ufB4Md1ch7yOkZsbaz6Q6rR2CCjwLF9UmmCAY5IG0XpreT2OWdS2TaMO6NDF YPIA== X-Gm-Message-State: AOAM530sSFMk62FuXcQfvYUNOcHGoB6JI6LHE4UtP3dH3dIF512OuqEr ve9LfxiqOjwqxLaGz+PjfZUlQgmD7YU= X-Google-Smtp-Source: ABdhPJxzT0Xcgsw3d3FpcO2aPpe6Y/G/PH51aIj/QQly63w2w140t3NFqa2EsSBjOFZYuR2rY5G97g== X-Received: by 2002:a17:902:854c:: with SMTP id d12mr1325639plo.343.1593152579662; Thu, 25 Jun 2020 23:22:59 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id h35sm10989487pje.29.2020.06.25.23.22.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:22:59 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:21 +0530 Message-Id: <2b946a2ec5c8083e326e4bb4ba08db3f0f9ad66f.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 08/19] syscalls/io_pgetevents: 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 io_pgetevents() syscall tests. While at it, also pass mode to SAFE_OPEN() to avoid any errors when the tests are run for multiple variants together. Also get rid of an extra copy of local fd variable, which is incorrect. Signed-off-by: Viresh Kumar --- include/lapi/io_pgetevents.h | 15 ++++-- .../syscalls/io_pgetevents/io_pgetevents01.c | 33 +++++++++++- .../syscalls/io_pgetevents/io_pgetevents02.c | 51 +++++++++++++++---- 3 files changed, 83 insertions(+), 16 deletions(-) diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h index 3c9d5b2d7618..5bb9a60c352a 100644 --- a/include/lapi/io_pgetevents.h +++ b/include/lapi/io_pgetevents.h @@ -16,15 +16,20 @@ #ifdef HAVE_LIBAIO #include -#ifndef HAVE_IO_PGETEVENTS -int io_pgetevents(io_context_t ctx, long min_nr, long max_nr, - struct io_event *events, struct timespec *timeout, - sigset_t *sigmask) +static inline int sys_io_pgetevents(io_context_t ctx, long min_nr, long max_nr, + struct io_event *events, void *timeout, sigset_t *sigmask) { return tst_syscall(__NR_io_pgetevents, ctx, min_nr, max_nr, events, timeout, sigmask); } -#endif /* HAVE_IO_PGETEVENTS */ + +static inline int sys_io_pgetevents_time64(io_context_t ctx, long min_nr, long max_nr, + struct io_event *events, void *timeout, sigset_t *sigmask) +{ + return tst_syscall(__NR_io_pgetevents_time64, ctx, min_nr, max_nr, + events, timeout, sigmask); +} + #endif /* HAVE_LIBAIO */ #endif /* IO_PGETEVENTS_H */ diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c index e6077e47984d..fea380e52f4d 100644 --- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c +++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c @@ -6,11 +6,32 @@ * Basic io_pgetevents() test to receive 1 event successfully. */ #include "tst_test.h" +#include "tst_timer.h" #include "lapi/io_pgetevents.h" #ifdef HAVE_LIBAIO static int fd; +static struct test_variants { + int (*io_pgetevents)(io_context_t ctx, long min_nr, long max_nr, + struct io_event *events, void *timeout, sigset_t *sigmask); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_io_pgetevents != __LTP__NR_INVALID_SYSCALL) + { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL) + { .io_pgetevents = sys_io_pgetevents_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +static void setup(void) +{ + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); +} + static void cleanup(void) { if (fd > 0) @@ -19,12 +40,18 @@ static void cleanup(void) static void run(void) { + struct test_variants *tv = &variants[tst_variant]; struct io_event events[1]; struct iocb cb, *cbs[1]; io_context_t ctx = 0; + struct tst_ts to; sigset_t sigmask; char data[4096]; - int ret, fd; + int ret; + + to.type = tv->type; + tst_ts_set_sec(&to, 0); + tst_ts_set_nsec(&to, 10000); cbs[0] = &cb; sigemptyset(&sigmask); @@ -41,7 +68,7 @@ static void run(void) tst_brk(TBROK | TERRNO, "io_submit() failed"); /* get the reply */ - ret = io_pgetevents(ctx, 1, 1, events, NULL, &sigmask); + ret = tv->io_pgetevents(ctx, 1, 1, events, tst_ts_get(&to), &sigmask); if (ret == 1) tst_res(TPASS, "io_pgetevents() works as expected"); @@ -55,8 +82,10 @@ static void run(void) static struct tst_test test = { .min_kver = "4.18", .test_all = run, + .test_variants = ARRAY_SIZE(variants), .needs_tmpdir = 1, .cleanup = cleanup, + .setup = setup, }; #else diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c index 62a8afba3bf1..a15b3d0dda92 100644 --- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c +++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c @@ -6,6 +6,7 @@ * Basic io_pgetevents() test to check various failures. */ #include "tst_test.h" +#include "tst_timer.h" #include "lapi/io_pgetevents.h" #ifdef HAVE_LIBAIO @@ -14,30 +15,55 @@ static struct io_event events[1]; static io_context_t ctx, invalid_ctx = 0; static int fd, ctx_initialized; +static struct tst_ts to; +static void *bad_addr; + static struct tcase { char *name; io_context_t *ctx; long min_nr; long max_nr; struct io_event *events; - struct timespec *timeout; + struct tst_ts *timeout; sigset_t *sigmask; int exp_errno; } tcases[] = { - {"invalid ctx", &invalid_ctx, 1, 1, events, NULL, &sigmask, EINVAL}, - {"invalid min_nr", &ctx, -1, 1, events, NULL, &sigmask, EINVAL}, - {"invalid max_nr", &ctx, 1, -1, events, NULL, &sigmask, EINVAL}, - {"invalid events", &ctx, 1, 1, NULL, NULL, &sigmask, EFAULT}, - {"invalid timeout", &ctx, 1, 1, events, (void *)(0xDEAD), &sigmask, EFAULT}, - {"invalid sigmask", &ctx, 1, 1, events, NULL, (void *)(0xDEAD), EFAULT}, + {"invalid ctx", &invalid_ctx, 1, 1, events, &to, &sigmask, EINVAL}, + {"invalid min_nr", &ctx, -1, 1, events, &to, &sigmask, EINVAL}, + {"invalid max_nr", &ctx, 1, -1, events, &to, &sigmask, EINVAL}, + {"invalid events", &ctx, 1, 1, NULL, &to, &sigmask, EFAULT}, + {"invalid timeout", &ctx, 1, 1, events, NULL, &sigmask, EFAULT}, + {"invalid sigmask", &ctx, 1, 1, events, &to, NULL, EFAULT}, +}; + +static struct test_variants { + int (*io_pgetevents)(io_context_t ctx, long min_nr, long max_nr, + struct io_event *events, void *timeout, sigset_t *sigmask); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_io_pgetevents != __LTP__NR_INVALID_SYSCALL) + { .io_pgetevents = sys_io_pgetevents, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL) + { .io_pgetevents = sys_io_pgetevents_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif }; static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; struct iocb cb, *cbs[1]; char data[4096]; int ret; + tst_res(TINFO, "Testing variant: %s", tv->desc); + bad_addr = tst_get_bad_addr(NULL); + to.type = tv->type; + tst_ts_set_sec(&to, 0); + tst_ts_set_nsec(&to, 10000); + cbs[0] = &cb; sigemptyset(&sigmask); @@ -69,10 +95,16 @@ static void cleanup(void) static void run(unsigned int n) { + struct test_variants *tv = &variants[tst_variant]; struct tcase *tc = &tcases[n]; + struct timespec *to; + sigset_t *sigmask; + + sigmask = tc->sigmask ? tc->sigmask : bad_addr; + to = tc->timeout ? tc->timeout : bad_addr; - TEST(io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events, - tc->timeout, tc->sigmask)); + TEST(tv->io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events, to, + sigmask)); if (TST_RET == 1) { tst_res(TFAIL, "%s: io_pgetevents() passed unexpectedly", @@ -95,6 +127,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .tcnt = ARRAY_SIZE(tcases), .test = run, + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, }; From patchwork Fri Jun 26 06:22:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317400 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=NEB/UmRu; 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 49tRg71Ls5z9sRR for ; Fri, 26 Jun 2020 16:24:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 65E533C5858 for ; Fri, 26 Jun 2020 08:24:15 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 708B43C5843 for ; Fri, 26 Jun 2020 08:23:05 +0200 (CEST) Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 826941000D3D for ; Fri, 26 Jun 2020 08:23:04 +0200 (CEST) Received: by mail-pj1-x1041.google.com with SMTP id h22so4519183pjf.1 for ; Thu, 25 Jun 2020 23:23:04 -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=LFZd9P5Q5kn9z9zCL7gKYfyvogwPWXJbq0lUe8BU1ic=; b=NEB/UmRuUhUzZWOUZorP/YXM2qa9P/oUPV4nHIf+68yrgYD3sjnHe8Z+koZ/zlU4t2 hRdSx1Oxhw6bjk7Pz2C8AK1evDHygE0bp3xh9cVPAJxEyU16skWsOkfBFxAybWROA732 el5nxUhIxN1zOeckZz1EHsw3c2raYAvvQ+gl0nfzS55m05mbMl1/OOeFfhU4La4kuYiM 5v89nhLdB89Pyh3QCy8LadZG5aPZ3yQZAd8RHq2YPCNQOQ6jwB3QRS7OEhm3n4566pgC Bs5HNAVKtRd8uhPEDT9kv37AczCBB9zR/ARUsOB3JmqrOjshuMSiFslcPKzZj5mlkbSq MDjA== 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=LFZd9P5Q5kn9z9zCL7gKYfyvogwPWXJbq0lUe8BU1ic=; b=q947ZE12b0sAQD/CfOfRlUxcXj3h9gZlXKfPHe74mr1MSiZEPRrB4mWW3tahs0OVuy qOAPnlo2mTC96WrmSAGqs5cjZjY7tbGUh8XtSI9EzThMY7OU7kidJSfIis2mx2coZM68 gjEvEBLEeNw3g/nj6tJnGjnnjp9GC2KU/8Ep0UQYJvAugXZmIZ26GNzzsRRXAGQfk2/g 0vRLEAwyW/XCZAp41kNR3Y0vd0cF2c58TMyGamR8Dd6E8+1m+E0iUG0aTtA/rK9Gxd/q Z2GbRa+AUEHdRglPf1O1YffI5943hINcTwIlksWYGuleZiokO8U6qNFQxKyhlng7WUvJ G6rA== X-Gm-Message-State: AOAM533sG1cw3F5+EQGp+ESej74t+99+DX9Ebx4/zi9ktzneX+RtOw6E /3aFQlCFB7SXJNW+ShwIxgaJtPRMz2Y= X-Google-Smtp-Source: ABdhPJxVb5MGcYAIstMnYENGtCou+E2jxQyDpmbPZz+67vO9B8L5qID/LamhA/JjEIu/+dn6Ibj6XQ== X-Received: by 2002:a17:902:7896:: with SMTP id q22mr1303480pll.338.1593152582450; Thu, 25 Jun 2020 23:23:02 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id 3sm15220552pfv.156.2020.06.25.23.23.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:01 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:22 +0530 Message-Id: <18d8603306f51f243faca04cf63bcaf2c7168d56.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH V7 09/19] syscalls/sigwaitinfo: Migrate to new test framework 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 migrates the sigwaitinfo tests to use the new test framework. Signed-off-by: Viresh Kumar --- .../syscalls/sigwaitinfo/sigwaitinfo01.c | 209 +++++++----------- 1 file changed, 84 insertions(+), 125 deletions(-) diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c index 6a30c27f6f2f..1b976a271d28 100644 --- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c @@ -1,93 +1,58 @@ -/* - * Copyright (c) Jiri Palecek, 2009 - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "test.h" +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) Jiri Palecek, 2009 */ + +#include "tst_test.h" #include +#include #include -#include "../utils/include_j_h.h" -#include "../utils/common_j_h.c" #include #include "lapi/syscalls.h" +#include "tst_sig_proc.h" #define SUCCEED_OR_DIE(syscall, message, ...) \ (errno = 0, \ ({int ret=syscall(__VA_ARGS__); \ if (ret==-1) \ - tst_brkm(TBROK|TERRNO, cleanup, message);\ + tst_brk(TBROK|TERRNO, message);\ ret;})) -/* Report success iff TEST_RETURN and TEST_ERRNO are equal to +/* Report success iff TST_RET and TST_ERR are equal to exp_return and exp_errno, resp., and cond is true. If cond is not true, report condition_errmsg */ -static void report_success_cond(const char *func, const char *file, int line, +static void report_success_cond(const char *func, int line, long exp_return, int exp_errno, int condition, char *condition_errmsg) { - if (exp_return == TEST_RETURN - && (exp_return != -1 || exp_errno == TEST_ERRNO)) + if (exp_return == TST_RET + && (exp_return != -1 || exp_errno == TST_ERR)) if (condition) - tst_resm(TPASS, "Test passed"); + tst_res(TPASS, "%s (%d): Test passed", func, line); else - tst_resm(TFAIL, "%s (%s: %d): %s", func, file, line, + tst_res(TFAIL, "%s (%d): %s", func, line, condition_errmsg); - else if (TEST_RETURN != -1) - tst_resm(TFAIL, - "%s (%s: %d): Unexpected return value; expected %ld, got %ld", - func, file, line, exp_return, TEST_RETURN); + else if (TST_RET != -1) + tst_res(TFAIL, + "%s (%d): Unexpected return value; expected %ld, got %ld", + func, line, exp_return, TST_RET); else - tst_resm(TFAIL | TTERRNO, "%s (%s: %d): Unexpected failure", - func, file, line); + tst_res(TFAIL | TTERRNO, "%s (%d): Unexpected failure", + func, line); } #define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg) \ - report_success_cond(__FUNCTION__, __FILE__, __LINE__, exp_return, exp_errno, condition, condition_errmsg); + report_success_cond(__FUNCTION__, __LINE__, exp_return, exp_errno, condition, condition_errmsg); -/* Report success iff TEST_RETURN and TEST_ERRNO are equal to +/* Report success iff TST_RET and TST_ERR are equal to exp_return and exp_errno, resp. */ #define REPORT_SUCCESS(exp_return, exp_errno) \ REPORT_SUCCESS_COND(exp_return, exp_errno, 1, ""); -static void cleanup(void); - static void empty_handler(int sig) { } -static void setup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); - signal(SIGUSR1, empty_handler); - signal(SIGALRM, empty_handler); - signal(SIGUSR2, SIG_IGN); - - TEST_PAUSE; -} - -static void cleanup(void) -{ -} - typedef int (*swi_func) (const sigset_t * set, siginfo_t * info, struct timespec * timeout); typedef void (*test_func) (swi_func, int); @@ -110,7 +75,6 @@ static int my_sigwait(const sigset_t * set, siginfo_t * info, static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info, struct timespec *timeout) { - return sigwaitinfo(set, info); } #endif @@ -119,7 +83,6 @@ static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info, static int my_sigtimedwait(const sigset_t * set, siginfo_t * info, struct timespec *timeout) { - return sigtimedwait(set, info, timeout); } #endif @@ -129,7 +92,7 @@ static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info, struct timespec *timeout) { /* _NSIG is always the right number of bits of signal map for all arches */ - return ltp_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8); + return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8); } #endif @@ -141,12 +104,13 @@ void test_empty_set(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); /* Run a child that will wake us up */ - child = create_sig_proc(100000, signo, UINT_MAX); + child = create_sig_proc(signo, INT_MAX, 100000); TEST(sigwaitinfo(&sigs, &si, NULL)); REPORT_SUCCESS(-1, EINTR); - kill(child, SIGTERM); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_timeout(swi_func sigwaitinfo, int signo) @@ -159,12 +123,13 @@ void test_timeout(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); /* Run a child that will wake us up */ - child = create_sig_proc(100000, signo, UINT_MAX); + child = create_sig_proc(signo, INT_MAX, 100000); TEST(sigwaitinfo(&sigs, &si, &ts)); REPORT_SUCCESS(-1, EAGAIN); - kill(child, SIGTERM); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } /* Note: sigwait-ing for a signal that is not blocked is unspecified @@ -180,14 +145,15 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); /* Run a child that will wake us up */ - child = create_sig_proc(100000, signo, UINT_MAX); + child = create_sig_proc(signo, INT_MAX, 100000); TEST(sigwaitinfo(&sigs, &si, NULL)); REPORT_SUCCESS_COND(signo, 0, si.si_pid == child && si.si_code == SI_USER && si.si_signo == signo, "Struct siginfo mismatch"); - kill(child, SIGTERM); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo) @@ -198,12 +164,13 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); /* Run a child that will wake us up */ - child = create_sig_proc(100000, signo, UINT_MAX); + child = create_sig_proc(signo, INT_MAX, 100000); TEST(sigwaitinfo(&sigs, NULL, NULL)); REPORT_SUCCESS(signo, 0); - kill(child, SIGTERM); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_masked_matching(swi_func sigwaitinfo, int signo) @@ -224,7 +191,7 @@ void test_masked_matching(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); /* Run a child that will wake us up */ - child = create_sig_proc(0, signo, 1); + child = create_sig_proc(signo, 1, 0); TEST(sigwaitinfo(&sigs, &si, NULL)); REPORT_SUCCESS_COND(signo, 0, si.si_pid == child @@ -234,13 +201,14 @@ void test_masked_matching(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", SIG_SETMASK, &oldmask, &oldmask); - tst_count--; - if (sigismember(&oldmask, signo)) - tst_resm(TPASS, "sigwaitinfo restored the original mask"); + tst_res(TPASS, "sigwaitinfo restored the original mask"); else - tst_resm(TFAIL, + tst_res(TFAIL, "sigwaitinfo failed to restore the original mask"); + + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_masked_matching_rt(swi_func sigwaitinfo, int signo) @@ -265,12 +233,12 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigdelset, "sigdelset failed", &sigs, SIGCHLD); /* Run a child that will wake us up */ - child[0] = create_sig_proc(0, signo, 1); - child[1] = create_sig_proc(0, signo + 1, 1); + child[0] = create_sig_proc(signo, 1, 0); + child[1] = create_sig_proc(signo + 1, 1, 0); /* Ensure that the signals have been sent */ - waitpid(child[0], &status, 0); - waitpid(child[1], &status, 0); + SAFE_WAITPID(child[0], &status, 0); + SAFE_WAITPID(child[1], &status, 0); TEST(sigwaitinfo(&sigs, &si, NULL)); REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0] @@ -278,7 +246,6 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo) && si.si_signo == signo, "Struct siginfo mismatch"); /* eat the other signal */ - tst_count--; TEST(sigwaitinfo(&sigs, &si, NULL)); REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1] && si.si_code == SI_USER @@ -288,12 +255,10 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", SIG_SETMASK, &oldmask, &oldmask); - tst_count--; - if (sigismember(&oldmask, signo)) - tst_resm(TPASS, "sigwaitinfo restored the original mask"); + tst_res(TPASS, "sigwaitinfo restored the original mask"); else - tst_resm(TFAIL, + tst_res(TFAIL, "sigwaitinfo failed to restore the original mask"); } @@ -314,7 +279,7 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); /* Run a child that will wake us up */ - child = create_sig_proc(0, signo, 1); + child = create_sig_proc(signo, 1, 0); TEST(sigwaitinfo(&sigs, NULL, NULL)); REPORT_SUCCESS(signo, 0); @@ -322,14 +287,14 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", SIG_SETMASK, &oldmask, &oldmask); - tst_count--; - if (sigismember(&oldmask, signo)) - tst_resm(TPASS, "sigwaitinfo restored the original mask"); + tst_res(TPASS, "sigwaitinfo restored the original mask"); else - tst_resm(TFAIL, + tst_res(TFAIL, "sigwaitinfo failed to restore the original mask"); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_bad_address(swi_func sigwaitinfo, int signo) @@ -349,7 +314,7 @@ void test_bad_address(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); /* Run a child that will wake us up */ - child = create_sig_proc(0, signo, 1); + child = create_sig_proc(signo, 1, 0); TEST(sigwaitinfo(&sigs, (void *)1, NULL)); REPORT_SUCCESS(-1, EFAULT); @@ -357,7 +322,8 @@ void test_bad_address(swi_func sigwaitinfo, int signo) SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &oldmask, &oldmask); - kill(child, SIGTERM); + SAFE_KILL(child, SIGTERM); + SAFE_WAIT(NULL); } void test_bad_address2(swi_func sigwaitinfo, int signo) @@ -367,7 +333,7 @@ void test_bad_address2(swi_func sigwaitinfo, int signo) switch (pid = fork()) { case -1: - tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); + tst_brk(TBROK | TERRNO, "fork() failed"); case 0: signal(SIGSEGV, SIG_DFL); @@ -377,31 +343,31 @@ void test_bad_address2(swi_func sigwaitinfo, int signo) */ TEST(sigwaitinfo((void *)1, NULL, NULL)); - if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT) + if (TST_RET == -1 && TST_ERR == EFAULT) _exit(0); - tst_resm(TINFO | TTERRNO, "swi_func returned: %ld", - TEST_RETURN); + tst_res(TINFO | TTERRNO, "swi_func returned: %ld", + TST_RET); _exit(1); break; default: break; } - SUCCEED_OR_DIE(waitpid, "waitpid failed", pid, &status, 0); + SAFE_WAITPID(pid, &status, 0); if ((WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) || (WIFEXITED(status) && WEXITSTATUS(status) == 0)) { - tst_resm(TPASS, "Test passed"); + tst_res(TPASS, "Test passed"); return; } if (WIFEXITED(status)) { - tst_resm(TFAIL, "Unrecognised child exit code: %d", + tst_res(TFAIL, "Unrecognised child exit code: %d", WEXITSTATUS(status)); } if (WIFSIGNALED(status)) { - tst_resm(TFAIL, "Unrecognised child termsig: %d", + tst_res(TFAIL, "Unrecognised child termsig: %d", WTERMSIG(status)); } } @@ -474,38 +440,31 @@ struct test_desc { #endif }; -#if defined TEST_SIGWAITINFO -const char *TCID = "sigwaitinfo01"; -#elif defined TEST_RT_SIGTIMEDWAIT -const char *TCID = "rt_sigtimedwait01"; -#elif defined TEST_SIGTIMEDWAIT -const char *TCID = "sigtimedwait01"; -#elif defined TEST_SIGWAIT -const char *TCID = "sigwait01"; -#endif - -int TST_TOTAL = ARRAY_SIZE(tests); - -int main(int argc, char **argv) +static void run(unsigned int i) { - unsigned i; - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); + struct test_desc *tc = &tests[i]; - setup(); + tc->tf(tc->swi, tc->signo); +} - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; +static void setup(void) +{ + signal(SIGUSR1, empty_handler); + signal(SIGALRM, empty_handler); + signal(SIGUSR2, SIG_IGN); - for (i = 0; i < ARRAY_SIZE(tests); i++) { - alarm(10); /* arrange a 10 second timeout */ - tst_resm(TINFO, "%p, %d", tests[i].swi, tests[i].signo); - tests[i].tf(tests[i].swi, tests[i].signo); - } - alarm(0); - } + alarm(10); /* arrange a 10 second timeout */ +} - cleanup(); - tst_exit(); +static void cleanup(void) +{ + alarm(0); } + +static struct tst_test test = { + .test= run, + .tcnt = ARRAY_SIZE(tests), + .setup = setup, + .cleanup = cleanup, + .forks_child = 1, +}; From patchwork Fri Jun 26 06:22:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317401 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=Q5AVrKjs; 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 49tRgJ24Yqz9sRR for ; Fri, 26 Jun 2020 16:24:28 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A3B5B3C2B60 for ; Fri, 26 Jun 2020 08:24:25 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 0698E3C2B5E for ; Fri, 26 Jun 2020 08:23:07 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id EF6851000D34 for ; Fri, 26 Jun 2020 08:23:06 +0200 (CEST) Received: by mail-pl1-x643.google.com with SMTP id x11so3896941plo.7 for ; Thu, 25 Jun 2020 23:23:06 -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=3jXLBmcNFgzJSxHlaCxvGwXW6yHMAmlPCFPo7wxrKMQ=; b=Q5AVrKjsSc0lBCIoiH1mHGcfOqv/0iOGFe/eBL3B9KoRwr+os9UFkrca0p2SzckAki TznbVw+beqX4woAXyYO529WX21ovSv7mnV1gUg4bI/5CzoDPF1PPO2EkQNBPel3XUvh0 uAZdk0GWT5698TXVv1l8ReoJ9mS39hEiDjFk22RtpiviH52OWEiQI5VWYfN+rhu4s5Wb 5z3h+ugWsm+7OCaQFmpNqkFNnL4kYCgyrqqvGCelupcKfdhPaT6ATbXQggu2Ql49uKXp Hda8yYxl8cIRrpZ7+BYmAYyRqd2BHChgBln1JMh26pw8bhIS64HZouQ+/AGWX900Qi0B ccuw== 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=3jXLBmcNFgzJSxHlaCxvGwXW6yHMAmlPCFPo7wxrKMQ=; b=XI1636mr5IJHTMA3ocRBKobLkj2AtPw+3a5piGhztVS1T0F4w+4W3LKgUQe3r5NJMk 6LV5LpIPP4s9ggF6mijbak3GqKMXjoYBxwqCB9i07PwO0mNMklvdTX8TSjr+9Om1uUSU /XGpmDcq1wOKjKx3lI47V9SDONHrMaCS4cEQtYwePnwZlctNEIWCuQIkznM5d3+fzoGf cWkDsDDqBebUIf+WqwX2aylRdsZKOuOAQze1w2xnPH40BOlzJzmxWzXWXgLtuwENMS7c MejijvoeWTrht29UbRqgnhSWUpzVlax63E/aqQgB8EFEvYtMBJ+rW3cVwCfdSpQjJ+PL aS4Q== X-Gm-Message-State: AOAM531zhO/9fUaPz/8VsklB+z4iFxK8RnQ53asTCfEDyr896IhM7kTv LOGdWwM4peJcpAY8mAh9qfwux6jYY8Y= X-Google-Smtp-Source: ABdhPJw+Tk2/NIjN82wtL6Fawt6W135iDnMnZBVSuk5ywj8q4jd/FoaTzKsMs019KGv35DSssPRGhQ== X-Received: by 2002:a17:90a:ec13:: with SMTP id l19mr1565694pjy.81.1593152585062; Thu, 25 Jun 2020 23:23:05 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id d7sm24789946pfh.78.2020.06.25.23.23.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:04 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:23 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH V7 10/19] syscalls/rt_sigtimedwait: 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 rt_sigtimedwait() syscall tests. Signed-off-by: Viresh Kumar --- .../syscalls/sigwaitinfo/sigwaitinfo01.c | 112 +++++++++++++----- 1 file changed, 80 insertions(+), 32 deletions(-) diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c index 1b976a271d28..05e62999ca6c 100644 --- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c @@ -2,6 +2,7 @@ /* Copyright (c) Jiri Palecek, 2009 */ #include "tst_test.h" +#include "tst_timer.h" #include #include #include @@ -54,12 +55,12 @@ static void empty_handler(int sig) } typedef int (*swi_func) (const sigset_t * set, siginfo_t * info, - struct timespec * timeout); -typedef void (*test_func) (swi_func, int); + void * timeout); +typedef void (*test_func) (swi_func, int, enum tst_ts_type type); #ifdef TEST_SIGWAIT static int my_sigwait(const sigset_t * set, siginfo_t * info, - struct timespec *timeout) + void *timeout) { int ret; int err = sigwait(set, &ret); @@ -73,7 +74,7 @@ static int my_sigwait(const sigset_t * set, siginfo_t * info, #ifdef TEST_SIGWAITINFO static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info, - struct timespec *timeout) + void *timeout) { return sigwaitinfo(set, info); } @@ -81,7 +82,7 @@ static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info, #ifdef TEST_SIGTIMEDWAIT static int my_sigtimedwait(const sigset_t * set, siginfo_t * info, - struct timespec *timeout) + void *timeout) { return sigtimedwait(set, info, timeout); } @@ -89,14 +90,23 @@ static int my_sigtimedwait(const sigset_t * set, siginfo_t * info, #ifdef TEST_RT_SIGTIMEDWAIT static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info, - struct timespec *timeout) + void *timeout) { /* _NSIG is always the right number of bits of signal map for all arches */ return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8); } + +#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL) +static int my_rt_sigtimedwait_time64(const sigset_t * set, siginfo_t * info, + void *timeout) +{ + /* _NSIG is always the right number of bits of signal map for all arches */ + return tst_syscall(__NR_rt_sigtimedwait_time64, set, info, timeout, _NSIG/8); +} +#endif #endif -void test_empty_set(swi_func sigwaitinfo, int signo) +void test_empty_set(swi_func sigwaitinfo, int signo, enum tst_ts_type type) { sigset_t sigs; siginfo_t si; @@ -113,19 +123,23 @@ void test_empty_set(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_timeout(swi_func sigwaitinfo, int signo) +void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type) { sigset_t sigs; siginfo_t si; pid_t child; - struct timespec ts = {.tv_sec = 1 }; + struct tst_ts ts; + + ts.type = type; + tst_ts_set_sec(&ts, 1); + tst_ts_set_nsec(&ts, 0); SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); /* Run a child that will wake us up */ child = create_sig_proc(signo, INT_MAX, 100000); - TEST(sigwaitinfo(&sigs, &si, &ts)); + TEST(sigwaitinfo(&sigs, &si, tst_ts_get(&ts))); REPORT_SUCCESS(-1, EAGAIN); SAFE_KILL(child, SIGTERM); @@ -135,7 +149,8 @@ void test_timeout(swi_func sigwaitinfo, int signo) /* Note: sigwait-ing for a signal that is not blocked is unspecified * by POSIX; but works for non-ignored signals under Linux */ -void test_unmasked_matching(swi_func sigwaitinfo, int signo) +void test_unmasked_matching(swi_func sigwaitinfo, int signo, + enum tst_ts_type type) { sigset_t sigs; siginfo_t si; @@ -156,7 +171,8 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo) +void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo, + enum tst_ts_type type) { sigset_t sigs; pid_t child; @@ -173,7 +189,8 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_masked_matching(swi_func sigwaitinfo, int signo) +void test_masked_matching(swi_func sigwaitinfo, int signo, + enum tst_ts_type type) { sigset_t sigs, oldmask; siginfo_t si; @@ -211,7 +228,8 @@ void test_masked_matching(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_masked_matching_rt(swi_func sigwaitinfo, int signo) +void test_masked_matching_rt(swi_func sigwaitinfo, int signo, + enum tst_ts_type type) { sigset_t sigs, oldmask; siginfo_t si; @@ -262,7 +280,8 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo) "sigwaitinfo failed to restore the original mask"); } -void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo) +void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo, + enum tst_ts_type type) { sigset_t sigs, oldmask; pid_t child; @@ -297,7 +316,7 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_bad_address(swi_func sigwaitinfo, int signo) +void test_bad_address(swi_func sigwaitinfo, int signo, enum tst_ts_type type) { sigset_t sigs, oldmask; pid_t child; @@ -326,7 +345,7 @@ void test_bad_address(swi_func sigwaitinfo, int signo) SAFE_WAIT(NULL); } -void test_bad_address2(swi_func sigwaitinfo, int signo) +void test_bad_address2(swi_func sigwaitinfo, int signo, enum tst_ts_type type) { pid_t pid; int status; @@ -372,7 +391,7 @@ void test_bad_address2(swi_func sigwaitinfo, int signo) } } -void test_bad_address3(swi_func sigwaitinfo, int signo) +void test_bad_address3(swi_func sigwaitinfo, int signo, enum tst_ts_type type) { sigset_t sigs; SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); @@ -388,28 +407,28 @@ struct test_desc { } tests[] = { #ifdef TEST_RT_SIGTIMEDWAIT { - test_empty_set, my_rt_sigtimedwait, SIGUSR1}, { - test_unmasked_matching, my_rt_sigtimedwait, SIGUSR1}, { - test_masked_matching, my_rt_sigtimedwait, SIGUSR1}, { - test_unmasked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, { - test_masked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, { - test_bad_address, my_rt_sigtimedwait, SIGUSR1}, { - test_bad_address2, my_rt_sigtimedwait, SIGUSR1}, { - test_bad_address3, my_rt_sigtimedwait, SIGUSR1}, { - test_timeout, my_rt_sigtimedwait, 0}, + test_empty_set, NULL, SIGUSR1}, { + test_unmasked_matching, NULL, SIGUSR1}, { + test_masked_matching, NULL, SIGUSR1}, { + test_unmasked_matching_noinfo, NULL, SIGUSR1}, { + test_masked_matching_noinfo, NULL, SIGUSR1}, { + test_bad_address, NULL, SIGUSR1}, { + test_bad_address2, NULL, SIGUSR1}, { + test_bad_address3, NULL, SIGUSR1}, { + test_timeout, NULL, 0}, /* Special cases */ /* 1: sigwaitinfo does respond to ignored signal */ { - test_masked_matching, my_rt_sigtimedwait, SIGUSR2}, + test_masked_matching, NULL, SIGUSR2}, /* 2: An ignored signal doesn't cause sigwaitinfo to return EINTR */ { - test_timeout, my_rt_sigtimedwait, SIGUSR2}, + test_timeout, NULL, SIGUSR2}, /* 3: The handler is not called when the signal is waited for by sigwaitinfo */ { - test_masked_matching, my_rt_sigtimedwait, SIGTERM}, + test_masked_matching, NULL, SIGTERM}, /* 4: Simultaneous realtime signals are delivered in the order of increasing signal number */ { - test_masked_matching_rt, my_rt_sigtimedwait, -1}, + test_masked_matching_rt, NULL, -1}, #endif #if defined TEST_SIGWAIT { @@ -440,15 +459,43 @@ struct test_desc { #endif }; +static struct test_variants { + swi_func swi; + enum tst_ts_type type; + char *desc; +} variants[] = { +#ifdef TEST_RT_SIGTIMEDWAIT + +#if (__NR_rt_sigtimedwait != __LTP__NR_INVALID_SYSCALL) + { .swi = my_rt_sigtimedwait, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL) + { .swi = my_rt_sigtimedwait_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif + +#else /* !TEST_RT_SIGTIMEDWAIT */ + + { .swi = NULL, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"}, + +#endif /* TEST_RT_SIGTIMEDWAIT */ +}; + static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; struct test_desc *tc = &tests[i]; + swi_func swi; - tc->tf(tc->swi, tc->signo); + swi = tv->swi ? tv->swi : tc->swi; + + tc->tf(swi, tc->signo, tv->type); } static void setup(void) { + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); + signal(SIGUSR1, empty_handler); signal(SIGALRM, empty_handler); signal(SIGUSR2, SIG_IGN); @@ -464,6 +511,7 @@ static void cleanup(void) static struct tst_test test = { .test= run, .tcnt = ARRAY_SIZE(tests), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .forks_child = 1, From patchwork Fri Jun 26 06:22:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317402 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=acJqHNz/; 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 49tRgV5qL2z9sRR for ; Fri, 26 Jun 2020 16:24:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1C5663C5839 for ; Fri, 26 Jun 2020 08:24:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 533AB3C5838 for ; Fri, 26 Jun 2020 08:23:11 +0200 (CEST) Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id BC58420110D for ; Fri, 26 Jun 2020 08:23:09 +0200 (CEST) Received: by mail-pf1-x442.google.com with SMTP id 67so149218pfg.5 for ; Thu, 25 Jun 2020 23:23:09 -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=qJN0SFAs1cNZ9omorLn0RtRB0M8LqzsfUwlb0ibCubw=; b=acJqHNz/cl1cnHIonAw8AU//4yoT5Rly4Oa/TwcRWQPNNXrOW3sQT/ohFsCQaPTxBL IeFFRsV/rPGwPYvBLdsPdf2ac7vvtJSB4ZaEwJ1yWlHJ1KttzEzbaBL1JcgLobzbh/5X 69S1V+8ThizUUHpw85YhZLYhGH5UcuD73MWp1AVb5iXkHfA0YgxLMbqubrjsVa0pkbm4 55Qz2ofPlpKb7vaKgHaa28lc3GPwHXgOiCE4BTFpEo+0s1oygTWXV9y8460lOjcil/mK yEBNIsae4HICxoZGue8Y8R75kJE/WbjO0n1dYxLxcoxvLMFtN3pUxk96gqzVq6W8XANZ 8Urw== 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=qJN0SFAs1cNZ9omorLn0RtRB0M8LqzsfUwlb0ibCubw=; b=DL40M/NybL11fxt4xD+6FQMUWQwJsdQvDU3ohjiAqw5ARoGuGJc7WtBDzi0+0gFi41 hoR+G3+hW59LWveDXO21T/Nc/lWIYQlb8ibCfjnzGZ9GJsu+jILxqs4JDH5MjKejHeF9 djAm7DqjLXGfj8rJkRvYwzXNnKzPabLtvoxkcRfB7zajo/GKQW4X0ILiy3D/6TikJYBQ 4ADqQ3v6M/a0Aq/P3bWh0i0aNSm37UM1M7/TwMVbSr2aDDWi3AgWnozMsstRjdCgsfVo S/Xr+KKibQu6iv2bO8avgpOfBacTunNATuFRPeaPgen4Pcpmzz+m0d+W4wJ79xVfKHS/ uPpA== X-Gm-Message-State: AOAM531BeFTiiLTCn+yqSz8FSH9sPuTR8dUPvue5W/QicudOrXnjwa4D XrZdFYdcjPoVOAso1Dm9VGFVameNRCk= X-Google-Smtp-Source: ABdhPJzw652KHrvr5KzTb+IW2qULfKFUuF2l7zzjMX0E+CcoocDaQEV5Jy2S6hiAuljHTmp3FkgjKw== X-Received: by 2002:a63:4b0f:: with SMTP id y15mr1378191pga.72.1593152587698; Thu, 25 Jun 2020 23:23:07 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id d9sm21701461pgg.74.2020.06.25.23.23.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:07 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:24 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Subject: [LTP] [PATCH V7 11/19] syscalls/mq_timed{send|receive}: 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 mq_timed{send|receive}() syscall tests. Signed-off-by: Viresh Kumar --- .../mq_timedreceive/mq_timedreceive01.c | 92 ++++++++++++------ .../syscalls/mq_timedsend/mq_timedsend01.c | 96 +++++++++++++------ testcases/kernel/syscalls/utils/mq_timed.h | 42 +++----- 3 files changed, 141 insertions(+), 89 deletions(-) diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c index 1be515ced671..876b54c81332 100644 --- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Crackerjack Project., 2007-2008, Hitachi, Ltd * Copyright (c) 2017 Petr Vorel @@ -6,19 +7,6 @@ * Takahiro Yasui , * Yumiko Sugita , * Satoshi Fujiwara - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ #include @@ -28,7 +16,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1; #include "mq_timed.h" -static struct timespec ts; +static struct tst_ts ts; static struct test_case tcase[] = { { @@ -95,21 +83,27 @@ static struct test_case tcase[] = { { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = -1, .tv_nsec = 0}, + .tv_sec = -1, + .tv_nsec = 0, + .rq = &ts, .ret = -1, .err = EINVAL, }, { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = -1}, + .tv_sec = 0, + .tv_nsec = -1, + .rq = &ts, .ret = -1, .err = EINVAL, }, { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = 1000000000}, + .tv_sec = 0, + .tv_nsec = 1000000000, + .rq = &ts, .ret = -1, .err = EINVAL, }, @@ -131,8 +125,40 @@ static struct test_case tcase[] = { }, }; +static struct test_variants { + int (*send)(mqd_t mqdes, const char *msg_ptr, size_t msg_len, + unsigned int msg_prio, void *abs_timeout); + ssize_t (*receive)(mqd_t mqdes, char *msg_ptr, size_t msg_len, + unsigned int *msg_prio, void *abs_timeout); + + int (*gettime)(clockid_t clk_id, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .gettime = libc_clock_gettime, .send = libc_mq_timedsend, .receive = libc_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + +#if (__NR_mq_timedsend != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_mq_timedsend_time64 != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime64, .send = sys_mq_timedsend64, .receive = sys_mq_timedreceive64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +static void setup(void) +{ + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + ts.type = tv->type; + + setup_common(); +} + static void do_test(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; const struct test_case *tc = &tcase[i]; unsigned int j; unsigned int prio; @@ -140,19 +166,26 @@ static void do_test(unsigned int i) char rmsg[len]; pid_t pid = -1; + tst_ts_set_sec(&ts, tc->tv_sec); + tst_ts_set_nsec(&ts, tc->tv_nsec); + if (tc->signal) - pid = set_sig(tc->rq); + pid = set_sig(tc->rq, tv->gettime); if (tc->timeout) - set_timeout(tc->rq); + set_timeout(tc->rq, tv->gettime); - if (tc->send) - send_msg(*tc->fd, tc->len, tc->prio); + if (tc->send) { + if (tv->send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) { + tst_res(TFAIL | TTERRNO, "mq_timedsend() failed"); + return; + } + } if (tc->invalid_msg) len -= 1; - TEST(mq_timedreceive(*tc->fd, rmsg, len, &prio, tc->rq)); + TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq))); if (pid > 0) kill_pid(pid); @@ -163,22 +196,22 @@ static void do_test(unsigned int i) if (TST_RET < 0) { if (tc->err != TST_ERR) tst_res(TFAIL | TTERRNO, - "mq_timedreceive failed unexpectedly, expected %s", + "mq_timedreceive() failed unexpectedly, expected %s", tst_strerrno(tc->err)); else - tst_res(TPASS | TTERRNO, "mq_timedreceive failed expectedly"); + tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly"); return; } if (tc->len != TST_RET) { - tst_res(TFAIL, "mq_timedreceive wrong length %ld, expected %zu", + tst_res(TFAIL, "mq_timedreceive() wrong length %ld, expected %u", TST_RET, tc->len); return; } if (tc->prio != prio) { - tst_res(TFAIL, "mq_timedreceive wrong prio %d, expected %d", + tst_res(TFAIL, "mq_timedreceive() wrong prio %d, expected %d", prio, tc->prio); return; } @@ -186,20 +219,21 @@ static void do_test(unsigned int i) for (j = 0; j < tc->len; j++) { if (rmsg[j] != smsg[j]) { tst_res(TFAIL, - "mq_timedreceive wrong data %d in %u, expected %d", + "mq_timedreceive() wrong data %d in %u, expected %d", rmsg[j], i, smsg[j]); return; } } - tst_res(TPASS, "mq_timedreceive returned %ld, priority %u, length: %zu", + tst_res(TPASS, "mq_timedreceive() returned %ld, priority %u, length: %zu", TST_RET, prio, len); } static struct tst_test test = { .tcnt = ARRAY_SIZE(tcase), .test = do_test, - .setup = setup_common, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, .cleanup = cleanup_common, .forks_child = 1, }; diff --git a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c index 8f209d396040..4ff1da65c570 100644 --- a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c +++ b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Crackerjack Project., 2007-2008, Hitachi, Ltd * Copyright (c) 2017 Petr Vorel @@ -6,29 +7,17 @@ * Takahiro Yasui , * Yumiko Sugita , * Satoshi Fujiwara - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ #include #include static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1; -static struct timespec ts; #include "mq_timed.h" +static struct tst_ts ts; + static struct test_case tcase[] = { { .fd = &fd, @@ -95,7 +84,9 @@ static struct test_case tcase[] = { { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = -1, .tv_nsec = 0}, + .tv_sec = -1, + .tv_nsec = 0, + .rq = &ts, .send = 1, .ret = -1, .err = EINVAL, @@ -103,7 +94,9 @@ static struct test_case tcase[] = { { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = -1}, + .tv_sec = 0, + .tv_nsec = -1, + .rq = &ts, .send = 1, .ret = -1, .err = EINVAL, @@ -111,7 +104,9 @@ static struct test_case tcase[] = { { .fd = &fd, .len = 16, - .rq = &(struct timespec) {.tv_sec = 0, .tv_nsec = 1000000000}, + .tv_sec = 0, + .tv_nsec = 1000000000, + .rq = &ts, .send = 1, .ret = -1, .err = EINVAL, @@ -136,8 +131,40 @@ static struct test_case tcase[] = { }, }; +static struct test_variants { + int (*send)(mqd_t mqdes, const char *msg_ptr, size_t msg_len, + unsigned int msg_prio, void *abs_timeout); + ssize_t (*receive)(mqd_t mqdes, char *msg_ptr, size_t msg_len, + unsigned int *msg_prio, void *abs_timeout); + + int (*gettime)(clockid_t clk_id, void *ts); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .gettime = libc_clock_gettime, .send = libc_mq_timedsend, .receive = libc_mq_timedreceive, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + +#if (__NR_mq_timedsend != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime, .send = sys_mq_timedsend, .receive = sys_mq_timedreceive, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_mq_timedsend_time64 != __LTP__NR_INVALID_SYSCALL) + { .gettime = sys_clock_gettime64, .send = sys_mq_timedsend64, .receive = sys_mq_timedreceive64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +static void setup(void) +{ + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + ts.type = tv->type; + + setup_common(); +} + static void do_test(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; const struct test_case *tc = &tcase[i]; unsigned int j; unsigned int prio; @@ -145,18 +172,24 @@ static void do_test(unsigned int i) char rmsg[len]; pid_t pid = -1; + tst_ts_set_sec(&ts, tc->tv_sec); + tst_ts_set_nsec(&ts, tc->tv_nsec); + if (tc->signal) - pid = set_sig(tc->rq); + pid = set_sig(tc->rq, tv->gettime); if (tc->timeout) - set_timeout(tc->rq); + set_timeout(tc->rq, tv->gettime); if (tc->send) { for (j = 0; j < MSG_LENGTH; j++) - send_msg(*tc->fd, tc->len, tc->prio); + if (tv->send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) { + tst_res(TFAIL | TTERRNO, "mq_timedsend() failed"); + return; + } } - TEST(mq_timedsend(*tc->fd, smsg, tc->len, tc->prio, tc->rq)); + TEST(tv->send(*tc->fd, smsg, tc->len, tc->prio, tst_ts_get(tc->rq))); if (pid > 0) kill_pid(pid); @@ -164,10 +197,10 @@ static void do_test(unsigned int i) if (TST_RET < 0) { if (tc->err != TST_ERR) tst_res(TFAIL | TTERRNO, - "mq_timedsend failed unexpectedly, expected %s", + "mq_timedsend() failed unexpectedly, expected %s", tst_strerrno(tc->err)); else - tst_res(TPASS | TTERRNO, "mq_timedreceive failed expectedly"); + tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly"); if (*tc->fd == fd) cleanup_queue(fd); @@ -175,7 +208,7 @@ static void do_test(unsigned int i) return; } - TEST(mq_timedreceive(*tc->fd, rmsg, len, &prio, tc->rq)); + TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq))); if (*tc->fd == fd) cleanup_queue(fd); @@ -183,26 +216,26 @@ static void do_test(unsigned int i) if (TST_RET < 0) { if (tc->err != TST_ERR) { tst_res(TFAIL | TTERRNO, - "mq_timedreceive failed unexpectedly, expected %s", + "mq_timedreceive() failed unexpectedly, expected %s", tst_strerrno(tc->err)); return; } if (tc->ret >= 0) { - tst_res(TFAIL | TTERRNO, "mq_timedreceive returned %ld, expected %d", + tst_res(TFAIL | TTERRNO, "mq_timedreceive() returned %ld, expected %d", TST_RET, tc->ret); return; } } if (tc->len != TST_RET) { - tst_res(TFAIL, "mq_timedreceive wrong length %ld, expected %d", + tst_res(TFAIL, "mq_timedreceive() wrong length %ld, expected %u", TST_RET, tc->len); return; } if (tc->prio != prio) { - tst_res(TFAIL, "mq_timedreceive wrong prio %d, expected %d", + tst_res(TFAIL, "mq_timedreceive() wrong prio %d, expected %d", prio, tc->prio); return; } @@ -210,20 +243,21 @@ static void do_test(unsigned int i) for (j = 0; j < tc->len; j++) { if (rmsg[j] != smsg[j]) { tst_res(TFAIL, - "mq_timedreceive wrong data %d in %u, expected %d", + "mq_timedreceive() wrong data %d in %u, expected %d", rmsg[j], i, smsg[j]); return; } } - tst_res(TPASS, "mq_timedreceive returned %ld, priority %u, length: %zu", + tst_res(TPASS, "mq_timedreceive() returned %ld, priority %u, length: %zu", TST_RET, prio, len); } static struct tst_test test = { .tcnt = ARRAY_SIZE(tcase), .test = do_test, - .setup = setup_common, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, .cleanup = cleanup_common, .forks_child = 1, }; diff --git a/testcases/kernel/syscalls/utils/mq_timed.h b/testcases/kernel/syscalls/utils/mq_timed.h index a163ddcee3af..1d5515f9d629 100644 --- a/testcases/kernel/syscalls/utils/mq_timed.h +++ b/testcases/kernel/syscalls/utils/mq_timed.h @@ -1,30 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2017 Petr Vorel - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ #ifndef MQ_TIMED_H #define MQ_TIMED_H #include "mq.h" +#include "tst_timer.h" struct test_case { int *fd; unsigned int len; unsigned int prio; - struct timespec *rq; + struct tst_ts *rq; + long tv_sec; + long tv_nsec; int invalid_msg; int send; int signal; @@ -33,27 +24,20 @@ struct test_case { int err; }; -static pid_t set_sig(struct timespec *ts) +static pid_t set_sig(struct tst_ts *ts, + int (*gettime)(clockid_t clk_id, void *ts)) { - clock_gettime(CLOCK_REALTIME, ts); - ts->tv_sec += 3; + gettime(CLOCK_REALTIME, tst_ts_get(ts)); + *ts = tst_ts_add_us(*ts, 3000000); return create_sig_proc(SIGINT, 40, 200000); } -static void set_timeout(struct timespec *ts) +static void set_timeout(struct tst_ts *ts, + int (*gettime)(clockid_t clk_id, void *ts)) { - clock_gettime(CLOCK_REALTIME, ts); - ts->tv_nsec += 50000000; - ts->tv_sec += ts->tv_nsec / 1000000000; - ts->tv_nsec %= 1000000000; -} - -static void send_msg(int fd, int len, int prio) -{ - if (mq_timedsend(fd, smsg, len, prio, - &((struct timespec){0})) < 0) - tst_brk(TBROK | TERRNO, "mq_timedsend failed"); + gettime(CLOCK_REALTIME, tst_ts_get(ts)); + *ts = tst_ts_add_us(*ts, 50000); } static void kill_pid(pid_t pid) From patchwork Fri Jun 26 06:22:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317403 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=uzbOrm1e; 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 49tRgg2SVfz9sRR for ; Fri, 26 Jun 2020 16:24:47 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B4F293C2CDA for ; Fri, 26 Jun 2020 08:24:44 +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 DBF3B3C2B7A for ; Fri, 26 Jun 2020 08:23:12 +0200 (CEST) Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) (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 027B3140119D for ; Fri, 26 Jun 2020 08:23:12 +0200 (CEST) Received: by mail-pj1-x1043.google.com with SMTP id b92so4512477pjc.4 for ; Thu, 25 Jun 2020 23:23:11 -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=3hSmG9cFNH+goXqeZoTWiFE5aD5ilhVTpXpfke+DEIQ=; b=uzbOrm1eKfudzPwuuhntAxtgz2EwSnZN4iFKh9XxNgtNg/uIKeXyMVaPJYPKIHSKk6 xp5haC0y0lXsiQFfdtOprdIXeOquQzP28GW5giqIVzi2zQwJjJw+LQ0Gp0gWrGvprVHa qEba1mzgDvCzMfBwdQXj8wwi/0Q8mTBYki4tSaYq+VandgkzWDpIvmECjQCOmRcvbUXv ExpaJZ/zHw5rfizbSOGIuUYqXhRcXRYT+8eiNPROLWv7fgEHpq65wFeen4bmqQaz55L6 Ix8uKbnpGJjVMm+U+XbGIH1gjkhkM2IqkuL0ARRf1PBXqOfKHzMA0SBsskK7Locrgchm 7k+Q== 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=3hSmG9cFNH+goXqeZoTWiFE5aD5ilhVTpXpfke+DEIQ=; b=WDw6NapbxL7tt4IBFtBDHh0Hv01ws6ip6Q924rU+6Q0PgPjXg3zQapYHJCzL9/+/m/ fRKU7ZEGwv5faul5trG/FObFambzId/U73CKjUOo079Kw2iioVqDCh0RkjI/OiWrDM+2 QQMowW5tmcIzzICt5DmaWMjJmCKxGo8Bmgse9PZVFXsPl/6jo5NeCTaMnuJRBVdV+cSb pJ5AptTq6HfGJKVM7LmArCW1H5d3of+LJ7LERz2o1U/N7AwYQX4qhZCGEVU2BucgMMFF znRKrvQ2ATHnJsD0np1+gARpnjRE5OqoG99rzRExIPd69QHzFIPa3kyTwxpos7QV6Y/F bpeg== X-Gm-Message-State: AOAM531sTA0Vmi1JZ4szTTguAxMilwgjrL1ALzApGhaOk27x1jN1Rn4o KUH2CjNT3CvGrExCzo4KR29/qYQRahg= X-Google-Smtp-Source: ABdhPJzZJhYM18bZXj/ZW5N7pbVwExV3E43i0hw2WFTd7wIk7ytmrDETLIS/rD07cxUmJqvF9r1cbQ== X-Received: by 2002:a17:90a:e983:: with SMTP id v3mr1732949pjy.71.1593152590208; Thu, 25 Jun 2020 23:23:10 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id br9sm6716457pjb.56.2020.06.25.23.23.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:09 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:25 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 12/19] syscalls/recvmmsg: 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 recvmmsg() syscall tests. Signed-off-by: Viresh Kumar --- .../kernel/syscalls/sendmmsg/sendmmsg01.c | 40 ++++++++++---- .../kernel/syscalls/sendmmsg/sendmmsg_var.h | 55 ++++++++----------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c index 37084102ee09..016bbc6813c4 100644 --- a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c +++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c @@ -14,7 +14,6 @@ #include "tst_test.h" #include "lapi/socket.h" #include "tst_safe_macros.h" - #include "sendmmsg_var.h" #define BUFSIZE 16 @@ -25,27 +24,48 @@ static int receive_sockfd; static struct mmsghdr *snd_msg, *rcv_msg; static struct iovec *snd1, *snd2, *rcv1, *rcv2; +static struct test_variants { + int (*receive)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, + unsigned int flags, void *timeout); + int (*send)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, + unsigned int flags); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .receive = libc_recvmmsg, .send = libc_sendmmsg, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + +#if (__NR_recvmmsg != __LTP__NR_INVALID_SYSCALL) + { .receive = sys_recvmmsg, .send = sys_sendmmsg, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_recvmmsg_time64 != __LTP__NR_INVALID_SYSCALL) + { .receive = sys_recvmmsg64, .send = sys_sendmmsg, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void run(void) { - struct timespec timeout; + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; int retval; - retval = do_sendmmsg(send_sockfd, snd_msg, VLEN, 0); + retval = tv->send(send_sockfd, snd_msg, VLEN, 0); if (retval < 0 || snd_msg[0].msg_len != 6 || snd_msg[1].msg_len != 6) { - tst_res(TFAIL|TTERRNO, "sendmmsg failed"); + tst_res(TFAIL|TTERRNO, "sendmmsg() failed"); return; } memset(rcv1->iov_base, 0, rcv1->iov_len); memset(rcv2->iov_base, 0, rcv2->iov_len); - timeout.tv_sec = 1; - timeout.tv_nsec = 0; + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 0); - retval = do_recvmmsg(receive_sockfd, rcv_msg, VLEN, 0, &timeout); + retval = tv->receive(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout)); if (retval == -1) { - tst_res(TFAIL | TTERRNO, "recvmmsg failed"); + tst_res(TFAIL | TTERRNO, "recvmmsg() failed"); return; } if (retval != 2) { @@ -96,7 +116,7 @@ static void setup(void) rcv_msg[1].msg_hdr.msg_iov = rcv2; rcv_msg[1].msg_hdr.msg_iovlen = 1; - test_info(); + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); } static void cleanup(void) @@ -111,7 +131,7 @@ static struct tst_test test = { .test_all = run, .setup = setup, .cleanup = cleanup, - .test_variants = TEST_VARIANTS, + .test_variants = ARRAY_SIZE(variants), .bufs = (struct tst_buffers []) { {&snd1, .iov_sizes = (int[]){3, 3, -1}}, {&snd2, .iov_sizes = (int[]){6, -1}}, diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h b/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h index f00cf056a747..a142b17f9718 100644 --- a/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h +++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h @@ -6,55 +6,46 @@ #ifndef SENDMMSG_VAR__ #define SENDMMSG_VAR__ +#include "tst_timer.h" #include "lapi/syscalls.h" -static int do_sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, - int flags) +static inline int libc_sendmmsg(int sockfd, struct mmsghdr *msgvec, + unsigned int vlen, unsigned int flags) { - switch (tst_variant) { - case 0: - return tst_syscall(__NR_sendmmsg, sockfd, msgvec, vlen, flags); - case 1: #ifdef HAVE_SENDMMSG - return sendmmsg(sockfd, msgvec, vlen, flags); + return sendmmsg(sockfd, msgvec, vlen, flags); #else - tst_brk(TCONF, "libc sendmmsg not present"); + tst_brk(TCONF, "libc sendmmsg not present"); #endif - } +} - return -1; +static inline int sys_sendmmsg(int sockfd, struct mmsghdr *msgvec, + unsigned int vlen, unsigned int flags) +{ + return tst_syscall(__NR_sendmmsg, sockfd, msgvec, vlen, flags); } -static int do_recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, - int flags, struct timespec *timeout) +static inline int libc_recvmmsg(int sockfd, struct mmsghdr *msgvec, + unsigned int vlen, unsigned int flags, void *timeout) { - switch (tst_variant) { - case 0: - return tst_syscall(__NR_recvmmsg, sockfd, msgvec, vlen, flags, - timeout); - case 1: #ifdef HAVE_RECVMMSG - return recvmmsg(sockfd, msgvec, vlen, flags, timeout); + return recvmmsg(sockfd, msgvec, vlen, flags, timeout); #else - tst_brk(TCONF, "libc recvmmsg not present"); + tst_brk(TCONF, "libc recvmmsg not present"); #endif - } - - return -1; } -static void test_info(void) +static inline int sys_recvmmsg(int sockfd, struct mmsghdr *msgvec, + unsigned int vlen, unsigned int flags, void *timeout) { - switch (tst_variant) { - case 0: - tst_res(TINFO, "Testing direct sendmmsg and recvmmsg syscalls"); - break; - case 1: - tst_res(TINFO, "Testing libc sendmmsg and recvmmsg syscalls"); - break; - } + return tst_syscall(__NR_recvmmsg, sockfd, msgvec, vlen, flags, timeout); } -#define TEST_VARIANTS 2 +static inline int sys_recvmmsg64(int sockfd, struct mmsghdr *msgvec, + unsigned int vlen, unsigned int flags, void *timeout) +{ + return tst_syscall(__NR_recvmmsg_time64, sockfd, msgvec, vlen, flags, + timeout); +} #endif /* SENDMMSG_VAR__ */ From patchwork Fri Jun 26 06:22:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317404 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=ibInWsR6; 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 49tRgs3yKRz9sRR for ; Fri, 26 Jun 2020 16:24:57 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0721D3C583C for ; Fri, 26 Jun 2020 08:24:55 +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 5432D3C5847 for ; Fri, 26 Jun 2020 08:23:15 +0200 (CEST) Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (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 59F17600B9E for ; Fri, 26 Jun 2020 08:22:19 +0200 (CEST) Received: by mail-pl1-x642.google.com with SMTP id j4so3903833plk.3 for ; Thu, 25 Jun 2020 23:23:14 -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=3LmMCyrOJvEaTuQXQmCs5s8dg/UO7OTfdi7lndvVZlw=; b=ibInWsR6rb3Y7sokXcLZeNz86M/GlIqYkGZjKYDfooyHi/JuUZRnh2apI5szoBMvSG 2rh4Nz5QYZ5Z92TPaP32PVK5UQdv8BC8WMfRbBUsofvc1X9syh7q+evBBJ7W2NToKC6U VZUiFzf1TYZ43DKotLGErGO6CsQ49zDYUJJE5RtsIMemMnaDOztJaQwkw3NyGkTUx2UY Ijz1DLSM2hS5al/Zb2dYs5v9UUqfYBOxpcXpHb7EysURPQc7AtOaEp/H37sdyIbA7NXD lpjdfJg9Kkq+Q7na5KZOQv16ADjuyrI2kgiSjdT7XlwA0EyxDEU6MOSFSbJWzFRetKpy oDVw== 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=3LmMCyrOJvEaTuQXQmCs5s8dg/UO7OTfdi7lndvVZlw=; b=cWBtERXKSz83LUAJdpYwdeomKeh3XRIEnNEGscqgIyOhZN2//YHm8Pe5xMxSDWCSM4 rrbr7eI1pzEt2qWUnm5Xv3szoRhS/2eqdsaebbY4v4PMeRSERK/ih6Dko0wHqm6LkZbj gqlCWrqle0dBXErtPL2tdqVPboH0KfKOdkooPBIh5ef4ISkJK2nryjZwzYTKgfsrRA3B /ey+Nlm2uohgNJ0qWYeHsdvEKV4O+UaM+eamDwvOt9yg/kSNgS9LsLFQekSuvWsyNTwq nKf3w/YoojTEGpNnTx9sPr3HRSdTOQRYQUcKYUAOA4u7bshKsLlsqgoleMeCxaH6Qo5v Y1uA== X-Gm-Message-State: AOAM532p165mimSM/oLpHqaqUnmP3zYMd4JVEEcPTKaCmR1pPdfinflX 6XakAVCqr+assZD/qNVKYiYzReq+RIY= X-Google-Smtp-Source: ABdhPJw2+K80JfXxcnQydN4qOpyykXKB4QUN1mXy+GxEn9pGQXifNwj3piePD9ODe3Rtccm6PtUPiQ== X-Received: by 2002:a17:90a:648b:: with SMTP id h11mr1714213pjj.59.1593152592703; Thu, 25 Jun 2020 23:23:12 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id o1sm10464619pja.49.2020.06.25.23.23.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:12 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:26 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 13/19] syscalls/ppoll: 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 ppoll() syscall tests. Note that the O_EXCL flag is removed from SAFE_OPEN() calls as it made the tests failed when run for the second variant as the file existed. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/ppoll/ppoll01.c | 71 ++++++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/testcases/kernel/syscalls/ppoll/ppoll01.c b/testcases/kernel/syscalls/ppoll/ppoll01.c index 2fadd0653948..a217254022d4 100644 --- a/testcases/kernel/syscalls/ppoll/ppoll01.c +++ b/testcases/kernel/syscalls/ppoll/ppoll01.c @@ -21,6 +21,7 @@ #include "ltp_signal.h" #include "tst_sig_proc.h" #include "tst_test.h" +#include "tst_timer.h" /* Older versions of glibc don't publish this constant's value. */ #ifndef POLLRDHUP @@ -38,7 +39,7 @@ struct test_case { unsigned int nfds; /* nfds ppoll parameter */ sigset_t *sigmask; /* sigmask ppoll parameter */ sigset_t *sigmask_cur; /* sigmask set for current process */ - struct timespec *ts; /* ts ppoll parameter */ + struct tst_ts *ts; /* ts ppoll parameter */ struct pollfd *fds; /* fds ppoll parameter */ int sigint_count; /* if > 0, spawn process to send SIGINT */ /* 'count' times to current process */ @@ -60,14 +61,7 @@ static int fd1 = -1; static sigset_t sigmask_empty, sigmask_sigint; static struct pollfd fds_good[1], fds_already_closed[1]; -static struct timespec ts_short = { - .tv_sec = 0, - .tv_nsec = 200000000, -}; -static struct timespec ts_long = { - .tv_sec = 2, - .tv_nsec = 0, -}; +static struct tst_ts ts_short, ts_long; /* Test cases * @@ -160,14 +154,53 @@ static struct test_case tcase[] = { }, }; +static inline int libc_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p, + const sigset_t *sigmask, size_t sigsetsize) +{ + return ppoll(fds, nfds, tmo_p, sigmask); +} + +static inline int sys_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p, + const sigset_t *sigmask, size_t sigsetsize) +{ + return tst_syscall(__NR_ppoll, fds, nfds, tmo_p, sigmask, sigsetsize); +} + +static inline int sys_ppoll_time64(struct pollfd *fds, nfds_t nfds, void *tmo_p, + const sigset_t *sigmask, size_t sigsetsize) +{ + return tst_syscall(__NR_ppoll_time64, fds, nfds, tmo_p, sigmask, + sigsetsize); +} + +static struct test_variants { + int (*ppoll)(struct pollfd *fds, nfds_t nfds, void *tmo_p, + const sigset_t *sigmask, size_t sigsetsize); + + enum tst_ts_type type; + char *desc; +} variants[] = { + { .ppoll = libc_ppoll, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"}, + +#if (__NR_ppoll != __LTP__NR_INVALID_SYSCALL) + { .ppoll = sys_ppoll, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_ppoll_time64 != __LTP__NR_INVALID_SYSCALL) + { .ppoll = sys_ppoll_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) { } static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; int fd2; + tst_res(TINFO, "Testing variant: %s", tv->desc); SAFE_SIGNAL(SIGINT, sighandler); if (sigemptyset(&sigmask_empty) == -1) @@ -177,18 +210,22 @@ static void setup(void) if (sigaddset(&sigmask_sigint, SIGINT) == -1) tst_brk(TBROK | TERRNO, "sigaddset"); - fd1 = SAFE_OPEN("testfile1", O_CREAT | O_EXCL | O_RDWR, - S_IRUSR | S_IWUSR); + fd1 = SAFE_OPEN("testfile1", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); fds_good[0].fd = fd1; fds_good[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP; fds_good[0].revents = 0; - fd2 = SAFE_OPEN("testfile2", O_CREAT | O_EXCL | O_RDWR, - S_IRUSR | S_IWUSR); + fd2 = SAFE_OPEN("testfile2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); fds_already_closed[0].fd = fd2; fds_already_closed[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP; fds_already_closed[0].revents = 0; SAFE_CLOSE(fd2); + + ts_short.type = ts_long.type = tv->type; + tst_ts_set_sec(&ts_short, 0); + tst_ts_set_nsec(&ts_short, 200000000); + tst_ts_set_sec(&ts_long, 2); + tst_ts_set_nsec(&ts_long, 0); } static void cleanup(void) @@ -199,10 +236,11 @@ static void cleanup(void) static void do_test(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; pid_t pid = 0; int sys_ret, sys_errno = 0, dummy; struct test_case *tc = &tcase[i]; - struct timespec ts, *tsp = NULL; + struct tst_ts ts, *tsp = NULL; if (tc->ts) { memcpy(&ts, tc->ts, sizeof(ts)); @@ -223,8 +261,8 @@ static void do_test(unsigned int i) /* test */ errno = 0; - sys_ret = tst_syscall(__NR_ppoll, tc->fds, tc->nfds, tsp, - tc->sigmask, SIGSETSIZE); + sys_ret = tv->ppoll(tc->fds, tc->nfds, tst_ts_get(tsp), tc->sigmask, + SIGSETSIZE); sys_errno = errno; /* cleanup */ @@ -261,6 +299,7 @@ static void do_test(unsigned int i) static struct tst_test test = { .tcnt = ARRAY_SIZE(tcase), .test = do_test, + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .forks_child = 1, From patchwork Fri Jun 26 06:22:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317405 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=f14P0Eiy; 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 49tRh35Gx7z9sRR for ; Fri, 26 Jun 2020 16:25:07 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 194FF3C2B6D for ; Fri, 26 Jun 2020 08:25:05 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 562DC3C5838 for ; Fri, 26 Jun 2020 08:23:18 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id B350E600666 for ; Fri, 26 Jun 2020 08:23:17 +0200 (CEST) Received: by mail-pl1-x643.google.com with SMTP id j4so3903882plk.3 for ; Thu, 25 Jun 2020 23:23:17 -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=UE4iMqTs4i9KzbJPU0Gcr5oWBJazrzy9VeoHPqXEgak=; b=f14P0EiymKCKihRVvNewv4fgmVcCGicIifnh6K5R7493wQMSjbsuRXpSILIhaKfXBj C8EiwhAkV6o9HBeWk4FftFko+XoF/AqKLRNU2HSE35j2btCXhCQ3S5a6e/cl05QM2+ep e55xV1AYD6NnnE/tjXNwOEI2x6ZQJEZUcdlUqpH9DFK0VPsGTYXftbOB3lP8Hfrrk6iA Spp7f3ZkNcp9k7NvMOQXiRuLeODHbcdbwLg/6xAQ98lZ0o2b7uXkwZZ6jnRFV7kf7Y5B c/0ZsuU5ermv2oe1EBWzPSG8d/+RVLDtVp1Yhk1bBChKLok0+GtueANafQTqYYNcnVUv JiAg== 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=UE4iMqTs4i9KzbJPU0Gcr5oWBJazrzy9VeoHPqXEgak=; b=H7nvoq3ig1P6ZqihY8ZrVq2kzxo06rX2yOuJgM/MXfAp+RPx0PJAn0JHZ1SK6hjPOM sHUJmQj/BuiXE5CFTpTgZdVKjh/GhHb14ISQj1n0pVd41qcuIQIflzM4PjFD3aKQVY82 qK0Ai1tivTyNRK74SOOmWXCOrNA7m9I1ry60bSxXLGUIUnyMjVeaZ4pFYfHvpSWLe+67 cbwFliyuoe/dag2Gs7vNXwwdbw2VVWHw24jgg+A9PD9VJKhsTHFRikPKWDZACtOrL49+ uzdkesjDytSGT5TpIWZ+fhXJiQIJEFJ7XUwmYdVoBG5U/3fx62tceTuUBkLalE784xpx tTNA== X-Gm-Message-State: AOAM5332AdegL53XMMtAfzWAZBKy4zizXcPcZTbuMX+/1N+2u63Zk2Td wVnjKMgWnnEc1xYuGMq5PODopd6TkXk= X-Google-Smtp-Source: ABdhPJyUjSPvFA0Yiu/VznOiFYvAUOnIc06efGhUBdThalfjYNMBiA5Ac7C4YanHF90QwOj/qgtiVg== X-Received: by 2002:a17:902:6ac1:: with SMTP id i1mr1380461plt.147.1593152595915; Thu, 25 Jun 2020 23:23:15 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id p12sm21609653pgk.40.2020.06.25.23.23.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:14 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:27 +0530 Message-Id: <883a188e83c201b23074bf0ac974b41d89d818c7.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.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-2.smtp.seeweb.it Subject: [LTP] [PATCH V7 14/19] syscalls/select6: 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 select6() syscall tests. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/select/select_var.h | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/select/select_var.h b/testcases/kernel/syscalls/select/select_var.h index b19a1d1bf085..2c7604807cf6 100644 --- a/testcases/kernel/syscalls/select/select_var.h +++ b/testcases/kernel/syscalls/select/select_var.h @@ -6,6 +6,7 @@ #define SELECT_VAR__ #include "lapi/syscalls.h" +#include "tst_timer.h" struct compat_sel_arg_struct { long _n; @@ -38,7 +39,7 @@ static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *except } case 2: { int ret; - struct timespec ts = { + struct __kernel_old_timespec ts = { .tv_sec = timeout->tv_sec, .tv_nsec = timeout->tv_usec * 1000, }; @@ -47,7 +48,22 @@ static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *except timeout->tv_usec = ts.tv_nsec / 1000; return ret; } - case 3: + case 3: { + int ret = 0; +#if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL) + struct __kernel_timespec ts = { + .tv_sec = timeout->tv_sec, + .tv_nsec = timeout->tv_usec * 1000, + }; + ret = tst_syscall(__NR_pselect6_time64, nfds, readfds, writefds, exceptfds, &ts, NULL); + timeout->tv_sec = ts.tv_sec; + timeout->tv_usec = ts.tv_nsec / 1000; +#else + tst_brk(TCONF, "__NR_pselect6 time64 variant not supported"); +#endif + return ret; + } + case 4: #ifdef __NR__newselect return tst_syscall(__NR__newselect, nfds, readfds, writefds, exceptfds, timeout); #else @@ -72,11 +88,14 @@ static void select_info(void) tst_res(TINFO, "Testing SYS_pselect6 syscall"); break; case 3: + tst_res(TINFO, "Testing SYS_pselect6 time64 syscall"); + break; + case 4: tst_res(TINFO, "Testing SYS__newselect syscall"); break; } } -#define TEST_VARIANTS 4 +#define TEST_VARIANTS 5 #endif /* SELECT_VAR__ */ From patchwork Fri Jun 26 06:22:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317406 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=YzlRCDjc; 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 49tRhD4dvYz9sSc for ; Fri, 26 Jun 2020 16:25:16 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BE7913C5842 for ; Fri, 26 Jun 2020 08:25:13 +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 7F7083C2B6A for ; Fri, 26 Jun 2020 08:23:22 +0200 (CEST) Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 BC455600BAF for ; Fri, 26 Jun 2020 08:22:25 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id q90so3773797pjh.3 for ; Thu, 25 Jun 2020 23:23:20 -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=x3a/LTiLnXGCj2nwQHh0OLRoeQqI2oYeRw47lEHoc+4=; b=YzlRCDjcTU/nbbIvOiCwarG6b4PIRXaC+AaOQX6rJ+KTnZ8AlN4GdNUmq4x8bdYDwv fQkjW3IZ6aaK3w1cfrFsEVN7YEDHvdNA80ZjyoXA2bxVxkmidd+Z1jKdk9Y5dqc/5mV0 DybAkAg6dumVM0/M0orflDQAjV78+8PrYZwAdhBHGmxxHRh8Hb505/vOv8NQ+PMwJicQ T6MJuDGkvjAv+L2F1kui76QP/vehWB/lSc0macd6m3TjUyoq4QV7F4CTG97scq2k+lcT ue1MEFiHGsURiFY52rbQYHt7Gqn+N017q/vrR0pEPz6UyCDjSBbclqV/thVy3j38u02S Mnwg== 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=x3a/LTiLnXGCj2nwQHh0OLRoeQqI2oYeRw47lEHoc+4=; b=cuSbMTkxQhIg4n7h5elqIqTb+G1wVhsbZZ3GU/SJmKPaKl4TSWLTVQnJ7QK8YbxBxC fi1muyWp1K7QnAQtUpZ0/lmQQBVaqYjWhLoccyefNveCjeBS26w4OfrjBC8xiHlYFhYt eBrppdncbDIR5sGlG8dOsHmFpdpauQ9Iz7q1sG0WhpsAmgF5+LHWuF/7koTYKLsLvLEd /yot8xmrOjDEERV4D0/0oHbJc8fuoagJeHTK3AW2muLQX8MhOdQ+oqcC+JyOXtJN6hrd is8SK6lgD4WIwaM4675b6u5Pg9phtQvr1kDwafjbO5q8Ibh3xrRDA2G5WOgkvkUjvDbj zprA== X-Gm-Message-State: AOAM530NGaNshQnm6X3xjmhZrm3neVZybPe2RWeYcQ7tE6VT6E/SQ8zO XdZwQFTQERqgimiEjPq54JIIWKL2EF8= X-Google-Smtp-Source: ABdhPJytYy2StELw3AlghmsnHD3ejnMxRC7i0qwd5TAiTJSNXjXm9ecTJ0FrgcKQ/rsNbutWEUdMGQ== X-Received: by 2002:a17:90a:ff0c:: with SMTP id ce12mr995971pjb.100.1593152598705; Thu, 25 Jun 2020 23:23:18 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id v9sm24788671pfe.198.2020.06.25.23.23.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:18 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:28 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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,T_FILL_THIS_FORM_SHORT 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 V7 15/19] syscalls/semop: Migrate to new test framework 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 migrates the semop tests to the new test framework. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/ipc/semop/Makefile | 4 +- testcases/kernel/syscalls/ipc/semop/semop01.c | 140 ++++---- testcases/kernel/syscalls/ipc/semop/semop02.c | 145 +++------ testcases/kernel/syscalls/ipc/semop/semop03.c | 150 +++------ testcases/kernel/syscalls/ipc/semop/semop04.c | 165 ++++------ testcases/kernel/syscalls/ipc/semop/semop05.c | 303 ++++++++---------- 6 files changed, 348 insertions(+), 559 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semop/Makefile b/testcases/kernel/syscalls/ipc/semop/Makefile index f62cd1f481d9..a11cbcf2e699 100644 --- a/testcases/kernel/syscalls/ipc/semop/Makefile +++ b/testcases/kernel/syscalls/ipc/semop/Makefile @@ -3,10 +3,10 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -LDLIBS += -lltpipc +LDLIBS += -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semop/semop01.c b/testcases/kernel/syscalls/ipc/semop/semop01.c index ea05c53eb919..bcb45fa69320 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop01.c +++ b/testcases/kernel/syscalls/ipc/semop/semop01.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -52,92 +36,73 @@ * none */ -#include "ipcsem.h" +#include +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" #define NSEMS 4 /* the number of primitive semaphores to test */ -char *TCID = "semop01"; -int TST_TOTAL = 1; - -int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ +static int sem_id = -1; /* a semaphore set with read & alter permissions */ +static key_t semkey; -union semun get_arr; -struct sembuf sops[PSEMS]; +static union semun get_arr; +static struct sembuf sops[PSEMS]; -int main(int ac, char **av) +static void run(void) { - int lc; - int i; + union semun arr = { .val = 0 }; int fail = 0; + int i; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - TEST(semop(sem_id_1, sops, NSEMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "%s call failed - errno = %d : %s", - TCID, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - /* get the values and make sure they */ - /* are the same as what was set */ - if (semctl(sem_id_1, 0, GETALL, get_arr) == -1) { - tst_brkm(TBROK, cleanup, - "semctl() failed in functional test"); - } - - for (i = 0; i < NSEMS; i++) { - if (get_arr.array[i] != i * i) { - fail = 1; - } - } - if (fail) - tst_resm(TFAIL, - "semaphore values are wrong"); - else - tst_resm(TPASS, - "semaphore values are correct"); - } + TEST(semop(sem_id, sops, NSEMS)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "semop() failed"); + } else { /* - * clean up things in case we are looping + * Get the values and make sure they are the same as what was + * set */ - union semun set_arr; - set_arr.val = 0; + if (semctl(sem_id, 0, GETALL, get_arr) == -1) { + tst_brk(TBROK | TERRNO, "semctl() failed in functional test"); + } + for (i = 0; i < NSEMS; i++) { - if (semctl(sem_id_1, i, SETVAL, set_arr) == -1) { - tst_brkm(TBROK, cleanup, "semctl failed"); + if (get_arr.array[i] != i * i) { + fail = 1; } } + if (fail) + tst_res(TFAIL | TERRNO, "semaphore values are wrong"); + else + tst_res(TPASS, "semaphore values are correct"); } - cleanup(); - tst_exit(); + /* + * clean up things in case we are looping + */ + for (i = 0; i < NSEMS; i++) { + if (semctl(sem_id, i, SETVAL, arr) == -1) { + tst_brk(TBROK | TERRNO, "semctl failed"); + } + } } -void setup(void) +static void setup(void) { int i; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - get_arr.array = malloc(sizeof(unsigned short int) * PSEMS); if (get_arr.array == NULL) - tst_brkm(TBROK, cleanup, "malloc failed"); + tst_brk(TBROK, "malloc failed"); - semkey = getipckey(); + semkey = GETIPCKEY(); - sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); - if (sem_id_1 == -1) - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); + if (sem_id == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); for (i = 0; i < NSEMS; i++) { sops[i].sem_num = i; @@ -146,11 +111,20 @@ void setup(void) } } -void cleanup(void) +static void cleanup(void) { - rm_sema(sem_id_1); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } free(get_arr.array); - - tst_rmdir(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index f067229b1cf5..f24d284776a4 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * DESCRIPTION @@ -31,30 +15,27 @@ #define _GNU_SOURCE #include -#include "test.h" -#include "safe_macros.h" -#include "ipcsem.h" - -char *TCID = "semop02"; - -static void semop_verify(int i); -int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ -int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ -int bad_id = -1; - -struct sembuf s_buf[PSEMS]; - -int badbuf = -1; +#include +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" + +static int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ +static int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ +static int bad_id = -1; +static key_t semkey; +static struct sembuf s_buf[PSEMS]; #define NSOPS 5 /* a resonable number of operations */ #define BIGOPS 1024 /* a value that is too large for the number */ /* of semop operations that are permitted */ -struct test_case_t { +static struct test_case_t { int *semid; struct sembuf *t_sbuf; unsigned t_ops; int error; -} TC[] = { +} tc[] = { {&sem_id_1, (struct sembuf *)&s_buf, BIGOPS, E2BIG}, {&sem_id_2, (struct sembuf *)&s_buf, NSOPS, EACCES}, {&sem_id_1, (struct sembuf *)-1, NSOPS, EFAULT}, @@ -63,29 +44,7 @@ struct test_case_t { {&sem_id_1, (struct sembuf *)&s_buf, 1, ERANGE} }; -int TST_TOTAL = ARRAY_SIZE(TC); - -int main(int ac, char **av) -{ - int lc; - int 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++) - semop_verify(i); - } - - cleanup(); - tst_exit(); -} - -void setup(void) +static void setup(void) { char nobody_uid[] = "nobody"; struct passwd *ltpuser; @@ -93,71 +52,73 @@ void setup(void) struct seminfo ipc_buf; union semun arr; - tst_require_root(); - - ltpuser = SAFE_GETPWNAM(NULL, nobody_uid); - SAFE_SETUID(NULL, ltpuser->pw_uid); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); + ltpuser = SAFE_GETPWNAM(nobody_uid); + SAFE_SETUID(ltpuser->pw_uid); /* get an IPC resource key */ - semkey = getipckey(); + semkey = GETIPCKEY(); /* create a semaphore set with read and alter permissions */ sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); - if (sem_id_1 == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "couldn't create semaphore in setup"); - } + if (sem_id_1 == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); /* Get an new IPC resource key. */ - semkey2 = getipckey(); + semkey2 = GETIPCKEY(); /* create a semaphore set without read and alter permissions */ sem_id_2 = semget(semkey2, PSEMS, IPC_CREAT | IPC_EXCL); - if (sem_id_2 == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "couldn't create semaphore in setup"); - } + if (sem_id_2 == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); arr.__buf = &ipc_buf; if (semctl(sem_id_1, 0, IPC_INFO, arr) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "semctl() IPC_INFO failed"); + tst_brk(TBROK | TERRNO, "semctl() IPC_INFO failed"); /* for ERANGE errno test */ arr.val = 1; s_buf[0].sem_op = ipc_buf.semvmx; if (semctl(sem_id_1, 0, SETVAL, arr) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "semctl() SETVAL failed"); + tst_brk(TBROK | TERRNO, "semctl() SETVAL failed"); } -static void semop_verify(int i) +static void run(unsigned int i) { - TEST(semop(*(TC[i].semid), TC[i].t_sbuf, TC[i].t_ops)); + TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + if (TST_RET != -1) { + tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); return; } - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS | TTERRNO, "semop failed as expected"); + if (TST_ERR == tc[i].error) { + tst_res(TPASS | TTERRNO, "semop failed as expected"); } else { - tst_resm(TFAIL | TTERRNO, + tst_res(TFAIL | TTERRNO, "semop failed unexpectedly; expected: " - "%d - %s", TC[i].error, strerror(TC[i].error)); + "%d - %s", tc[i].error, strerror(tc[i].error)); } } -void cleanup(void) +static void cleanup(void) { - /* if they exist, remove the semaphore resources */ - rm_sema(sem_id_1); - rm_sema(sem_id_2); + union semun arr; - tst_rmdir(); + if (sem_id_1 != -1) { + if (semctl(sem_id_1, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } + if (sem_id_2 != -1) { + if (semctl(sem_id_2, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c index 9c1c58202ad3..4f5f78eb6d8d 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ b/testcases/kernel/syscalls/ipc/semop/semop03.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -50,109 +34,75 @@ * none */ -#include "ipcsem.h" - -char *TCID = "semop03"; -int TST_TOTAL = 2; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -int sem_id_1 = -1; +static key_t semkey; +static int sem_id = -1; +static struct sembuf s_buf; -struct sembuf s_buf; +static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas */ -int TC[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas */ - -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - /* initialize two fields in the sembuf structure here */ s_buf.sem_op = 1; /* add this value to struct sem.semval */ s_buf.sem_flg = SEM_UNDO; /* undo when process exits */ - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the last field in the sembuf */ - /* structure to the test dependent value */ - s_buf.sem_num = TC[i]; - - /* - * use the TEST macro to make the call - */ + /* + * initialize the last field in the sembuf structure to the test + * dependent value. + */ + s_buf.sem_num = tc[i]; - TEST(semop(sem_id_1, &s_buf, 1)); + /* + * use the TEST macro to make the call + */ - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } + TEST(semop(sem_id, &s_buf, 1)); - switch (TEST_ERRNO) { - case EFBIG: - tst_resm(TPASS, "expected failure - errno = " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - break; - } - } + if (TST_RET != -1) { + tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); + return; } - cleanup(); - - tst_exit(); + switch (TST_ERR) { + case EFBIG: + tst_res(TPASS | TTERRNO, "expected failure"); + break; + default: + tst_res(TFAIL | TTERRNO, "unexpected failure"); + break; + } } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. - */ - tst_tmpdir(); - /* get an IPC resource key */ - semkey = getipckey(); + semkey = GETIPCKEY(); /* create a semaphore with read and alter permissions */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); - } + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c index c1fa2eba7584..0faf00a3585f 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ b/testcases/kernel/syscalls/ipc/semop/semop04.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -50,22 +34,24 @@ * none */ -#include "ipcsem.h" - -char *TCID = "semop04"; -int TST_TOTAL = 2; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -int sem_id_1 = -1; +static int sem_id = -1; +static int val; /* value for SETVAL */ -struct sembuf s_buf; +static key_t semkey; +static struct sembuf s_buf; -struct test_case_t { +static struct test_case_t { union semun get_arr; short op; short flg; short num; int error; -} TC[] = { +} tc[] = { /* EAGAIN sem_op = 0 */ { { 1}, 0, IPC_NOWAIT, 2, EAGAIN}, @@ -74,104 +60,61 @@ struct test_case_t { 0}, -1, IPC_NOWAIT, 2, EAGAIN} }; -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - int val; /* value for SETVAL */ - - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - val = 1; - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; - - /* initialize all the primitive semaphores */ - TC[i].get_arr.val = val--; - if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].get_arr) - == -1) { - tst_brkm(TBROK, cleanup, "semctl() failed"); - } - - /* - * make the call with the TEST macro - */ - - TEST(semop(sem_id_1, &s_buf, 1)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, - "expected failure - errno = %d" - " : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } - } + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; + + /* initialize all the primitive semaphores */ + tc[i].get_arr.val = val--; + if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1) + tst_brk(TBROK | TERRNO, "semctl() failed"); + + TEST(semop(sem_id, &s_buf, 1)); + if (TST_RET != -1) { + tst_res(TFAIL, "call succeeded unexpectedly"); + return; } - cleanup(); - - tst_exit(); + if (TST_ERR == tc[i].error) + tst_res(TPASS | TTERRNO, "expected failure"); + else + tst_res(TFAIL | TTERRNO, "unexpected failure"); } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { + val = 1; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + /* get an IPC resource key */ + semkey = GETIPCKEY(); /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. + * create a semaphore set with read and alter permissions and PSEMS + * "primitive" semaphores. */ - tst_tmpdir(); - - /* get an IPC resource key */ - semkey = getipckey(); - - /* create a semaphore set with read and alter permissions */ - /* and PSEMS "primitive" semaphores */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) { + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); } } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop05.c index e97ad42fe01d..9e8e040b0b19 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop05.c +++ b/testcases/kernel/syscalls/ipc/semop/semop05.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -60,18 +44,18 @@ * none */ -#include "ipcsem.h" - +#include +#include #include #include -#include "safe_macros.h" - -char *TCID = "semop05"; -int TST_TOTAL = 4; - -int sem_id_1 = -1; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -struct sembuf s_buf; +static key_t semkey; +static int sem_id = -1; +static struct sembuf s_buf; struct test_case_t { union semun semunptr; @@ -79,7 +63,7 @@ struct test_case_t { short flg; short num; int error; -} TC[] = { +} tc[] = { /* EIRDM sem_op = 0 */ { { 1}, 0, 0, 2, EIDRM}, @@ -96,189 +80,166 @@ struct test_case_t { #ifdef UCLINUX #define PIPE_NAME "semop05" -void do_child_uclinux(); +static void do_child_uclinux(); static int i_uclinux; #endif -int main(int ac, char **av) +static inline int process_state_wait2(pid_t pid, const char state) { - int lc; - int i; - pid_t pid; - void do_child(); + char proc_path[128], cur_state; - tst_parse_opts(ac, av, NULL, NULL); + snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid); -#ifdef UCLINUX - maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1); -#endif - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; - - /* initialize all of the primitive semaphores */ - if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr) - == -1) { - tst_brkm(TBROK, cleanup, "semctl() failed"); - } - - if ((pid = FORK_OR_VFORK()) == -1) { - tst_brkm(TBROK, cleanup, "could not fork"); - } - - if (pid == 0) { /* child */ + for (;;) { + FILE *f = fopen(proc_path, "r"); + if (!f) { + tst_res(TFAIL, "Failed to open '%s': %s\n", proc_path, + strerror(errno)); + return 1; + } -#ifdef UCLINUX - if (self_exec(av[0], "dd", i, sem_id_1) < 0) { - tst_brkm(TBROK, cleanup, - "could not self_exec"); - } -#else - do_child(i); -#endif - } else { - TST_PROCESS_STATE_WAIT(cleanup, pid, 'S'); - - /* - * If we are testing for EIDRM then remove - * the semaphore, else send a signal that - * must be caught as we are testing for - * EINTR. - */ - if (TC[i].error == EIDRM) { - /* remove the semaphore resource */ - rm_sema(sem_id_1); - } else { - SAFE_KILL(cleanup, pid, SIGHUP); - } - - /* let the child carry on */ - waitpid(pid, NULL, 0); - } - - /* - * recreate the semaphore resource if needed - */ - if (TC[i].error == EINTR) { - continue; - } - - if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | - IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't recreate " - "semaphore"); - } + if (fscanf(f, "%*i %*s %c", &cur_state) != 1) { + fclose(f); + tst_res(TFAIL, "Failed to read '%s': %s\n", proc_path, + strerror(errno)); + return 1; } - } + fclose(f); - cleanup(); + if (state == cur_state) + return 0; - tst_exit(); + usleep(10000); + } } -/* - * do_child() - */ -void do_child(int i) +static void do_child(int i) { - /* - * make the call with the TEST macro - */ - - TEST(semop(sem_id_1, &s_buf, 1)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded when error expected"); + TEST(semop(sem_id, &s_buf, 1)); + if (TST_RET != -1) { + tst_res(TFAIL, "call succeeded when error expected"); exit(-1); } - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, "expected failure - errno = %d" - " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - } + if (TST_ERR == tc[i].error) + tst_res(TPASS | TTERRNO, "expected failure"); + else + tst_res(TFAIL | TTERRNO, "unexpected failure"); exit(0); } -void sighandler(int sig) +static void sighandler(int sig) { - if (sig == SIGHUP) - return; - else - tst_brkm(TBROK, NULL, "unexpected signal %d received", sig); + if (sig != SIGHUP) + tst_brk(TBROK, "unexpected signal %d received", sig); } -#ifdef UCLINUX -/* - * do_child_uclinux() - capture signals, re-initialize s_buf then call do_child - * with the appropriate argument - */ -void do_child_uclinux(void) +static void setup(void) { - int i = i_uclinux; + SAFE_SIGNAL(SIGHUP, sighandler); - tst_sig(FORK, sighandler, cleanup); + /* get an IPC resource key */ + semkey = GETIPCKEY(); - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; + /* + * create a semaphore set with read and alter permissions and PSEMS + * "primitive" semaphores. + */ + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); +} - do_child(i); +static void cleanup(void) +{ + union semun arr; + + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } -#endif -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void run(unsigned int i) { + pid_t pid; - tst_sig(FORK, sighandler, cleanup); +#ifdef UCLINUX + maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id); +#endif + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; - TEST_PAUSE; + /* initialize all of the primitive semaphores */ + if (semctl(sem_id, tc[i].num, SETVAL, tc[i].semunptr) == -1) + tst_brk(TBROK | TERRNO, "semctl() failed"); - /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. - */ - tst_tmpdir(); + pid = SAFE_FORK(); - /* get an IPC resource key */ - semkey = getipckey(); + if (pid == 0) { /* child */ +#ifdef UCLINUX + if (self_exec(av[0], "dd", i, sem_id) < 0) + tst_brk(TBROK, "could not self_exec"); +#else + do_child(i); +#endif + } else { + process_state_wait2(pid, 'S'); + + /* + * If we are testing for EIDRM then remove + * the semaphore, else send a signal that + * must be caught as we are testing for + * EINTR. + */ + if (tc[i].error == EIDRM) { + /* remove the semaphore resource */ + cleanup(); + } else { + SAFE_KILL(pid, SIGHUP); + } - /* create a semaphore set with read and alter permissions */ - /* and PSEMS "primitive" semaphores */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + /* let the child carry on */ + waitpid(pid, NULL, 0); } + + /* + * recreate the semaphore resource if needed + */ + if (tc[i].error == EINTR) + return; + + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't recreate semaphore"); } +#ifdef UCLINUX /* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. + * do_child_uclinux() - capture signals, re-initialize s_buf then call do_child + * with the appropriate argument */ -void cleanup(void) +static void do_child_uclinux(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); + int i = i_uclinux; + + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; - tst_rmdir(); + do_child(i); } +#endif + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .forks_child = 1, +}; From patchwork Fri Jun 26 06:22:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317407 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=HLT2dQnN; 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 49tRhS4fdjz9sRR for ; Fri, 26 Jun 2020 16:25:28 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DA7523C5850 for ; Fri, 26 Jun 2020 08:25:25 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 060123C583F for ; Fri, 26 Jun 2020 08:23:24 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id EEF6D2010EF for ; Fri, 26 Jun 2020 08:23:23 +0200 (CEST) Received: by mail-pl1-x643.google.com with SMTP id x8so3003782plm.10 for ; Thu, 25 Jun 2020 23:23:23 -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=/umuoG1hqIRFFmgoQJqYphcG+TLUaqxCgGZnYyatyK0=; b=HLT2dQnNJlowFJwr1kZBEgeMUNuXfBfy0SlbrhBeBwC8HOV3dT7wLkrSi7p9iMuIwU j3TnVVy073YaTZNAan57LY00NPyD3EVEicTEL7Hsb81XAbbv2PvDagH2SLYnvKTheajX rYQK2PH+3NbjLmT+s6tXxvGmuIKb5bfWTfCH7zBzYN3INAgJP/ujN2hiad1zcpanXHS7 ZpQvMp6lHlGwUkEvUJ8MOEHYPyXtipNv+twSeimvuc7OMVtpJmJok8o/VvJZTJSTMHEk RGudsrcBRSYp4503ejpK7ztWZ+QxCz9gdX/eLoE10h2DdoQ4XBGyVgFCvxqi0faVp6h6 ES1g== 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=/umuoG1hqIRFFmgoQJqYphcG+TLUaqxCgGZnYyatyK0=; b=gZA6UFGOXWXKup3fbZlrxTs4AIC+UoX0wmZerJ6adUhpA7wbM179esaZEui2D4ySTt 6BoPuApuG6wprOeRNhpj29vpEZutjMOgtK9vAfrJ/WDOhT/OTm5aSSVQA8Df5WI0CeLX XjabfOIUW8u7xDSQzsmRaogOwk9uSmDKvZHhZSyT1+sRm9xHQPqKtVV55+DqHhIqKlgE v206yOt3zSiiQyRUB/jBCDkUpqO5Bb85IhssxAzK7bCuTStp3/dWhKswZionzaIAyWR6 Wi7yY/QFK4DI2f+Z7W8Q8+0lEWJt6hWRt41RJlz+EqN2UXk4QImhHSSl67C7Q8Bd6kfz 3HWw== X-Gm-Message-State: AOAM53062Cb5iyfa+HEtForvBXTYVeW7JoWqz7kijFafbENMl/jF7kkN usysb6G1iPna5dQAv06s+MMhLPWy5jU= X-Google-Smtp-Source: ABdhPJwIM9yXVRzjsMTuC6bbsTOShapjxUc6cOyUPbkdBJxW8ByEHVcKFgd0Cyz9y6I27GMMCgDZzw== X-Received: by 2002:a17:90a:e08f:: with SMTP id q15mr1906147pjy.178.1593152601591; Thu, 25 Jun 2020 23:23:21 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id z5sm4809849pfb.1.2020.06.25.23.23.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:20 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:29 +0530 Message-Id: <89b2cbc1c97030026d0eb71112cce293a23675c2.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Subject: [LTP] [PATCH V7 16/19] syscalls/semtimedop: Add support for semtimedop and its time64 version 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 semtimedop() and its time64 variant to the existing semop() syscall tests. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/ipc/semop/semop.h | 55 +++++++++++++++++++ testcases/kernel/syscalls/ipc/semop/semop01.c | 14 ++++- testcases/kernel/syscalls/ipc/semop/semop02.c | 15 ++++- testcases/kernel/syscalls/ipc/semop/semop03.c | 16 +++++- testcases/kernel/syscalls/ipc/semop/semop04.c | 16 +++++- testcases/kernel/syscalls/ipc/semop/semop05.c | 16 +++++- 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h diff --git a/testcases/kernel/syscalls/ipc/semop/semop.h b/testcases/kernel/syscalls/ipc/semop/semop.h new file mode 100644 index 000000000000..584d12c68e0d --- /dev/null +++ b/testcases/kernel/syscalls/ipc/semop/semop.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef SEMOP_VAR__ +#define SEMOP_VAR__ + +#include +#include "tst_timer.h" + +static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops, + void *timeout) +{ + return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout); +} + +static inline int sys_semtimedop_time64(int semid, struct sembuf *sops, + size_t nsops, void *timeout) +{ + return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout); +} + +struct test_variants { + int (*semop)(int semid, struct sembuf *sops, size_t nsops); + int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"}, + +#if (__NR_semtimedop != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with old kernel spec"}, +#endif + +#if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec"}, +#endif +}; + +static inline int call_semop(struct test_variants *tv, int semid, + struct sembuf *sops, size_t nsops, struct tst_ts *timeout) +{ + if (tv->semop) + return tv->semop(semid, sops, nsops); + + return tv->semtimedop(semid, sops, nsops, tst_ts_get(timeout)); +} + +static inline void semop_supported_by_kernel(struct test_variants *tv) +{ + /* Check if the syscall is implemented on the platform */ + TEST(call_semop(tv, 0, NULL, 0, NULL)); + if (TST_RET == -1 && TST_ERR == ENOSYS) + tst_brk(TCONF, "Test not supported on kernel/platform"); +} + +#endif /* SEMOP_VAR__ */ diff --git a/testcases/kernel/syscalls/ipc/semop/semop01.c b/testcases/kernel/syscalls/ipc/semop/semop01.c index bcb45fa69320..7947183c837b 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop01.c +++ b/testcases/kernel/syscalls/ipc/semop/semop01.c @@ -41,6 +41,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" #define NSEMS 4 /* the number of primitive semaphores to test */ @@ -52,11 +53,17 @@ static struct sembuf sops[PSEMS]; static void run(void) { + struct test_variants *tv = &variants[tst_variant]; union semun arr = { .val = 0 }; + struct tst_ts timeout; int fail = 0; int i; - TEST(semop(sem_id, sops, NSEMS)); + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + + TEST(call_semop(tv, sem_id, sops, NSEMS, &timeout)); if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "semop() failed"); @@ -92,8 +99,12 @@ static void run(void) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; int i; + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + get_arr.array = malloc(sizeof(unsigned short int) * PSEMS); if (get_arr.array == NULL) tst_brk(TBROK, "malloc failed"); @@ -124,6 +135,7 @@ static void cleanup(void) static struct tst_test test = { .test_all = run, + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index f24d284776a4..4ffb9dd72c1c 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -20,6 +20,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ static int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ @@ -46,12 +47,16 @@ static struct test_case_t { static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; char nobody_uid[] = "nobody"; struct passwd *ltpuser; key_t semkey2; struct seminfo ipc_buf; union semun arr; + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + ltpuser = SAFE_GETPWNAM(nobody_uid); SAFE_SETUID(ltpuser->pw_uid); @@ -84,7 +89,14 @@ static void setup(void) static void run(unsigned int i) { - TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops)); + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + + TEST(call_semop(tv, *(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops, &timeout)); if (TST_RET != -1) { tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); @@ -117,6 +129,7 @@ static void cleanup(void) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c index 4f5f78eb6d8d..40a6b095c57d 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ b/testcases/kernel/syscalls/ipc/semop/semop03.c @@ -38,6 +38,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static key_t semkey; static int sem_id = -1; @@ -47,6 +48,13 @@ static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + /* initialize two fields in the sembuf structure here */ s_buf.sem_op = 1; /* add this value to struct sem.semval */ s_buf.sem_flg = SEM_UNDO; /* undo when process exits */ @@ -61,7 +69,7 @@ static void run(unsigned int i) * use the TEST macro to make the call */ - TEST(semop(sem_id, &s_buf, 1)); + TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout)); if (TST_RET != -1) { tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); @@ -80,6 +88,11 @@ static void run(unsigned int i) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + /* get an IPC resource key */ semkey = GETIPCKEY(); @@ -102,6 +115,7 @@ static void cleanup(void) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c index 0faf00a3585f..5e4bfeb625e2 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ b/testcases/kernel/syscalls/ipc/semop/semop04.c @@ -38,6 +38,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static int sem_id = -1; static int val; /* value for SETVAL */ @@ -62,6 +63,13 @@ static struct test_case_t { static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + /* initialize the s_buf buffer */ s_buf.sem_op = tc[i].op; s_buf.sem_flg = tc[i].flg; @@ -72,7 +80,7 @@ static void run(unsigned int i) if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1) tst_brk(TBROK | TERRNO, "semctl() failed"); - TEST(semop(sem_id, &s_buf, 1)); + TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout)); if (TST_RET != -1) { tst_res(TFAIL, "call succeeded unexpectedly"); return; @@ -86,6 +94,11 @@ static void run(unsigned int i) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + val = 1; /* get an IPC resource key */ @@ -114,6 +127,7 @@ static void cleanup(void) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop05.c index 9e8e040b0b19..770646bc564c 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop05.c +++ b/testcases/kernel/syscalls/ipc/semop/semop05.c @@ -52,6 +52,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static key_t semkey; static int sem_id = -1; @@ -115,7 +116,14 @@ static inline int process_state_wait2(pid_t pid, const char state) static void do_child(int i) { - TEST(semop(sem_id, &s_buf, 1)); + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + + TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout)); if (TST_RET != -1) { tst_res(TFAIL, "call succeeded when error expected"); exit(-1); @@ -137,6 +145,11 @@ static void sighandler(int sig) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + SAFE_SIGNAL(SIGHUP, sighandler); /* get an IPC resource key */ @@ -238,6 +251,7 @@ static void do_child_uclinux(void) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, From patchwork Fri Jun 26 06:22:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317408 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=RUJlTt+x; 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 49tRhd34N2z9sRR for ; Fri, 26 Jun 2020 16:25:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C82213C176D for ; Fri, 26 Jun 2020 08:25:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 29C443C583C for ; Fri, 26 Jun 2020 08:23:29 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id 5511C1000D33 for ; Fri, 26 Jun 2020 08:23:27 +0200 (CEST) Received: by mail-pj1-x1044.google.com with SMTP id q90so3773892pjh.3 for ; Thu, 25 Jun 2020 23:23:27 -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=taIwybofKHdLPWVe9G7+6Gmg0wdFgFQ0pqLw/AkdTGU=; b=RUJlTt+xLCGtGqYs6RgPc1TgHN1yn6E276HJL0fREEfiz4LGEU34iPySj1JlSMR6N2 wpUcIpp/HaCnbfNCeJwRu58WgddV7hybQiOxvzgPnXFwbcagTQiqPx1kl7mN3OzScKQv OGc6ShZSOWzaROj9v0tTL83oSgH4J8YLb1sxQHYaMC2jUUEymu95XVnkZBtp6MAWAsXV EbQM51ImsfMYq2eax9/jzRBtBiybg8Sx5pO0ppMeZ02Lvv/L0JGqE63zWxdbEGaHOp5j WA4SNBrhgrA9EuIPS/5vBrvvka7EzJJKRcnzeRh4B8n5yBd5x4TAmYPSUrKKAXCXcP28 oB2Q== 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=taIwybofKHdLPWVe9G7+6Gmg0wdFgFQ0pqLw/AkdTGU=; b=U89RkUrLdfRO7p9VD9W+tTkH3ZQJten1k4WLFd26yuAUZvNUxEKlvTa5D4aBNqz9ih mYwD/iOzDEIkBRSKxrV2NUzFqLikBVs+NXU4qQH3/EL7Yt32TANNqV57obGXppBZou0l aa5IavQaz8A48XWn547Nguu5qdoZ0vMCF+vtoZHVmN38dXftqWTHmCvs2vwS4D/L875Q 1BCL/qNAkBriy70+7WJvrI6VsP5qBxfNof0ALGRqpKwuiltXFq1egArixH151JkStykz a/NXFOzLptjF/GN21QBttEtFzhG2CQ+t8BhFMOBW6aZokrxln/h7fRPPWU4ngIEqAeXM ji/g== X-Gm-Message-State: AOAM533gMK81gZdsuwndZyDICiJzMswJKn4j921Nnxy0uCRArQTzaF3c Q6BuKkeOKt8vIyTuxmJkm9Vwi4IQ0Ss= X-Google-Smtp-Source: ABdhPJxgUeIJYfRgm1vYGCoUSaVklMN/z0/2fj8Kyj96ty6maZ3N3bHwmDmRAFLzZHGrBJ9T339LNg== X-Received: by 2002:a17:90a:fe88:: with SMTP id co8mr1729762pjb.209.1593152604856; Thu, 25 Jun 2020 23:23:24 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id z1sm21307973pgk.89.2020.06.25.23.23.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:24 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:30 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH V7 17/19] syscalls/utimensat: Migrate to new test framework 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 gets rid of the test script and updates the utimensat01.c file to handle most of the tests covered earlier (apart from testing the same for files owned by root, as the test is run as root right now). Signed-off-by: Viresh Kumar --- .../kernel/syscalls/utimensat/utimensat01.c | 424 ++++++-------- .../syscalls/utimensat/utimensat_tests.sh | 517 ------------------ 2 files changed, 179 insertions(+), 762 deletions(-) delete mode 100755 testcases/kernel/syscalls/utimensat/utimensat_tests.sh diff --git a/testcases/kernel/syscalls/utimensat/utimensat01.c b/testcases/kernel/syscalls/utimensat/utimensat01.c index 264ca1e15120..97a43713454f 100644 --- a/testcases/kernel/syscalls/utimensat/utimensat01.c +++ b/testcases/kernel/syscalls/utimensat/utimensat01.c @@ -1,282 +1,216 @@ -/*************************************************************************************/ -/* */ -/* Copyright (C) 2008, Michael Kerrisk , */ -/* Copyright (C) 2008, Linux Foundation */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/*************************************************************************************/ -/* */ -/* File: utimnsat01.c */ -/* Description: A command-line interface for testing the utimensat() system call. */ -/* Author: Michael Kerrisk */ -/* History: */ -/* 17 Mar 2008 Initial creation, */ -/* 31 May 2008 Reworked for easier test automation, */ -/* 2 June 2008 Renamed from t_utimensat.c to test_utimensat.c, */ -/* 05 June 2008 Submitted to LTP by Subrata Modak */ -/*************************************************************************************/ - -#define _GNU_SOURCE -#define _ATFILE_SOURCE +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2008 Michael Kerrisk + * Copyright (c) 2008 Subrata Modak + * Copyright (c) 2020 Viresh Kumar + * + * Basic utimnsat() test. + */ + #include #include #include #include #include -#include #include #include #include -#include "test.h" +#include "lapi/fs.h" +#include "tst_test.h" #include "lapi/syscalls.h" -char *TCID = "utimensat01"; -int TST_TOTAL = 0; - -#define cleanup tst_exit +#define UTIME_NOW ((1l << 30) - 1l) +#define UTIME_OMIT ((1l << 30) - 2l) + +#define TEST_FILE "test_file" +#define TEST_DIR "test_dir" + +static void *bad_addr; + +struct mytime { + long access_tv_sec; + long access_tv_nsec; + long mod_tv_sec; + long mod_tv_nsec; +}; + +static struct mytime tnn = {0, UTIME_NOW, 0, UTIME_NOW}, *time_nn = &tnn; +static struct mytime too = {0, UTIME_OMIT, 0, UTIME_OMIT}, *time_oo = &too; +static struct mytime tno = {0, UTIME_NOW, 0, UTIME_OMIT}, *time_no = &tno; +static struct mytime ton = {0, UTIME_OMIT, 0, UTIME_NOW}, *time_on = &ton; +static struct mytime t11 = {1, 1, 1, 1}, *time_11 = &t11; + +struct test_case { + int dirfd; + char *pathname; + struct mytime **mytime; + int flags; + int oflags; + int attr; + int mode; + int exp_err; +} tcase[] = { + /* Testing read-only file */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, 0, 0400, 0}, + {AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, 0, 0400, 0}, + {AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, 0, 0400, 0}, + {AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, 0, 0400, 0}, + {AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, 0, 0400, 0}, + {AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, 0, 0400, 0}, + + /* Testing writable file */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, 0, 0666, 0}, + {AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, 0, 0666, 0}, + {AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, 0, 0666, 0}, + {AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, 0, 0666, 0}, + {AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, 0, 0666, 0}, + {AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, 0, 0666, 0}, + + /* Testing append-only file */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, FS_APPEND_FL, 0600, 0}, + {AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, FS_APPEND_FL, 0600, 0}, + {AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, FS_APPEND_FL, 0600, 0}, + {AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, FS_APPEND_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, FS_APPEND_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, FS_APPEND_FL, 0600, EPERM}, + + /* Testing immutable file */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, -1}, + {AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, -1}, + {AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, 0}, + {AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, FS_IMMUTABLE_FL, 0600, EPERM}, + + /* Testing immutable-append-only file */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, -1}, + {AT_FDCWD, TEST_FILE, &time_nn, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, -1}, + {AT_FDCWD, TEST_FILE, &time_oo, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, 0}, + {AT_FDCWD, TEST_FILE, &time_no, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_on, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, EPERM}, + {AT_FDCWD, TEST_FILE, &time_11, 0, O_RDONLY, FS_APPEND_FL|FS_IMMUTABLE_FL, 0600, EPERM}, + + /* Other failure tests */ + {AT_FDCWD, TEST_FILE, NULL, 0, O_RDONLY, 0, 0400, EFAULT}, + {AT_FDCWD, NULL, &time_nn, 0, O_RDONLY, 0, 0400, EFAULT}, + {-1, NULL, &time_nn, AT_SYMLINK_NOFOLLOW, O_RDONLY, 0, 0400, EINVAL}, + {-1, TEST_FILE, &time_nn, 0, O_RDONLY, 0, 0400, ENOENT}, +}; + +static inline int sys_utimensat(int dirfd, const char *pathname, + const struct timespec times[2], int flags) +{ + return tst_syscall(__NR_utimensat, dirfd, pathname, times, flags); +} -/* We use EXIT_FAILURE for an expected failure from utimensat() - (e.g., EACCES and EPERM), and one of the following for unexpected - failures (i.e., something broke in our test setup). */ +static void setup(void) +{ + bad_addr = tst_get_bad_addr(NULL); +} -#ifndef AT_FDCWD -#define AT_FDCWD -100 -#endif -#ifndef AT_SYMLINK_NOFOLLOW -#define AT_SYMLINK_NOFOLLOW 0x100 -#endif +static void update_error(struct test_case *tc) +{ + if (tc->exp_err != -1) + return; + + /* + * Starting with 4.8.0 operations on immutable files return EPERM + * instead of EACCES. + * This patch has also been merged to stable 4.4 with + * b3b4283 ("vfs: move permission checking into notify_change() for utimes(NULL)") + */ + if (tst_kvercmp(4, 4, 27) < 0) + tc->exp_err = EACCES; + else + tc->exp_err = EPERM; +} -#define EXIT_bad_usage 3 -#define EXIT_failed_syscall 3 +static void change_attr(struct test_case *tc, int fd, int set) +{ + int attr; -#define errExit(msg) do { perror(msg); exit(EXIT_failed_syscall); \ - } while (0) + if (!tc->attr) + return; -#define UTIME_NOW ((1l << 30) - 1l) -#define UTIME_OMIT ((1l << 30) - 2l) + SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attr); -static inline int -utimensat_sc(int dirfd, const char *pathname, - const struct timespec times[2], int flags) -{ - return ltp_syscall(__NR_utimensat, dirfd, pathname, times, flags); -} + if (set) + attr |= tc->attr; + else + attr &= ~tc->attr; -static void usageError(char *progName) -{ - fprintf(stderr, "Usage: %s pathname [atime-sec " - "atime-nsec mtime-sec mtime-nsec]\n\n", progName); - fprintf(stderr, "Permitted options are:\n"); - fprintf(stderr, " [-d path] " - "open a directory file descriptor" - " (instead of using AT_FDCWD)\n"); - fprintf(stderr, " -q Quiet\n"); - fprintf(stderr, " -w Open directory file " - "descriptor with O_RDWR|O_APPEND\n" - " (instead of O_RDONLY)\n"); - fprintf(stderr, " -n Use AT_SYMLINK_NOFOLLOW\n"); - fprintf(stderr, "\n"); - - fprintf(stderr, "pathname can be \"NULL\" to use NULL " - "argument in call\n"); - fprintf(stderr, "\n"); - - fprintf(stderr, "Either nsec field can be\n"); - fprintf(stderr, " 'n' for UTIME_NOW\n"); - fprintf(stderr, " 'o' for UTIME_OMIT\n"); - fprintf(stderr, "\n"); - - fprintf(stderr, "If the time fields are omitted, " - "then a NULL 'times' argument is used\n"); - fprintf(stderr, "\n"); - - exit(EXIT_bad_usage); + SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attr); } -int main(int argc, char *argv[]) +static void run(unsigned int i) { - int flags, dirfd, opt, oflag; + struct test_case *tc = &tcase[i]; struct timespec ts[2]; - struct timespec *tsp; - char *pathname, *dirfdPath; + void *tsp = NULL; + char *pathname = NULL; + int dfd = AT_FDCWD, fd = 0; struct stat sb; - int verbose; - - /* Command-line argument parsing */ - - flags = 0; - verbose = 1; - dirfd = AT_FDCWD; - dirfdPath = NULL; - oflag = O_RDONLY; - - while ((opt = getopt(argc, argv, "d:nqw")) != -1) { - switch (opt) { - case 'd': - dirfdPath = optarg; - break; - - case 'n': - flags |= AT_SYMLINK_NOFOLLOW; - if (verbose) - printf("Not following symbolic links\n"); - break; - - case 'q': - verbose = 0; - break; - - case 'w': - oflag = O_RDWR | O_APPEND; - break; - - default: - usageError(argv[0]); - } - } - - if ((optind + 5 != argc) && (optind + 1 != argc)) - usageError(argv[0]); - - if (dirfdPath != NULL) { - dirfd = open(dirfdPath, oflag); - if (dirfd == -1) - errExit("open"); - - if (verbose) { - printf("Opened dirfd %d", oflag); - if ((oflag & O_ACCMODE) == O_RDWR) - printf(" O_RDWR"); - if (oflag & O_APPEND) - printf(" O_APPEND"); - printf(": %s\n", dirfdPath); - } - } - pathname = (strcmp(argv[optind], "NULL") == 0) ? NULL : argv[optind]; + SAFE_MKDIR(TEST_DIR, 0700); + update_error(tc); - /* Either, we get no values for 'times' fields, in which case - we give a NULL pointer to utimensat(), or we get four values, - for secs+nsecs for each of atime and mtime. The special - values 'n' and 'o' can be used for tv_nsec settings of - UTIME_NOW and UTIME_OMIT, respectively. */ + if (tc->dirfd != AT_FDCWD) + dfd = SAFE_OPEN(TEST_DIR, tc->oflags); - if (argc == optind + 1) { - tsp = NULL; - - } else { - ts[0].tv_sec = atoi(argv[optind + 1]); - if (argv[optind + 2][0] == 'n') { - ts[0].tv_nsec = UTIME_NOW; - } else if (argv[optind + 2][0] == 'o') { - ts[0].tv_nsec = UTIME_OMIT; - } else { - ts[0].tv_nsec = atoi(argv[optind + 2]); - } - - ts[1].tv_sec = atoi(argv[optind + 3]); - if (argv[optind + 4][0] == 'n') { - ts[1].tv_nsec = UTIME_NOW; - } else if (argv[optind + 4][0] == 'o') { - ts[1].tv_nsec = UTIME_OMIT; - } else { - ts[1].tv_nsec = atoi(argv[optind + 4]); - } + if (tc->mytime) { + struct mytime *mytime = *tc->mytime; + ts[0].tv_sec = mytime->access_tv_sec; + ts[0].tv_nsec = mytime->access_tv_nsec; + ts[1].tv_sec = mytime->mod_tv_sec; + ts[1].tv_nsec = mytime->mod_tv_nsec; tsp = ts; + } else if (tc->exp_err == EFAULT) { + tsp = bad_addr; } - /* For testing purposes, it may have been useful to run this program - as set-user-ID-root so that a directory file descriptor could be - opened as root. (This allows us to obtain a file descriptor even - if normal user doesn't have permissions on the file.) Now we - reset to the real UID before making the utimensat() call, so that - the permission checking for the utimensat() call is performed - under that UID. */ - - if (geteuid() == 0) { - uid_t u; - - u = getuid(); - - if (verbose) - printf("Resetting UIDs to %ld\n", (long)u); - - if (setresuid(u, u, u) == -1) - errExit("setresuid"); + if (tc->pathname) { + fd = SAFE_OPEN(tc->pathname, O_WRONLY | O_CREAT); + pathname = tc->pathname; + SAFE_CHMOD(tc->pathname, tc->mode); + change_attr(tc, fd, 1); + } else if (tc->exp_err == EFAULT) { + pathname = bad_addr; } - /* Display information allowing user to verify arguments for call */ + TEST(sys_utimensat(dfd, pathname, tsp, tc->flags)); + if (tc->pathname) + change_attr(tc, fd, 0); - if (verbose) { - printf("dirfd is %d\n", dirfd); - printf("pathname is %s\n", pathname); - printf("tsp is %p", tsp); - if (tsp != NULL) { - printf("; struct = { %ld, %ld } { %ld, %ld }", - (long)tsp[0].tv_sec, (long)tsp[0].tv_nsec, - (long)tsp[1].tv_sec, (long)tsp[1].tv_nsec); - } - printf("\n"); - printf("flags is %d\n", flags); - } - - /* Make the call and see what happened */ - - if (utimensat_sc(dirfd, pathname, tsp, flags) == -1) { - if (errno == EPERM) { - if (verbose) - printf("utimensat() failed with EPERM\n"); - else - printf("EPERM\n"); - exit(EXIT_FAILURE); - - } else if (errno == EACCES) { - if (verbose) - printf("utimensat() failed with EACCES\n"); - else - printf("EACCES\n"); - exit(EXIT_FAILURE); - - } else if (errno == EINVAL) { - if (verbose) - printf("utimensat() failed with EINVAL\n"); - else - printf("EINVAL\n"); - exit(EXIT_FAILURE); - - } else { /* Unexpected failure case from utimensat() */ - errExit("utimensat"); + if (TST_RET) { + if (!tc->exp_err) { + tst_res(TFAIL | TTERRNO, "%2d: utimensat() failed", i); + } else if (tc->exp_err == TST_ERR) { + tst_res(TPASS | TTERRNO, "%2d: utimensat() failed expectedly", i); + } else { + tst_res(TFAIL | TTERRNO, "%2d: utimensat() failed with incorrect error, expected %s", + i, tst_strerrno(tc->exp_err)); } - } - - if (verbose) - printf("utimensat() succeeded\n"); - - if (stat((pathname != NULL) ? pathname : dirfdPath, &sb) == -1) - errExit("stat"); - - if (verbose) { - printf("Last file access: %s", ctime(&sb.st_atime)); - printf("Last file modification: %s", ctime(&sb.st_mtime)); - printf("Last status change: %s", ctime(&sb.st_ctime)); - + } else if (tc->exp_err) { + tst_res(TFAIL, "%2d: utimensat() passed unexpectedly", i); } else { - printf("SUCCESS %ld %ld\n", (long)sb.st_atime, - (long)sb.st_mtime); + TEST(stat(tc->pathname ? tc->pathname : TEST_DIR, &sb)); + tst_res(TPASS, "%2d: utimensat() passed: access time: %lu %lu", i, + sb.st_atime, sb.st_mtime); } - exit(EXIT_SUCCESS); + if (dfd != AT_FDCWD) + SAFE_CLOSE(dfd); + + if (tc->pathname) + SAFE_CLOSE(fd); + SAFE_RMDIR(TEST_DIR); } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tcase), + .setup = setup, + .needs_root = 1, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/utimensat/utimensat_tests.sh b/testcases/kernel/syscalls/utimensat/utimensat_tests.sh deleted file mode 100755 index 46a0cc64bf90..000000000000 --- a/testcases/kernel/syscalls/utimensat/utimensat_tests.sh +++ /dev/null @@ -1,517 +0,0 @@ -#!/bin/sh -# -# Automated tests for utimensat() -# -# Copyright (C) 2008, Linux Foundation -# Written by Michael Kerrisk -# Licensed under GPLv2 or later -# -# Not (yet) included in this automated test set: -# * AT_SYMLINK_NOFOLLOW in flags: If pathname specifies a symbolic link, -# then update the timestamps of the link, rather than the file to which -# it refers. -# * Setting of nanosecond components of timestamps (support for -# nanosecond timestamps is file-system-dependent) -# * "Updated file timestamps are set to the greatest value supported -# by the file system that is not greater than the specified time." -# (i.e., if we set timestamp to {0, 999999999}, then the setting -# is rounded down, rather than up, to unit of timestamp resolution. -# * Privileged processes should be able to bypass permission checks. -# (except when file is marked with the "Immutable" EFA). - -#===================================================================== - -export TCID=utimensat01 -export TST_TOTAL=99 -export TST_COUNT=0 -. test.sh - -if tst_kvcmp -lt "2.6.22"; then - tst_brkm TCONF "System kernel version is less than 2.6.22,cannot execute test" -fi - -# Starting with 4.8.0 operations on immutable files return EPERM instead of -# EACCES. -# This patch has also been merged to stable 4.4 with -# b3b4283 ("vfs: move permission checking into notify_change() for utimes(NULL)") -if tst_kvcmp -ge "4.4.27" -a -lt "4.5.0"; then - imaccess=EPERM -elif tst_kvcmp -lt "4.4.27"; then - imaccess=EACCES -else - imaccess=EPERM -fi - - -RESULT_FILE=$TMPDIR/utimensat.result - -TEST_DIR=$TMPDIR/utimensat_tests -FILE=$TEST_DIR/utimensat.test_file - -TEST_PROG=utimensat01 - -if [ ! -f $LTPROOT/testcases/bin/$TEST_PROG ]; then - tst_brkm TBROK "$LTPROOT/testcases/bin/$TEST_PROG is missing (please check install)" -fi - -# Summary counters of all test results - -test_num=0 -failed_cnt=0 -passed_cnt=0 -failed_list="" - -#===================================================================== - -setup_file() -{ -# $1 is test file pathname -# $2 is owner for test file (chown(1)) -# $3 is permissions for test file (chmod(1)) -# $4 is "ext2" extended file attributes for test file (chattr(1)) - - FILE=$1 - - # Make sure any old version of file is deleted - - if test -e $FILE; then - sudo $s_arg chattr -ai $FILE || return $? - sudo $s_arg rm -f $FILE || return $? - fi - - # Create file and make atime and mtime zero. - - sudo $s_arg -u $test_user touch $FILE || return $? - if ! $TEST_PROG -q $FILE 0 0 0 0 > $RESULT_FILE; then - echo "Failed to set up test file $FILE" 1>&2 - exit 1 - fi - - read res atime mtime < $RESULT_FILE - if test "X$res" != "XSUCCESS" || - test $atime -ne 0 || test $mtime != 0; then - echo "Failed to set correct times on test file $FILE" 1>&2 - exit 1 - fi - - # Set owner, permissions, and EFAs for file. - - if test -n "$2"; then - sudo $s_arg chown $2 $FILE || return $? - fi - - sudo $s_arg chmod $3 $FILE || return $? - - if test -n "$4"; then - sudo $s_arg chattr $4 $FILE || return $? - fi - - # Display file setup, for visual verification - - ls -l $FILE | awk '{ printf "Owner=%s; perms=%s; ", $3, $1}' - if ! sudo $s_arg lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' - then - return $? - fi - -} - -test_failed() -{ - tst_resm TFAIL "FAILED test $test_num" - - failed_cnt=$(expr $failed_cnt + 1) - failed_list="$failed_list $test_num" -} - -check_result() -{ - STATUS=$1 # Exit status from test program - EXPECTED_RESULT=$2 # SUCCESS / EACCES / EPERM / EINVAL - EXPECT_ATIME_CHANGED=$3 # Should be 'y' or 'n' (only for SUCCESS) - EXPECT_MTIME_CHANGED=$4 # Should be 'y' or 'n' (only for SUCCESS) - - test_num=$(expr $test_num + 1) - - # If our test setup failed, stop immediately - - if test $STATUS -gt 1; then - echo "FAILED (bad test setup)" - exit 1 - fi - - read res atime mtime < $RESULT_FILE - - echo "EXPECTED: $EXPECTED_RESULT $EXPECT_ATIME_CHANGED "\ - "$EXPECT_MTIME_CHANGED" - echo "RESULT: $res $atime $mtime" - - if test "$res" != "$EXPECTED_RESULT"; then - test_failed - return - fi - - passed=1 - - # If the test program exited successfully, then check that atime and - # and mtime were updated / not updated, as expected. - - if test $EXPECTED_RESULT = "SUCCESS"; then - if test $EXPECT_ATIME_CHANGED = "y"; then - if test $atime -eq 0; then - echo "atime should have changed, but did not" - passed=0 - fi - else - if test $atime -ne 0; then - echo "atime should not have changed, but did" - passed=0 - fi - fi - - if test $EXPECT_MTIME_CHANGED = "y"; then - if test $mtime -eq 0; then - echo "mtime should have changed, but did not" - passed=0 - fi - else - if test $mtime -ne 0; then - echo "mtime should not have changed, but did" - passed=0 - fi - fi - - if test $passed -eq 0; then - test_failed - return - fi - fi - - passed_cnt=$(expr $passed_cnt + 1) - tst_resm TPASS "PASSED test $test_num" -} - -run_test() -{ - # By default, we do three types of test: - # a) pathname (pathname != NULL) - # b) readable file descriptor (pathname == NULL, dirfd opened O_RDONLY) - # c) writable file descriptor (pathname == NULL, dirfd opened O_RDWR). - # For this case we also include O_APPEND in open flags, since that - # is needed if testing with a file that has the Append-only - # attribute enabled. - - # -R says don't do tests with readable file descriptor - # -W says don't do tests with writable file descriptor - - OPTIND=1 - - do_read_fd_test=1 - do_write_fd_test=1 - while getopts "RW" opt; do - case "$opt" in - R) do_read_fd_test=0 - ;; - W) do_write_fd_test=0 - ;; - *) echo "run_test: bad usage" - exit 1 - ;; - esac - done - shift `expr $OPTIND - 1` - - echo "Pathname test" - setup_file $FILE "$1" "$2" "$3" - cp $LTPROOT/testcases/bin/$TEST_PROG ./ - CMD="./$TEST_PROG -q $FILE $4" - echo "$CMD" - sudo $s_arg -u $test_user $CMD > $RESULT_FILE - check_result $? $5 $6 $7 - echo - - if test $do_read_fd_test -ne 0; then - echo "Readable file descriptor (futimens(3)) test" - setup_file $FILE "$1" "$2" "$3" - CMD="./$TEST_PROG -q -d $FILE NULL $4" - echo "$CMD" - sudo $s_arg -u $test_user $CMD > $RESULT_FILE - check_result $? $5 $6 $7 - echo - fi - - # Can't do the writable file descriptor test for immutable files - # (even root can't open an immutable file for writing) - - if test $do_write_fd_test -ne 0; then - echo "Writable file descriptor (futimens(3)) test" - setup_file $FILE "$1" "$2" "$3" - CMD="./$TEST_PROG -q -w -d $FILE NULL $4" - echo "$CMD" - sudo $s_arg -u $test_user $CMD > $RESULT_FILE - check_result $? $5 $6 $7 - echo - fi - - sudo $s_arg chattr -ai $FILE - sudo $s_arg rm -f $FILE -} - -#===================================================================== - -# Since some automated testing systems have no tty while testing, -# comment this line in /etc/sudoers to avoid the error message: -# `sudo: sorry, you must have a tty to run sudo' -# Use trap to restore this line after program terminates. -sudoers=/etc/sudoers -if [ ! -r $sudoers ]; then - tst_brkm TBROK "can't read $sudoers" -fi -pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*" -if grep -q "^${pattern}" $sudoers; then - tst_resm TINFO "Comment requiretty in $sudoers for automated testing systems" - if ! sed -r -i.$$ -e "s/^($pattern)/#\1/" $sudoers; then - tst_brkm TBROK "failed to mangle $sudoers properly" - fi - trap 'trap "" EXIT; restore_sudoers' EXIT -fi - -restore_sudoers() -{ - tst_resm TINFO "Restore requiretty in $sudoers" - mv /etc/sudoers.$$ /etc/sudoers -} - -test_user=nobody -echo "test sudo for -n option, non-interactive" -if sudo -h | grep -q -- -n; then - s_arg="-n" - echo "sudo supports -n" -else - s_arg= - echo "sudo does not support -n" -fi - -if ! sudo $s_arg true; then - tst_brkm TBROK "sudo cannot be run by user non-interactively" -fi -if test ! -f $sudoers -then - echo "root ALL=(ALL) ALL" > $sudoers || exit - chmod 440 $sudoers - trap 'trap "" EXIT; nuke_sudoers' EXIT -fi - -nuke_sudoers() -{ - sudo rm -f $sudoers -} - -sudo $s_arg -u $test_user mkdir -p $TEST_DIR - -# Make sure chattr command is supported -touch $TEST_DIR/tmp_file -chattr +a $TEST_DIR/tmp_file -if [ $? -ne 0 ] ; then - rm -rf $TEST_DIR - tst_brkm TCONF "chattr not supported" -fi -chattr -a $TEST_DIR/tmp_file - -cd $TEST_DIR -chown root $LTPROOT/testcases/bin/$TEST_PROG -chmod ugo+x,u+s $LTPROOT/testcases/bin/$TEST_PROG - -#===================================================================== - - -echo "============================================================" - -echo -echo "Testing read-only file, owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test -W "" 400 "" "" SUCCESS y y - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test -W "" 400 "" "0 n 0 n" SUCCESS y y - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test -W "" 400 "" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test -W "" 400 "" "0 n 0 o" SUCCESS y n - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test -W "" 400 "" "0 o 0 n" SUCCESS n y - -echo "***** Testing times=={ x, y } case *****" -run_test -W "" 400 "" "1 1 1 1" SUCCESS y y - -echo "============================================================" - -echo -echo "Testing read-only file, not owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test -RW root 400 "" "" EACCES - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test -RW root 400 "" "0 n 0 n" EACCES - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test -RW root 400 "" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test -RW root 400 "" "0 n 0 o" EPERM - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test -RW root 400 "" "0 o 0 n" EPERM - -echo "***** Testing times=={ x, y } case *****" -run_test -RW root 400 "" "1 1 1 1" EPERM - -echo "============================================================" - -echo -echo "Testing writable file, not owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test root 666 "" "" SUCCESS y y - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test root 666 "" "0 n 0 n" SUCCESS y y - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test root 666 "" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test root 666 "" "0 n 0 o" EPERM - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test root 666 "" "0 o 0 n" EPERM - -echo "***** Testing times=={ x, y } case *****" -run_test root 666 "" "1 1 1 1" EPERM - -echo "============================================================" - -echo -echo "Testing append-only file, owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test "" 600 "+a" "" SUCCESS y y - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test "" 600 "+a" "0 n 0 n" SUCCESS y y - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test "" 600 "+a" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test "" 600 "+a" "0 n 0 o" EPERM - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test "" 600 "+a" "0 o 0 n" EPERM - -echo "***** Testing times=={ x, y } case *****" -run_test "" 600 "+a" "1 1 1 1" EPERM - -echo "============================================================" - -echo -echo "Testing immutable file, owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test -W "" 600 "+i" "" $imaccess - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test -W "" 600 "+i" "0 n 0 n" $imaccess - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test -W "" 600 "+i" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test -W "" 600 "+i" "0 n 0 o" EPERM - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test -W "" 600 "+i" "0 o 0 n" EPERM - -echo "***** Testing times=={ x, y } case *****" -run_test -W "" 600 "+i" "1 1 1 1" EPERM - -echo "============================================================" - -# Immutable+append-only should have same results as immutable - -echo -echo "Testing immutable append-only file, owned by self" -echo - -echo "***** Testing times==NULL case *****" -run_test -W "" 600 "+ai" "" $imaccess - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test -W "" 600 "+ai" "0 n 0 n" $imaccess - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test -W "" 600 "+ai" "0 o 0 o" SUCCESS n n - -echo "***** Testing times=={ UTIME_NOW, UTIME_OMIT } case *****" -run_test -W "" 600 "+ai" "0 n 0 o" EPERM - -echo "***** Testing times=={ UTIME_OMIT, UTIME_NOW } case *****" -run_test -W "" 600 "+ai" "0 o 0 n" EPERM - -echo "***** Testing times=={ x, y } case *****" -run_test -W "" 600 "+ai" "1 1 1 1" EPERM - -echo "============================================================" - -echo - -# EINVAL should result, if pathname is NULL, dirfd is not -# AT_FDCWD, and flags contains AT_SYMLINK_NOFOLLOW. - -echo "***** Testing pathname==NULL, dirfd!=AT_FDCWD, flags has" \ - "AT_SYMLINK_NOFOLLOW *****" -setup_file $FILE "" 600 "" -CMD="$TEST_PROG -q -n -d $FILE NULL $4" -echo "$CMD" -$CMD > $RESULT_FILE -check_result $? EINVAL -echo - -echo "============================================================" - -echo - -# If UTIME_NOW / UTIME_OMIT in tv_nsec field, the tv_sec should -# be ignored. - -echo "tv_sec should be ignored if tv_nsec is UTIME_OMIT or UTIME_NOW" - -echo "***** Testing times=={ UTIME_NOW, UTIME_NOW } case *****" -run_test -RW "" 600 "" "1 n 1 n" SUCCESS y y - -echo "***** Testing times=={ UTIME_OMIT, UTIME_OMIT } case *****" -run_test -RW "" 600 "" "1 o 1 o" SUCCESS n n - -echo "============================================================" - -echo - -rm -rf "$TEST_DIR" -uname -a -date -echo "Total tests: $test_num; passed: $passed_cnt; failed: $failed_cnt" -if test $failed_cnt -gt 0; then - echo "Failed tests: $failed_list" -fi - -tst_exit From patchwork Fri Jun 26 06:22:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317409 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=ExhrfDM8; 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 49tRhr1FM9z9sRR for ; Fri, 26 Jun 2020 16:25:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3BA993C2B66 for ; Fri, 26 Jun 2020 08:25:45 +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 F32D93C5851 for ; Fri, 26 Jun 2020 08:23:29 +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 3277B1401194 for ; Fri, 26 Jun 2020 08:23:29 +0200 (CEST) Received: by mail-pj1-x1042.google.com with SMTP id m2so4517426pjv.2 for ; Thu, 25 Jun 2020 23:23:29 -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=c093F8X39H7/ZifZf8xug6KaMHkqPofWNlbOXHvXWx0=; b=ExhrfDM8EiPM2DQ6e/vrgxtoo302J32T1mYmRB+XmK0vteq/PktaCGlPF7faSLDgEt RvuCc2xrBUC+t8kBw/mBvNPTNurqV9E3q4ajYILztWa/9KFcisHPlF8tJPqx3mhhsPE0 HE4nMnpBzsXB8kD6so9y50D32M6NvTU6Zwv6ytPPVbyBj5oAn/i2fLc/vHSkDEt5yEnp 9g1YWZUBjygsH4NT7t4D5wuJSeYyuLsvdD8j34gB7WhfaVZk4V3tuV2I6OZ+TmHgnvlx PosivwgWA8Gcabi04YW3rTUKvRiLhFAZ14Noh74MBV42mzBWQc/dppkWoh+OBvi8iN8z 0nFQ== 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=c093F8X39H7/ZifZf8xug6KaMHkqPofWNlbOXHvXWx0=; b=PBNEQ+TW0VTdsZDgRdBH2a1pS5LTa8jUR4GthinYypKnxo2IGdsmRUONn2wK3WYDir C7IxGZaSbcE97I06bVAeUsXN1jvDVVwzmNs1J3oQQ42zR3VYMcdeO0U82tnkgvxC2/q6 H/XMkf/vJ53pdvsQxlgYUrFBiAiMy5eRNvW4K+2/0OEEZH7mpTJJ3QG0wopPgWpk/20I MMTIsx3PiAd4C+mHeE7TAkjJ2AsRrhHVZ2wof4S4itHndI1/Ryw4/MgD3aVCLCx4+9JE pYC95Au2ZKApzYIbENr98lR9jS66I7Ws2BNUc+z03gOkUdNwjIX3G/Onf0js3tcONgYI B9GA== X-Gm-Message-State: AOAM531QO1wHoOsJuK/IFVz1qciiERbiHGiS1bX3QC8UAZvAaz21D9tw MMLBlJ8dVJMn14b/nxnANIXOSP2L3wg= X-Google-Smtp-Source: ABdhPJzev0W8LyryzhQRkelL5nIeaS4bXbJ78uD0Npb5kG5BROtHHqbiJ8DF68UGD4VOh/dbQhb/CQ== X-Received: by 2002:a17:90b:a02:: with SMTP id gg2mr1750921pjb.110.1593152607377; Thu, 25 Jun 2020 23:23:27 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id s187sm3725274pfs.83.2020.06.25.23.23.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:26 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:31 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 18/19] syscalls/utimensat: 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 utimensat() syscall tests. Signed-off-by: Viresh Kumar --- runtest/syscalls | 2 +- testcases/kernel/syscalls/utimensat/Makefile | 4 - .../kernel/syscalls/utimensat/utimensat01.c | 74 ++++++++++++++++--- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/runtest/syscalls b/runtest/syscalls index 5b3a0862faea..2d2e24615be6 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1607,7 +1607,7 @@ utime06 utime06 utimes01 utimes01 # Introduced from Kernel 2.6.22 onwards -utimensat01 utimensat_tests.sh +utimensat01 utimensat01 vfork01 vfork01 vfork02 vfork02 diff --git a/testcases/kernel/syscalls/utimensat/Makefile b/testcases/kernel/syscalls/utimensat/Makefile index 69cab8dbc057..044619fb8724 100644 --- a/testcases/kernel/syscalls/utimensat/Makefile +++ b/testcases/kernel/syscalls/utimensat/Makefile @@ -5,8 +5,4 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -vpath %.c $(srcdir):$(top_srcdir)/lib - -INSTALL_TARGETS := utimensat_tests.sh - include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/utimensat/utimensat01.c b/testcases/kernel/syscalls/utimensat/utimensat01.c index 97a43713454f..0139d6ddfedf 100644 --- a/testcases/kernel/syscalls/utimensat/utimensat01.c +++ b/testcases/kernel/syscalls/utimensat/utimensat01.c @@ -16,8 +16,7 @@ #include #include #include "lapi/fs.h" -#include "tst_test.h" -#include "lapi/syscalls.h" +#include "tst_timer.h" #define UTIME_NOW ((1l << 30) - 1l) #define UTIME_OMIT ((1l << 30) - 2l) @@ -98,13 +97,68 @@ struct test_case { }; static inline int sys_utimensat(int dirfd, const char *pathname, - const struct timespec times[2], int flags) + void *times, int flags) { return tst_syscall(__NR_utimensat, dirfd, pathname, times, flags); } +static inline int sys_utimensat_time64(int dirfd, const char *pathname, + void *times, int flags) +{ + return tst_syscall(__NR_utimensat_time64, dirfd, pathname, times, flags); +} + +static struct test_variants { + int (*utimensat)(int dirfd, const char *pathname, void *times, + int flags); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_utimensat != __LTP__NR_INVALID_SYSCALL) + { .utimensat = sys_utimensat, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_utimensat_time64 != __LTP__NR_INVALID_SYSCALL) + { .utimensat = sys_utimensat_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +union tst_multi { + struct timespec libc_ts[2]; + struct __kernel_old_timespec kern_old_ts[2]; + struct __kernel_timespec kern_ts[2]; +} ts; + +static void tst_multi_set_time(enum tst_ts_type type, long access_tv_sec, + long access_tv_nsec, long mod_tv_sec, long mod_tv_nsec) +{ + switch (type) { + case TST_LIBC_TIMESPEC: + ts.libc_ts[0].tv_sec = access_tv_sec; + ts.libc_ts[0].tv_nsec = access_tv_nsec; + ts.libc_ts[1].tv_sec = mod_tv_sec; + ts.libc_ts[1].tv_nsec = mod_tv_nsec; + break; + case TST_KERN_OLD_TIMESPEC: + ts.kern_old_ts[0].tv_sec = access_tv_sec; + ts.kern_old_ts[0].tv_nsec = access_tv_nsec; + ts.kern_old_ts[1].tv_sec = mod_tv_sec; + ts.kern_old_ts[1].tv_nsec = mod_tv_nsec; + break; + case TST_KERN_TIMESPEC: + ts.kern_ts[0].tv_sec = access_tv_sec; + ts.kern_ts[0].tv_nsec = access_tv_nsec; + ts.kern_ts[1].tv_sec = mod_tv_sec; + ts.kern_ts[1].tv_nsec = mod_tv_nsec; + break; + default: + tst_brk(TBROK, "Invalid type: %d", type); + } +} + static void setup(void) { + tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); bad_addr = tst_get_bad_addr(NULL); } @@ -144,8 +198,8 @@ static void change_attr(struct test_case *tc, int fd, int set) static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; struct test_case *tc = &tcase[i]; - struct timespec ts[2]; void *tsp = NULL; char *pathname = NULL; int dfd = AT_FDCWD, fd = 0; @@ -160,11 +214,10 @@ static void run(unsigned int i) if (tc->mytime) { struct mytime *mytime = *tc->mytime; - ts[0].tv_sec = mytime->access_tv_sec; - ts[0].tv_nsec = mytime->access_tv_nsec; - ts[1].tv_sec = mytime->mod_tv_sec; - ts[1].tv_nsec = mytime->mod_tv_nsec; - tsp = ts; + tst_multi_set_time(tv->type, mytime->access_tv_sec, + mytime->access_tv_nsec, mytime->mod_tv_sec, + mytime->mod_tv_nsec); + tsp = &ts.libc_ts; } else if (tc->exp_err == EFAULT) { tsp = bad_addr; } @@ -178,7 +231,7 @@ static void run(unsigned int i) pathname = bad_addr; } - TEST(sys_utimensat(dfd, pathname, tsp, tc->flags)); + TEST(tv->utimensat(dfd, pathname, tsp, tc->flags)); if (tc->pathname) change_attr(tc, fd, 0); @@ -210,6 +263,7 @@ static void run(unsigned int i) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tcase), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .needs_root = 1, .needs_tmpdir = 1, From patchwork Fri Jun 26 06:22:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1317410 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=fCNpNTzK; 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 49tRj23pQmz9sSc for ; Fri, 26 Jun 2020 16:25:58 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E359D3C5850 for ; Fri, 26 Jun 2020 08:25:55 +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 7AEEC3C2B6E for ; Fri, 26 Jun 2020 08:23:32 +0200 (CEST) Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 BF9C4140119D for ; Fri, 26 Jun 2020 08:23:31 +0200 (CEST) Received: by mail-pf1-x444.google.com with SMTP id u185so2189832pfu.1 for ; Thu, 25 Jun 2020 23:23:31 -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=PL/dCm76JeK1omvSJcyrmaZgledJfVJsdrGkc4b5sv8=; b=fCNpNTzKOksgD+E4pU3co/5wtrBCWPL27WCgIavVGfw9RxSUJZ1LidqO4RALnb91Ah 9fFkFdks9awzgWBOBu9EdWzNNxvP30tT41aieAWqWkMypWX3YjoNfNw6hmWx/yKvN/CL QQdc2U+x1mMmXV7s45WBDbI5981d4lrLE5cEoOssTjIcMLMvvejw7McoioisDPkfHe45 tZXZb97HYl2x37FaDPadvNjt9HWhEzOUzJVNY+pOZwu3SiC2i219UmFsLggstR7j25+u oO8w2w0fjFYZRbkSrjTv9wwKBrxLMOD7+R0vsGKE1uZQLBqR/ydWwfVnwZOxEc0sZbCC h8pw== 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=PL/dCm76JeK1omvSJcyrmaZgledJfVJsdrGkc4b5sv8=; b=EuXnk5qqn0EZvOYxSUz9VN+LRhQ+KOiS77ns5hcLwOXAAqP5GfHsE8Jkd8PSwZ9oVs 4bo5j/bowuJHNwg2chIziVhVwcj1PIj7DbqStYJ2fOmjz4bjc6pGQkbqq0LkDXxuk6Ze /ccfuKvOtYvFN7BcKeFKDnap6pbJdgspMlxsvOT85cOVYfiErfuIvFlrq7Ax11PWieZC XlLLfH8pLEMW/D9jQVvahFKuLVj6EAPcx4N5lxAUyeYjbtaQC5EP0fODOheOq5IEG7DX qDHdZoNAUOIY6ih1qzbjVg/Ltmz00iY72QZr4bdpOHd4X/PR67b+X82aRgsy7SY5nsen Tn9w== X-Gm-Message-State: AOAM531zVrksHpfrcHWhFK+PblzDrkgtW3/PS3KFfFw1isZcL2hi6fUK 0n7IC4EchbbNdkDZFb4zMbzYjvMq3zU= X-Google-Smtp-Source: ABdhPJwbtBXDPmbq8mYlMz1C2LOvVxaH3gxlGP6PzahQDLPA5ymzL68UYlnNLGLUSE6do3vMfsHVGQ== X-Received: by 2002:a63:d40d:: with SMTP id a13mr1362690pgh.225.1593152609939; Thu, 25 Jun 2020 23:23:29 -0700 (PDT) Received: from localhost ([122.172.127.76]) by smtp.gmail.com with ESMTPSA id x8sm10820179pje.31.2020.06.25.23.23.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2020 23:23:29 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 26 Jun 2020 11:52:32 +0530 Message-Id: <5b16889b19e969b79fa7d46c533bb5989ace1e46.1593152309.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: 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 V7 19/19] syscalls: clock_settime: Add test around y2038 vulnerability 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 a test around the y2038 vulnerability, it sets the system time to just before y2038 time (i.e. max value that can be stored in s32), and adds a timer to expire just after crossing it. Signed-off-by: Viresh Kumar --- runtest/syscalls | 1 + .../kernel/syscalls/clock_settime/.gitignore | 1 + .../syscalls/clock_settime/clock_settime03.c | 119 ++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime03.c diff --git a/runtest/syscalls b/runtest/syscalls index 2d2e24615be6..718ac1148392 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -101,6 +101,7 @@ leapsec01 leapsec01 clock_settime01 clock_settime01 clock_settime02 clock_settime02 +clock_settime03 clock_settime03 clone01 clone01 clone02 clone02 diff --git a/testcases/kernel/syscalls/clock_settime/.gitignore b/testcases/kernel/syscalls/clock_settime/.gitignore index 28121755006b..b66169b3eb7b 100644 --- a/testcases/kernel/syscalls/clock_settime/.gitignore +++ b/testcases/kernel/syscalls/clock_settime/.gitignore @@ -1,2 +1,3 @@ clock_settime01 clock_settime02 +clock_settime03 diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime03.c b/testcases/kernel/syscalls/clock_settime/clock_settime03.c new file mode 100644 index 000000000000..7245863137b5 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime03.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Linaro Limited. All rights reserved. + * Author: Viresh Kumar + * + * Check Year 2038 related vulnerabilities. + */ + +#include +#include "config.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" + +#define TIMER_DELTA 3 +#define ALLOWED_DELTA (50 * 1000) /* 50 ms */ + +static struct tst_ts start, end; +static struct tst_its its; + +static struct test_variants { + int (*clock_gettime)(clockid_t clk_id, void *ts); + int (*clock_settime)(clockid_t clk_id, void *ts); + int (*timer_settime)(timer_t timerid, int flags, void *its, + void *old_its); + enum tst_ts_type type; + char *desc; +} variants[] = { +#if (__NR_clock_settime != __LTP__NR_INVALID_SYSCALL) + { .clock_gettime = sys_clock_gettime, .clock_settime = sys_clock_settime, .timer_settime = sys_timer_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, +#endif + +#if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL) + { .clock_gettime = sys_clock_gettime64, .clock_settime = sys_clock_settime64, .timer_settime = sys_timer_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, +#endif +}; + +static void setup(void) +{ + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + start.type = end.type = its.type = tv->type; + + /* Check if the kernel is y2038 safe */ + if (tv->type != TST_KERN_OLD_TIMESPEC && + sizeof(start.ts.kern_old_ts) == 8) + tst_brk(TFAIL, "Not Y2038 safe to run test"); +} + +static void run(void) +{ + struct test_variants *tv = &variants[tst_variant]; + unsigned long long time = 0x7FFFFFFE; /* Time just before y2038 */ + struct sigevent ev = { + .sigev_notify = SIGEV_SIGNAL, + .sigev_signo = SIGABRT, + }; + long long diff; + timer_t timer; + sigset_t set; + int sig, ret; + + if (sigemptyset(&set) == -1) + tst_brk(TBROK, "sigemptyset() failed"); + + if (sigaddset(&set, SIGABRT) == -1) + tst_brk(TBROK, "sigaddset() failed"); + + if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) + tst_brk(TBROK, "sigprocmask() failed"); + + TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME_ALARM, &ev, &timer)); + if (TST_RET != 0) + tst_brk(TBROK | TERRNO, "timer_create() failed"); + + tst_ts_set_sec(&start, time); + tst_ts_set_nsec(&start, 0); + + ret = tv->clock_settime(CLOCK_REALTIME, tst_ts_get(&start)); + if (ret == -1) + tst_brk(TBROK | TERRNO, "clock_settime() failed"); + + tst_its_set_interval_sec(&its, 0); + tst_its_set_interval_nsec(&its, 0); + tst_its_set_value_sec(&its, time + TIMER_DELTA); + tst_its_set_value_nsec(&its, 0); + + TEST(tv->timer_settime(timer, TIMER_ABSTIME, tst_its_get(&its), NULL)); + if (TST_RET == -1) + tst_brk(TBROK | TTERRNO, "timer_settime() failed"); + + if (sigwait(&set, &sig) == -1) + tst_brk(TBROK, "sigwait() failed"); + + ret = tv->clock_gettime(CLOCK_REALTIME, tst_ts_get(&end)); + if (ret == -1) + tst_brk(TBROK | TERRNO, "clock_gettime() failed"); + + if (sig == SIGABRT) { + diff = tst_ts_diff_ms(end, start); + + if (diff < TIMER_DELTA * 1000 - ALLOWED_DELTA || + diff > TIMER_DELTA * 1000 + ALLOWED_DELTA) + tst_res(TINFO, "Slept for unexpected duration, expected:%d, actual:%lld", + TIMER_DELTA * 1000, diff); + tst_res(TPASS, "clock_settime(): Y2038 test passed"); + return; + } + + tst_res(TFAIL, "clock_settime(): Y2038 test failed"); +} + +static struct tst_test test = { + .test_all = run, + .test_variants = ARRAY_SIZE(variants), + .setup = setup, + .needs_root = 1, + .restore_wallclock = 1, +};