From patchwork Tue Feb 19 09:28:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158697 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3447132jaa; Tue, 19 Feb 2019 01:29:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IZHkSdte/eLTK6HwQSmt6fHuaJiYYDOpGANRYI6P0H8aIP7gMau2/hZWz7ZpkYjVTxQnSz8 X-Received: by 2002:a50:97b3:: with SMTP id e48mr22778724edb.159.1550568553542; Tue, 19 Feb 2019 01:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550568553; cv=none; d=google.com; s=arc-20160816; b=UbpaSq5mn5rMz/EUiUZLHmLg6IRSMuGnwoRBv+qVxobDV26PPG8jA+2Oq4CZe3Wu88 Yqi3MNCP20KMqYrstAkkZvtjOtx18hBbw+qzrNHpv6dfINT3Vqe6n/A388FeP/DUTQ9i OoPfrmSn2isJo2PFWqT1SuU8CPIEI244msoeqF2BPA98RnATaYCsawOSQo2F8iMjUNrW MK2zuVoc3GarNaR1Qm1nvLQYgPPeCM5RjfiZfpqoJLgUXZlk2BBqp5es9cL1+bVlno17 9TlM+Gt/NPyslvDM0ZM7CcKNJAdPRmRt/I2WhO60UcVnDwqmw2QhyYX1cVHc94weFH8G fjBA== 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=+5LzyJphNiidctnL6B3H2TeaRZ3yfmm/+Qz0FtbwdIE=; b=k18dyYaPhwgDI4SdNnclrhCM+YELrEdR8tIS41upuo5HDU+EsEQM3tzjh43Q6ofxvI A3q+MXg97lSAZXfgGoxTTyUsBcpizch6CBjG91TwS0W8xOHTah3dPfM8PTiZLsrKpqMx MnueWWDRLNMLFrmZNeNmhYzQzBrY3jLRXbY23VOaEyvkMF3LoKUawz6AcAVqGnibjJj7 aLfywY/v7cy2o0v7IlgRzip/JPDkXA9TR/ps6pl9aNEhQPF3Wtn4HMI+bIF+InsGW9yG jYMvl01JGVYs+qs+LcDX4IwdbxuYskrgQ5W/GpWjJT/hU8ouBY6O6TrFbCwOEhutWHu3 iJ5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IQFCeqdJ; 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 d46si1994957ede.307.2019.02.19.01.29.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 01:29:13 -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=IQFCeqdJ; 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 18C6A3EA2E4 for ; Tue, 19 Feb 2019 10:29:13 +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 [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 00A9C3EA2E4 for ; Tue, 19 Feb 2019 10:29:06 +0100 (CET) Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 D46C01000C5A for ; Tue, 19 Feb 2019 10:29:04 +0100 (CET) Received: by mail-pl1-x641.google.com with SMTP id p8so10171319plo.2 for ; Tue, 19 Feb 2019 01:29:05 -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=t1afbiXeu5gtjQqQBxXTHGBQTys8Jwl1Stg/ONboF9A=; b=IQFCeqdJ3k66MqZXHuiE2iPQJoBTP/wSDjMsoztvpRY5GFJSK63PgA3TQQjZqYKtTz wAP3bURzX0a4VhX1MrZfiUBauzxD8+hXp4h1H2shXnkcHiO115wZ1skWjF7QHiGXJ986 UC52JYdJCRrlkCnWYfYbY1axjMMC3ZGwTf3Wvmwch9++HTIqWEoLREQPJKipxdj98FkF eOtjT6YXs39HmC+ksGS/iibzsSnJxduYsz5H8TySnQxYc4MSnY+G5CCyorO1aL0gJdWT b0urn54AdQ4m6OEVx2O4/0oTcxfZtY/faqYipk1JkxjFAxwfAeUAyAPkJ78gPQbwWuaR akRw== 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=t1afbiXeu5gtjQqQBxXTHGBQTys8Jwl1Stg/ONboF9A=; b=MqGYYqwU8uyplfXGTictYV+TTnQLn+67R0LFVvFPaa5MJ79Vt6jj65vawmKh0JbRPu q0NVlBcnoc6cNP97AXg3BTU+uI1xGLr/BUOtHRabgPvNfSScw/VYVPCXfSEhBHHbbGW4 gh9iF/BudYBGLJKPqlHKyS4VZvY+7iPWHRjaavoE7HD4DiulERvZNnBCFnlKp2EE2wSg QVWExeVMM1dzLHAafn0zE7qvJwvHuon7hnbiixsBu1uX0NjwJPLTq3QNMUqfPeSMzNVX 6W5aIEMcNGzYz/W6NLGQ+hxT5edHkrLR0q5x84Nj9CSx02uA6yG6urKfs5sMDGPFbvlI YHaQ== X-Gm-Message-State: AHQUAuZYuU/KfRVuQ69Aoebqwp6H8v1iyOcPaCDQGD6t/zzCmSOv9cCP 1kmw1HugqT6UlRw3Sz9yM4Tilo7cYcE/Pw== X-Received: by 2002:a17:902:f24:: with SMTP id 33mr30090481ply.65.1550568544205; Tue, 19 Feb 2019 01:29:04 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id n19sm34442229pfg.67.2019.02.19.01.29.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Feb 2019 01:29:03 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Tue, 19 Feb 2019 14:58:14 +0530 Message-Id: <1550568500-10871-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550568500-10871-1-git-send-email-sumit.garg@linaro.org> References: <1550568500-10871-1-git-send-email-sumit.garg@linaro.org> 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: daniel.thompson@linaro.org Subject: [LTP] [PATCH v3 1/7] lib: Add library functions for sync related syscalls 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" These library functions are used to add common test for minimal sectors written on device for various sync related syscalls. Signed-off-by: Sumit Garg --- include/tst_sync_device.h | 17 ++++++++++ lib/tst_sync_device.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 include/tst_sync_device.h create mode 100644 lib/tst_sync_device.c diff --git a/include/tst_sync_device.h b/include/tst_sync_device.h new file mode 100644 index 0000000..b07c490 --- /dev/null +++ b/include/tst_sync_device.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Sumit Garg + */ + +#ifndef TST_SYNC_DEVICE_H__ +#define TST_SYNC_DEVICE_H__ + +#include + +void tst_sync_device_init(const char *dev); +int tst_sync_device_write(const char *file, unsigned int size_mb); +bool tst_sync_device_check(unsigned int size_mb); +void tst_sync_device_cleanup(void); + +#endif diff --git a/lib/tst_sync_device.c b/lib/tst_sync_device.c new file mode 100644 index 0000000..5a0a17c --- /dev/null +++ b/lib/tst_sync_device.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Sumit Garg + */ + +#include +#include +#include + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "lapi/stat.h" +#include "tst_sync_device.h" + +#define SIZE_MB (1024*1024) +#define MODE 0644 + +static char dev_stat_path[1024]; +static char *buffer; +static int fd; +static unsigned long prev_write_sec; + +void tst_sync_device_init(const char *dev) +{ + struct stat st; + + snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat", + strrchr(dev, '/') + 1); + + if (stat(dev_stat_path, &st) != 0) + tst_brk(TCONF, "Test device stat file: %s not found", + dev_stat_path); + + buffer = SAFE_MALLOC(SIZE_MB); + + memset(buffer, 0, SIZE_MB); +} + +int tst_sync_device_write(const char *file, unsigned int size_mb) +{ + unsigned int counter; + + SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu", + &prev_write_sec); + + fd = SAFE_OPEN(file, O_RDWR|O_CREAT, MODE); + + /* Filling the test file */ + for (counter = 0; counter < size_mb; counter++) + SAFE_WRITE(1, fd, buffer, SIZE_MB); + + return fd; +} + +bool tst_sync_device_check(unsigned int size_mb) +{ + unsigned long write_sec = 0; + bool res = false; + + SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu", + &write_sec); + + if ((write_sec - prev_write_sec) * 512 >= + (size_mb * SIZE_MB)) + res = true; + + SAFE_CLOSE(fd); + + return res; +} + +void tst_sync_device_cleanup(void) +{ + if (buffer) + free(buffer); + + if (fd > 0) + SAFE_CLOSE(fd); +}