From patchwork Thu Mar 12 00:40:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45709 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B75A4214C6 for ; Thu, 12 Mar 2015 00:41:11 +0000 (UTC) Received: by lbiz11 with SMTP id z11sf9329976lbi.2 for ; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=9spacl3/O5rCavO3xDO6YZo7Q8UOH9BfdM/UKndHYB8=; b=ERvHICzFtfawWK9qYReuzF24fRzuUObWRzOTFaibdKdZk6QzVXpc2cB25JscA9V/uo BzExYz/6gYur+YW2FXHlo52rt6JcTBRPKQp5Zv3voD9XGC4KIFdTWIci52xI+9mcJMZs nCiGQ83GxZZfEKzocAXKtYe/DZglQZkCNcPjnI56j3j9RYkrd96I6dMxp+wUAc6t2H6n ztoc2RB6ncf5j6u6BygedKpVY0VzP5rl10f3eI8qDPu5RWi6cAkl0u0fYnAm3NH5Nuvr 2MwosYVEJJ95iHW8WuMpNhvurSXPl34M88I2vLal8Bc+IoPvHVhFwwcHxNXJxxB8lxxb GY6A== X-Gm-Message-State: ALoCoQnOb5NK/UQDBAHksB8XAuQa2/icdpyrccd/4Hy/fX3vcdkTes0uG2YTrNr7cs9WyLop8Thy X-Received: by 10.112.77.101 with SMTP id r5mr6064226lbw.4.1426120870771; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.168 with SMTP id a8ls209172lab.14.gmail; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) X-Received: by 10.112.199.36 with SMTP id jh4mr2277186lbc.49.1426120870498; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id r2si3372175lbb.46.2015.03.11.17.41.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 17:41:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbiw7 with SMTP id w7so12601620lbi.6 for ; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) X-Received: by 10.152.30.103 with SMTP id r7mr33646112lah.76.1426120870409; Wed, 11 Mar 2015 17:41:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp3098705lbj; Wed, 11 Mar 2015 17:41:09 -0700 (PDT) X-Received: by 10.70.88.172 with SMTP id bh12mr65799731pdb.52.1426120839473; Wed, 11 Mar 2015 17:40:39 -0700 (PDT) Received: from mail-pd0-f179.google.com (mail-pd0-f179.google.com. [209.85.192.179]) by mx.google.com with ESMTPS id am9si10189167pad.8.2015.03.11.17.40.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 17:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.179 as permitted sender) client-ip=209.85.192.179; Received: by pdjy10 with SMTP id y10so15361166pdj.8 for ; Wed, 11 Mar 2015 17:40:38 -0700 (PDT) X-Received: by 10.70.100.39 with SMTP id ev7mr66280363pdb.29.1426120838604; Wed, 11 Mar 2015 17:40:38 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qa1sm7783493pdb.84.2015.03.11.17.40.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 17:40:37 -0700 (PDT) From: John Stultz To: Linux Kernel Mailing List Cc: John Stultz , Shuah Khan , Prarit Bhargava , Thomas Gleixner , Richard Cochran Subject: [PATCH 17/19] selftests/timers: Add set-tai from the timetest suite Date: Wed, 11 Mar 2015 17:40:13 -0700 Message-Id: <1426120815-32528-18-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426120815-32528-1-git-send-email-john.stultz@linaro.org> References: <1426120815-32528-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds the set-tai test which ensures the tai offset can be set properly from adjtimex. Cc: Shuah Khan Cc: Prarit Bhargava Cc: Thomas Gleixner Cc: Richard Cochran Signed-off-by: John Stultz --- tools/testing/selftests/timers/Makefile | 3 +- tools/testing/selftests/timers/set-tai.c | 79 ++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/set-tai.c diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index d733324..7e2fba7 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -5,7 +5,7 @@ LDFLAGS += -lrt -lpthread bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \ set-timer-lat threadtest mqueue-lat valid-adjtimex \ alarmtimer-suspend change_skew skew_consistency clocksource-switch \ - leap-a-day leapcrash + leap-a-day leapcrash set-tai all: ${bins} @@ -32,6 +32,7 @@ run_destructive_tests: run_tests ./clocksource-switch ./leap-a-day -s -i 10 ./leapcrash + ./set-tai clean: rm -f ${bins} diff --git a/tools/testing/selftests/timers/set-tai.c b/tools/testing/selftests/timers/set-tai.c new file mode 100644 index 0000000..dc88dbc --- /dev/null +++ b/tools/testing/selftests/timers/set-tai.c @@ -0,0 +1,79 @@ +/* Set tai offset + * by: John Stultz + * (C) Copyright Linaro 2013 + * Licensed under the GPLv2 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef KTEST +#include "../kselftest.h" +#else +static inline int ksft_exit_pass(void) +{ + exit(0); +} +static inline int ksft_exit_fail(void) +{ + exit(1); +} +#endif + +int set_tai(int offset) +{ + struct timex tx; + + memset(&tx, 0, sizeof(tx)); + + tx.modes = ADJ_TAI; + tx.constant = offset; + + return adjtimex(&tx); +} + +int get_tai(void) +{ + struct timex tx; + + memset(&tx, 0, sizeof(tx)); + + adjtimex(&tx); + return tx.tai; +} + +int main(int argc, char **argv) +{ + int i, ret; + + ret = get_tai(); + printf("tai offset started at %i\n", ret); + + printf("Checking tai offsets can be properly set: "); + for (i = 1; i <= 60; i++) { + ret = set_tai(i); + ret = get_tai(); + if (ret != i) { + printf("[FAILED] expected: %i got %i\n", i, ret); + return ksft_exit_fail(); + } + } + printf("[OK]\n"); + return ksft_exit_pass(); +}