From patchwork Thu Feb 21 09:00:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158877 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp242542jaa; Thu, 21 Feb 2019 01:00:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZmcAP6K8or/DXtCD8jQqU7DEPrzp1az7dDZzGh7WSO3yupdsgdSfurdeGP4bvO8OC1wdGC X-Received: by 2002:a17:906:ca09:: with SMTP id jt9mr8472117ejb.74.1550739655848; Thu, 21 Feb 2019 01:00:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550739655; cv=none; d=google.com; s=arc-20160816; b=GnSNbZOwYAyw4zAJ1/I3atH7dhIxVRiP1qY7r3MzlyxT3pi6QAHJf/ng1nVafNd5Wy CStWNI5NpyBNEQ9OcY2J0t8KvirHXYpxWURFlsQFBH2n7HuetjWsU5zrSq5ggAXvLFYD aC+aTGP46iPbKhnMzPF4Ita12t691DUSJVVkpX7SNxPFZcgjEQrgHq6rByqEjFLoYYs0 5Orfe2UdYUj/9UZNnyRuM1Wx4sWE2ri1rMGlznlPI11LD4hw/qBsWmyfHh76AXVOvdCz dfWgSx+jlXqEVwViGC2dBqiGuMWcOcGqCHy0MLQAx2b/mxrdHd7Ujhw7CWmXNb25xTp7 vjRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=z8BecS6fLYQEJ00rmBESO9o72GCqvExk3JIxEsLBkPE=; b=A7HbnjQbfua+uLKEugt3AxK/rVEgT14VLiFEPSJrkmjqJIJ8BUiuf80bb02eT/MsaM t3YcnHqcaT2wbarIJchJMGqDAvWiSXe8r0W9SIBsCpbB6+pXw9C8R8GfA1wmd9bWjMva lZn1oHq1PYqTfy6zGNYZxC0ZTQYSloCAjH712X1LzMBQCFMd9at+bMdXzNhzg+M0GSfs RLgGfU+/TZERwbnu1kU8zH8Lrtr0A+gze3Nb4hvz16bAdwCp5sKYHDHcFcxXNBCgSF91 46nbuURePNqymPW2OZ2AqajBclkcHqU9k2XHjc50kYOhsS24Kh/28OR/obiaNqrVtzDC MnOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P+hIUvQD; 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 gx17si1143646ejb.28.2019.02.21.01.00.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 01:00:55 -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=P+hIUvQD; 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 44B173EA293 for ; Thu, 21 Feb 2019 10:00:55 +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 4A0ED3EA0CD for ; Thu, 21 Feb 2019 10:00:50 +0100 (CET) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 10F5F201406 for ; Thu, 21 Feb 2019 10:00:50 +0100 (CET) Received: by mail-pg1-x544.google.com with SMTP id r11so13459945pgp.6 for ; Thu, 21 Feb 2019 01:00:49 -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; bh=jNUd4eLku/WiUSnGz+4YUU68EW3EaILulUvnMGu8ipU=; b=P+hIUvQDvEScxNwr0L7JzQZ2R7srPPnydOwW1iub143St0Jivc2hOXhqEi0anbFuac 3lSfTdt90AZ4t7eQ2OmhJCWSBjzHsYSPY8Oam/1BS7ePEnh0V+IMkXcCBIDX5g+uFGnR 5YpGrQ/GiGn2G2pDBfcgaIqpgBAwghOQZA79Z2PDZut1OpKhd7UZ0FrVGMXOQm1O7+HU uPQ8WnfSmjnehOp+BLdeFZDJkANvPxPzoyLXOAfFcWizewIurrlulDeyS3grr3WU/7iR AoLXm699eZx3+dNG5EwwB/iQTCKQc/P2capnTxpfg/W39wvkfIfYjZbkhS0m7NyUSWKD vOjw== 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; bh=jNUd4eLku/WiUSnGz+4YUU68EW3EaILulUvnMGu8ipU=; b=SOzHXyPaSDKLPOCikG+Ih1L4yDvDzrrUfnz4h2uVI4DytbjMAgMyKEBh4pIuARaRww gNi0qYo5/tqS1iEHVj/1W4ae6/nYG1Jw4ln3bTCb2FF0DoTXoXWzOpwk6Hpx6mCZa2io oYD0+TNiQ4sjOqp2n3dR2tHXNEY3ASdpUWTUZtJTaKWRoB+Yce1sD4qzij73H/utJexH LvYFQ8ArNwlYteIJSqxfexb9RxszXZeeYpVpRX6+1uR3Tz+der7oQ7YMuYsaHofpcUSr 2TAW3ju6rwtYBLc4WLfToEjTpMKjtdY1IgQVTvsneyjjHj6xwAlt2Qq8wpJpMwHM+KyA F7cg== X-Gm-Message-State: AHQUAuYY083/VKLbIwlmIRQlav1hAKyU5tTW3czI0DqR+fv2mXYfLu1z HX+5do10OKM83P8ILE6CxCj7Rg== X-Received: by 2002:a62:20c9:: with SMTP id m70mr38065032pfj.118.1550739648353; Thu, 21 Feb 2019 01:00:48 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id v4sm27703948pff.77.2019.02.21.01.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Feb 2019 01:00:47 -0800 (PST) From: Sumit Garg To: chrubis@suse.cz, ltp@lists.linux.it Date: Thu, 21 Feb 2019 14:30:08 +0530 Message-Id: <1550739616-24054-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> References: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> 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: daniel.thompson@linaro.org Subject: [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" This api reads test block device stat file and returns the bytes written since the last invocation of this api. Signed-off-by: Sumit Garg --- include/tst_device.h | 7 +++++++ lib/tst_device.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/tst_device.h b/include/tst_device.h index 7ac2883..61902b7 100644 --- a/include/tst_device.h +++ b/include/tst_device.h @@ -44,4 +44,11 @@ int tst_umount(const char *path); */ int tst_clear_device(const char *dev); +/* + * Reads test block device stat file and returns the bytes written since the + * last call of this function. + * @dev: test block device + */ +unsigned long tst_dev_bytes_written(const char *dev); + #endif /* TST_DEVICE_H__ */ diff --git a/lib/tst_device.c b/lib/tst_device.c index fd4e277..65fcc13 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -45,6 +45,7 @@ static char dev_path[1024]; static int device_acquired; +static unsigned long prev_dev_sec_write; static const char *dev_variants[] = { "/dev/loop%i", @@ -364,3 +365,31 @@ int tst_umount(const char *path) errno = err; return -1; } + +unsigned long tst_dev_bytes_written(const char *dev) +{ + struct stat st; + unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0; + char dev_stat_path[1024]; + + snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat", + strrchr(dev, '/') + 1); + + if (stat(dev_stat_path, &st) != 0) + tst_brkm(TCONF, NULL, "Test device stat file: %s not found", + dev_stat_path); + + SAFE_FILE_SCANF(NULL, dev_stat_path, + "%*s %*s %*s %*s %*s %*s %lu %*s %*s %lu", + &dev_sec_write, &io_ticks); + + if (!io_ticks) + tst_brkm(TCONF, NULL, "Test device stat file: %s broken", + dev_stat_path); + + dev_bytes_written = (dev_sec_write - prev_dev_sec_write) * 512; + + prev_dev_sec_write = dev_sec_write; + + return dev_bytes_written; +}