From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 01E0FA0A02;
	Tue, 18 May 2021 15:29:14 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 832104110C;
	Tue, 18 May 2021 15:29:07 +0200 (CEST)
Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com
 [64.147.123.19]) by mails.dpdk.org (Postfix) with ESMTP id 5F40241111
 for <dev@dpdk.org>; Tue, 18 May 2021 15:29:05 +0200 (CEST)
Received: from compute5.internal (compute5.nyi.internal [10.202.2.45])
 by mailout.west.internal (Postfix) with ESMTP id 71C681363;
 Tue, 18 May 2021 09:29:04 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162])
 by compute5.internal (MEProxy); Tue, 18 May 2021 09:29:04 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding; s=fm1; bh=0mYgIphyWpxjh
 AuDjEMMr0P55y1n8KlefROj4QxLflA=; b=V1a9O89LtCknBp8d0rShC91cm5W1e
 UudK9Ef8ce+G+AflcyD22WYWXVek3OPObhZlD+WfYtP3HvzhB4jkQxq7gPlw0Q2T
 2K2PU4FOydNfxOH9xRpXK/J8hEHkN8HX8STt9iD5w//iOt1tl89GeWD1nfuVuxng
 A83USxE43Qh4sX1NjZLX8QMhXkLqmRfp0etw2GqqYX8tLyTWDgUsFxkZc1KuF090
 wxrc3pL0I4440eMpPXX6Zq+gYOM8J0jsT7uA5NgjNnSyhh9O3k79TMu3k1R7R0af
 ULctdI/b0oa2l4xjp+u0eXe/NQcOgWBWVj68AaNQJYlTPXVMyH4XdS1QQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:date:from
 :in-reply-to:message-id:mime-version:references:subject:to
 :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
 fm2; bh=0mYgIphyWpxjhAuDjEMMr0P55y1n8KlefROj4QxLflA=; b=cQ3H7sTz
 QJK1CQk2l6UGR6glrdS22FT11J/4/Du/bGmSGNKga0N48CVdAZSnHVzc7Rnyc1NC
 UyuJnxyb1T9gmQRwZSce9CsAajKoND8v2v0u7OUQb/dMOUtWZoVrP934zIfYvHqm
 yXajnR9q7qIlxFlOdwViLkxib/rlr7D/R/JJxYWYFqLcdjxACGI+MsP8dlNCs0WN
 gyBkvGZRvJ+hprGP2+rK2ucXfc1x5EATbuyIAYD9NyY1N65rX4KnUhGmFXGrpFgf
 DMmT1uwNlGRgDtKw03GLCINkCPFwHEjOzuHLxg986bAYcVFu8IktprI/qUC5RTdZ
 E4jCKgoDlMaBTg==
X-ME-Sender: <xms:H8GjYJwnqc4kPJg9aDL8wbB8oertbEYMNnjvU5fl-1v4GbZa8yFVDw>
 <xme:H8GjYJQhYguXVpMpAX0WT7EBe-6XDjfXQFJWbowIQgCgg7yotMmZWWXcKkqKuOQXd
 79icKBBPGcSq3aA3w>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdeijedgieehucetufdoteggodetrfdotf
 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
 uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre
 dtredttdenucfhrhhomhepvfhhohhmrghsucfoohhnjhgrlhhonhcuoehthhhomhgrshes
 mhhonhhjrghlohhnrdhnvghtqeenucggtffrrghtthgvrhhnpedvhefgiedvjeegtdevhe
 efhfetleefgfeivefgffevfeejgedtgfeutdehtdegveenucfkphepjeejrddufeegrddv
 tdefrddukeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh
 homhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth
X-ME-Proxy: <xmx:H8GjYDWcw0Yl-qE5BQHqPFophPF6pPcDf3rctNXx5sSkuFgzbDDJMA>
 <xmx:H8GjYLiMYBt5zU-a-TLpDw7FRuw5sEOnCforb6SA-U2Cr7bJY03Xyg>
 <xmx:H8GjYLD-bOy81QXM3QOZ2qtl8W3bbPQ8YziAqnezRkVJ06c9Rxj-AQ>
 <xmx:IMGjYOoqMkRkOSMDTwtZyWLKokIfyVFe7ZeUwFVPNG5k4L7C0L4cAw>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA;
 Tue, 18 May 2021 09:29:02 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com,
	andrew.rybchenko@oktetlabs.ru
Date: Tue, 18 May 2021 15:28:44 +0200
Message-Id: <20210518132844.3779728-4-thomas@monjalon.net>
X-Mailer: git-send-email 2.31.1
In-Reply-To: <20210518132844.3779728-1-thomas@monjalon.net>
References: <1612458325-13508-1-git-send-email-asafp@nvidia.com>
 <20210518132844.3779728-1-thomas@monjalon.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v6 3/3] devtools: check flow API doc tables
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

The script check-doc-vs-code.sh may be used to add
some automatic checks of the doc.

If run without any argument, a complete check is done.
The optional argument is a git history reference point
to check faster only what has changed since this commit.

In this commit, the only check is for rte_flow tables,
achieved through the script parse-flow-support.sh.
If run without a .ini reference, it prints rte_flow tables.
Note: detected features are marked with the value Y,
while the real .ini file could have special values like I.
The script allow parsing exceptions (exclude or include),
like for bnxt code which lists unsupported items and actions.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
v6 changes:
	- fix redundant drivers
	- ignore indirect action
	- prefix misses with a category (item or action)
---
 devtools/check-doc-vs-code.sh  | 84 ++++++++++++++++++++++++++++++++++
 devtools/parse-flow-support.sh | 78 +++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+)
 create mode 100755 devtools/check-doc-vs-code.sh
 create mode 100755 devtools/parse-flow-support.sh

diff --git a/devtools/check-doc-vs-code.sh b/devtools/check-doc-vs-code.sh
new file mode 100755
index 0000000000..c58c239c87
--- /dev/null
+++ b/devtools/check-doc-vs-code.sh
@@ -0,0 +1,84 @@
+#! /bin/sh -e
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2021 Mellanox Technologies, Ltd
+
+# Check whether doc & code are in sync.
+# Optional argument: check only what changed since a commit.
+trusted_commit=$1 # example: origin/main
+
+selfdir=$(dirname $(readlink -f $0))
+rootdir=$(readlink -f $selfdir/..)
+
+# speed up by ignoring Unicode details
+export LC_COLLATE=C
+
+result=0
+error() # <message>
+{
+	echo "$*"
+	result=$(($result + 1))
+}
+
+changed_files()
+{
+	[ -n "$files" ] ||
+		files=$(git diff-tree --name-only -r $trusted_commit..)
+	echo "$files"
+}
+
+has_code_change() # <pattern>
+{
+	test -n "$(git log --format='%h' -S"$1" $trusted_commit..)"
+}
+
+has_file_change() # <pattern>
+{
+	changed_files | grep -q "$1"
+}
+
+changed_net_drivers()
+{
+	net_paths='drivers/net/|doc/guides/nics/features/'
+	[ -n "$drivers" ] ||
+		drivers=$(changed_files |
+			sed -rn "s,^($net_paths)([^./]*).*,\2,p" |
+			sort -u)
+	echo "$drivers"
+}
+
+all_net_drivers()
+{
+	find $rootdir/drivers/net -mindepth 1 -maxdepth 1 -type d |
+	sed 's,.*/,,' |
+	sort
+}
+
+check_rte_flow() # <driver>
+{
+	code=$rootdir/drivers/net/$1
+	doc=$rootdir/doc/guides/nics/features/$1.ini
+	[ -d $code ] || return 0
+	[ -f $doc ] || return 0
+	report=$($selfdir/parse-flow-support.sh $code $doc)
+	if [ -n "$report" ]; then
+		error "rte_flow doc out of sync for $1"
+		echo "$report" | sed 's,^,\t,'
+	fi
+}
+
+if [ -z "$trusted_commit" ]; then
+	# check all
+	for driver in $(all_net_drivers); do
+		check_rte_flow $driver
+	done
+	exit $result
+fi
+
+# find what changed and check
+if has_code_change 'RTE_FLOW_.*_TYPE_' ||
+		has_file_change 'doc/guides/nics/features'; then
+	for driver in $(changed_net_drivers); do
+		check_rte_flow $driver
+	done
+fi
+exit $result
diff --git a/devtools/parse-flow-support.sh b/devtools/parse-flow-support.sh
new file mode 100755
index 0000000000..aeed76e55f
--- /dev/null
+++ b/devtools/parse-flow-support.sh
@@ -0,0 +1,78 @@
+#! /bin/sh -e
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2021 Mellanox Technologies, Ltd
+
+# Parse rte_flow support of a driver directory,
+# and optionally show difference with a doc file in .ini format.
+
+dir=$1 # drivers/net/foo
+ref=$2 # doc/guides/nics/features/foo.ini
+
+if [ -z "$dir" ]; then
+	echo "directory argument is required" >&2
+	exit 1
+fi
+
+# sorting order
+export LC_COLLATE=C
+
+# exclude exceptions
+exclude() # <pattern>
+{
+	case $(basename $dir) in
+		bnxt)
+			filter=$(sed -n "/$1/{N;/TYPE_NOT_SUPPORTED/P;}" \
+				$dir/tf_ulp/ulp_template_db{,_tbl}.c |
+				grep -wo "$1[[:alnum:]_]*" | sort -u |
+				tr '\n' '|' | sed 's,.$,\n,')
+			grep -vE "$filter";;
+		*) cat
+	esac
+}
+
+# include exceptions
+include() # <pattern>
+{
+	case $(basename $dir) in
+	esac
+}
+
+# generate INI section
+list() # <title> <pattern>
+{
+	echo "[$1]"
+	git grep -who "$2[[:alnum:]_]*" $dir |
+	(exclude $2; include $2) | sort -u |
+	awk 'sub(/'$2'/, "") {printf "%-20s = Y\n", tolower($0)}'
+}
+
+rte_flow_support() # <category>
+{
+	title="rte_flow $1s"
+	pattern=$(echo "RTE_FLOW_$1_TYPE_" | awk '{print toupper($0)}')
+	list "$title" "$pattern" | grep -vwE 'void|indirect|end'
+}
+
+if [ -z "$ref" ]; then # generate full tables
+	rte_flow_support item
+	echo
+	rte_flow_support action
+	exit 0
+fi
+
+# compare with reference input
+rte_flow_compare() # <category>
+{
+	section="rte_flow $1s]"
+	{
+		rte_flow_support $1
+		sed -n "/$section/,/]/p" "$ref" | sed '/^$/d'
+	} |
+	sed '/]/d' | # ignore section title
+	sed 's, *=.*,,' | # ignore value (better in doc than generated one)
+	sort | uniq -u | # show differences
+	sed "s,^,$1 ," # prefix with category name
+}
+
+rte_flow_compare item
+rte_flow_compare action
-- 
2.31.1