tests: Add SPDX headers to vsp-unit-test-0026.sh
[renesas/vsp-tests.git] / tests / vsp-unit-test-0011.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # SPDX-FileCopyrightText: 2016-2017 Renesas Electronics Corporation
4
5 #
6 # Test all combinations of horizontal flip, vertical flip and rotation on WPF.0.
7 #
8
9 . ./vsp-lib.sh
10
11 features="rpf.0 wpf.0 wpf.0[control:'Vertical+Flip']"
12 optional_features="wpf.0[control:'Horizontal+Flip'] wpf.0[control:'Rotate']"
13
14 directions="horizontal vertical rotate"
15 dir_horizontal_control="Horizontal+Flip"
16 dir_horizontal_label="hflip"
17 dir_horizontal_values="0 1"
18 dir_vertical_control="Vertical+Flip"
19 dir_vertical_label="vflip"
20 dir_vertical_values="0 1"
21 dir_rotate_control="Rotate"
22 dir_rotate_label="rotate"
23 dir_rotate_values="0 90"
24
25 format="RGB24"
26
27 get_var() {
28         echo $(eval echo \$dir_$1_$2)
29 }
30
31 set_var() {
32         eval dir_$1_$2=$3
33 }
34
35 get_array_value() {
36         local index=$2
37
38         echo $1 | cut -d ' ' -f $((index+1))
39 }
40
41 get_array_length() {
42         echo $#
43 }
44
45 dir_next_value() {
46         # Get the direction name corresponding to the index
47         local direction=$(get_array_value "$supported_directions" $1)
48
49         # Get the current value index and increase it
50         local value=$(get_var $direction index)
51         value=$((value+1))
52
53         # If the index exceeds the possible values array length, reset it to 0.
54         if [ $value -ge $(get_array_length $(get_var $direction values)) ] ; then
55                 value=0
56         fi
57
58         # Update the current value index for the direction
59         set_var $direction index $value
60
61         # Return whether we have exceeded the maximum
62         [ $value != 0 ]
63 }
64
65 dir_set_flipping_control() {
66         local direction=$1
67
68         local index=$(get_var $direction index)
69         local control=$(get_var $direction control)
70         local values=$(get_var $direction values)
71         local value=$(get_array_value "$values" $index)
72
73         vsp1_set_control wpf.0 "$control" $value
74 }
75
76 test_flipping() {
77         local label=$1
78
79         test_start "$label"
80
81         pipe_configure rpf-wpf 0 0
82         format_configure rpf-wpf 0 0 $format 640x480 $format
83
84         vsp_runner rpf.0 &
85         vsp_runner wpf.0
86
87         local result=$(compare_frames $label)
88
89         test_complete $result
90 }
91
92 test_main() {
93         local direction
94
95         for direction in $directions ; do
96                 $(vsp1_has_feature "wpf.0[control:'$(get_var $direction control)']") && {
97                         set_var $direction index 0
98                         supported_directions="$supported_directions $direction"
99                 }
100         done
101
102         local dir_max=$(get_array_length $supported_directions)
103         local dir_current=0
104
105         while true ; do
106                 # Update all controls
107                 local label=
108                 for direction in $supported_directions ; do
109                         local index=$(get_var $direction index)
110                         local values=$(get_var $direction values)
111                         local value=$(get_array_value "$values" $index)
112                         label="$label $(get_var $direction label)=$value"
113                         dir_set_flipping_control $direction
114                 done
115
116                 test_flipping "$label"
117
118                 while [ $dir_current -lt $dir_max ] ; do
119                         dir_next_value $dir_current && break
120                         dir_current=$((dir_current+1))
121                 done
122
123                 if [ $dir_current -ge $dir_max ] ; then
124                         break
125                 fi
126
127                 dir_current=0
128         done
129 }
130
131 test_init $0 "$features" "$optional_features"
132 test_run