From patchwork Wed Mar 20 21:41:33 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: 160736 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp69476jan; Wed, 20 Mar 2019 14:41:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXuS41h/BtZH9Nr+fvWLB9dAJ9ozIP9+vVwwtceXSGFrzIOi+gq9zJ1Ln3zZZCXC4E4bQD X-Received: by 2002:a17:906:905:: with SMTP id i5mr244491ejd.23.1553118107493; Wed, 20 Mar 2019 14:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553118107; cv=none; d=google.com; s=arc-20160816; b=XzM2A3KBJnzLzluo580pj1x0i0I0SecB04YL5mgNlXCK5Y+VFq7nfuvAh1AtBwJ96L p291vQz8E3zByc78WlbHc+dd3P8F3Y/5g44h1wkdKU4PYL5OZY5kNgQD03ofLgcNIop0 VH2bLfcK6Vjt3elrthbTjzev8RciYDJve/MFxgS6oiZYSRCte3D3xg620RUOXJnHHxwF RAZr4QMoNZwzQ7Wqj2cFYi2JN+5pOGJCzDXJ0f+b69O8LBmTm+8fDSrhrsgI0MKMmopw gUiUBxaUHw41BqsAQXwIvBs4vXQZyBv7TFlJJh0SLq7x0ZYMoc/OfTLopCAVpnSLeQOl tCcw== 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 :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=O1K7N7rNdV50fllYr319600JsvM7lz+RVi37VJNJr1c=; b=XzHClj0K/pKCOtGZN/ikW2sUSzb06phhWKZLONLBt0jqteC4SDJCaxaecTGM1NMku6 JBuN7UyiTJn0C+tJW5dtTfKq3MeJZtU1kjnEOttk1SNVVkS1UtHrVFIRGoJ7XEYY/oW3 N+ZhlQ54iggUfbR4o15Us1lHMkL6iAfao3jwkMgpAvJbBLruY7KLetw5y5shFF16nYoT r4CWxJ/RWgxBRQiT2lyy1CKqhY/ncuKSQcFMVCU8mAkIoMHkB6YZx2yxgAWRJA//oIxj Shxs+fXVmHTV79bmcs998HlKn/okEO4Fvzxaalp5wou3v7XEKGRUk841GzxjsC6dhSdY 7TFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="x49/Ogic"; 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 d13si1251952edx.162.2019.03.20.14.41.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:41:47 -0700 (PDT) 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="x49/Ogic"; 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 1C6F6294AE4 for ; Wed, 20 Mar 2019 22:41:47 +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 [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 9DF2A3EA8F2 for ; Wed, 20 Mar 2019 22:41:42 +0100 (CET) Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 C45DD140074A for ; Wed, 20 Mar 2019 22:41:41 +0100 (CET) Received: by mail-qt1-x844.google.com with SMTP id t28so4416127qte.6 for ; Wed, 20 Mar 2019 14:41:41 -0700 (PDT) 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=++1fMHmpDkFbngg7rQIasHvye23O4GxQFNunUk07TcU=; b=x49/OgicTau1eMVs/BqsB0bierFTvHtZROgS660jH3qhNod7pZ3EOiri7fUnBp4GXb h34vdw/reyqG4BlCmCalP+AzVJVWfJ7Hq3fieVGS4wHy3EBYI4pmYMO1QaJfyhlcr9Zy D/6khGZCv4MG3uSmdatUsDl2Te1fbuCbgEGO1U0MJwrJRyfHlYywtfMv3XZuTNaMzytb /X/LZSRc+t1j0JicSfSq+cmdH4gRmV+8V8tgz320QHBWPA4LxGskCozDxLl5j1+F7svt RzwsZczyJ8rIql5ZfrzFgYcIv+JMgeDCGcKLeWnaf9ww+xQVhbtahYOm03eaCL7/RqEY v9PA== 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=++1fMHmpDkFbngg7rQIasHvye23O4GxQFNunUk07TcU=; b=lJlCP+L4k8v6sQLVfvnUgq1g9wv01VI6SXjT2iJZP7ko/RD9tc/q1DYgpcwyvbm5KL a7AXCXYUFNA+PO/5BU8EYA+zp7sHGKolQETvipCzqXQ03uQLa4IDa2XADELjVHsPhxE4 IhMWzrAeycCeiESXrDPqq72TJFgW5YxooD8AbhRvzZy+ugmh3MfSKCULCScFbVeUAwJh C1yVd4/cX/2BBlYNkHQKJGdb5LhP20vdOE2SZR1oiSLlntM52w+/wfAc6q+/EWxknXYp Bl9zGCuc8eQX379ZxHIGmZcK4ef+Jv7gotJ7VSbk/V7bKqIzw+gg9ydnbDG6t+avwccK a6eA== X-Gm-Message-State: APjAAAV+F1PGEHB0/YmXmHlmNFG2S8fO1FHjDYbpxKNZPu2j7/R263M7 3BCfxU7PU/1wwTnQOeWv9yzd4CbP7C8Szw== X-Received: by 2002:ac8:263d:: with SMTP id u58mr33654qtu.295.1553118100419; Wed, 20 Mar 2019 14:41:40 -0700 (PDT) Received: from workstation.celeiro.br ([191.177.184.97]) by smtp.gmail.com with ESMTPSA id p6sm2113654qtk.70.2019.03.20.14.41.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:41:39 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 20 Mar 2019 18:41:33 -0300 Message-Id: <20190320214135.7029-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190313163239.GC6171@rei> References: <20190313163239.GC6171@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 Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v2 1/3] 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/tst_safe_clocks.h b/include/tst_safe_clocks.h index d5cd83394..a952be4bf 100644 --- a/include/tst_safe_clocks.h +++ b/include/tst_safe_clocks.h @@ -6,7 +6,9 @@ */ #include +#include #include "tst_test.h" +#include "lapi/syscalls.h" #include "lapi/posix_clocks.h" static inline void safe_clock_getres(const char *file, const int lineno, @@ -44,6 +46,18 @@ 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)) @@ -52,3 +66,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 Wed Mar 20 21:41:34 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: 160737 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp69539jan; Wed, 20 Mar 2019 14:41:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrZIfuWxUQ0kN1vJV6cXlTP0QF83m2sHGZ4YJEBZ2Yl9Mbk7olROVkKaR248N0I/z0i0LN X-Received: by 2002:adf:edcf:: with SMTP id v15mr245528wro.20.1553118112526; Wed, 20 Mar 2019 14:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553118112; cv=none; d=google.com; s=arc-20160816; b=fBt9ZfIYB/zV3KWUAY9ZPxYLVvR9P6hHcwrFI3qP+qAp28BCQFqUKDzqXw29eof4GZ JtgbhK6PRaIWydjpnFevjrSjD9uefrXtl/9jaNFhu+9CdbpF4qkwY55K4Jn9L0qp02Gt t3aHt0Uax6jjy6y8bVYZHUQlpJ2vE1U6Ovvm+ZXiZ/Crs6MCGu/rzefB2cFk/e0Tl9/n +m2+0WiLPO3cM/L0Dt9cwAK0nNqvD6VVtFKcMfqtLPrdP6mADfyXu5gIUQ4OvuCH9pm4 MxtO7zIR9GP7vsYUD1gzsFMeN+rx2xugml+bbdYrP+nlIfdviugXorH1rG0QCOVFJo0c Qu6g== 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 :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=QDRe0EHXgHAgX3KmjSQTBTaKTondGPg9kenr3vb7Dds=; b=nFHcuXoPTZ1L0Lk9vojjoXpIE9iCegd8f1Sh0qsBqjxm60udRf2AARYIvdUpQLxGcc OOKtaPGScvBxK/Z+XqzhrkSjptfl4GtprK8nOJk+9hM6orO6GcxrxZkfgUEdrdy8GzKV 3X3EBvMfiVF/pZ9yTEWyiqKxpD7IeCtHdTvWjIEiuVxh6BErPCu8Zv68Jw/eLX2YFozd /VOfeZ3AMwISJJJfNuXfbh42wpxQH41WrkqOSUp2u8SDO3MpTctsDr3f/ml+MoFyrwI3 xYHd0UEda2yQzyyiCfTa0BXcMLRpVe7KmvfdmOmhF7vMUL2fo/zEPuU929uLT8yS/R6f wdeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XxcGFQYX; 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 q1si2010376wrv.258.2019.03.20.14.41.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:41:52 -0700 (PDT) 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=XxcGFQYX; 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 10B50294AC1 for ; Wed, 20 Mar 2019 22:41:52 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id C4EF6294ABA for ; Wed, 20 Mar 2019 22:41:44 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 2B83F200A1A for ; Wed, 20 Mar 2019 22:41:44 +0100 (CET) Received: by mail-qt1-x841.google.com with SMTP id k2so4463072qtm.1 for ; Wed, 20 Mar 2019 14:41:44 -0700 (PDT) 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=fDT14x0rF7AqqGJn6Cn+F6o/adLy612O8cGATgrbNtY=; b=XxcGFQYX6sdMXPqvGIm3cWzFDSmMcDdVmzO9pOh2reZ6xcMI6qwYG8Qw8TcdYaQJBc xbmmkEs7dXYEihO6NWP3XgjHy8gyntTkOcm7ZpLAsqAQt9093l0D9VVT6Daj1c9onm+G nx6JD8djJbV1cZ7yVmUJavebqjwX2MYV9ivPyya/n68SOCOQOmc6iK9881Ca20Xy49DL wCkack1luQULU3wiMTItnOvwSGVhTi1SXdZi1oM8vPQUojG1QwkZUpBoEfTH41wwqI0M Mo/0Xw1QGslVn98hMKY6i24nLGCJW2nZW9gVV2DZetQ4qDZwsTo1H7WQztt7WLJAiHzn tkPw== 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=fDT14x0rF7AqqGJn6Cn+F6o/adLy612O8cGATgrbNtY=; b=BxyppH5HeREEq++2R6vYu+ZHuvnaevI2ULp6yH7Gu2TppHoMvIVMMp93sKmVrZmjLV zPXhTgVZ1pdHFtHFmmT5cnKI9lbJyB9kNBtMxeyvIZh58u9UHtAmk4kIq3Nz5ff3xWsa f9fvu1WVHyeVLRv8/LxnsxcW4R13kxEL/iKtmg7MRRX1QhhvPMxTwDD5b0Uk4Ts0QvZg Ak1mYGfupaUMicjXt3To2SpTRmxymCUx63NvTiXNU7PnI5sQYBHN++geve7uq7L5KG1w 8aXG1HwwcKskR204oTxyOfpkxr56xDW4Ojd34g+fiUrzTT8aAanUHHWw1W/LTtYRGyab eTtw== X-Gm-Message-State: APjAAAW0nbUWaZVi3bAuMDvopqi7zgUYkv81OeIbMaVr4NI/BQOUFeOe u1j0AtGHjjv29NrE3vykFXSUru++D78nFg== X-Received: by 2002:ac8:3517:: with SMTP id y23mr58504qtb.57.1553118102511; Wed, 20 Mar 2019 14:41:42 -0700 (PDT) Received: from workstation.celeiro.br ([191.177.184.97]) by smtp.gmail.com with ESMTPSA id p6sm2113654qtk.70.2019.03.20.14.41.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:41:41 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 20 Mar 2019 18:41:34 -0300 Message-Id: <20190320214135.7029-2-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320214135.7029-1-rafael.tinoco@linaro.org> References: <20190313163239.GC6171@rei> <20190320214135.7029-1-rafael.tinoco@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v2 2/3] lapi/posix_clocks.h: add MAX_CLOCKS definition 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" Used by clock_XXXtime() tests, defining MAX_CLOCKS in common header. Signed-off-by: Rafael David Tinoco --- include/lapi/posix_clocks.h | 2 ++ testcases/kernel/syscalls/clock_gettime/clock_gettime02.c | 2 -- testcases/kernel/syscalls/clock_settime/clock_settime02.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/lapi/posix_clocks.h b/include/lapi/posix_clocks.h index 0d1f0e99c..4914479ac 100644 --- a/include/lapi/posix_clocks.h +++ b/include/lapi/posix_clocks.h @@ -9,6 +9,8 @@ #ifndef POSIX_CLOCKS_H__ #define POSIX_CLOCKS_H__ +#define MAX_CLOCKS 16 + #ifndef CLOCK_MONOTONIC_RAW # define CLOCK_MONOTONIC_RAW 4 #endif diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c index 2a29a71e6..b4bc6e2d5 100644 --- a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c @@ -24,8 +24,6 @@ #include "tst_timer.h" #include "tst_safe_clocks.h" -#define MAX_CLOCKS 16 - struct test_case { clockid_t clktype; int exp_err; diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime02.c b/testcases/kernel/syscalls/clock_settime/clock_settime02.c index 8db417b6b..e16e9061a 100644 --- a/testcases/kernel/syscalls/clock_settime/clock_settime02.c +++ b/testcases/kernel/syscalls/clock_settime/clock_settime02.c @@ -16,7 +16,6 @@ #define DELTA_SEC 10 #define NSEC_PER_SEC (1000000000L) -#define MAX_CLOCKS 16 struct test_case { clockid_t type; From patchwork Wed Mar 20 21:41:35 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: 160738 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp69644jan; Wed, 20 Mar 2019 14:42:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl/0M25fisIAN3qr2fmzU956uQv99hmyX+gLGf9TK5W9uHOp5/PQvpRuPvllOE+ZpoGoMR X-Received: by 2002:a1c:f30d:: with SMTP id q13mr270001wmq.21.1553118120979; Wed, 20 Mar 2019 14:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553118120; cv=none; d=google.com; s=arc-20160816; b=WTYPzXeTEaMGqVArv7hb8Y02pYOiEES0gblkXDyyx35dl0tROHvdC7x4ewgZIDSxYS y8jhBG63e8z9ttFDoh4qhP+9rkKw29zSH/tvie8vra0zIspYd2Hx/kgbznPfC7wT6T/3 oxfLbFsDfO9FplOUIAkr2Y4ICTgl7pn+fVCPrPXImP6w0WB8Hy1JUfvc0Ey192Y3si7q pdKlidWUgYH5DXR/0vyEdp61ZjXD3juhB7/isF9W29cgb/EspnCi57gG77c763Y0URx9 uEejIiGgQ/WLPhPkSGLCAV8BeyZZJmXrrwIQuuzqiiAyZHIi66zBuKgQ4nxSlVFvw0HS 4SRw== 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 :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=QGV0eCq/itNsd/yul79+gBUvHJSLgjzv8YTXhoATT2k=; b=d6swMl7CHRuq+pce/InFXBOhv1a9TPgzowbcprfj0UbMPTShMQ9KLKy7YzmibAKqiA DCcOEVEWloSXra1db0dblcah80vvNpxoWpbghCGLB+6gQbyMMKfPLqtyQbFSbl1Rjj0t p0B7VDYeVOge7ZqTSDHWkEm8y/XP1kal5DTT97QsUOBxcMQ+wU3CDVq1yIK3RczwIQlm zR/53VeuG0qDiPjIyt632GyVCPX5CRpiVzPsYHn4kt5spSy3gOhREivPnGO9hvEYycD1 Ow5hmtMx7vcwOFrk1ILFAcwkdaEaCJRFWRm0yMNxEfoSiYe/hhkgs1phnQFAY/DZXktH RfIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=odaDo+3X; 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 a21si2161985wmb.35.2019.03.20.14.42.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:42:00 -0700 (PDT) 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=odaDo+3X; 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 2CD4D294ADC for ; Wed, 20 Mar 2019 22:41:58 +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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 025FF294AC4 for ; Wed, 20 Mar 2019 22:41:48 +0100 (CET) Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 15D861000543 for ; Wed, 20 Mar 2019 22:41:45 +0100 (CET) Received: by mail-qt1-x844.google.com with SMTP id v20so4383716qtv.12 for ; Wed, 20 Mar 2019 14:41:46 -0700 (PDT) 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=ptzy9UBOA7UPxjN1ArdpWq+nJuefMaggNtssI2sqaik=; b=odaDo+3XTR9eYoRgCSCwPUwjWZojmjSZZafarpSOa1kkbeLUloePPBEDrO0PdZ6TZn o9Z5I7kqsbZ9IalKCRSXMWaHLnXzQi5arVHNvocL7/AtJQPHYqmzkWCo0JFipixyOe6N WLWaotCn8SE+okK05hCQdABoBxbqPn6s4uBUNMPvcc6W6Nyd+5c8RwxWo14ltXEJFeQq BAH0BxzgUWMuzKqu+wFLDpiacyplr5YhHHHmjH7zvn18CPi2O/l9aZvujrgSDbqmE5pL ZtSmAQY4Ag39zz4eFrFHcNAD1sMNOKC8zRhzFIqylkA7IPeTzf/SVWbaMF71XuItPFUB Lqig== 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=ptzy9UBOA7UPxjN1ArdpWq+nJuefMaggNtssI2sqaik=; b=bTgtJxPbx+W/sgJr59ymeYipzINIm5J3HG3O383SdjfiQ/pe4miDhjGXqsPs7LAe6a cVxsu2J+g4C4iBFrQGi9UOLOlzVztT2VsLeVNP77/HTwr+sCqe4kDdqX3hKuzz8hSRgl VMO4/j8B3/Kf7HZNTlpnlRxUHnIO36H2c370neyzAOYd9PbQjdBZOQ3nhSrUz6+Z6jK5 D9M3HaHWVuYqtOI2BtEskWqHENIKn37NJp4S9h0dd7ziCVw8Z2KFpfqfHdgG+TX/X++D fTeB6asmgmuiKc6hzU4VcwJ1Tw/6hz6fDH7BZbWL7HzdAlRQjT8AqRWEb5qGVkVOQfJs v6iw== X-Gm-Message-State: APjAAAXIdmX5wiIpTNHwAvpibxy23VMtYB/YDnETR2PGCquYENXt/BrK +yfv2cyi9F6KSA1djmlADPayQzD9eNfT5g== X-Received: by 2002:aed:23c6:: with SMTP id k6mr74137qtc.244.1553118104957; Wed, 20 Mar 2019 14:41:44 -0700 (PDT) Received: from workstation.celeiro.br ([191.177.184.97]) by smtp.gmail.com with ESMTPSA id p6sm2113654qtk.70.2019.03.20.14.41.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 14:41:44 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 20 Mar 2019 18:41:35 -0300 Message-Id: <20190320214135.7029-3-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320214135.7029-1-rafael.tinoco@linaro.org> References: <20190313163239.GC6171@rei> <20190320214135.7029-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 Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v2 3/3] 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 --- include/lapi/posix_clocks.h | 4 + runtest/syscalls | 3 + .../kernel/syscalls/clock_adjtime/.gitignore | 2 + .../kernel/syscalls/clock_adjtime/Makefile | 10 + .../syscalls/clock_adjtime/clock_adjtime.h | 57 +++++ .../syscalls/clock_adjtime/clock_adjtime01.c | 216 +++++++++++++++++ .../syscalls/clock_adjtime/clock_adjtime02.c | 218 ++++++++++++++++++ 7 files changed, 510 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_adjtime.h 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/include/lapi/posix_clocks.h b/include/lapi/posix_clocks.h index 4914479ac..b1f7a7c55 100644 --- a/include/lapi/posix_clocks.h +++ b/include/lapi/posix_clocks.h @@ -11,6 +11,10 @@ #define MAX_CLOCKS 16 +#define ADJ_ALL (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | \ + ADJ_ESTERROR | ADJ_STATUS | ADJ_TIMECONST | \ + ADJ_TICK) + #ifndef CLOCK_MONOTONIC_RAW # define CLOCK_MONOTONIC_RAW 4 #endif diff --git a/runtest/syscalls b/runtest/syscalls index a13d51918..817f3576b 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_adjtime.h b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime.h new file mode 100644 index 000000000..34b97fdfa --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime.h @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +#include "config.h" +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_safe_clocks.h" +#include "lapi/syscalls.h" +#include "lapi/posix_clocks.h" +#include +#include +#include +#include + +static int sys_clock_adjtime(clockid_t, struct timex *); +static void timex_show(char *, struct timex); + +/* + * 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); +} 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..48cfbe6c5 --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c @@ -0,0 +1,216 @@ +// 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 "clock_adjtime.h" + +static long hz; +static struct timex saved, ttxc; + +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 = 500000, + .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, + }, +}; + +static void verify_clock_adjtime(unsigned int i) +{ + long ptroff, *ptr = NULL; + 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 = tc[i].highlimit; + } + } + + 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; + + /* save original clock flags */ + + SAFE_CLOCK_ADJTIME(CLOCK_REALTIME, &saved); + + hz = SAFE_SYSCONF(_SC_CLK_TCK); + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + + /* fix high and low limits by dividing it per HZ value */ + + if (tc[i].modes == ADJ_TICK) + tc[i].highlimit /= hz; + + /* fix usec as being test default resolution */ + + if (saved.modes & ADJ_NANO) { + if (tc[i].modes == ADJ_OFFSET) { + tc[i].highlimit *= 1000; + tc[i].delta *= 1000; + } + } + } +} + +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, + .restore_wallclock = 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..de9bae860 --- /dev/null +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c @@ -0,0 +1,218 @@ +// 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 "clock_adjtime.h" + +static long hz; +static struct timex saved, ttxc; + +static void cleanup(void); + +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, + }, +}; + +static void verify_clock_adjtime(unsigned int i) +{ + uid_t whoami = 0; + struct timex *txcptr; + struct passwd *nobody; + static const 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: EFAULT for NULL pointers + * txcptr = tst_get_bad_addr() -> SIGSEGV is thrown (and not EFAULT) + */ + + 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 (tc[i].exp_err != TST_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, + .restore_wallclock = 1, +};