From patchwork Mon Dec 6 16:11:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1564032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=szSGCN1N; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J77hs5CqPz9s1l for ; Tue, 7 Dec 2021 03:11:25 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 33FFE3C222D for ; Mon, 6 Dec 2021 17:11:23 +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]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 356D73C0681 for ; Mon, 6 Dec 2021 17:11:21 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 9391620004D for ; Mon, 6 Dec 2021 17:11:20 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CC8501FD34; Mon, 6 Dec 2021 16:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638807079; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8pnwA+LoYE/b89KyG4Q4msyLiUNOo4x7m+ke9alcT2c=; b=szSGCN1NyWvo2TnOlQqldTLdF999ZAcaPvJQ1Hgk5BMefqNjxJup6i8UK8y9E0s3pefmEN h3yNL4x3p2Lg1DBvCSLN/biHdx9RRjKiUNjjCe5nv0TH/6blHvbkiiVKC4IdH3x2RtHrRD JpMLOPZ8Z9PsnQLtRlfAVVBTj9FFPFg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A771413C4C; Mon, 6 Dec 2021 16:11:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wKfNJic2rmElagAAMHmgww (envelope-from ); Mon, 06 Dec 2021 16:11:19 +0000 To: ltp@lists.linux.it Date: Mon, 6 Dec 2021 17:11:12 +0100 Message-Id: <20211206161112.5726-1-andrea.cervesato@suse.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v1] Add tst_parse_filesize functionality in LTP test API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrea Cervesato via ltp From: Andrea Cervesato Reply-To: Andrea Cervesato Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Andrea Cervesato --- lib/tst_test.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/tst_test.c b/lib/tst_test.c index a79275722..6cb003802 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -679,6 +679,47 @@ int tst_parse_float(const char *str, float *val, float min, float max) return 0; } +int tst_parse_filesize(const char *str, long long *val, long long min, long long max) +{ + long long rval; + char *end; + + if (!str) + return 0; + + errno = 0; + rval = strtoll(str, &end, 10); + + if (str == end) + return EINVAL; + + if (errno) + return errno; + + switch (*end) { + case 'g': + case 'G': + rval *= (1024 * 1024 * 1024); + break; + case 'm': + case 'M': + rval *= (1024 * 1024); + break; + case 'k': + case 'K': + rval *= 1024; + break; + default: + break; + } + + if (rval > max || rval < min) + return ERANGE; + + *val = rval; + return 0; +} + static void print_colored(const char *str) { if (tst_color_enabled(STDOUT_FILENO))