From patchwork Wed Dec 12 20:37:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 153594 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp26616ljp; Wed, 12 Dec 2018 12:37:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/XifR2vnpI0zauvn0rxCTYqqjgnPhug+HfGiif7dooxAJ+Fe/KeLDofX8VyDU2gjEsTtCvb X-Received: by 2002:a17:906:6b43:: with SMTP id o3-v6mr16349135ejs.31.1544647074304; Wed, 12 Dec 2018 12:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544647074; cv=none; d=google.com; s=arc-20160816; b=jVJbUXgM1aI2KulY901UJxT/UJdxtdM9vND9/hWtTvqucbCiEeO9XzDBEmJP8cocWu DaiDWyGgLtiPddAkbgKYBRcXv3gx74/9VMgYbiKIo2COBiudys74MyLdutlid1oGcivW ESQgzO04/0ygYIB6l4qwrf/uVv7aI5f/11gtaj0HrsmKRSsFNoHB0FzHYZ0vTDqG7H2w 9uDkUPzla8+wBQBr910/4p5HVHbUi2Nj6VpG1QmZ2vlkMbl822hZEKqQuf/rEeGiqtBG 5SjeymHMLR//g889K/hp9NbO3RWNNV22KuOa7UIWYCk8ZcUYH0FB2hpf4lRBPYO9tskH Lwhw== 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=cMBFNO9hC/ffsXlmVS7P+8ZDdQo7aFSHDjXSme+ZYRY=; b=sgygtjPaEU2pGpuLOsyBGvPDR+RcBAmWSxBlpegiKUv6sBDdKXX9fqX6SLUZtR0a/F VIwoKsRers/DhEbMCS/Tos0FDRJtVQfgw0LOFn2TH85OoIfW96vAdPw4yCUMJmpI1axE ppdwRFvh6KcrAZg1iwLm43yge/uVTEqPBnXYuvmZbC9Rvru/wKNkcjrvi/b135rYmk4Q QGvvzwGwdJLMWx0c+467Bw0GRwpXV9JV2Ds/2v1zIkOK+kQxNCdYdsCSxxcbHWMPGZis M9k96L2L+R+QRFyULAMmg5besyGL6lz1jC9ozyfhTXBIL5e27k1RNERFSLxVDOwzPlGg Y3ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HaDkETPx; 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 g17-v6si40396ejc.222.2018.12.12.12.37.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 12:37:54 -0800 (PST) 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=HaDkETPx; 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 EA0783E6FF5 for ; Wed, 12 Dec 2018 21:37:53 +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 412C83E6F94 for ; Wed, 12 Dec 2018 21:37:36 +0100 (CET) Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 92019601C64 for ; Wed, 12 Dec 2018 21:37:35 +0100 (CET) Received: by mail-qk1-x743.google.com with SMTP id o125so11626286qkf.3 for ; Wed, 12 Dec 2018 12:37:35 -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=SC8/tFdtnpu12EZuucE2jE2icThtUYh/4MUtk5kxKQE=; b=HaDkETPxBqbd0+QTTq0A22XFNbCSohyyOcAptrtxFmGEJPtqkCf/uGFEjMn1BVykQJ MYk7A3mQRLrX9zEUX45eFXlc2cWXWzeeCd6lrlqYxXE3uS51i6CXL2sshSbBRVt9wD1h hceTVU4QdcPzZtgTs2s0HcMMwuhrTZEYORH54= 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=SC8/tFdtnpu12EZuucE2jE2icThtUYh/4MUtk5kxKQE=; b=SsQIYLXOxJ/LMyEqD30Zow9F5uWjpnkNNjOH/ngmD+CZ/RfUMBJQqbQlKbxUpTYb/y mE8wZGbd9rlCXh0WqIgtoftEpIwpnaqArVp+5yzp0oyUvwX8fXy4gZ7dZ4PIGABHLGFa xYZHW8xJDLA9H2uYmkSTgQCaJqpcMIf12LEQbhS15OqQXvISzQ8i/9/+Oq0pYyqAb+td VoGLrTtrPryss2Y96mN06TGKw+w5D1yi+mI9Mu7yIvF5Invitju2mmblBih7Hxcgmrtl lLtkPkhYL9G/4yDrirhA+VtLnXcgl9BLArAVwdmv/jc07KgAXu0YCfsGqHvsBaQ9QndL DOTQ== X-Gm-Message-State: AA+aEWao/RQSaCBGjZPQAQjZH7jQ2IPMhpslIAOySI6cFtLK9a63AeNG OHgNjmAoBW041yeRCVyEINTxxfIX6YEBhw== X-Received: by 2002:a37:2bcf:: with SMTP id r76mr19007464qkr.218.1544647054229; Wed, 12 Dec 2018 12:37:34 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.7]) by smtp.gmail.com with ESMTPSA id n3sm11846872qtc.81.2018.12.12.12.37.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 12:37:33 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 12 Dec 2018 18:37:21 -0200 Message-Id: <20181212203723.18810-4-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181212203723.18810-1-rafael.tinoco@linaro.org> References: <20181211142750.GA27159@rei> <20181212203723.18810-1-rafael.tinoco@linaro.org> 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 v3 4/6] lib: new restore_wallclock field to restore realtime clock 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" Some tests around clocks need to restore the correct date and time after the tests, including possible iterations, run. This commit introduces a new field to tst_test called "restore_wallclock", which makes the test to save current realtime clock during setup phase, and, later, during cleanup, restore it to the appropriate time using a monotonic raw clock difference. Signed-off-by: Rafael David Tinoco --- include/tst_test.h | 1 + lib/tst_test.c | 6 ++++++ lib/tst_wallclock.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/tst_wallclock.c diff --git a/include/tst_test.h b/include/tst_test.h index 2ebf746eb..170bddc21 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -131,6 +131,7 @@ struct tst_test { int needs_rofs:1; int child_needs_reinit:1; int needs_devfs:1; + int restore_wallclock:1; /* * If set the test function will be executed for all available * filesystems and the current filesytem type would be set in the diff --git a/lib/tst_test.c b/lib/tst_test.c index 661fbbfce..aa3d674f0 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -868,6 +868,9 @@ static void do_setup(int argc, char *argv[]) if (tst_test->resource_files) copy_resources(); + + if (tst_test->restore_wallclock) + tst_wallclock_save(); } static void do_test_setup(void) @@ -899,6 +902,9 @@ static void do_cleanup(void) tst_sys_conf_restore(0); cleanup_ipc(); + + if (tst_test->restore_wallclock) + tst_wallclock_restore(); } static void run_tests(void) diff --git a/lib/tst_wallclock.c b/lib/tst_wallclock.c new file mode 100644 index 000000000..ef08e1dba --- /dev/null +++ b/lib/tst_wallclock.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +#include + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_clocks.h" +#include "lapi/posix_clocks.h" + +static struct timespec real_begin, mono_begin; + +void tst_wallclock_save(void) +{ + /* save initial monotonic time to restore it when needed */ + + if (tst_clock_gettime(CLOCK_REALTIME, &real_begin)) + tst_brk(TBROK | TERRNO, "tst_clock_gettime() realtime failed"); + + if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_begin)) + tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed"); +} + +void tst_wallclock_restore(void) +{ + static struct timespec mono_end, elapsed, adjust; + + if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_end)) + tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed"); + + elapsed = tst_timespec_diff(mono_end, mono_begin); + + adjust = tst_timespec_add_us(real_begin, tst_timespec_to_us(elapsed)); + + /* restore realtime clock based on monotonic delta */ + + if (tst_clock_settime(CLOCK_REALTIME, &adjust)) + tst_brk(TBROK | TERRNO, "tst_clock_settime() realtime failed"); +}