From patchwork Tue Feb 19 22:03:54 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: 158740 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4185176jaa; Tue, 19 Feb 2019 14:04:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IaCHI/9Uk9+QIkCtWGqB0tuMklc+s2I9Wwm+fp+jqAYxNYitpy7tyhTL/bZkfJIkNh62W3e X-Received: by 2002:adf:f145:: with SMTP id y5mr23587197wro.240.1550613849361; Tue, 19 Feb 2019 14:04:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550613849; cv=none; d=google.com; s=arc-20160816; b=QUzJy613BSkXtTtSsYlZv/snQd78v34JkBYcqSWghNdwHVGYNO/rwLVlBSzqocgjfT 5MWxObICeKZuOUs+MjNs9YeNCnZ5NKEvOf16TNxYel/IsEtI911fZ1HxOYrfjjn1fw6g 7i7i3KXzIZW/RtRB3FrXkhM7APGpH1EVDov/TjHqqGrK3VrW9nRhm2UYzzxNEwpr0DDm 2AxgpCF72yTY3OoeM8HEjWprW6bPiLmHTPpYQjYuzioBxla2Pc+h7URPcwcDTEu5Ea92 G2OJMvBWjl+ITu7eZBh3cK5ld/47R2sJ+/WHLOaTuHBL6fGKYoCReB91Gus3RT1QDTFU 4Pzg== 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=So7uChrcIv19jQR55YdPCXvYjNipdfZZUkVP/mikJKg=; b=VhJF9KrA+g5fClGdbbVRaAQORYoEC/IfrZEPdwIKKVVwm9VlxiEC59GsIkbt4L690/ WxPA6nmNyeE18r+LA9iris9U8X9MdoaC2Q/q8IppmJ0LlWqR2zR8zTaVob3IsYVCEGar 1HBGTGg8+UKKRblSkAVZeoPjqlAulH3ilLv+l0SF89w8OdwA3IDNI+kut1RZHZEqSPBF lHHODDHyVEHsn8Y6OG3peOKRX5uPVEIGzlC2eVy2JiMJJ7DH1pvhVe28K4Sm482k6l/u je96xAa0YI1OFAsFSqRzhYoD59a4I6dHi5+KXApoQukRxeE5Npn0dsvl1ABP7j0LI4zC ypWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="j/Pa3K9J"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 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. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id d16si2296588wmb.173.2019.02.19.14.04.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 14:04:09 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="j/Pa3K9J"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 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 821A13EA410 for ; Tue, 19 Feb 2019 23:04:08 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id EE6FF3EA2F6 for ; Tue, 19 Feb 2019 23:04:03 +0100 (CET) Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 BBA06140013B for ; Tue, 19 Feb 2019 23:04:02 +0100 (CET) Received: by mail-qk1-x742.google.com with SMTP id p15so702619qkl.5 for ; Tue, 19 Feb 2019 14:04:02 -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=KTzf3UCBfgp0DYyXGvpKf1GG8GVxKQS+T//Rx+d+Ijk=; b=j/Pa3K9JsX/qwFx5Rz83d57sOLF4gJxnk77y6qH/GUbyprpFQm6vinFgXdJMOSKW1h KMVlEVvdznODGQG24XKL96eVPodmUEzn4g3m2ML2GG6AtSCwWANkX2y3jKBlGhSVny5Y o9zG77Dp+SFY8qRbCWyprPV2KIWV/4c212QDREDVctVauZZFkRAupvRFTEQBbxhJs29k Parnv7wsZYI6PHM25mJr5RKzrceylxKQ7O+6BydsY3Do2PzzlTSA6QWcblpEamoj8aiQ vHjyz19AsdmqrJJL686aaG6ZIXLJnnc9Po/Ii4tBdr92KWkQq1clmW3GefvI/byExI7X g60g== 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=KTzf3UCBfgp0DYyXGvpKf1GG8GVxKQS+T//Rx+d+Ijk=; b=MaibZ2jmFYlq7PInHr5OXcGE4dWTx/ly8LYrN2Pgu4xbH4qib0yL/98noSsC4Bxi6N NgpTdE6SEFkZFLEqO4ffVAIVunehVfstEsZLWER9c8jHmwJ7ubvbRAJlnjp+qLYAB+We N/CxLtEtm6cponP2Weyu/IqMG9+Lvhgf1tie9ASR58nAcgzKo8kFrA0KhRaqIMpekAm4 p8ojWTlU7KjQxI94YMx7jiuI5tGgnPWD0WM2SQhdO6y9iyU7I1b8zeQbQ8SDMAIywINR YkHdFy5zyScDK50xje7xEtsigVgESkoJ8MKmFCykLYawjAkvPNl/FLY8W3q9rCaEbII2 odvw== X-Gm-Message-State: AHQUAuabmU+3/t3oeTDE46qCG8egvDwtG4P8HPfjMiqZJBNgLNGfeSCy 15SNuMVf5AFCZq24UYnNgVxYyHBN37yH8w== X-Received: by 2002:a37:c442:: with SMTP id h2mr21392621qkm.53.1550613841107; Tue, 19 Feb 2019 14:04:01 -0800 (PST) Received: from workstation.celeiro.br. ([2804:14c:8782:8061:32b5:c2ff:fe04:ac0]) by smtp.gmail.com with ESMTPSA id p15sm11674177qta.81.2019.02.19.14.03.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 14:03:59 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Tue, 19 Feb 2019 19:03:54 -0300 Message-Id: <20190219220355.32593-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207123137.GA9277@rei> References: <20190207123137.GA9277@rei> 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_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 v3 1/2] syscalls/clock_gettime: create clock_gettime syscall 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: 342 clock_gettime{01,02} are created using the new API, based on existing kernel/timers/clock_gettime{02,03} tests, which will be deleted in the next commits. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 3 + .../kernel/syscalls/clock_gettime/.gitignore | 2 + .../kernel/syscalls/clock_gettime/Makefile | 10 ++ .../syscalls/clock_gettime/clock_gettime01.c | 141 ++++++++++++++++++ .../syscalls/clock_gettime/clock_gettime02.c | 135 +++++++++++++++++ 5 files changed, 291 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_gettime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_gettime/Makefile create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime01.c create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime02.c diff --git a/runtest/syscalls b/runtest/syscalls index 668c87cd1..7bccda996 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_gettime01 clock_gettime01 +clock_gettime02 clock_gettime02 + clock_settime01 clock_settime01 clock_settime02 clock_settime02 diff --git a/testcases/kernel/syscalls/clock_gettime/.gitignore b/testcases/kernel/syscalls/clock_gettime/.gitignore new file mode 100644 index 000000000..0f9b24ab6 --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/.gitignore @@ -0,0 +1,2 @@ +clock_gettime01 +clock_gettime02 diff --git a/testcases/kernel/syscalls/clock_gettime/Makefile b/testcases/kernel/syscalls/clock_gettime/Makefile new file mode 100644 index 000000000..79f671f1c --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/Makefile @@ -0,0 +1,10 @@ +# Copyright (c) 2019 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +LDLIBS+=-lrt + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c new file mode 100644 index 000000000..d365823b2 --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ +/* + * Basic test for clock_gettime(2) on multiple clocks: + * + * 1) CLOCK_REALTIME + * 2) CLOCK_MONOTONIC + * 3) CLOCK_PROCESS_CPUTIME_ID + * 4) CLOCK_THREAD_CPUTIME_ID + * 5) CLOCK_REALTIME_COARSE + * 6) CLOCK_MONOTONIC_COARSE + * 7) CLOCK_MONOTONIC_RAW + * 8) CLOCK_BOOTTIME + */ + +#include "config.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +struct test_case { + clockid_t clktype; + int allow_inval; +}; + +struct tmpfunc { + int (*func)(clockid_t clk_id, struct timespec *tp); + char *desc; +}; + +struct test_case tc[] = { + { + .clktype = CLOCK_REALTIME, + }, + { + .clktype = CLOCK_MONOTONIC, + }, + { + .clktype = CLOCK_PROCESS_CPUTIME_ID, + }, + { + .clktype = CLOCK_THREAD_CPUTIME_ID, + }, + { + .clktype = CLOCK_REALTIME_COARSE, + .allow_inval = 1, + }, + { + .clktype = CLOCK_MONOTONIC_COARSE, + .allow_inval = 1, + }, + { + .clktype = CLOCK_MONOTONIC_RAW, + .allow_inval = 1, + }, + { + .clktype = CLOCK_BOOTTIME, + .allow_inval = 1, + }, +}; + +static int sys_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_gettime, clk_id, tp); +} + +static int check_spec(struct timespec *spec) +{ + return (spec->tv_nsec != 0 || spec->tv_sec != 0) ? 1 : 0; +} + +static void verify_clock_gettime(unsigned int i) +{ + size_t sz; + struct timespec spec; + + /* + * check clock_gettime() syscall AND libc (or vDSO) functions + */ + struct tmpfunc tf[] = { + { .func = sys_clock_gettime, .desc = "syscall" }, + { .func = clock_gettime, .desc = "vDSO or syscall" }, + }; + + for (sz = 0; sz < ARRAY_SIZE(tf); sz++) { + + memset(&spec, 0, sizeof(struct timespec)); + + TEST(tf[sz].func(tc[i].clktype, &spec)); + + if (TST_RET == -1) { + + /* errors: allow unsupported clock types */ + + if (tc[i].allow_inval && TST_ERR == EINVAL) { + + tst_res(TPASS, "clock_gettime(2): unsupported " + "clock %s (%s) failed as " + "expected", + tst_clock_name(tc[i].clktype), + tf[sz].desc); + + } else { + + tst_res(TFAIL | TTERRNO, "clock_gettime(2): " + "clock %s (%s) failed " + "unexpectedly", + tst_clock_name(tc[i].clktype), + tf[sz].desc); + } + + } else { + + /* success: also check if timespec was changed */ + + if (check_spec(&spec)) { + tst_res(TPASS, "clock_gettime(2): clock %s " + "(%s) passed", + tst_clock_name(tc[i].clktype), + tf[sz].desc); + } else { + + tst_res(TFAIL, "clock_gettime(2): clock %s " + "(%s) passed, unchanged " + "timespec", + tst_clock_name(tc[i].clktype), + tf[sz].desc); + } + } + } +} + +static struct tst_test test = { + .test = verify_clock_gettime, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c new file mode 100644 index 000000000..c08f0f0de --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ +/* + * Bad argument tests for clock_gettime(2) on multiple clocks: + * + * 1) MAX_CLOCKS + * 2) MAX_CLOCKS + 1 + * 3) CLOCK_REALTIME + * 4) CLOCK_MONOTONIC + * 5) CLOCK_PROCESS_CPUTIME_ID + * 6) CLOCK_THREAD_CPUTIME_ID + * 7) CLOCK_REALTIME_COARSE + * 8) CLOCK_MONOTONIC_COARSE + * 9) CLOCK_MONOTONIC_RAW + * 10) CLOCK_BOOTTIME + */ + +#include "config.h" +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "lapi/posix_clocks.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" + +#define MAX_CLOCKS 16 + +struct test_case { + clockid_t clktype; + int exp_err; + int allow_inval; +}; + +struct test_case tc[] = { + { + .clktype = MAX_CLOCKS, + .exp_err = EINVAL, + }, + { + .clktype = MAX_CLOCKS + 1, + .exp_err = EINVAL, + }, + /* + * Different POSIX clocks have different (*clock_get)() handlers. + * It justifies testing EFAULT for all. + */ + { + .clktype = CLOCK_REALTIME, + .exp_err = EFAULT, + }, + { + .clktype = CLOCK_MONOTONIC, + .exp_err = EFAULT, + }, + { + .clktype = CLOCK_PROCESS_CPUTIME_ID, + .exp_err = EFAULT, + }, + { + .clktype = CLOCK_THREAD_CPUTIME_ID, + .exp_err = EFAULT, + }, + { + .clktype = CLOCK_REALTIME_COARSE, + .exp_err = EFAULT, + .allow_inval = 1, + }, + { + .clktype = CLOCK_MONOTONIC_COARSE, + .exp_err = EFAULT, + .allow_inval = 1, + }, + { + .clktype = CLOCK_MONOTONIC_RAW, + .exp_err = EFAULT, + .allow_inval = 1, + }, + { + .clktype = CLOCK_BOOTTIME, + .exp_err = EFAULT, + .allow_inval = 1, + }, +}; + +/* + * bad pointer w/ libc causes SIGSEGV signal, call syscall directly + */ +static int sys_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + return tst_syscall(__NR_clock_gettime, clk_id, tp); +} + +static void verify_clock_gettime(unsigned int i) +{ + struct timespec spec, *specptr; + + specptr = &spec; + + /* bad pointer cases */ + if (tc[i].exp_err == EFAULT) + specptr = tst_get_bad_addr(NULL); + + TEST(sys_clock_gettime(tc[i].clktype, specptr)); + + if (TST_RET == -1) { + + if ((tc[i].exp_err == TST_ERR) || + (tc[i].allow_inval && TST_ERR == EINVAL)) { + + tst_res(TPASS | TTERRNO, "clock_gettime(2): " + "clock %s failed as expected", + tst_clock_name(tc[i].clktype)); + + } else { + + tst_res(TFAIL | TTERRNO, "clock_gettime(2): " + "clock %s failed unexpectedly", + tst_clock_name(tc[i].clktype)); + } + + } else { + + tst_res(TFAIL, "clock_gettime(2): clock %s passed" + " unexcpectedly", + tst_clock_name(tc[i].clktype)); + } +} + +static struct tst_test test = { + .test = verify_clock_gettime, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +};