From patchwork Fri Feb 8 13:29:55 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: 157844 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1958142jaa; Fri, 8 Feb 2019 05:30:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IaAxC9HWn54rC5mUxprAaG89HGQbUH43a+CFGKEoHifssE+RPkpHJ1P+ETsP0k5I7piRidm X-Received: by 2002:a50:f141:: with SMTP id z1mr16880022edl.44.1549632610615; Fri, 08 Feb 2019 05:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549632610; cv=none; d=google.com; s=arc-20160816; b=mEmqGrqjCr1n5rwEO7c8jYyNB23CAXrBz40mhF+lfqpFMwlFS3XKW3luZVpZlf55CS boP1KN2gHZvKhshJkXBx/s22zIrO5jF+2fVXc1cmw5l3JIzqc0YccPLhJDh5+ArQw8ws t2yZMmbAHgHLJ9/hknbb5puT+wEvaBCk4FoPqHmoGpoMt/d5LeVKYYe5zw1WTbxKgpzM nOs7L4QUrK4n4xHTK0FmK6iEYw33Q2nW5fhfCpI0S8fIzojfgMY3a8mLHDknZxkVNG7t PGwBqVBb6SVRwv6KHC8l9RLVVRfb2wNd0oYGY69E7yxIMcwb4jYdAi5Ff/YYZBUfWSdK GMVw== 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=sfw0E3u0x52Zf1sCWLbB9x218vT3drkpOfD/EVlCK78=; b=c53u3ehsKf1rtXsU90WwZMaimsXRS5b6x5u9JS/OpLvimk/bxF+JT3waVk19y7qYbX 25CWyYSiAVJ/NNVPPQumeuNXdNNnSPk0k66nIAYQiGF2zHw/4xPXHCYOE63cq8lFiyv9 ClRXNz6XyDh16T00zfur+NZCtrrqTygzPVob6t556Kh9gC02rRZPDeqJBqFCt4EOsrAY HoeZ3oLWYbcc/CSKjEyuHYQGDN0uXilnTcuUkwOifqiymZdG4ZvJ+7JTwq35fOKPUqDG WEIXr5sgMpXSYsOuyBGUycdCVS3Y7UvWI8Z0LTl1x7Rnitt+w9QK82EdBVHjLMPCHW6B ivWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XCwDUsOE; 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 e7si864289ejd.159.2019.02.08.05.30.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 05:30:10 -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=XCwDUsOE; 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 28A273EA664 for ; Fri, 8 Feb 2019 14:30:10 +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 2C9F73EA661 for ; Fri, 8 Feb 2019 14:30:02 +0100 (CET) Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) (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 CA9E1100170E for ; Fri, 8 Feb 2019 14:30:00 +0100 (CET) Received: by mail-qt1-x841.google.com with SMTP id n32so3802517qte.11 for ; Fri, 08 Feb 2019 05:30:01 -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=GU+/PMxwvzwzviUwSENmhc1jYQHxOE01yAT6E4eJPZ8=; b=XCwDUsOEmjwhXGgnM1WF8ELjWey/5wG42WZsI3ORtV6c3lAq6A5RE8vb5nL2hryxci SzwCYP9DllfSVWDvXkEs3uTs81ejTmxyDBS3pSrvyc6Wz9RgCUy7WOnriVnmskkDH4VK phaD4TqfrsxclzpJUU36oS03xq8INt+NA7fVWUEvGSUiUa0aTB0My8v9C0FCgqO7yrzP 3dJqPQGXBv4J3FvHRN/udoxj0ihc0myJFdR00hJGU1zmirRbslD8kA/okD1KfThaPzVn K43fd1KRZvRMAWh7M2gkpGHGWvotz353BHRzSYOJl84Amcc0qdjNMLqZS2/5sp0/0QXm Jf3w== 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=GU+/PMxwvzwzviUwSENmhc1jYQHxOE01yAT6E4eJPZ8=; b=IqX74wyv1nEFTDtW+YwG9VxoRKtwMkchaQaswEkIMS07JZMdY8MFbpmnDhUgD5mcXw O9Dl/nmb+R9hUPx5oVZI1NfzBxv0oJNtm53GUBku/qQ7tvLvwKTuxFaIHMOuyRLbgV1N 5SK3ugt1uFopXYgPQsBEDwF/bLRF6LO3nnh82B3QxfHV4DmiyQF6s3L2V36fUJzLzkbN O47dV6LWN7llKKmURsgue2YKw2bw7pr/ovWgiQqeepDx/+qvq6feULP5qHIAhGthF2yC rHNzNi/SGYaaIL1PnfLlsXanXs/Rici4Z0k+nNQaPw4MwfJHP0PFccU/TaRQwRBvuykb RBZA== X-Gm-Message-State: AHQUAubnninRlQ9K6zVG7aHqopWmsnrf0DnEXeyDkEj60HjAUa7IOli3 pSqX1DUe/iB5UWKllGBUeR/QWjh2hLY= X-Received: by 2002:ac8:300a:: with SMTP id f10mr6051731qte.236.1549632600137; Fri, 08 Feb 2019 05:30:00 -0800 (PST) Received: from workstation.celeiro.br. ([138.204.25.64]) by smtp.gmail.com with ESMTPSA id e186sm1872799qkb.32.2019.02.08.05.29.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 05:29:59 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Fri, 8 Feb 2019 11:29:55 -0200 Message-Id: <20190208132956.18990-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-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 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 v2 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 | 139 +++++++++++++++++ 5 files changed, 295 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..4db52c09d --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c @@ -0,0 +1,139 @@ +// 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" + +#include + +#define DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#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, +};