From patchwork Wed Feb 6 17:17:02 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: 1037635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="CkGKg7wG"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vp671kQyz9sN6 for ; Thu, 7 Feb 2019 04:17:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9E8A53EA293 for ; Wed, 6 Feb 2019 18:17:12 +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 36B7F3EA063 for ; Wed, 6 Feb 2019 18:17:10 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id 6143D600637 for ; Wed, 6 Feb 2019 18:17:08 +0100 (CET) Received: by mail-qt1-x843.google.com with SMTP id 2so8708362qtb.5 for ; Wed, 06 Feb 2019 09:17:08 -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=KGneR7AIU82tSzEKzL5g7dS73IDHJE50hVqZ8lgLA58=; b=CkGKg7wGYx8hRq8xuPb8OdW9uE4AJ+EEbtel9FdNaJ6a7bTmcy8G6KUGrA15gchdcO gy51exqqpxe4pS8Qb++W1pZZt7Diw2v0+hcR1m86wbMjvYXBn2dPAJ38tnWs3NjlUUOM dl6w9rd3rBWyGfHaTa5tbvQsWVw0THxMYDNfTbODUmY79XLavGQezjKTnr1gbyqyIbww G3LYifXKuWxsEJgu49yzFUilEm2LiKyeqBJestnNzQ4yrrIopasJv1+F5/Qbz8PE/cD6 ehPgeSafMzrpQ/P9ovxE5SLHHqefPAsx4m6DTBpFCx9wZmI5F1XN+21h8aPjc8FpUm22 MjQA== 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=KGneR7AIU82tSzEKzL5g7dS73IDHJE50hVqZ8lgLA58=; b=RnaRvcuPZnkqu5U11yWE0rYjutPHYQ5P3eHKzxIdsrr8B6fwsTlaWrnj+iVN0F1/Jw Dpkmjhn+sgejOH2EDwTbaas4X2PhLjJsdO5+oix4Ta7Q4FGnC65Yu9iqz60tCfKs+g7p W+o3f5mQjlNV+1XVLnUUmMcO/Ugt6coBl0O825ZOO/fVIljMAlswqM5hAa7mZUmYl3iw kp+Cj8Wf08UmLZ8+Ex+0ZjbqdpJbV604YR/OIkTiy9ODimMXQu37CuXiSnahvjoN+M6G B4cKJjxYeym/JbkjKOiIZ/qzTo7Ucs3O4vxOtEUaKh2hLDGGgiud+nb7cGu0qYIViwQg JEOA== X-Gm-Message-State: AHQUAuY/d7LTvLPTJBPsT6Si6vvQNDGJmzQZn1aE8fRxLIGj2dnX7hRE Ln1ajgUDNbCSr4Oo1B6wgAc6acWpcHA= X-Google-Smtp-Source: AHgI3IY7HFP6CbqoSeFy/pWlmqY/SpGzl/FFDNaEeC3O2e9yrsFpSSjxEUBE3WYbubKdE7HHYSXkoQ== X-Received: by 2002:a0c:e5c1:: with SMTP id u1mr8606347qvm.113.1549473427535; Wed, 06 Feb 2019 09:17:07 -0800 (PST) Received: from workstation.celeiro.br. ([168.194.163.49]) by smtp.gmail.com with ESMTPSA id o21sm20147070qto.18.2019.02.06.09.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 09:17:06 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 6 Feb 2019 15:17:02 -0200 Message-Id: <20190206171703.5761-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 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 1/2] syscalls/clock_gettime: create syscall clock_gettime 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+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Fixes: 342 clock_gettime01 creates a new test, using new API, based on existing and older kernel/timers/clock_gettime02 test. clock_gettime02 creates another test based on older kernel/timers/clock_gettime03 test. Both 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 | 134 +++++++++++++++ .../syscalls/clock_gettime/clock_gettime02.c | 155 ++++++++++++++++++ 5 files changed, 304 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..89a2041e2 --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c @@ -0,0 +1,134 @@ +// 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_REALTIME_COARSE + * 4) CLOCK_MONOTONIC_COARSE + * 5) CLOCK_MONOTONIC_RAW + * 6) CLOCK_BOOTTIME + * 7) CLOCK_PROCESS_CPUTIME_ID + * 8) CLOCK_THREAD_CPUTIME_ID + * + * If unsupported, checks for correct return code. + */ + +#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 clocktype; + int exp_ret; + int exp_err; + int unsupported; +}; + +struct test_case tc[] = { + { + .clocktype = CLOCK_REALTIME, + }, + { + .clocktype = CLOCK_REALTIME_COARSE, +#ifndef CLOCK_REALTIME_COARSE + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, + { + .clocktype = CLOCK_MONOTONIC, +#ifndef CLOCK_MONOTONIC + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, + { + .clocktype = CLOCK_MONOTONIC_COARSE, +#ifndef CLOCK_MONOTONIC_COARSE + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, + { + .clocktype = CLOCK_MONOTONIC_RAW, +#ifndef CLOCK_MONOTONIC_RAW + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, + { + .clocktype = CLOCK_BOOTTIME, +#ifndef CLOCK_BOOTTIME + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, + { + .clocktype = CLOCK_PROCESS_CPUTIME_ID, +#ifndef CLOCK_PROCESS_CPUTIME_ID + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, +{ + .clocktype = CLOCK_THREAD_CPUTIME_ID, +#ifndef CLOCK_THREAD_CPUTIME_ID + .exp_ret = -1, + .exp_err = EINVAL, +#endif + }, +}; + +static void verify_clock_gettime(unsigned int i) +{ + struct timespec spec; + + TEST(clock_gettime(tc[i].clocktype, &spec)); + + if (TST_RET == -1 && tc[i].exp_ret == -1) { + + if (tc[i].exp_err == TST_ERR) { + tst_res(TPASS, "clock_gettime(2): unsupported clock %s " + "failed as expected", + tst_clock_name(tc[i].clocktype)); + } else { + tst_res(TFAIL | TTERRNO, "clock_gettime(2): " + "unsupported clock %s failed " + "unexpectedly", + tst_clock_name(tc[i].clocktype)); + } + return; + } + + if (TST_RET == -1 && tc[i].exp_ret == 0) { + + tst_res(TFAIL | TTERRNO, "clock_gettime(2): clock %s " + "failed unexpectedly", + tst_clock_name(tc[i].clocktype)); + return; + } + + if (TST_RET == 0 && tc[i].exp_ret == -1) { + + tst_res(TFAIL, "clock_gettime(2): unsupported clock %s passed " + "unexpectedly", + tst_clock_name(tc[i].clocktype)); + return; + } + + tst_res(TPASS, "clock_gettime(2): clock %s passed", + tst_clock_name(tc[i].clocktype)); +} + +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..5985cdec0 --- /dev/null +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c @@ -0,0 +1,155 @@ +// 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 - bad clock + * 2) MAX_CLOCKS + 1 - bad clock + * 3) CLOCK_REALTIME - bad time spec ptr (if supported) + * 4) CLOCK_MONOTONIC - bad time spec ptr (if supported) + * 5) CLOCK_REALTIME_COARSE - bad time spec ptr (if supported) + * 6) CLOCK_MONOTONIC_COARSE - bad time spec ptr (if supported) + * 7) CLOCK_MONOTONIC_RAW - bad time spec ptr (if supported) + * 8) CLOCK_BOOTTIME - bad time spec ptr (if supported) + * 9) CLOCK_PROCESS_CPUTIME_ID - bad time spec ptr (if supported) + * 10) CLOCK_THREAD_CPUTIME_ID - bad time spec ptr (if supported) + */ + +#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 DELTA_SEC 10 +#define NSEC_PER_SEC (1000000000L) +#define MAX_CLOCKS 16 + +struct test_case { + clockid_t clocktype; + int exp_err; +}; + +struct test_case tc[] = { + { + .clocktype = MAX_CLOCKS, + .exp_err = EINVAL, + }, + { + .clocktype = MAX_CLOCKS + 1, + .exp_err = EINVAL, + }, + { + .clocktype = CLOCK_REALTIME, + .exp_err = EFAULT, + }, + { + .clocktype = CLOCK_MONOTONIC, + .exp_err = EFAULT, + }, + /* + * Different POSIX clocks have different (*clock_get)() handlers. + * It justifies testing EFAULT for all. + */ + { + .clocktype = CLOCK_REALTIME_COARSE, +#ifndef CLOCK_REALTIME_COARSE + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, + { + .clocktype = CLOCK_MONOTONIC_COARSE, +#ifndef CLOCK_MONOTONIC_COARSE + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, + { + .clocktype = CLOCK_MONOTONIC_RAW, +#ifndef CLOCK_MONOTONIC_RAW + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, + { + .clocktype = CLOCK_BOOTTIME, +#ifndef CLOCK_BOOTTIME + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, + { + .clocktype = CLOCK_PROCESS_CPUTIME_ID, +#ifndef CLOCK_PROCESS_CPUTIME_ID + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, + { + .clocktype = CLOCK_THREAD_CPUTIME_ID, +#ifndef CLOCK_THREAD_CPUTIME_ID + .exp_err = EINVAL, +#else + .exp_err = EFAULT, +#endif + }, +}; + +/* + * Some tests may cause libc to segfault when passing bad arguments. + */ +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 case */ + if (tc[i].exp_err == EFAULT) + specptr = tst_get_bad_addr(NULL); + + TEST(sys_clock_gettime(tc[i].clocktype, specptr)); + + if (TST_RET == -1) { + + if (tc[i].exp_err == TST_ERR) { + tst_res(TPASS, "clock_gettime(2): %sclock %s failed as " + "expected", (tc[i].exp_err == EINVAL) ? + "unsupported " : "", + tst_clock_name(tc[i].clocktype)); + } else { + tst_res(TFAIL | TTERRNO, "clock_gettime(2): %sclock %s " + "failed unexpectedly", + (tc[i].exp_err == EINVAL) ? + "unsupported " : "", + tst_clock_name(tc[i].clocktype)); + } + return; + } + + tst_res(TFAIL, "clock_gettime(2): %sclock %s passed unexpectedly", + (tc[i].exp_err == EINVAL) ? "unsupported " : "", + tst_clock_name(tc[i].clocktype)); +} + +static struct tst_test test = { + .test = verify_clock_gettime, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, + .restore_wallclock = 1, +};