Skip to content

Commit

Permalink
src: plugins: subsystems: drm: Adding verbose mode
Browse files Browse the repository at this point in the history
This commit adds support for the verbose parameter within `kw drm`.  The
verbose parameter gives details of the commands that are executed behind
the scenes.

Note: This is part of the issue: #179

Reviewed-by: Rodrigo Siqueira <siqueirajordao@riseup.net>
Signed-off-by: Aquila Macedo <aquilamacedo@riseup.net>
  • Loading branch information
aquilamacedo authored and rodrigosiqueira committed Apr 30, 2023
1 parent 7f34cac commit a42592a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
7 changes: 6 additions & 1 deletion documentation/man/features/drm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SYNOPSIS
| *kw* *drm* [\--local | \--remote [<remote>:<port>]]
| [\--load-module=<module>[:<param1>,...][;<module>:...] |
| \--unload-module=<module>[;<module>;...] |
| \--gui-on | \--gui-off | \--conn-available | \--modes]
| \--gui-on | \--gui-off | \--conn-available | \--modes | \--verbose]
DESCRIPTION
===========
Expand Down Expand Up @@ -61,6 +61,11 @@ OPTIONS
\--modes:
Show all available modes per card.

\--verbose:
Verbose mode is an option that causes the kw program to display debug messages to track
its progress. This functionality is very useful during the debugging process, allowing
you to identify possible errors more easily.

EXAMPLES
========
For these examples, we suppose the fields in your **kworkflow.config** file are
Expand Down
2 changes: 1 addition & 1 deletion src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ _kw_diff()
_kw_drm()
{
_arguments : \
'(-v --verbose)'{-v,--verbose}'[verbose output]' \
'(--verbose)--verbose[enable verbose mode]' \
'(--unload-module)--load-module=-[specify one or more modules to be loaded with or without parameters]: : ' \
'(--load-module)--unload-module=-[specify one or more modules to be unloaded]: : ' \
'(--remote)--local[specify host as the target machine]' \
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function _kw_autocomplete()
kw_options['remote']='add remove rename --set-default --verbose --list'

kw_options['drm']='--remote --local --gui-on --gui-off --load-module
--unload-module --conn-available --modes --help'
--unload-module --conn-available --modes --help --verbose'

kw_options['env']='--create --list --use --exit-env --verbose'

Expand Down
35 changes: 24 additions & 11 deletions src/plugins/subsystems/drm/drm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function drm_main()
local load_module
local unload_module
local test_mode
local flag

if [[ "$*" =~ -h|--help ]]; then
drm_help "$*"
Expand All @@ -41,6 +42,8 @@ function drm_main()
unload_module="${options_values['UNLOAD_MODULE']}"
remote="${remote_parameters['REMOTE']}"

[[ -n "${options_values['VERBOSE']}" ]] && flag='VERBOSE'

if [[ "$target" == "$REMOTE_TARGET" ]]; then
# Check connection before try to work with remote
is_ssh_connection_configured "$flag"
Expand All @@ -51,30 +54,30 @@ function drm_main()
fi

if [[ -n "$load_module" ]]; then
module_control 'LOAD' "$target" "$remote" "$load_module"
module_control 'LOAD' "$target" "$remote" "$load_module" "$flag"
if [[ "$?" != 0 ]]; then
return 22
fi
fi

if [[ "$gui_on" == 1 ]]; then
gui_control 'ON' "$target" "$remote"
gui_control 'ON' "$target" "$remote" "$flag"
elif [[ "$gui_off" == 1 ]]; then
gui_control 'OFF' "$target" "$remote"
gui_control 'OFF' "$target" "$remote" "$flag"
fi

if [[ -n "$unload_module" ]]; then
# For unload DRM drivers, we need to make sure that we turn off user GUI
[[ "$gui_off" != 1 ]] && gui_control 'OFF' "$target" "$remote"
module_control 'UNLOAD' "$target" "$remote" "$unload_module"
module_control 'UNLOAD' "$target" "$remote" "$unload_module" "$flag"
fi

if [[ "$conn_available" == 1 ]]; then
get_available_connectors "$target" "$remote"
get_available_connectors "$target" "$remote" "$flag"
fi

if [[ "$modes_available" == 1 ]]; then
get_supported_mode_per_connector "$target" "$remote"
get_supported_mode_per_connector "$target" "$remote" "$flag"
fi

if [[ "$help_opt" == 1 ]]; then
Expand All @@ -101,6 +104,8 @@ function module_control()
local remote
local port

flag=${flag:-'SILENT'}

module_cmd=$(convert_module_info "$operation" "$parameters")
if [[ "$?" != 0 ]]; then
complain 'Wrong parameter in --[un]load-module='
Expand Down Expand Up @@ -204,6 +209,8 @@ function gui_control()
local remote
local port

flag=${flag:-'SILENT'}

if [[ "$operation" == 'ON' ]]; then
isolate_target='graphical.target'
vt_console=1
Expand Down Expand Up @@ -241,7 +248,7 @@ function get_available_connectors()
{
local target="$1"
local unformatted_remote="$2"
local flag=${3:-'SILENT'}
local flag="$3"
local target_label
local card
local key
Expand All @@ -253,6 +260,8 @@ function get_available_connectors()
local find_conn_cmd
declare -A cards

flag=${flag:-'SILENT'}

case "$target" in
2) # LOCAL TARGET
cards_raw_list=$(find "$SYSFS_CLASS_DRM" -name 'card*' | sort -d)
Expand Down Expand Up @@ -308,10 +317,13 @@ function get_supported_mode_per_connector()
{
local target="$1"
local unformatted_remote="$2"
local flag="$3"
local cmd
local port
local remote

flag=${flag:-'SILENT'}

cmd="for f in $SYSFS_CLASS_DRM/*/modes;"' do c=$(< $f) && [[ ! -z $c ]] && printf "%s\n" "$f:" "$c" ""; done'

case "$target" in
Expand Down Expand Up @@ -339,7 +351,7 @@ function get_supported_mode_per_connector()

function parse_drm_options()
{
local long_options='remote:,local,gui-on,gui-off,load-module:,unload-module:,help'
local long_options='remote:,local,gui-on,gui-off,load-module:,unload-module:,help,verbose'
long_options+=',conn-available,modes'
local short_options='h'
local raw_options="$*"
Expand All @@ -363,7 +375,7 @@ function parse_drm_options()
options_values['UNLOAD_MODULE']=''
options_values['CONN_AVAILABLE']=''
options_values['MODES_AVAILABLE']=''
options_values['VERBOSE']='SILENT'
options_values['VERBOSE']=''

populate_remote_info ''
if [[ "$?" == 22 ]]; then
Expand Down Expand Up @@ -433,8 +445,8 @@ function parse_drm_options()
options_values['MODES_AVAILABLE']=1
shift
;;
--verbose | -v)
options_values['VERBOSE']=''
--verbose)
options_values['VERBOSE']=1
shift
;;
--help | -h)
Expand Down Expand Up @@ -469,6 +481,7 @@ function drm_help()
' drm [--local | --remote [<remote>:<port>]] --gui-on' \
' drm [--local | --remote [<remote>:<port>]] --gui-off' \
' drm [--local | --remote [<remote>:<port>]] --conn-available' \
' drm [--local | --remote [<remote>:<port>]] --verbose' \
' drm [--local | --remote [<remote>:<port>]] --modes'
}

Expand Down
3 changes: 3 additions & 0 deletions tests/drm_plugin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ function test_drm_parser_options()
parse_drm_options --gui-off
assertEquals "($LINENO)" 1 "${options_values['GUI_OFF']}"

parse_drm_options --verbose
assertEquals "($LINENO)" 1 "${options_values['VERBOSE']}"

parse_drm_options --conn-available
assertEquals "($LINENO)" 1 "${options_values['CONN_AVAILABLE']}"

Expand Down

0 comments on commit a42592a

Please sign in to comment.