From patchwork Wed Dec 12 20:37:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 153595 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp26689ljp; Wed, 12 Dec 2018 12:37:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/WVtUJaDTY1sQipBvdM1qZaBVOXTFEohYD9t+JP8PDt2AufQm03fxKKbgNQ8e4YolCMZQ5M X-Received: by 2002:a50:9624:: with SMTP id y33mr19582960eda.206.1544647078922; Wed, 12 Dec 2018 12:37:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544647078; cv=none; d=google.com; s=arc-20160816; b=J5Tp6GJBjTyTRpEFIgFgmunJoXbFZQ/jS8mrXHpqvNf8sbSlboMWcCDJ8yQuwMwCr2 6L5rP4FxHophldRqzlX3w4urps/ZcaqqyXB+StjJtTB/tzcU6MOX0UEe/u5tbd/Bq5ei X9JAXoHMSOiV4mPts9uv+SOa2BlyshZmYWqhRKfmHIoDufYR+Nh93zshmgyyk9G7JJaI BOhpZQ0vM/w++zGwv+6FfDc/1lamiy5YYH9FaR52wRu8iAwu+GLj72ORUWGnECiW6chK KhFYecD+ifV4bhcktX+NhLqRW6HeepKSK/iWsP5/g1qnfq8mUVDqAcgophAWJuosd2wX a5Mg== 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=S96aqvx1wEamgaIcC8R6ChTuBYK9oPEXzJ6j6g7safE=; b=qj3+fuzVNQdk1oCUHPIySUdDk/VWE4/NNLOlEq+7TrU1HbV5wkJgoE4KMj0c8XV4Y5 uzh642C50HUs1joveUOiinnozTwFeD3BIm0jXe2jHLmGbFdgtRRzYTurkeZNQIgewifX RmqmJdml20I2C753fpmmylpOGnUg6LWAqGWTQKBIzryFt2UZX+Z24LmTwSZbkujoLXDG R1EJRzfuh9zY+poBcwdOmAHyEhdzA0oG8uoEL90asldiF2BfT9KvOAomTDXBib9ocfVd o8U5Vj8QtgnLB5k7mmyoEdaoJLhdzIOaqnIxfSE2e5qxjoq1T34FNbp9jsyyDSDjH3Hc FaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=g9XDpDkv; 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 e15-v6si44327ejr.99.2018.12.12.12.37.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 12:37:58 -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=g9XDpDkv; 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 803AC3E6F1C for ; Wed, 12 Dec 2018 21:37:58 +0100 (CET) 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 C1FC23E6F14 for ; Wed, 12 Dec 2018 21:37:38 +0100 (CET) Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 B92C91000B0C for ; Wed, 12 Dec 2018 21:37:37 +0100 (CET) Received: by mail-qt1-x843.google.com with SMTP id z16so22092630qtq.4 for ; Wed, 12 Dec 2018 12:37:37 -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=pQAi+9y2rcHflONOJzgbdWg6UJAdBJLNhFLdG1c0X9M=; b=g9XDpDkv6h754t0kgcppVUjfVgkcWk0ng4ilwugIFAvUjxMtbjzo7/ficbf50NFpqs 5ZzdMjXsQgl2Xv385mSZcK2aicq4d+C3GjsNycFGtr4pCDHYwghJLmeYhpzmpwTIX8Tu LlIOeAMrA/EMYjjNHSLhTKe/Q9uc8IctRE7sk= 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=pQAi+9y2rcHflONOJzgbdWg6UJAdBJLNhFLdG1c0X9M=; b=AYpaujC9Hk/bucalpmrPMB5dmNvai7cQjUeqchEf6ZVKYjlJge6rpcoYaNZlej1iib +fe4IgedLLM9S/3eDwdwPBQtHkzkxvkXLpUTXUDrTIW+ykOZgGnCqu3sWAV0Hwfm9zP9 XY8MjMxkFfs4ajZL26D6nHtODSmKxodsGOk66LLIPeeyrqNOLMgqFTXHflt9lFGZV/Uk 5QbtG9YA+5PDh5QiZyjwofLwrJDiBcuJB6hCUw0lmB5TbcwsevYRi9hv+NPBjYLyprxZ TclrnUhsUn6IniD0AbbSCf+i0Q/sq29WK+rMoKgPY1AlGFxFR4wur4+U7ZcqZDqzsmU8 z/UQ== X-Gm-Message-State: AA+aEWajC1Hyq19RFEgQ6+G9E7olSM++efDjNZhvaeK5YmtlNFGZRj6u vxjYgO01zeYlxuOeclvvuGUUeHcNwDMWPQ== X-Received: by 2002:aed:3e22:: with SMTP id l31mr21734369qtf.342.1544647056193; Wed, 12 Dec 2018 12:37:36 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.7]) by smtp.gmail.com with ESMTPSA id n3sm11846872qtc.81.2018.12.12.12.37.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 12:37:35 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 12 Dec 2018 18:37:22 -0200 Message-Id: <20181212203723.18810-5-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181212203723.18810-1-rafael.tinoco@linaro.org> References: <20181211142750.GA27159@rei> <20181212203723.18810-1-rafael.tinoco@linaro.org> 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_PASS,T_MIXED_ES 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 v3 5/6] 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 | 75 +++++++++ .../syscalls/clock_settime/clock_settime02.c | 150 ++++++++++++++++++ 5 files changed, 238 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 34b47f36b..dd03ad31a 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..6e0ee47c4 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime01.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 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_SEC_US (long long) (DELTA_SEC * 1000000) +#define DELTA_SEC_VAR_POS (long long) (DELTA_SEC_US * 1.10) +#define DELTA_SEC_VAR_NEG (long long) (DELTA_SEC_US * 0.90) + +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_SEC_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_SEC_US && elapsed < DELTA_SEC_VAR_POS) { + 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_rem_us(begin, DELTA_SEC_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_SEC_VAR_NEG) { + 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..25fcbfe09 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime02.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 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, + .newtime.tv_sec = -2, + .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 saved, spec, *specptr; + + if (tc[i].replace == 0) { + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &saved); + + /* add 1 sec to test clock */ + specptr = &spec; + specptr->tv_sec = saved.tv_sec + 1; + specptr->tv_nsec = saved.tv_nsec; + + } else { + + + if (tc[i].newtime.tv_sec == -2) { + + /* bad pointer case */ + specptr = tst_get_bad_addr(NULL); + } else { + + /* use given values */ + specptr = &spec; + specptr->tv_sec = tc[i].newtime.tv_sec; + specptr->tv_nsec = tc[i].newtime.tv_nsec; + } + } + + 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): " + "failed with different error"); + } + + return; + } + + tst_res(TFAIL | TTERRNO, "clock_settime(2): clock type %d failed", + tc[i].type); +} + +static struct tst_test test = { + .test = verify_clock_settime, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, + .restore_wallclock = 1, +};