From patchwork Mon Mar 2 21:10:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45332 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 58A73214B5 for ; Mon, 2 Mar 2015 21:11:31 +0000 (UTC) Received: by wivr20 with SMTP id r20sf11758798wiv.3 for ; Mon, 02 Mar 2015 13:11:30 -0800 (PST) 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=mfVcd11JNqtULQOlvw6VXF+1z0O/8cTEqL9XYx3iUX57AnbvpputkQL01LgAdeHSKS Tk8wPp480RFR+tUmS4GcVczkdVzOtz5AkIyIy9FUDDQIeY7/D+M3PXRpYUoWYL77Zbf2 zPPGre9h68GC3DLJo6el4i86Ef+F7M/CUeF0LhJJlkKLEjnU5tncn8/taR73W3kFuEwG CHwebVQ+/ai4PUPjKux+AuisiJrjmkYEmCk1V8zC5mmRD3Udx8D+75zDJ1q0TUwJ7Aok G6OyBGdX636XyU9hxbsCdL1ZaCX7ekCBvdCgKYIXGRQOGUpZ7ZiGgW9M0HEDH9mjzTJG JQfg== X-Gm-Message-State: ALoCoQnxIE9i4w4MgSJnSei9Y837VFrNJBuG4tbTFlWEb4VgnRvATrE9pRUNoK82Xv1i49GyoEsm X-Received: by 10.180.101.101 with SMTP id ff5mr2493426wib.5.1425330690681; Mon, 02 Mar 2015 13:11:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.14 with SMTP id t14ls494508laz.61.gmail; Mon, 02 Mar 2015 13:11:30 -0800 (PST) X-Received: by 10.152.10.66 with SMTP id g2mr26132148lab.44.1425330690376; Mon, 02 Mar 2015 13:11:30 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id mj9si9711615lbc.97.2015.03.02.13.11.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 13:11:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbiw7 with SMTP id w7so32949528lbi.9 for ; Mon, 02 Mar 2015 13:11:30 -0800 (PST) X-Received: by 10.152.206.70 with SMTP id lm6mr26660360lac.35.1425330690284; Mon, 02 Mar 2015 13:11:30 -0800 (PST) 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 h5csp158730lbj; Mon, 2 Mar 2015 13:11:29 -0800 (PST) X-Received: by 10.66.221.135 with SMTP id qe7mr49238316pac.97.1425330664596; Mon, 02 Mar 2015 13:11:04 -0800 (PST) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com. [209.85.192.170]) by mx.google.com with ESMTPS id ta8si10041290pac.175.2015.03.02.13.11.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 13:11:04 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.170 as permitted sender) client-ip=209.85.192.170; Received: by pdbnh10 with SMTP id nh10so16682311pdb.4 for ; Mon, 02 Mar 2015 13:11:03 -0800 (PST) X-Received: by 10.66.137.98 with SMTP id qh2mr49924791pab.76.1425330663715; Mon, 02 Mar 2015 13:11:03 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id ym10sm11765258pac.10.2015.03.02.13.11.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Mar 2015 13:11:03 -0800 (PST) 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: Mon, 2 Mar 2015 13:10:10 -0800 Message-Id: <1425330612-24280-18-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425330612-24280-1-git-send-email-john.stultz@linaro.org> References: <1425330612-24280-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.182 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(); +}