From patchwork Wed Dec 5 19:30:57 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: 152936 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp9679047ljp; Wed, 5 Dec 2018 11:31:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/VV3yvH6WQaBthV0oFJVJfywd7E3RVIw6aB1QyWD8Ty30qIhYToD6a/7lBdBE/7wCqpnuvP X-Received: by 2002:a5d:6988:: with SMTP id g8mr22019668wru.33.1544038272662; Wed, 05 Dec 2018 11:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544038272; cv=none; d=google.com; s=arc-20160816; b=PSzpl14TAWYBssf0iUsseUgk+41MrfZxcu14Vj+cDGlZBVMN2qILssMDWrc40WTgDm lxRw0vpdBzlrEZOQdnrfSvsdEWtMRGl3OYydHCP9PIGdo8ZgO6f3Ekfuicd7OuOQ2YgK sW8B7jyx1g8PbUcVO8B6rhYLFwJh19S+6x2IBlxPy6p25x8iYwzV9Zt4WMqC5JiCenG4 UyGKop+CyZ7HfnfiuvpSrLzApkgmYUbADHdV467FfOGpH17qK8y0vYqulkmfqhGHWntR BDu3JkmyxuH1/1pXV4JHooSka9wlmx4DdUeDM3eFMl8H+SO3N5A59YDH/tG27kDsl+xb J/sg== 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:message-id:date:to:from:dkim-signature:delivered-to; bh=ybv+7iPkb04P7wvgtH6W/R3JRbmX+ZFtdA+UxjaPF4g=; b=Aqv86cgtkodSarLW0mnAbzNHFsfq8c/jR10+f/yKKSPpzbsD5C+aVsDAbECD2w6ZPm lVMN1TWWPjlOW9B9XT+dg7McsoneANasoHwSHyU6KpFsnDBfuotirZSvps4liiWapNg8 g0pbiAnUSbWby3rfHuQdH8RmAhYc6IR1c9S4ou+zWodfsBNkVElKSkiwIZqS/XC9H0l7 TXK0bY/lOK4kGFoVn+REQYcP6pon58+QTsNyEjE4VGZIUX++aYaBkuPS/r9BFfNNsStN BJJk5geGVmfSxX5lhMzLzwPQynyxnTC3eiCb+XWn8gpJ+vC2obTgRGOYhWiv1VgsPyC+ DRYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="XIMPbdx/"; 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 h64si10953629wmg.38.2018.12.05.11.31.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 11:31:12 -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="XIMPbdx/"; 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 2C4383E7670 for ; Wed, 5 Dec 2018 20:31:12 +0100 (CET) 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 D46DE3E6BD6 for ; Wed, 5 Dec 2018 20:31:05 +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-5.smtp.seeweb.it (Postfix) with ESMTPS id 056B86007B0 for ; Wed, 5 Dec 2018 20:31:03 +0100 (CET) Received: by mail-qt1-x843.google.com with SMTP id y20so23621978qtm.13 for ; Wed, 05 Dec 2018 11:31:03 -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:mime-version :content-transfer-encoding; bh=bKWHVp/UqJEZU5ecCDqzayX9p34GNFxNxiEc1mwRmck=; b=XIMPbdx/G0By6Lm5VBeii+XAe2pYyFGZQ7xZq1w59Yh13wHom6XCtz1e/U9Fax5uzF G4W1l6nY0s2EwmlZUYaR93OKjKqBC0teucr7+oeO9BcawrfhkvHRi7tjndNTnZ7lS0q8 Os7nZwTcoFcw+RDDM4c81qoFTCoZR/oZLY8U4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bKWHVp/UqJEZU5ecCDqzayX9p34GNFxNxiEc1mwRmck=; b=KKl0jBtLxB0nB6FwAIv+sSMSB7BhjTThSuJYQ9m3Fkl0znIhYd/ufO/js9jxGFJd9e FwpKzhUFroqSHhKo2AZLApQAzeAVCzr2JGrVQM3L5XQKaZm6iQScj0DpgzXGnxX2/0ej UdJrdhcpY66+3I9m4bsYg4pZI3DpRWyf1taCl0hhQRqxBpNFxznDwkMY5aoLxOrQVLKt v7lNvpAiCnjFeHZUpoOqTgtdYgSt9sVZlnLSGi6uRT3B1I0YHBiE/72MhsmrZE99zsY6 e9TwKnvR1CGIG43eAUBuGS2H480K6YCfH/WY3kn2TV3z5CxYUpF2chv4SxYeJL9Yo32K /avg== X-Gm-Message-State: AA+aEWaWOIhpVLJA8AlsS7DiOj7RDR5ljYBwz5V0Q1O34gGX7Cjxonqz szE7HZFWf/G3dY8kwy4cB1na1UCgCZgyuQ== X-Received: by 2002:a0c:b02c:: with SMTP id k41mr24039305qvc.154.1544038262295; Wed, 05 Dec 2018 11:31:02 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.29]) by smtp.gmail.com with ESMTPSA id 24sm17655330qkp.65.2018.12.05.11.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 11:31:01 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 5 Dec 2018 17:30:57 -0200 Message-Id: <20181205193058.11146-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 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_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] syscalls/clock_settime01.c: create syscall clock_settime test 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_settime tests. It includes tests from files clock_settime02 and clock_settime03, which will be deleted in next commits. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 2 + .../kernel/syscalls/clock_settime/.gitignore | 1 + .../kernel/syscalls/clock_settime/Makefile | 8 + .../syscalls/clock_settime/clock_settime01.c | 187 ++++++++++++++++++ 4 files changed, 198 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 diff --git a/runtest/syscalls b/runtest/syscalls index ac1d2d2cd..4cbc13209 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -79,6 +79,8 @@ clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 clock_nanosleep2_01 clock_nanosleep2_01 +clock_settime01 clock_settime01 + 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..fcbb9fecc --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/.gitignore @@ -0,0 +1 @@ +clock_settime01 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..591e5c723 --- /dev/null +++ b/testcases/kernel/syscalls/clock_settime/clock_settime01.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Basic tests for clock_settime(2) on different clock types + */ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +static struct timespec clock_realtime_saved; + +struct test_case { + clockid_t type; + struct timespec newtime; + int exp_ret; + int exp_err; + int replace; +}; + +struct test_case tc[] = { + { /* case 01: REALTIME */ + .type = CLOCK_REALTIME, + .exp_ret = 0, + }, + { /* case 02: REALTIME: timespec NULL */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -2, + .exp_ret = -1, + .exp_err = EFAULT, + .replace = 1, + }, + { /* case 03: REALTIME: tv_sec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_sec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 04: REALTIME: tv_nsec = -1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = -1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 05: REALTIME: tv_nsec = 1s+1 */ + .type = CLOCK_REALTIME, + .newtime.tv_nsec = NSEC_PER_SEC + 1, + .exp_ret = -1, + .exp_err = EINVAL, + .replace = 1, + }, + { /* case 06: MONOTONIC */ + .type = CLOCK_MONOTONIC, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 07: MAXCLOCK */ + .type = MAX_CLOCKS, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 08: MAXCLOCK+1 */ + .type = MAX_CLOCKS + 1, + .exp_ret = -1, + .exp_err = EINVAL, + }, + /* Linux specific */ + { /* case 09: CLOCK_MONOTONIC_COARSE */ + .type = CLOCK_MONOTONIC_COARSE, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 10: CLOCK_MONOTONIC_RAW */ + .type = CLOCK_MONOTONIC_RAW, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 11: CLOCK_BOOTTIME */ + .type = CLOCK_BOOTTIME, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 12: CLOCK_PROCESS_CPUTIME_ID */ + .type = CLOCK_PROCESS_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, + { /* case 13: CLOCK_THREAD_CPUTIME_ID */ + .type = CLOCK_THREAD_CPUTIME_ID, + .exp_ret = -1, + .exp_err = EINVAL, + }, +}; + +static int sys_clock_settime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_settime, clk_id, tp); +} + +static int sys_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_gettime, clk_id, tp); +} + +static void cleanup(void) +{ + /* restore realtime clock */ + + if (sys_clock_settime(CLOCK_REALTIME, &clock_realtime_saved) < 0) + tst_res(TBROK | TTERRNO, "clock_settime(2): could not set " + "current time back"); +} + +static void setup(void) +{ + if (sys_clock_gettime(CLOCK_REALTIME, &clock_realtime_saved) < 0) + tst_res(TBROK | TTERRNO, "clock_gettime(2): could not get " + "current time"); +} + +static void verify_clock_settime(unsigned int i) +{ + struct timespec spec, *specptr; + + if (tc[i].replace == 0) { + + /* add 1 sec to test clock */ + + specptr = &spec; + specptr->tv_sec = clock_realtime_saved.tv_sec + 1; + specptr->tv_nsec = clock_realtime_saved.tv_nsec; + + } else { + + /* bad pointer case */ + + if (tc[i].newtime.tv_sec == -2) + specptr = tst_get_bad_addr(cleanup); + + /* use given values */ + + else { + 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 (tc[i].exp_ret == TST_RET) { + + if (TST_RET >= 0) + tst_res(TPASS, "clock_settime(2): worked as expected"); + + else { + 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 = { + .setup = setup, + .test = verify_clock_settime, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +};