3 # Bash completions for piglit
4 # Copyright © 2016 Intel Corporation
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # This provides completions for piglit in bash
26 # It requires debian's bash_completions (which are available on most
27 # linux and BSD OSes) for it's _filedir function.
29 __piglit_results_extensions
="@(json|json.xz|json.gz|json.bz2)"
31 # Function that handles 'piglit run'
33 # This is a *very* complex function. It handles *most*, but not all of the
34 # functionality of 'piglit run'.
36 # This handles everything piglit run expects, with one small caveat, after the
37 # first profile is provided, it mixes profiles and directories together, since
38 # either additional profiles or a directory can be provided. After something
39 # that isn't a profile is provided it won't auto complete any more positional
42 local cur
=${COMP_WORDS[COMP_CWORD]}
43 local prev
=${COMP_WORDS[COMP_CWORD-1]}
44 local opts
="-h --help -f --config -n --name -d --dry-run \
45 -t --include-tests -x --exclude-tests -b \
46 --backend -c --all-concurrent -1 \
47 --no-concurrency -p --platform --valgrind \
48 --dmesg -s --sync --junit_suffix -l \
49 --log-level --test-list -p --platform"
50 local with_args
=("-f" "--config" "-b" "--backend" "--junit_suffix"
51 "-l" "--log-level" "--test-list" "-n" "--name"
53 local profiles
=("all" "cl" "cpu" "cts_gl" "cts_gl45" "cts_gles" "deqp_egl"
54 "deqp_gles2" "deqp_gles3" "deqp_gles31" "deqp_vk"
55 "glslparser" "gpu" "igt" "khr_gl" "khr_gl45"
56 "llvmpipe" "no_error" "oglconform" "quick" "quick_cl"
57 "sanity" "shader" "xts" "xts-render")
59 # If the argument begins with - then just show the -* options
60 if [[ "$cur" == -* ]]; then
61 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
71 COMPREPLY
=( $
(compgen
-W "json junit" -- $cur) )
75 COMPREPLY
=( $
(compgen
-W "quiet verbose dummy http" -- $cur) )
83 COMPREPLY
=( $
(compgen
-W "glx x11_egl wayland gbm mixed_glx_egl" -- $cur) )
86 "-n" |
"--name" |
"--junit_suffix")
92 # Find any positional arguments.
93 # Positional arguments are arguments that don't start with - and that don't
94 # follow an argument that requires a positional argument
95 local list
=( "${COMP_WORDS[@]:2}" ) # remove "piglit run"
97 if [[ ${#list[@]} -gt 0 ]]; then
98 for i
in "${!list[@]}"; do
99 # If the element is an option argument continue
100 [[ ${list[$i]} == -* ]] && continue
102 # If the previous argument takes a positional argument continue
103 if [[ $i != 0 ]] && [[ "${with_args[@]}" =~
" ${list[$i-1]} " ]]; then
107 # The spaces around list are significant, they prevent partial matches
108 if [[ ${positional} -eq 0 ]] && [[ "${list[$i]}" != "" ]]; then
109 [[ "${profiles[@]}" =~
"${list[$i]}" ]] && ((++positional
))
111 # If the element is not a profile, and it is a complete file or directory
112 # then stop, there are no more positional arguments allowed, only switches
113 elif [[ ! "${profiles[@]}" =~
"${list[$i]}" ]]; then
114 [[ -a "${list[$i]}" ]] && [[ "${list[$i+1]}" == '' ]] && return 0
116 # Bash and whitespace...
117 elif [[ "${list[$i]}" != "" ]]; then
123 # 'piglit run' has two positional arguments
124 # TODO: more than one profile can be specified. but how?
125 # 1) The profile to run
126 # 2) the location to save the file to
127 COMPREPLY
=( $
(compgen
-W "${profiles[*]}" -- $cur) )
128 case "$positional" in
139 # Handle 'piglit resume'
141 # Resume is very simple, it takes only a couple of options, and a single
142 # positional argument.
144 local cur
=${COMP_WORDS[COMP_CWORD]}
145 local prev
=${COMP_WORDS[COMP_CWORD-1]}
146 local with_args
=("-f" "--config")
148 if [[ "$cur" == -* ]]; then
149 COMPREPLY
=( $
(compgen
-W "-f --config -n --no-retry -h --help" -- $cur) )
153 if [[ "$prev" == "-f" ]] ||
[[ "$prev" == "--config" ]]; then
159 for _
in "${COMP_WORDS[@]:3}"; do # remove 'piglit resume'
160 if [[ ! "$with_args" =~
" $prev" ]]; then
165 if [[ $count -eq 0 ]]; then
172 # Handle 'piglit summary aggregate'
174 # This is a very simple function, it takes only one positional argument, and only
175 # a single positional argument
176 __piglit_summary_aggregate
() {
177 local cur
=${COMP_WORDS[COMP_CWORD]}
178 local prev
=${COMP_WORDS[COMP_CWORD-1]}
179 local with_args
=("-f" "--config" "-o" "--output")
181 if [[ "$cur" == -* ]]; then
182 COMPREPLY
=( $
(compgen
-W "-f --config -o --output --help" -- $cur) )
192 _filedir
"${__piglit_results_extensions}"
198 for _
in "${COMP_WORDS[@]:4}"; do # remove 'piglit resume'
199 if [[ ! "$with_args" =~
"$prev" ]]; then
204 if [[ $count -eq 0 ]]; then
211 # Completions for 'summary console'
213 # This function is extremely simple, it takes an infinite number of positional
214 # arguments which are all the same, a couple of switches, and only two of them
216 __piglit_summary_console
() {
217 local cur
=${COMP_WORDS[COMP_CWORD]}
218 local prev
=${COMP_WORDS[COMP_CWORD-1]}
219 local opts
="-h --help -f --config -d --dif -s --summary -i --incomplete \
222 if [[ "$cur" == -* ]]; then
223 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
238 _filedir
"${__piglit_results_extensions}"
242 # Completions for 'summary csv'
244 # This is super simple, it has basically no switches, and the one positional
245 # argument can be provided multiple times
246 __piglit_summary_csv
() {
247 local cur
=${COMP_WORDS[COMP_CWORD]}
248 local prev
=${COMP_WORDS[COMP_CWORD-1]}
249 local opts
="-h --help -f --config -o --output"
251 if [[ "$cur" == -* ]]; then
252 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
267 _filedir
"${__piglit_results_extensions}"
272 # Completions for 'piglit summary feature'
274 # This is a very simple file. It takes 3 positional arguments, the last can be
275 # repeated as many times as desired, and two simple switches.
276 __piglit_summary_feature
() {
277 local cur
=${COMP_WORDS[COMP_CWORD]}
278 local prev
=${COMP_WORDS[COMP_CWORD-1]}
279 local opts
="-h --help -o --overwrite"
281 if [[ "$cur" == -* ]]; then
282 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
286 local list
=( "${COMP_WORDS[@]:3}" ) # remove "piglit run"
288 if [[ ${#list[@]} -gt 0 ]]; then
289 for i
in "${!list[@]}"; do
290 # If the element is an option argument continue
291 [[ ${list[$i]} == '-*' ]] && continue
293 # Bash and whitespace...
294 [[ "${list[$i]}" != "" ]] && ((++positional
))
298 case "${positional}" in
308 _filedir
"${__piglit_results_extensions}"
314 # Completions for 'piglit summary html'
316 # This is another fairly complex function to complete. It provides two
317 # different positional arguments, the first can be specified only once, the
318 # second can be provided an infinite number of times. It also provides a few
319 # switches that have positional arguments.
320 __piglit_summary_html
() {
321 local cur
=${COMP_WORDS[COMP_CWORD]}
322 local prev
=${COMP_WORDS[COMP_CWORD-1]}
323 local opts
="-h --help -o --overwrite -f --config -l --list \
324 -e --exclude-details"
325 local with_args
=("-f" "--config" "-e" "--exclude")
327 if [[ "$cur" == -* ]]; then
328 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
337 "-e" |
"--exclude-details")
338 local exclude
="all crash timeout incomplete \
339 pass dmesg-warn dmesg-fail \
340 notrun fail warn skip"
341 COMPREPLY
=( $
(compgen
-W "${exclude}" -- $cur) )
346 local list
=( "${COMP_WORDS[@]:3}" ) # remove "piglit run"
348 if [[ ${#list[@]} -gt 0 ]]; then
349 for i
in "${!list[@]}"; do
350 # If the element is an option argument continue
351 [[ ${list[$i]} == '-*' ]] && continue
353 # If the previous argument takes a positional argument continue
354 if [[ $i != 0 ]] && [[ "${with_args[@]}" =~
"${list[$i-1]}" ]]; then
358 # Bash and whitespace...
359 [[ "${list[$i]}" != "" ]] && ((++positional
))
363 case "$positional" in
369 _filedir
"${__piglit_results_extensions}"
375 # Completions for 'piglit'
377 # This function provides the completions for piglit, and calls subparsers for
378 # 'piglit run' and 'piglit resume', while it handles 'piglit summary' itself,
379 # delegating subparsers for the sub commands of 'piglit summary'
381 local cur
=${COMP_WORDS[COMP_CWORD]}
382 local sub
=${COMP_WORDS[1]}
394 case "${COMP_WORDS[2]}" in
396 __piglit_summary_aggregate
400 __piglit_summary_console
408 __piglit_summary_feature
412 __piglit_summary_html
416 if [[ $COMP_CWORD -gt 2 ]]; then
420 COMPREPLY
=( $
(compgen
-W "html console csv aggregate feature" -- "${cur}") )
426 if [[ $COMP_CWORD -gt 1 ]]; then
430 COMPREPLY
=( $
(compgen
-W "run summary resume" -- $cur) )
436 complete
-F _piglit piglit