From patchwork Tue Jan 29 17:36:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 157007 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4936075jaa; Tue, 29 Jan 2019 09:38:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN5WbMPcchYSFcJOFBn8ejCiOb2fD7NMAzqXpR9r0A5ly/7Egs/AqEujsCYopPmSJlRcZIqr X-Received: by 2002:a05:6402:121a:: with SMTP id c26mr25779717edw.104.1548783486793; Tue, 29 Jan 2019 09:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548783486; cv=none; d=google.com; s=arc-20160816; b=CzYNusIfz9vH+U2LyE/Cn3juwxPLqOzyWtLE1Ki1Ho3oIvrzBorYbUQClF5WQKTYCE CClG87nC5Yfa4KkHIf1TnCRqGvdYYCTEHVAySrzC2QvK8MLCpfwAUuEQHfNBX6EW7n0K 7d3ySTODoDQZE8AJoXZzVXyCp8FZ6vvFAelW0zN16gAIFN1h2q8BOpEL4/2u8GYGFsJt S5BGEUOGjgX90XoFC/AmcQ8Ix2Z5JZpy1P2OHd1V5t32OR4ymcwtsfyVejRdPKxjWMdv zH1svRcI+4NZUKXo3NCuR/fVEF3uc+kHlSjVf+8eq45B4AWQKQP6KGubWe1ybzW2Q+Kt 86eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=EIQrI1xfULjAkr9ssC9wT3t2aVsKWT4R5opv8ZUmkis=; b=U/Rw5/OMTO8sTTDrq+Opq56vkEsT+Anp6vE/QGrOec1yFcxBQ5IfvMQzV2YA9Eojti y/vTo3HIIZqyfjinP5S8aL4E3juRaFggmOAhOxV2iTs2wdt6sKn5xr23zX+Li8adxi4S 4YjPYhDS+Z/Q0FkRof0COwAoOhBNG3lAuVua0+NkLXn/Ow8rkY0SY6nOM28NtslMIrg7 ORje7SqdUNxDzyZCandW/3kBQVBUXIuOhXp+pGPq3aRFkRFL+yA6wjKThRuYZZIYhw7K xj/9+lwkm27L3uAc0ckjl6ca3RNJmhClUu/kFjZ7ZJbvlbnOvj4ffG3uIarjW7Sz+4Kl J5PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UTVFh7sV; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id n3si2844436edo.15.2019.01.29.09.38.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:38:06 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UTVFh7sV; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4A6A23EAD10 for ; Tue, 29 Jan 2019 18:38:06 +0100 (CET) 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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id DDA1E3EAD16 for ; Tue, 29 Jan 2019 18:37:16 +0100 (CET) Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (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 13662600258 for ; Tue, 29 Jan 2019 18:37:16 +0100 (CET) Received: by mail-qt1-x842.google.com with SMTP id p17so23172407qtl.5 for ; Tue, 29 Jan 2019 09:37:16 -0800 (PST) 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=/AkQJ1HT+MpG09Fhbnz31KN2+lWKYwwwosrDK2bi4rw=; b=UTVFh7sVpOYAMvddB5c3jEROVH6odckbStPILb00ic5EzphryLkpdA52ROBBB4gJx1 vDHJA4UcEMyKSKyBDIp5icRinRbEopAYHgWKOi7qvXhW4Y0InkZwwoIFcqgyCp1VaV56 3h3EXcFuVN78Vlta5vYUHrjpTWugfZAXchHRo= 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=/AkQJ1HT+MpG09Fhbnz31KN2+lWKYwwwosrDK2bi4rw=; b=srQdNV53efReR9X0HMG9IX3gkUvYVd1n8w9uj+3wVjPRF4Xjk2AMUKXB4S6ND/hx5V 0a8mrGfFQRP+TrwUQ/u9NhMgVXQEQq/qIF9LDUbBgm7XcrOD4XFdJBkIdoWn+WHbK6BL 2vREkAPyG7EjHf2Hbw6p1el05wZxxA8bPFILWxKqpWpHtnurh9oM1MF4EyYGog5ZLaoc Uhx5Me4lh4ZUkmx2OjGaJfKBg90pQNxsoz7koD42V6Vmh90mU3ZaiO3HR58npchKM9kH GxJWUAGoMyyQcMS9HUq8iTPuKiXFTztDfDqu/QGEVYqiNtyBTz9GHqsHi9gx3ggeX9o/ 1w7w== X-Gm-Message-State: AJcUukfugm7MrsUX8qMhXxISHQ316U0O9pJK47VfZVrTliqVIQ7za2TU CqmFuzlEM4slW7NPSiN+Nw5bo02VyPg= X-Received: by 2002:aed:2e63:: with SMTP id j90mr27087123qtd.35.1548783434708; Tue, 29 Jan 2019 09:37:14 -0800 (PST) Received: from workstation.celeiro.br. ([168.194.163.64]) by smtp.gmail.com with ESMTPSA id a20sm56890855qkj.28.2019.01.29.09.37.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:37:14 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Tue, 29 Jan 2019 15:36:58 -0200 Message-Id: <20190129173659.27901-7-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129173659.27901-1-rafael.tinoco@linaro.org> References: <20190124161159.GC16804@rei.lan> <20190129173659.27901-1-rafael.tinoco@linaro.org> 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_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 v4 7/8] syscalls/clock_settime: create syscall clock_settime tests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Fixes: 343 clock_settime01 creates a new test, using new API, based on existing and older kernel/timers/clock_settime02 test. clock_settime02 creates another test based on older kernel/timers/clock_settime03 test. Both will be deleted in the next commits. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 3 + .../kernel/syscalls/clock_settime/.gitignore | 2 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 72 +++++++++ .../syscalls/clock_settime/clock_settime02.c | 148 ++++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_settime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_settime/Makefile create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime01.c create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime02.c diff --git a/runtest/syscalls b/runtest/syscalls index 45fcebdd9..668c87cd1 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -79,6 +79,9 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 +clock_settime02 clock_settime02 + clone01 clone01 clone02 clone02 clone03 clone03 diff --git a/testcases/kernel/syscalls/clock_settime/.gitignore b/testcases/kernel/syscalls/clock_settime/.gitignore new file mode 100644 index 000000000..281217550 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/.gitignore @@ -0,0 +1,2 @@ +clock_settime01 +clock_settime02 diff --git a/testcases/kernel/syscalls/clock_settime/Makefile b/testcases/kernel/syscalls/clock_settime/Makefile new file mode 100644 index 000000000..e6674a6b2 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/Makefile @@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime01.c b/testcases/kernel/syscalls/clock_settime/clock_settime01.c new file mode 100644 index 000000000..227cfe38f --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime01.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Basic test for clock_settime(2) on REALTIME clock: + * + * 1) advance DELTA_SEC seconds + * 2) go backwards DELTA_SEC seconds + * + * Restore wall clock at the end of test. + */ + +#include "config.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define DELTA_SEC 10 +#define DELTA_US (long long) (DELTA_SEC * 1000000) +#define DELTA_EPS (long long) (DELTA_US * 0.1) + +static void verify_clock_settime(void) +{ + long long elapsed; + struct timespec begin, change, end; + + /* test 01: move forward */ + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &begin); + + change = tst_timespec_add_us(begin, DELTA_US); + + if (clock_settime(CLOCK_REALTIME, &change) != 0) + tst_brk(TBROK | TTERRNO, "could not set realtime change"); + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &end); + + elapsed = tst_timespec_diff_us(end, begin); + + if (elapsed > DELTA_US && elapsed < (DELTA_US + DELTA_EPS)) + tst_res(TPASS, "clock_settime(2): was able to advance time"); + else + tst_res(TFAIL, "clock_settime(2): could not advance time"); + + /* test 02: move backward */ + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &begin); + + change = tst_timespec_sub_us(begin, DELTA_US); + + if (clock_settime(CLOCK_REALTIME, &change) != 0) + tst_brk(TBROK | TTERRNO, "could not set realtime change"); + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &end); + + elapsed = tst_timespec_diff_us(end, begin); + + if (~(elapsed) < DELTA_US && ~(elapsed) > (DELTA_US - DELTA_EPS)) + tst_res(TPASS, "clock_settime(2): was able to recede time"); + else + tst_res(TFAIL, "clock_settime(2): could not recede time"); +} + +static struct tst_test test = { + .test_all = verify_clock_settime, + .needs_root = 1, + .restore_wallclock = 1, +}; diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime02.c b/testcases/kernel/syscalls/clock_settime/clock_settime02.c new file mode 100644 index 000000000..09c9dc4a4 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime02.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Basic tests for errors of clock_settime(2) on different clock types. + */ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +struct test_case { + clockid_t type; + struct timespec newtime; + int exp_err; + int replace; +}; + +struct test_case tc[] = { + { /* case 01: REALTIME: timespec NULL */ + .type = CLOCK_REALTIME, + .exp_err = EFAULT, + .replace = 1, + }, + { /* case 02: REALTIME: tv_sec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 03: REALTIME: tv_nsec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 04: REALTIME: tv_nsec = 1s+1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = NSEC_PER_SEC + 1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 05: MONOTONIC */ + .type = CLOCK_MONOTONIC, + .exp_err = EINVAL, + }, + { /* case 06: MAXCLOCK */ + .type = MAX_CLOCKS, + .exp_err = EINVAL, + }, + { /* case 07: MAXCLOCK+1 */ + .type = MAX_CLOCKS + 1, + .exp_err = EINVAL, + }, + /* Linux specific */ + { /* case 08: CLOCK_MONOTONIC_COARSE */ + .type = CLOCK_MONOTONIC_COARSE, + .exp_err = EINVAL, + }, + { /* case 09: CLOCK_MONOTONIC_RAW */ + .type = CLOCK_MONOTONIC_RAW, + .exp_err = EINVAL, + }, + { /* case 10: CLOCK_BOOTTIME */ + .type = CLOCK_BOOTTIME, + .exp_err = EINVAL, + }, + { /* case 11: CLOCK_PROCESS_CPUTIME_ID */ + .type = CLOCK_PROCESS_CPUTIME_ID, + .exp_err = EINVAL, + }, + { /* case 12: CLOCK_THREAD_CPUTIME_ID */ + .type = CLOCK_THREAD_CPUTIME_ID, + .exp_err = EINVAL, + }, +}; + +/* + * Some tests may cause libc to segfault when passing bad arguments. + */ +static int sys_clock_settime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_settime, clk_id, tp); +} + +static void verify_clock_settime(unsigned int i) +{ + struct timespec spec, *specptr; + + specptr = &spec; + + if (tc[i].replace == 0) { + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, specptr); + + /* add 1 sec to wall clock */ + specptr->tv_sec += 1; + + } else { + + /* use given time spec */ + *specptr = tc[i].newtime; + } + + /* bad pointer case */ + if (tc[i].exp_err == EFAULT) + specptr = tst_get_bad_addr(NULL); + + TEST(sys_clock_settime(tc[i].type, specptr)); + + if (TST_RET == -1) { + + if (tc[i].exp_err == TST_ERR) { + + tst_res(TPASS, "clock_settime(2): failed as expected"); + + } else { + + tst_res(TFAIL | TTERRNO, "clock_settime(2): clock %s " + "expected %s, failed with %s instead.", + clock_name(tc[i].type), + tst_strerrno(tc[i].exp_err)); + } + + return; + } + + tst_res(TFAIL | TTERRNO, "clock_settime(2): clock %s passed " + "unexpectedly, expected %s", + clock_name(tc[i].type), + tst_strerrno(tc[i].exp_err)); +} + +static struct tst_test test = { + .test = verify_clock_settime, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, + .restore_wallclock = 1, +};