From patchwork Thu Feb 21 20:05:46 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: 158959 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp895877jaa; Thu, 21 Feb 2019 12:05:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IYYU68xE0xdUUCX/qSUBu2mwC9U1w57HiONt9ZyX5VIHSyStBMckjimPiO3E3nTEwTJtf7G X-Received: by 2002:adf:f4c8:: with SMTP id h8mr232366wrp.6.1550779557299; Thu, 21 Feb 2019 12:05:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550779557; cv=none; d=google.com; s=arc-20160816; b=OnSk1tJb4pf2KW2t7UaOxb6m5BycOw3a4dSXJZz51uhBL0dh3sKr8CG0nQS58/I1NL 3Isjtk4oyXpDd+aqYxNEjel67xQLkUkgrG5vihX6+/7es7taSkzx40+VC11mS7p5z8r1 A0AzCC3mXiYtLwxtNqo+7AMJq7q99Y5lw6tW53P2A/lwupbuFRZn/EwIMes0kU201QPE LXX3lf5NRT1EAmIs8SMqOHBA8Ny8enHf+lV4c+iNRFsi/GQO3Fd9KaxLrIqz799BiBVJ 07f+bhfmhEvNRnVOZ6P36rKfsCENH91SzYb+8Yi6DDyhPi8nyZg/2zYjcw6MT7xbX5fg O+Gg== 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=DB7GU3a+csi1R4uJYPpbz+wNuaf1Vzld24mPwJvitts=; b=z3qbefP1KsJdXXPxvdXQVkr7whxPvpymWS4Z90rgTvEMWgT5ULpV7dKnG5LYEtO1Ls kmCztoJxmSTTGVnbEkkUmFeCnS+yk69x0z7/kf6udBsbpOC+HSNJF+vfeaSmKCXsNGHp L4wDUqF4er7AlXS8arhC3ExBrUaHLUCGmgAsCpHG7vGBZfdY+nFdCE399y57Di9PGkvr SpVLIhbhVzNeZ0rnRcf7mo5kqS5hpf8aR2EFc8LsJDyLeFMu0TNY42I4zIpT+JRPkDBo uwggQspdgdPskqvzYT7OtACBJzZiGmNd/voJZx+F+RiIBtiLN8e15EggXN2Ue8QEY7q5 aQOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Hnyi/VZ4"; 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 b85si6017863wmd.179.2019.02.21.12.05.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 12:05:57 -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="Hnyi/VZ4"; 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 D230F294AE9 for ; Thu, 21 Feb 2019 21:05:56 +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 [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 02199294AB6 for ; Thu, 21 Feb 2019 21:05:52 +0100 (CET) Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 588916013CE for ; Thu, 21 Feb 2019 21:05:53 +0100 (CET) Received: by mail-qk1-x744.google.com with SMTP id x9so5066533qkf.0 for ; Thu, 21 Feb 2019 12:05:52 -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=DhjB5EoiWbSSGfe6T3AqIhUKkM9IVletss0cHzBFZCo=; b=Hnyi/VZ4U6vkuD0MSCZ0D7HzpQhDp6Q1riCKngUWnwy9FQk8OPMHbUmfpTmjiIgV4J qlDNNsUnDISui6LFE1IY3WIyWN0zYIZkjfNzbnW1Ovtyw2BnGYWE9H7bZiv1KMoWrPel rRrwmA2HO9yI/ZzEa5wO1yqiaTh4Cc09PW2G75flFrEi/D7JhXOqwUeE6cbgh1siUsU1 BghjPQBcf06IWh8qO0L7QTV4T21xUCpQvz4s5oBEAMdSemrwfCpLwMlIhWoXTeVfb68l uxUpV16d+DY9hcn0YA7LYNZZsiNodOtaLIUFj/uWSXAharCvE8ffIY599ZWCCm4WS8KX iHUA== 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=DhjB5EoiWbSSGfe6T3AqIhUKkM9IVletss0cHzBFZCo=; b=WFvyApW1FMh1erjSIhadp5eqmbAn2A4LftMKKQ+4l2DTyB6EvJOOiCBFaJZ5KQHegp P5oqXxifTScaBMQ9D3xQfpMA0kX7e7wOTIosJdfhVRz6MCi2c8xQkqnqI9liEzsd94J7 O3lzWJfr/qyM2rLO73u73l/0Ch4/IDXK4vyLxrr27xYy7Yu1tpzZ8XgNU2S1SoeoQjoZ EdODKlAnMLHlko94nehs9V+bLc78TgrOg7tUvFEaWD2RIHflNVRZa0gWTniVko+b4c6L 37JP9eQj8+cpJhI9wTuDyCE9ZOwZ8AbX/571O7XlKYDqitezYtXyF3XAxCu4pw2OqmSI DYFg== X-Gm-Message-State: AHQUAuayuIMWlp4aemOXecaAiNbi+fxoBAmG+Ki2Tbz0v5onxBak1yG/ 5MhgTMo5OQDlXl0SE9bas0VOgIkvaX3jZw== X-Received: by 2002:a37:b581:: with SMTP id e123mr212081qkf.183.1550779550870; Thu, 21 Feb 2019 12:05:50 -0800 (PST) Received: from workstation.celeiro.br. ([2804:14c:8782:8061:32b5:c2ff:fe04:ac0]) by smtp.gmail.com with ESMTPSA id o21sm14257962qto.18.2019.02.21.12.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 12:05:50 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 21 Feb 2019 17:05:46 -0300 Message-Id: <20190221200547.7277-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-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] lib: include SAFE_CLOCK_ADJTIME() macro 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" Adds SAFE_CLOCK_ADJTIME() macro to tst_safe_clocks.h. Signed-off-by: Rafael David Tinoco --- include/tst_safe_clocks.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/tst_safe_clocks.h b/include/tst_safe_clocks.h index 553f8464a..304207f6b 100644 --- a/include/tst_safe_clocks.h +++ b/include/tst_safe_clocks.h @@ -6,6 +6,8 @@ #include #include "tst_test.h" +#include +#include "lapi/syscalls.h" static inline void safe_clock_getres(const char *file, const int lineno, clockid_t clk_id, struct timespec *res) @@ -42,6 +44,17 @@ static inline void safe_clock_settime(const char *file, const int lineno, "%s:%d clock_gettime() failed", file, lineno); } +static inline void safe_clock_adjtime(const char *file, const int lineno, + clockid_t clk_id, struct timex *txc) +{ + int rval; + + rval = tst_syscall(__NR_clock_adjtime, clk_id, txc); + + if (rval != 0) + tst_brk(TBROK | TERRNO, + "%s:%d clock_adjtime() failed", file, lineno); +} #define SAFE_CLOCK_GETRES(clk_id, res)\ safe_clock_getres(__FILE__, __LINE__, (clk_id), (res)) @@ -50,3 +63,6 @@ static inline void safe_clock_settime(const char *file, const int lineno, #define SAFE_CLOCK_SETTIME(clk_id, tp)\ safe_clock_settime(__FILE__, __LINE__, (clk_id), (tp)) + +#define SAFE_CLOCK_ADJTIME(clk_id, txc)\ + safe_clock_adjtime(__FILE__, __LINE__, (clk_id), (txc)) From patchwork Thu Feb 21 20:05:47 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: 158960 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp895967jaa; Thu, 21 Feb 2019 12:06:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IY0ce41eEszMlQMXG68YWrOgsGmTaoGmEuCX9d7zzjLUeeQg3Huo8DDmcb5u9LWZikTtUcG X-Received: by 2002:a1c:a789:: with SMTP id q131mr167510wme.82.1550779562198; Thu, 21 Feb 2019 12:06:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550779562; cv=none; d=google.com; s=arc-20160816; b=anfZ/TE+GfkUqnIgwc0DEiUsm2tttKjulfXOm7xUWe34hZ17XFWR6jERC7AMn4/TyU Q/fxIdV33g0WLP91KbL5Ra6b5+bZKvJtpz7d08/0VO0R5nX2KYTzxfwT5YvpUBdA05aB h55UrBgyxZiixRAjgDP2NVDxMQFc67tsL0v68k01hlU1sns1kMV97f51At+phX80G7vt cbudhaori6eJIUPBv+KjOrYrUp4hgsCJKU1sGHHvODC6kqXu5mFkurXMlFgMIdH1OkHy laxjb71mBdNGGQprJCzwUMbpCiYs+lif3cyCgla5ZVsUTVGrn/KqWpD58vfoI165SsyL VNtw== 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=z5sr+F8iEzF6rHjdyyqSqowzNO+1kdWK9qj3M11RCqE=; b=o5/Kcf1jmbeRrNuD6pKYxJaoEeBFM2hAqGtQ4v+NZld65jVHJ8+a4xOnWC5zXfWJzN 1+XVUetFs+rwW7YWPB36hoKnlf1FiXf/KjqtfxnnhC9h+tGEEWmvMhyowxOi9HAF7Jxs Rcf5yutZQlEjpJEozJJNuXl1e4pdNNcrsg27P0SNRrpID9i1m4dCnoKHPAU2y3VsGSgG Pa9fHW2vCbUH11egw/+yhTM0zop7b3tXj8AOnHSeHkbC4lJBMs86JiLWRql3VsiRyy2r SFZfbii/nhC9QIEYmJJ3VZ5tOz9C/7WbSu/C5K6CfQzWsGx+nbDzeeG9uZGY7lQzM70T 9sVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=X72PvF8G; 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 x1si12702611wrw.64.2019.02.21.12.06.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 12:06:02 -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=X72PvF8G; 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 B1920294AE3 for ; Thu, 21 Feb 2019 21:06:01 +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 0C674294AF2 for ; Thu, 21 Feb 2019 21:05:55 +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 611BB1000B6D for ; Thu, 21 Feb 2019 21:05:53 +0100 (CET) Received: by mail-qt1-x841.google.com with SMTP id p48so33034126qtk.2 for ; Thu, 21 Feb 2019 12:05:54 -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=2DflwzNsXpnbWfY7Dp+GDpz1lwCjsShP8DIaR/G52Zk=; b=X72PvF8GBTG4oDwVI/2Zbc3F36ne7RFegPDOZdfoUvbiKacgC9n3Fsj8iw68cLD9nu 3usowJSF6ZHT7ERM0Fep6kG+RNQMYn09PVVOwJZSrAbUFEjVzsTywx3xUZCLLpezFbSD 2tU/TR4EZ1xuP34gqyed3yFz7oww5J9SMrdTPS4BJYbG1pdZpqKGI9qd8b+1bZJ7dW7l WBMNwousKnrDWUK7F8BMHw+z/dEficvg4eAPVZRhB9o4AFB3JD3BiiCWtGYMWkLSu8l3 nrg/X5d2Jk0JOEoIi0AB0JD2iQefTydcMZT3ruigQS6LRSNI/SFMbG3sUEP1Qqyf9XeX iaaQ== 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=2DflwzNsXpnbWfY7Dp+GDpz1lwCjsShP8DIaR/G52Zk=; b=eg+TYL52CJisadQa38Wo6deJ2alHtdf/+zh6g3gwwXtYgQLpTg93OX3+/jJdTQ/z7P pcsTN0ItWj2XpwW6jMks86zkG/inzxfqNE83Xj99C4NbBF0aFbBgrsidBS2/TINbBzdq Rpv2QbBnh3UVOOlHMUB/yMGI8DmUZO9OeJnrc2XnJWWOR0T2tWDhBIFx1rDINYnli0H0 RJRR+kurWREnUGUSvG9rPW/yJqQep8xcQts/Wag11UpuJzS30m/+8j/9CS83TNga/7cc 8umhGDoPFHjeHdvdoSI7vjSBmsK+qPyEwoIb5UAqxuqX/23wR3myI6dc7w8JVt0oBJwD zALg== X-Gm-Message-State: AHQUAuYw/ieme2bcc1TEWjIl2eFwurZMQzaNZ/fVsA7jepo6n1tf5oeE UIOcavHyhwBfYmQWm56P3uEdbPntkuk2xw== X-Received: by 2002:ac8:3273:: with SMTP id y48mr145700qta.67.1550779552836; Thu, 21 Feb 2019 12:05:52 -0800 (PST) Received: from workstation.celeiro.br. ([2804:14c:8782:8061:32b5:c2ff:fe04:ac0]) by smtp.gmail.com with ESMTPSA id o21sm14257962qto.18.2019.02.21.12.05.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 12:05:52 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 21 Feb 2019 17:05:47 -0300 Message-Id: <20190221200547.7277-2-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221200547.7277-1-rafael.tinoco@linaro.org> References: <20190221200547.7277-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 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 2/2] syscalls/clock_adjtime: create clock_adjtime 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: 270 clock_adjtime{01,02} are created using the new API, based on existing adjtimex(2) tests. clock_adjtime() syscall might have as execution path: 1) a regular POSIX clock (only REALTIME clock implements adjtime()) - will behave exactly like adjtimex() system call. - only one being tested here. 2) a dynamic POSIX clock (which ops are implemented by PTP clocks) - will trigger the PTP clock driver function "adjtime()" - different implementations from one PTP clock to another - might return EOPNOTSUPP (like ptp_kvm_caps, for example) - no observed execution entry point for clock_adjtime() Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 3 + .../kernel/syscalls/clock_adjtime/.gitignore | 2 + .../kernel/syscalls/clock_adjtime/Makefile | 10 + .../syscalls/clock_adjtime/clock_adjtime01.c | 249 +++++++++++++++++ .../syscalls/clock_adjtime/clock_adjtime02.c | 261 ++++++++++++++++++ 5 files changed, 525 insertions(+) create mode 100644 testcases/kernel/syscalls/clock_adjtime/.gitignore create mode 100644 testcases/kernel/syscalls/clock_adjtime/Makefile create mode 100644 testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c create mode 100644 testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c diff --git a/runtest/syscalls b/runtest/syscalls index 7bccda996..093e7f2ef 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -74,6 +74,9 @@ chroot02 chroot02 chroot03 chroot03 chroot04 chroot04 +clock_adjtime01 clock_adjtime01 +clock_adjtime02 clock_adjtime02 + clock_getres01 clock_getres01 clock_nanosleep01 clock_nanosleep01 clock_nanosleep02 clock_nanosleep02 diff --git a/testcases/kernel/syscalls/clock_adjtime/.gitignore b/testcases/kernel/syscalls/clock_adjtime/.gitignore new file mode 100644 index 000000000..28d5a1d45 --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/.gitignore @@ -0,0 +1,2 @@ +clock_adjtime01 +clock_adjtime02 diff --git a/testcases/kernel/syscalls/clock_adjtime/Makefile b/testcases/kernel/syscalls/clock_adjtime/Makefile new file mode 100644 index 000000000..79f671f1c --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/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_adjtime/clock_adjtime01.c b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c new file mode 100644 index 000000000..958b08802 --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * clock_adjtime() syscall might have as execution path: + * + * 1) a regular POSIX clock (only REALTIME clock implements adjtime()) + * - will behave exactly like adjtimex() system call. + * - only one being tested here. + * + * 2) a dynamic POSIX clock (which ops are implemented by PTP clocks) + * - will trigger the PTP clock driver function "adjtime()" + * - different implementations from one PTP clock to another + * - might return EOPNOTSUPP (like ptp_kvm_caps, for example) + * - no entry point for clock_adjtime(), missing "CLOCK_PTP" model + * + * so it is sane to check possible adjustments: + * + * - ADJ_OFFSET - usec or nsec, kernel adjusts time gradually by offset + * (-512000 < offset < 512000) + * - ADJ_FREQUENCY - system clock frequency offset + * - ADJ_MAXERROR - maximum error (usec) + * - ADJ_ESTERROR - estimated time error in us + * - ADJ_STATUS - clock command/status of ntp implementation + * - ADJ_TIMECONST - PLL stiffness (jitter dependent) + poll int for PLL + * - ADJ_TICK - us between clock ticks + * (>= 900000/HZ, <= 1100000/HZ) + * + * and also the standalone ones (using .offset variable): + * + * - ADJ_OFFSET_SINGLESHOT - behave like adjtime() + * - ADJ_OFFSET_SS_READ - ret remaining time for completion after SINGLESHOT + * + * For ADJ_STATUS, consider the following flags: + * + * rw STA_PLL - enable phase-locked loop updates (ADJ_OFFSET) + * rw STA_PPSFREQ - enable PPS (pulse-per-second) freq discipline + * rw STA_PPSTIME - enable PPS time discipline + * rw STA_FLL - select freq-locked loop mode. + * rw STA_INS - ins leap sec after the last sec of UTC day (all days) + * rw STA_DEL - del leap sec at last sec of UTC day (all days) + * rw STA_UNSYNC - clock unsynced + * rw STA_FREQHOLD - hold freq. ADJ_OFFSET made w/out auto small adjs + * ro STA_PPSSIGNAL - valid PPS (pulse-per-second) signal is present + * ro STA_PPSJITTER - PPS signal jitter exceeded. + * ro STA_PPSWANDER - PPS signal wander exceeded. + * ro STA_PPSERROR - PPS signal calibration error. + * ro STA_CLOKERR - clock HW fault. + * ro STA_NANO - 0 = us, 1 = ns (set = ADJ_NANO, cl = ADJ_MICRO) + * rw STA_MODE - mode: 0 = phased locked loop. 1 = freq locked loop + * ro STA_CLK - clock source. unused. + */ + +#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 + +static long hz; +static struct timex saved, ttxc; + +#define ADJ_ALL (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \ + ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK) + +struct test_case { + unsigned int modes; + long highlimit; + long *ptr; + long delta; +}; + +struct test_case tc[] = { + { + .modes = ADJ_OFFSET_SINGLESHOT, + }, + { + .modes = ADJ_OFFSET_SS_READ, + }, + { + .modes = ADJ_ALL, + }, + { + .modes = ADJ_OFFSET, + .highlimit = 512000, + .ptr = &ttxc.offset, + .delta = 10000, + }, + { + .modes = ADJ_FREQUENCY, + .ptr = &ttxc.freq, + .delta = 100, + }, + { + .modes = ADJ_MAXERROR, + .ptr = &ttxc.maxerror, + .delta = 100, + }, + { + .modes = ADJ_ESTERROR, + .ptr = &ttxc.esterror, + .delta = 100, + }, + { + .modes = ADJ_TIMECONST, + .ptr = &ttxc.constant, + .delta = 1, + }, + { + .modes = ADJ_TICK, + .highlimit = 1100000, + .ptr = &ttxc.tick, + .delta = 1000, + }, +}; + +/* + * bad pointer w/ libc causes SIGSEGV signal, call syscall directly + */ +static int sys_clock_adjtime(clockid_t clk_id, struct timex *txc) +{ + return tst_syscall(__NR_clock_adjtime, clk_id, txc); +} + +static void timex_show(char *given, struct timex txc) +{ + tst_res(TINFO, "%s\n" + " mode: %d\n" + " offset: %ld\n" + " frequency: %ld\n" + " maxerror: %ld\n" + " esterror: %ld\n" + " status: %d (0x%x)\n" + " time_constant: %ld\n" + " precision: %ld\n" + " tolerance: %ld\n" + " tick: %ld\n" + " raw time: %d(s) %d(us)", + given, + txc.modes, + txc.offset, + txc.freq, + txc.maxerror, + txc.esterror, + txc.status, + txc.status, + txc.constant, + txc.precision, + txc.tolerance, + txc.tick, + (int)txc.time.tv_sec, + (int)txc.time.tv_usec); +} + +static void verify_clock_adjtime(unsigned int i) +{ + long ptroff, *ptr; + struct timex verify; + + memset(&ttxc, 0, sizeof(struct timex)); + memset(&verify, 0, sizeof(struct timex)); + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &ttxc); + timex_show("GET", ttxc); + + ttxc.modes = tc[i].modes; + + if (tc[i].ptr && tc[i].delta) { + + *tc[i].ptr += tc[i].delta; + + /* fix limits, if existent, so no errors occur */ + + if (tc[i].highlimit) { + if (*tc[i].ptr >= tc[i].highlimit) + *tc[i].ptr -= (2 * tc[i].delta); + } + } + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &ttxc); + timex_show("SET", ttxc); + + if (tc[i].ptr) { + + /* adjtimex field being tested so we can verify later */ + + ptroff = (long) tc[i].ptr - (long) &ttxc; + ptr = (void *) &verify + ptroff; + } + + TEST(sys_clock_adjtime(CLOCK_REALTIME, &verify)); + timex_show("VERIFY", verify); + + if (tc[i].ptr && *tc[i].ptr != *ptr) { + tst_res(TFAIL, "clock_adjtime(): could not set value (mode=%x)", + tc[i].modes); + } + + if (TST_RET < 0) { + tst_res(TFAIL | TTERRNO, "clock_adjtime(): mode=%x, returned " + "error", tc[i].modes); + } + + tst_res(TPASS, "clock_adjtime(): success (mode=%x)", tc[i].modes); +} + +static void setup(void) +{ + size_t i; + + hz = SAFE_SYSCONF(_SC_CLK_TCK); + + /* fix high and low limits by dividing it per HZ value */ + for (i=0; i < ARRAY_SIZE(tc); i++) { + if (tc[i].modes == ADJ_TICK) + tc[i].highlimit /= hz; + } + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &saved); +} + +static void cleanup(void) +{ + saved.modes = ADJ_ALL; + + /* restore clock resolution based on original status flag */ + + if (saved.status & STA_NANO) + saved.modes |= ADJ_NANO; + else + saved.modes |= ADJ_MICRO; + + /* restore original clock flags */ + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &saved); +} + +static struct tst_test test = { + .test = verify_clock_adjtime, + .setup = setup, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c new file mode 100644 index 000000000..74893a4e3 --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * clock_adjtime() syscall might have as execution path: + * + * 1) a regular POSIX clock (only REALTIME clock implements adjtime()) + * - will behave exactly like adjtimex() system call. + * - only one being tested here. + * + * 2) a dynamic POSIX clock (which ops are implemented by PTP clocks) + * - will trigger the PTP clock driver function "adjtime()" + * - different implementations from one PTP clock to another + * - might return EOPNOTSUPP (like ptp_kvm_caps, for example) + * - no entry point for clock_adjtime(), missing "CLOCK_PTP" model + * + * so it is sane to check for the following errors: + * + * EINVAL - clock id being used does not exist + * + * EFAULT - (struct timex *) does not point to valid memory + * + * EINVAL - ADJ_OFFSET + .offset outside range -512000 < x < 512000 + * (after 2.6.26, kernels normalize to the limit if outside range) + * + * EINVAL - ADJ_FREQUENCY + .freq outside range -32768000 < x < 3276800 + * (after 2.6.26, kernels normalize to the limit if outside range) + * + * EINVAL - .tick outside permitted range (900000/HZ < .tick < 1100000/HZ) + * + * EPERM - .modes is neither 0 nor ADJ_OFFSET_SS_READ (CAP_SYS_TIME required) + * + * EINVAL - .status other than those listed bellow + * + * For ADJ_STATUS, consider the following flags: + * + * rw STA_PLL - enable phase-locked loop updates (ADJ_OFFSET) + * rw STA_PPSFREQ - enable PPS (pulse-per-second) freq discipline + * rw STA_PPSTIME - enable PPS time discipline + * rw STA_FLL - select freq-locked loop mode. + * rw STA_INS - ins leap sec after the last sec of UTC day (all days) + * rw STA_DEL - del leap sec at last sec of UTC day (all days) + * rw STA_UNSYNC - clock unsynced + * rw STA_FREQHOLD - hold freq. ADJ_OFFSET made w/out auto small adjs + * ro STA_PPSSIGNAL - valid PPS (pulse-per-second) signal is present + * ro STA_PPSJITTER - PPS signal jitter exceeded. + * ro STA_PPSWANDER - PPS signal wander exceeded. + * ro STA_PPSERROR - PPS signal calibration error. + * ro STA_CLOKERR - clock HW fault. + * ro STA_NANO - 0 = us, 1 = ns (set = ADJ_NANO, cl = ADJ_MICRO) + * rw STA_MODE - mode: 0 = phased locked loop. 1 = freq locked loop + * ro STA_CLK - clock source. unused. + */ + +#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 +#include + +#include + +static long hz; +static struct timex saved, ttxc; + +#define ADJ_ALL (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \ + ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK) + +#define MAX_CLOCKS 16 + +struct test_case { + clockid_t clktype; + unsigned int modes; + long lowlimit; + long highlimit; + long *ptr; + long delta; + int exp_err; + int droproot; +}; + +struct test_case tc[] = { + { + .clktype = MAX_CLOCKS, + .exp_err = EINVAL, + }, + { + .clktype = MAX_CLOCKS + 1, + .exp_err = EINVAL, + }, + { + .clktype = CLOCK_REALTIME, + .modes = ADJ_ALL, + .exp_err = EFAULT, + }, + { + .clktype = CLOCK_REALTIME, + .modes = ADJ_TICK, + .lowlimit = 900000, + .ptr = &ttxc.tick, + .delta = 1, + .exp_err = EINVAL, + }, + { + .clktype = CLOCK_REALTIME, + .modes = ADJ_TICK, + .highlimit = 1100000, + .ptr = &ttxc.tick, + .delta = 1, + .exp_err = EINVAL, + }, + { + .clktype = CLOCK_REALTIME, + .modes = ADJ_ALL, + .exp_err = EPERM, + .droproot = 1, + }, +}; + +/* + * bad pointer w/ libc causes SIGSEGV signal, call syscall directly + */ +static int sys_clock_adjtime(clockid_t clk_id, struct timex *txc) +{ + return tst_syscall(__NR_clock_adjtime, clk_id, txc); +} + +static void timex_show(char *given, struct timex txc) +{ + tst_res(TINFO, "%s\n" + " mode: 0x%x\n" + " offset: %ld\n" + " frequency: %ld\n" + " maxerror: %ld\n" + " esterror: %ld\n" + " status: 0x%x\n" + " time_constant: %ld\n" + " precision: %ld\n" + " tolerance: %ld\n" + " tick: %ld\n" + " raw time: %d(s) %d(us)", + given, + txc.modes, + txc.offset, + txc.freq, + txc.maxerror, + txc.esterror, + txc.status, + txc.constant, + txc.precision, + txc.tolerance, + txc.tick, + (int)txc.time.tv_sec, + (int)txc.time.tv_usec); +} + +static void verify_clock_adjtime(unsigned int i) +{ + uid_t whoami=0; + struct timex *txcptr; + struct passwd *nobody; + static char name[] = "nobody"; + + txcptr = &ttxc; + + memset(txcptr, 0, sizeof(struct timex)); + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, txcptr); + timex_show("GET", *txcptr); + + if (tc[i].droproot) { + nobody = SAFE_GETPWNAM(name); + whoami = nobody->pw_uid; + SAFE_SETEUID(whoami); + } + + txcptr->modes = tc[i].modes; + + if (tc[i].ptr) { + + if (tc[i].lowlimit) + *tc[i].ptr = tc[i].lowlimit - tc[i].delta; + + if (tc[i].highlimit) + *tc[i].ptr = tc[i].highlimit + tc[i].delta; + } + + /* special case - if txcptr != NULL, SIGSEGV is throwed */ + if (tc[i].exp_err == EFAULT) + txcptr = NULL; + + TEST(sys_clock_adjtime(tc[i].clktype, txcptr)); + if (txcptr) + timex_show("TEST", *txcptr); + + if (TST_RET >= 0) { + tst_res(TFAIL, "clock_adjtime(): passed unexpectedly (mode=%x, " + "uid=%d)", tc[i].modes, whoami); + return; + } + + if (TST_ERR != tc[i].exp_err) { + tst_res(TFAIL | TTERRNO, "clock_adjtime(): expected %d but " + "failed with %d (mode=%x, uid=%d)", + tc[i].exp_err, TST_ERR, tc[i].modes, whoami); + return; + } + + tst_res(TPASS, "clock_adjtime(): failed as expected (mode=0x%x, " + "uid=%d)", tc[i].modes, whoami); + + if (tc[i].droproot) + SAFE_SETEUID(0); +} + +static void setup(void) +{ + size_t i; + + hz = SAFE_SYSCONF(_SC_CLK_TCK); + + /* fix high and low limits by dividing it per HZ value */ + for (i=0; i < ARRAY_SIZE(tc); i++) { + if (tc[i].modes == ADJ_TICK) { + tc[i].highlimit /= hz; + tc[i].lowlimit /= hz; + } + } + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &saved); +} + +static void cleanup(void) +{ + saved.modes = ADJ_ALL; + + /* restore clock resolution based on original status flag */ + + if (saved.status & STA_NANO) + saved.modes |= ADJ_NANO; + else + saved.modes |= ADJ_MICRO; + + /* restore original clock flags */ + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &saved); +} + +static struct tst_test test = { + .test = verify_clock_adjtime, + .setup = setup, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, +};