[VSP-Tests,3/7] vsp-lib: Provide command line argument parsing
diff mbox series

Message ID 20181204155146.9726-4-kieran.bingham@ideasonboard.com
State New
Delegated to: Kieran Bingham
Headers show
Series
  • Reset controls and unloved patches
Related show

Commit Message

Kieran Bingham Dec. 4, 2018, 3:51 p.m. UTC
Extend the vsp-lib to support command line parsing for all tests.  The
arguments parsed here should be common to all tests, and initially
provide shell level verbose debug output, and the option to easily keep
frames output by the VSP1.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 scripts/vsp-lib.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Laurent Pinchart Feb. 17, 2019, 2:48 a.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Tue, Dec 04, 2018 at 03:51:42PM +0000, Kieran Bingham wrote:
> Extend the vsp-lib to support command line parsing for all tests.  The
> arguments parsed here should be common to all tests, and initially
> provide shell level verbose debug output, and the option to easily keep
> frames output by the VSP1.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  scripts/vsp-lib.sh | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
> index 0f3992a7827e..56969606382f 100755
> --- a/scripts/vsp-lib.sh
> +++ b/scripts/vsp-lib.sh
> @@ -1094,3 +1094,37 @@ test_complete() {
>  test_run() {
>  	test_main | ./logger.sh error >> $logfile
>  }
> +
> +# ------------------------------------------------------------------------------
> +# Common argument parsing
> +#
> +# non-recognised arguments are restored, to allow tests to implement their own
> +# parsing if necessary.
> +
> +POSITIONAL=()

This work in bash only :-( Any chance to implement a solution that would
work in ash too ?

> +while [[ $# -gt 0 ]]
> +do
> +case $1 in
> +	-x|--debug)
> +		set -x;
> +		shift
> +		;;
> +	-k|--keep-frames)
> +		export VSP_KEEP_FRAMES=1
> +		shift
> +		;;
> +	-h|--help)
> +		echo "$(basename $0): VSP Test library"
> +		echo "  -x|--debug          enable shell debug"
> +		echo "  -k|--keep-frames    keep generated and captured frames"
> +		echo "  -h|--help           this help"
> +		exit
> +		shift
> +		;;
> +	*)    # unknown option
> +		POSITIONAL+=("$1") # save it in an array for later
> +		shift # past argument
> +		;;
> +esac
> +done
> +set -- "${POSITIONAL[@]}" # restore positional parameters
Kieran Bingham Feb. 17, 2019, 8:47 p.m. UTC | #2
Hi Laurent,

On 17/02/2019 02:48, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Tue, Dec 04, 2018 at 03:51:42PM +0000, Kieran Bingham wrote:
>> Extend the vsp-lib to support command line parsing for all tests.  The
>> arguments parsed here should be common to all tests, and initially
>> provide shell level verbose debug output, and the option to easily keep
>> frames output by the VSP1.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  scripts/vsp-lib.sh | 34 ++++++++++++++++++++++++++++++++++
>>  1 file changed, 34 insertions(+)
>>
>> diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
>> index 0f3992a7827e..56969606382f 100755
>> --- a/scripts/vsp-lib.sh
>> +++ b/scripts/vsp-lib.sh
>> @@ -1094,3 +1094,37 @@ test_complete() {
>>  test_run() {
>>  	test_main | ./logger.sh error >> $logfile
>>  }
>> +
>> +# ------------------------------------------------------------------------------
>> +# Common argument parsing
>> +#
>> +# non-recognised arguments are restored, to allow tests to implement their own
>> +# parsing if necessary.
>> +
>> +POSITIONAL=()
> 
> This work in bash only :-( Any chance to implement a solution that would
> work in ash too ?
> 

Hrm ... I'll have to look into that. Or drop the 'feature'. This was
nice because it let me parse arguments I could handle here, and just
pass everything else through.


>> +while [[ $# -gt 0 ]]
>> +do
>> +case $1 in
>> +	-x|--debug)
>> +		set -x;
>> +		shift
>> +		;;
>> +	-k|--keep-frames)
>> +		export VSP_KEEP_FRAMES=1
>> +		shift
>> +		;;
>> +	-h|--help)
>> +		echo "$(basename $0): VSP Test library"
>> +		echo "  -x|--debug          enable shell debug"
>> +		echo "  -k|--keep-frames    keep generated and captured frames"
>> +		echo "  -h|--help           this help"
>> +		exit
>> +		shift
>> +		;;
>> +	*)    # unknown option
>> +		POSITIONAL+=("$1") # save it in an array for later
>> +		shift # past argument
>> +		;;
>> +esac
>> +done
>> +set -- "${POSITIONAL[@]}" # restore positional parameters
>

Patch
diff mbox series

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 0f3992a7827e..56969606382f 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -1094,3 +1094,37 @@  test_complete() {
 test_run() {
 	test_main | ./logger.sh error >> $logfile
 }
+
+# ------------------------------------------------------------------------------
+# Common argument parsing
+#
+# non-recognised arguments are restored, to allow tests to implement their own
+# parsing if necessary.
+
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+case $1 in
+	-x|--debug)
+		set -x;
+		shift
+		;;
+	-k|--keep-frames)
+		export VSP_KEEP_FRAMES=1
+		shift
+		;;
+	-h|--help)
+		echo "$(basename $0): VSP Test library"
+		echo "  -x|--debug          enable shell debug"
+		echo "  -k|--keep-frames    keep generated and captured frames"
+		echo "  -h|--help           this help"
+		exit
+		shift
+		;;
+	*)    # unknown option
+		POSITIONAL+=("$1") # save it in an array for later
+		shift # past argument
+		;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters