[LTP] [PATCH v2 1/2] Add Coccinelle helper scripts for reference

Petr Vorel pvorel@suse.cz
Wed Jun 9 10:48:59 CEST 2021


Hi Richie,

> Check-in a couple of scripts used for removing the TEST macro from the
> library. Also a shell script to show how to run them. These are only
> intended to help someone develop their own refactoring scripts. Not
> for running automatically.
Nice, LGTM, with two notes bellow.

> +++ b/scripts/coccinelle/run-spatch.sh
> @@ -0,0 +1,39 @@
> +#!/bin/sh -eu
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 SUSE LLC  <rpalethorpe@suse.com>
> +
> +# Helper for running spatch Coccinelle scripts on the LTP source tree
> +
> +if [[ ! -d lib || ! -d scripts/coccinelle ]]; then
[[ ... ]] is bashism. It should be
if [ ! -d lib ] || [ ! -d scripts/coccinelle ]; then

or

> +    echo "$0: Can't find lib or scripts directories. Run me from top src dir"
> +    exit 1
> +fi
> +
> +# Run a script on the lib dir
> +libltp_spatch_report() {
> +    spatch --dir lib \
> +	   --ignore lib/parse_opts.c \
> +	   --ignore lib/newlib_tests \
> +	   --ignore lib/tests \
> +	   --use-gitgrep \
> +	   -D report \
> +	   --include-headers \
> +	   $*
> +}
> +
> +libltp_spatch_fix() {
> +    spatch --dir lib \
> +	   --ignore lib/parse_opts.c \
> +	   --ignore lib/newlib_tests \
> +	   --ignore lib/tests \
> +	   --use-gitgrep \
> +	   --in-place \
> +	   -D fix \
> +	   --include-headers \
> +	   $*
> +}
> +
> +echo You should uncomment one of the scripts below!
> +#libltp_spatch_report --sp-file scripts/coccinelle/libltp-test-macro.cocci
> +#libltp_spatch_report --sp-file scripts/coccinelle/libltp-test-macro-vars.cocci \
> +#		     --ignore lib/tst_test.c
Maybe have getopts to specify what needs to be running would prevent a need to
modify versioned file.

Kind regards,
Petr


More information about the ltp mailing list