devtools: check flow API doc tables
[dpdk.git] / devtools / parse-flow-support.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2021 Mellanox Technologies, Ltd
4
5 # Parse rte_flow support of a driver directory,
6 # and optionally show difference with a doc file in .ini format.
7
8 dir=$1 # drivers/net/foo
9 ref=$2 # doc/guides/nics/features/foo.ini
10
11 if [ -z "$dir" ]; then
12         echo "directory argument is required" >&2
13         exit 1
14 fi
15
16 # sorting order
17 export LC_COLLATE=C
18
19 # exclude exceptions
20 exclude() # <pattern>
21 {
22         case $(basename $dir) in
23                 bnxt)
24                         filter=$(sed -n "/$1/{N;/TYPE_NOT_SUPPORTED/P;}" \
25                                 $dir/tf_ulp/ulp_template_db{,_tbl}.c |
26                                 grep -wo "$1[[:alnum:]_]*" | sort -u |
27                                 tr '\n' '|' | sed 's,.$,\n,')
28                         grep -vE "$filter";;
29                 *) cat
30         esac
31 }
32
33 # include exceptions
34 include() # <pattern>
35 {
36         case $(basename $dir) in
37         esac
38 }
39
40 # generate INI section
41 list() # <title> <pattern>
42 {
43         echo "[$1]"
44         git grep -who "$2[[:alnum:]_]*" $dir |
45         (exclude $2; include $2) | sort -u |
46         awk 'sub(/'$2'/, "") {printf "%-20s = Y\n", tolower($0)}'
47 }
48
49 rte_flow_support() # <category>
50 {
51         title="rte_flow $1s"
52         pattern=$(echo "RTE_FLOW_$1_TYPE_" | awk '{print toupper($0)}')
53         list "$title" "$pattern" | grep -vwE 'void|indirect|end'
54 }
55
56 if [ -z "$ref" ]; then # generate full tables
57         rte_flow_support item
58         echo
59         rte_flow_support action
60         exit 0
61 fi
62
63 # compare with reference input
64 rte_flow_compare() # <category>
65 {
66         section="rte_flow $1s]"
67         {
68                 rte_flow_support $1
69                 sed -n "/$section/,/]/p" "$ref" | sed '/^$/d'
70         } |
71         sed '/]/d' | # ignore section title
72         sed 's, *=.*,,' | # ignore value (better in doc than generated one)
73         sort | uniq -u | # show differences
74         sed "s,^,$1 ," # prefix with category name
75 }
76
77 rte_flow_compare item
78 rte_flow_compare action