From patchwork Mon May 24 14:47:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1482829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: 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=K6vQ5KSO; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 ozlabs.org (Postfix) with ESMTPS id 4Fpg7q1vHhz9sRK for ; Tue, 25 May 2021 00:48:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 00C843C7A4A for ; Mon, 24 May 2021 16:48:29 +0200 (CEST) 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 [IPv6:2001:4b78:1:20::2]) (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 08FDF3C2B88 for ; Mon, 24 May 2021 16:48:16 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (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 78D6A600A3E for ; Mon, 24 May 2021 16:48:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621867696; 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: in-reply-to:in-reply-to:references:references; bh=5P1pCMXKX1dsljlUmrqQTcA8P24g3liWZDXeozvQtIU=; b=K6vQ5KSOHMkEk52teJVY5t7jkl6uC2F6UV3w+E6U2sWDksKx5FDzCZKDNfKArAUlTJU8je 84TsEjp18kL/xinZhKprjMp6A6os+WHFUy+DDzTT14x2YGLz06/DFrmV0n1YYgSn91XaZG JDnt7Ey86zuAcmxhtyT5tacWumuPo1w= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 09043AC11; Mon, 24 May 2021 14:48:16 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 24 May 2021 15:47:42 +0100 Message-Id: <20210524144745.10887-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524144745.10887-1-rpalethorpe@suse.com> References: <20210524144745.10887-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,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-2.smtp.seeweb.it Subject: [LTP] [RFC PATCH 1/4] Add scripts to remove TEST in library 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" --- .../coccinelle/libltp-test-macro-vars.cocci | 54 +++++++ scripts/coccinelle/libltp-test-macro.cocci | 137 ++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 scripts/coccinelle/libltp-test-macro-vars.cocci create mode 100644 scripts/coccinelle/libltp-test-macro.cocci diff --git a/scripts/coccinelle/libltp-test-macro-vars.cocci b/scripts/coccinelle/libltp-test-macro-vars.cocci new file mode 100644 index 000000000..679ce80fe --- /dev/null +++ b/scripts/coccinelle/libltp-test-macro-vars.cocci @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2021 SUSE LLC + +// The TEST macro should not be used in the library because it sets +// TST_RET and TST_ERR which are global variables. The test author +// only expects these to be changed if *they* call TEST directly. + +// Set with -D fix +virtual fix +// Set with -D report +virtual report + +// Find all positions where TEST's variables are used +@ find_use exists @ +identifier tst_var =~ "TST_(ERR|RET)"; +position p; +expression E; +@@ + +( + tst_var@p +| + TTERRNO@p | E +) + +@initialize:python depends on report@ +@@ + +import json + +errors = [] + +@script:python depends on report@ +p << find_use.p; +@@ + +msg = { + 'msg': "TEST macro variable use in library", + 'file': p[0].file, + 'line': p[0].line, + 'col': p[0].column, +} + +errors.append(msg) + +@finalize:python depends on report@ +@@ + +msgs = { + 'check_script': 'coccinelle/libltp-test-macro-vars.cocci', + 'errors': errors, +} + +print(json.dumps(msgs, indent=2)) diff --git a/scripts/coccinelle/libltp-test-macro.cocci b/scripts/coccinelle/libltp-test-macro.cocci new file mode 100644 index 000000000..960b5d325 --- /dev/null +++ b/scripts/coccinelle/libltp-test-macro.cocci @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2021 SUSE LLC + +// The TEST macro should not be used in the library because it sets +// TST_RET and TST_ERR which are global variables. The test author +// only expects these to be changed if *they* call TEST directly. + +// Set with -D fix +virtual fix +// Set with -D report +virtual report + +// Find all positions where TEST is _used_. +@ find_use exists @ +position p; +@@ + + TEST@p(...); + +// Print the position of the TEST usage +@initialize:python depends on report@ +@@ + +import json + +errors = [] + +@script:python depends on report@ +p << find_use.p; +@@ + +msg = { + 'msg': "TEST macro use in library", + 'file': p[0].file, + 'line': p[0].line, + 'col': p[0].column, +} + +errors.append(msg) + +@finalize:python depends on report@ +@@ + +msgs = { + 'check_script': 'coccinelle/libltp-test-macro.cocci', + 'errors': errors, +} + +print(json.dumps(msgs, indent=2)) + +// Below are rules which will create a patch to replace TEST usage +// It assumes we can use the ret var without conflicts + +// Fix all references to the variables TEST modifies when they occur in a +// function where TEST was used. +@ depends on fix && find_use @ +@@ + +( +- TST_RET ++ ret +| +- TST_ERR ++ errno +| +- TTERRNO ++ TERRNO +) + +// Replace TEST in all functions where it occurs only at the start. It +// is slightly complicated by adding a newline if a statement appears +// on the line after TEST(). It is not clear to me what the rules are +// for matching whitespace as it has no semantic meaning, but this +// appears to work. +@ depends on fix @ +identifier fn; +expression tested_expr; +statement st; +@@ + + fn (...) + { +- TEST(tested_expr); ++ const long ret = tested_expr; +( ++ + st +| + +) + ... when != TEST(...) + } + +// Replace TEST in all functions where it occurs at the start +// Functions where it *only* occurs at the start were handled above +@ depends on fix @ +identifier fn; +expression tested_expr; +statement st; +@@ + + fn (...) + { +- TEST(tested_expr); ++ long ret = tested_expr; +( ++ + st +| + +) + ... + } + +// Add ret var at the start of a function where TEST occurs and there +// is not already a ret declaration +@ depends on fix exists @ +identifier fn; +@@ + + fn (...) + { ++ long ret; + ... when != long ret; + + TEST(...) + ... + } + +// Replace any remaining occurances of TEST +@ depends on fix @ +expression tested_expr; +@@ + +- TEST(tested_expr); ++ ret = tested_expr; + From patchwork Mon May 24 14:47:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1482830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=eXQ5qVXe; dkim-atps=neutral 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fpg7r2nlcz9sW4 for ; Tue, 25 May 2021 00:48:40 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 05A0C3C77F4 for ; Mon, 24 May 2021 16:48:38 +0200 (CEST) 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]) (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 344AC3C1886 for ; Mon, 24 May 2021 16:48:17 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (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 B542C600A31 for ; Mon, 24 May 2021 16:48:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621867696; 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: in-reply-to:in-reply-to:references:references; bh=d1pmBd0k7oLxND8ITP8ca/Y+BwS0jlGkXl0HiBpdvSg=; b=eXQ5qVXeoUi581hAc94L8SU/0+/z3cEtfgm6ozT3+a2UVORUs0LYIX+S7pwCVQhlmnkgah 1ErYtQaE+swW4NsjxpUXgTbs7lmUGyd0xhrAkUfnHR045izu/4Oso59G3eOg2iWwWmKC6i 4BiaRfabG2D0S43KfyZkAvZVL+LOe3E= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 51B5CADCE; Mon, 24 May 2021 14:48:16 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 24 May 2021 15:47:43 +0100 Message-Id: <20210524144745.10887-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524144745.10887-1-rpalethorpe@suse.com> References: <20210524144745.10887-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,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-2.smtp.seeweb.it Subject: [LTP] [RFC PATCH 2/4] Add script to run Coccinelle checks 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" --- scripts/coccinelle/libltp_checks.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/coccinelle/libltp_checks.sh diff --git a/scripts/coccinelle/libltp_checks.sh b/scripts/coccinelle/libltp_checks.sh new file mode 100755 index 000000000..6fdaa7ae8 --- /dev/null +++ b/scripts/coccinelle/libltp_checks.sh @@ -0,0 +1,29 @@ +#!/bin/sh -eu +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 SUSE LLC + +# Run the Coccinelle checks for the library. Running the fixes +# requires passing -D fix instead of -D report. + +if [[ ! -d lib || ! -d scripts/coccinelle ]]; then + echo "$0: Can't find lib or scripts directories. Run me from top src dir" + exit 1 +fi + +echo Python args ${COCCI_PYTHON:=--python python3} >&2 + +libltp_spatch() { + spatch $COCCI_PYTHON --dir lib \ + --ignore lib/parse_opts.c \ + --ignore lib/newlib_tests \ + --ignore lib/tests \ + --very-quiet \ + --use-gitgrep \ + -D report \ + --include-headers \ + $* +} + +libltp_spatch --sp-file scripts/coccinelle/libltp-test-macro.cocci +libltp_spatch --sp-file scripts/coccinelle/libltp-test-macro-vars.cocci \ + --ignore lib/tst_test.c From patchwork Mon May 24 14:47:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1482833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=QEBvfk8M; dkim-atps=neutral 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fpg8F6zYVz9sWC for ; Tue, 25 May 2021 00:49:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 888353C57EB for ; Mon, 24 May 2021 16:48:59 +0200 (CEST) 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]) (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 C28F13C2B88 for ; Mon, 24 May 2021 16:48:17 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (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 EDC0110009A1 for ; Mon, 24 May 2021 16:48:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621867696; 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: in-reply-to:in-reply-to:references:references; bh=h4/9qONEDGAZv1UU62sEro5TutwGpdoulaLW2wpbTKc=; b=QEBvfk8MjYnd+ZhLopa8FQxQ3CS0Kzpx8MGOek62HfQ1Px9vQyAmMr5NJABE/fBuT6IiSz OVMNZtPzAjTHvXSvyItXslQ3UQhefddLumMx5YsdVwPk+WOOjTY4PbmDnnNcS+YZIDD919 WQclmd0K43wrzh7g2cmPGjwA+VUknaY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 92329ADDD; Mon, 24 May 2021 14:48:16 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 24 May 2021 15:47:44 +0100 Message-Id: <20210524144745.10887-4-rpalethorpe@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524144745.10887-1-rpalethorpe@suse.com> References: <20210524144745.10887-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,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-4.smtp.seeweb.it Subject: [LTP] [RFC PATCH 3/4] API: Mostly automatic removal of TEST() usage by Coccinelle 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Only manual change is to set ret = -1 due to prevent compiler warning in cgroup read. --- lib/tst_af_alg.c | 46 ++++++++++++++++++++---------------- lib/tst_cgroup.c | 13 +++++----- lib/tst_crypto.c | 20 +++++++++------- lib/tst_supported_fs_types.c | 10 ++++---- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/lib/tst_af_alg.c b/lib/tst_af_alg.c index d3895a83d..05caa6301 100644 --- a/lib/tst_af_alg.c +++ b/lib/tst_af_alg.c @@ -13,25 +13,28 @@ int tst_alg_create(void) { - TEST(socket(AF_ALG, SOCK_SEQPACKET, 0)); - if (TST_RET >= 0) - return TST_RET; - if (TST_ERR == EAFNOSUPPORT) + const long ret = socket(AF_ALG, SOCK_SEQPACKET, 0); + + if (ret >= 0) + return ret; + if (errno == EAFNOSUPPORT) tst_brk(TCONF, "kernel doesn't support AF_ALG"); - tst_brk(TBROK | TTERRNO, "unexpected error creating AF_ALG socket"); + tst_brk(TBROK | TERRNO, "unexpected error creating AF_ALG socket"); return -1; } void tst_alg_bind_addr(int algfd, const struct sockaddr_alg *addr) { - TEST(bind(algfd, (const struct sockaddr *)addr, sizeof(*addr))); - if (TST_RET == 0) + const long ret = bind(algfd, (const struct sockaddr *)addr, + sizeof(*addr)); + + if (ret == 0) return; - if (TST_ERR == ENOENT) { + if (errno == ENOENT) { tst_brk(TCONF, "kernel doesn't support %s algorithm '%s'", addr->salg_type, addr->salg_name); } - tst_brk(TBROK | TTERRNO, + tst_brk(TBROK | TERRNO, "unexpected error binding AF_ALG socket to %s algorithm '%s'", addr->salg_type, addr->salg_name); } @@ -63,6 +66,7 @@ void tst_alg_bind(int algfd, const char *algtype, const char *algname) bool tst_have_alg(const char *algtype, const char *algname) { + long ret; int algfd; struct sockaddr_alg addr; bool have_alg = true; @@ -71,10 +75,10 @@ bool tst_have_alg(const char *algtype, const char *algname) init_sockaddr_alg(&addr, algtype, algname); - TEST(bind(algfd, (const struct sockaddr *)&addr, sizeof(addr))); - if (TST_RET != 0) { - if (TST_ERR != ENOENT) { - tst_brk(TBROK | TTERRNO, + ret = bind(algfd, (const struct sockaddr *)&addr, sizeof(addr)); + if (ret != 0) { + if (errno != ENOENT) { + tst_brk(TBROK | TERRNO, "unexpected error binding AF_ALG socket to %s algorithm '%s'", algtype, algname); } @@ -96,6 +100,7 @@ void tst_require_alg(const char *algtype, const char *algname) void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen) { + long ret; uint8_t *keybuf = NULL; unsigned int i; @@ -106,9 +111,9 @@ void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen) keybuf[i] = rand(); key = keybuf; } - TEST(setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, keylen)); - if (TST_RET != 0) { - tst_brk(TBROK | TTERRNO, + ret = setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, keylen); + if (ret != 0) { + tst_brk(TBROK | TERRNO, "unexpected error setting key (len=%u)", keylen); } free(keybuf); @@ -116,12 +121,13 @@ void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen) int tst_alg_accept(int algfd) { - TEST(accept(algfd, NULL, NULL)); - if (TST_RET < 0) { - tst_brk(TBROK | TTERRNO, + const long ret = accept(algfd, NULL, NULL); + + if (ret < 0) { + tst_brk(TBROK | TERRNO, "unexpected error accept()ing AF_ALG request socket"); } - return TST_RET; + return ret; } int tst_alg_setup(const char *algtype, const char *algname, diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 1e036d3c3..5d13e2829 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -1037,6 +1037,7 @@ ssize_t safe_cgroup_read(const char *const file, const int lineno, const char *const file_name, char *const out, const size_t len) { + long ret = -1; const struct cgroup_file *const cfile = cgroup_file_find(file, lineno, file_name); struct cgroup_dir *const *dir; @@ -1051,9 +1052,9 @@ ssize_t safe_cgroup_read(const char *const file, const int lineno, if (prev_len) memcpy(prev_buf, out, prev_len); - TEST(safe_file_readat(file, lineno, - (*dir)->dir_fd, alias, out, len)); - if (TST_RET < 0) + ret = safe_file_readat(file, lineno, (*dir)->dir_fd, alias, + out, len); + if (ret < 0) continue; if (prev_len && memcmp(out, prev_buf, prev_len)) { @@ -1063,12 +1064,12 @@ ssize_t safe_cgroup_read(const char *const file, const int lineno, break; } - prev_len = MIN(sizeof(prev_buf), (size_t)TST_RET); + prev_len = MIN(sizeof(prev_buf), (size_t) ret); } - out[MAX(TST_RET, 0)] = '\0'; + out[MAX(ret, 0)] = '\0'; - return TST_RET; + return ret; } void safe_cgroup_printf(const char *const file, const int lineno, diff --git a/lib/tst_crypto.c b/lib/tst_crypto.c index 685e0871e..c01632c2a 100644 --- a/lib/tst_crypto.c +++ b/lib/tst_crypto.c @@ -14,16 +14,17 @@ void tst_crypto_open(struct tst_crypto_session *ses) { - TEST(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO)); - if (TST_RET < 0 && TST_ERR == EPROTONOSUPPORT) - tst_brk(TCONF | TTERRNO, "NETLINK_CRYPTO is probably disabled"); + const long ret = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO); - if (TST_RET < 0) { - tst_brk(TBROK | TTERRNO, + if (ret < 0 && errno == EPROTONOSUPPORT) + tst_brk(TCONF | TERRNO, "NETLINK_CRYPTO is probably disabled"); + + if (ret < 0) { + tst_brk(TBROK | TERRNO, "socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO)"); } - ses->fd = TST_RET; + ses->fd = ret; ses->seq_num = 0; } @@ -83,6 +84,7 @@ int tst_crypto_add_alg(struct tst_crypto_session *ses, int tst_crypto_del_alg(struct tst_crypto_session *ses, const struct crypto_user_alg *alg) { + long ret; unsigned int i = 0; struct nlmsghdr nh = { .nlmsg_len = sizeof(struct nlmsghdr) + sizeof(*alg), @@ -96,8 +98,8 @@ int tst_crypto_del_alg(struct tst_crypto_session *ses, SAFE_NETLINK_SEND(ses->fd, &nh, alg); - TEST(tst_crypto_recv_ack(ses)); - if (TST_RET != -EBUSY || i >= ses->retries) + ret = tst_crypto_recv_ack(ses); + if (ret != -EBUSY || i >= ses->retries) break; if (usleep(1) && errno != EINTR) @@ -106,5 +108,5 @@ int tst_crypto_del_alg(struct tst_crypto_session *ses, ++i; } - return TST_RET; + return ret; } diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c index 592a526ae..d0f745490 100644 --- a/lib/tst_supported_fs_types.c +++ b/lib/tst_supported_fs_types.c @@ -167,14 +167,16 @@ const char **tst_get_supported_fs_types(const char *const *skiplist) int tst_check_quota_support(const char *device, int format, char *quotafile) { - TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile)); + const long ret = quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, + quotafile); /* Not supported */ - if (TST_RET == -1 && TST_ERR == ESRCH) + + if (ret == -1 && errno == ESRCH) return 0; /* Broken */ - if (TST_RET) + if (ret) return -1; quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), device, 0, 0); @@ -192,5 +194,5 @@ void tst_require_quota_support_(const char *file, const int lineno, } if (status < 0) - tst_brk_(file, lineno, TBROK|TTERRNO, "FS quotas are broken"); + tst_brk_(file, lineno, TBROK|TERRNO, "FS quotas are broken"); } From patchwork Mon May 24 14:47:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1482831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=J5QRBKIT; dkim-atps=neutral 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fpg843zHvz9sRf for ; Tue, 25 May 2021 00:48:52 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 561023C59DB for ; Mon, 24 May 2021 16:48:50 +0200 (CEST) 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]) (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 A356A3C1886 for ; Mon, 24 May 2021 16:48:17 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (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 4D729600A1D for ; Mon, 24 May 2021 16:48:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621867696; 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: in-reply-to:in-reply-to:references:references; bh=w5c3pIDoIwbYFpVqu8NQzaRuTrIQJPw+cwbi23+yrjQ=; b=J5QRBKITt+cd95dOtAA9snPvZF1U+GjP2fKEdoQnbxksMkMnxKzNAgOWbDCfaI9eM0E2lo A9UF73YJ2u1OhU89yigKlE2MNvPN53h8ikQPopYShw7BZvlOasGYX6fyp61ME1LlDTgWLt iTBkMAnc4jBw293ZQVDWzscq1amH/t0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D038CADE5; Mon, 24 May 2021 14:48:16 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 24 May 2021 15:47:45 +0100 Message-Id: <20210524144745.10887-5-rpalethorpe@suse.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524144745.10887-1-rpalethorpe@suse.com> References: <20210524144745.10887-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,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-2.smtp.seeweb.it Subject: [LTP] [RFC PATCH 4/4] API: Removal of TST_ERR usage 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Use errno instead to stop Coccinelle test from failing. --- lib/tst_netdevice.c | 10 +++++----- lib/tst_rtnetlink.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tst_netdevice.c b/lib/tst_netdevice.c index d098173d5..cc2766be8 100644 --- a/lib/tst_netdevice.c +++ b/lib/tst_netdevice.c @@ -149,7 +149,7 @@ int tst_create_veth_pair(const char *file, const int lineno, tst_rtnl_destroy_context(file, lineno, ctx); if (!ret) { - tst_brk_(file, lineno, TBROK | TTERRNO, + tst_brk_(file, lineno, TBROK | TERRNO, "Failed to create veth interfaces %s+%s", ifname1, ifname2); } @@ -183,7 +183,7 @@ int tst_remove_netdev(const char *file, const int lineno, const char *ifname) tst_rtnl_destroy_context(file, lineno, ctx); if (!ret) { - tst_brk_(file, lineno, TBROK | TTERRNO, + tst_brk_(file, lineno, TBROK | TERRNO, "Failed to remove netdevice %s", ifname); } @@ -232,7 +232,7 @@ static int modify_address(const char *file, const int lineno, tst_rtnl_destroy_context(file, lineno, ctx); if (!ret) { - tst_brk_(file, lineno, TBROK | TTERRNO, + tst_brk_(file, lineno, TBROK | TERRNO, "Failed to modify %s network address", ifname); } @@ -301,7 +301,7 @@ static int change_ns(const char *file, const int lineno, const char *ifname, tst_rtnl_destroy_context(file, lineno, ctx); if (!ret) { - tst_brk_(file, lineno, TBROK | TTERRNO, + tst_brk_(file, lineno, TBROK | TERRNO, "Failed to move %s to another namespace", ifname); } @@ -392,7 +392,7 @@ static int modify_route(const char *file, const int lineno, unsigned int action, tst_rtnl_destroy_context(file, lineno, ctx); if (!ret) { - tst_brk_(file, lineno, TBROK | TTERRNO, + tst_brk_(file, lineno, TBROK | TERRNO, "Failed to modify network route"); } diff --git a/lib/tst_rtnetlink.c b/lib/tst_rtnetlink.c index 1ecda3a9f..d93f7e18d 100644 --- a/lib/tst_rtnetlink.c +++ b/lib/tst_rtnetlink.c @@ -380,7 +380,7 @@ int tst_rtnl_check_acks(const char *file, const int lineno, } if (res->err->error) { - TST_ERR = -res->err->error; + errno = -res->err->error; return 0; } } @@ -394,7 +394,7 @@ int tst_rtnl_send_validate(const char *file, const int lineno, struct tst_rtnl_message *response; int ret; - TST_ERR = 0; + errno = 0; if (tst_rtnl_send(file, lineno, ctx) <= 0) return 0;