github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/tests/lib/external/snapd-testing-tools/utils/spreadJ (about) 1 #!/bin/bash 2 3 show_help() { 4 echo "usage: spreadJ rerun [--suite SUITE] <RESULTS-PATH>" 5 echo " spreadJ show [--suite SUITE] <TARGET> <RESULTS-PATH>" 6 echo " spreadJ stats [--suite SUITE] <RESULTS-PATH>" 7 echo " spreadJ list [--suite SUITE] <TARGET> <RESULTS-PATH>" 8 echo "" 9 echo "Available options:" 10 echo " -h --help show this help message." 11 echo "" 12 echo "TARGET:" 13 echo " all,failed,passed,aborted" 14 echo "" 15 echo "Tool used to help with functions that are not already implemented in spread" 16 } 17 18 _filter_suite() { 19 local suite="$1" 20 if [ -z "$suite" ]; then 21 echo ".testsuites[]" 22 else 23 echo ".testsuites[] | select(.name == \"$suite\")" 24 fi 25 } 26 27 rerun() { 28 local suite="" 29 if [ "$1" == "--suite" ]; then 30 suite="$2" 31 shift 2 32 fi 33 local res_path="$1" 34 if [ ! -e "$res_path" ]; then 35 echo "spreadJ: results path not found: $res_path" 36 exit 1 37 fi 38 39 local query 40 query="$(_filter_suite $suite).tests[] | select((.result == \"failed\") or (.result == \"aborted\")).name" 41 jq -r "$query" "$res_path" 42 } 43 44 stats() { 45 local suite="" 46 if [ "$1" == "--suite" ]; then 47 suite="$2" 48 shift 2 49 fi 50 local res_path="$1" 51 52 if [ ! -e "$res_path" ]; then 53 echo "spreadJ: results path not found: $res_path" 54 exit 1 55 fi 56 57 local query 58 if [ -z "$suite" ]; then 59 query="del(.testsuites)" 60 else 61 query="$(_filter_suite $suite) | del(.tests) | del(.name)" 62 fi 63 jq -r "$query" "$res_path" 64 } 65 66 list() { 67 local suite="" 68 if [ "$1" == "--suite" ]; then 69 suite="$2" 70 shift 2 71 fi 72 local target="$1" 73 local res_path="$2" 74 75 if [ ! -e "$res_path" ]; then 76 echo "spreadJ: results path not found: $res_path" 77 exit 1 78 fi 79 80 if [ -z "$target" ]; then 81 echo "spreadJ: result target cannot be empty" 82 exit 1 83 fi 84 85 local query 86 if [ "$target" == "all" ]; then 87 query="$(_filter_suite $suite).tests[]).name" 88 else 89 query="$(_filter_suite $suite).tests[] | select((.result == \"$target\")).name" 90 fi 91 jq -r "$query" "$res_path" 92 } 93 94 main() { 95 if [ $# -eq 0 ]; then 96 show_help 97 exit 0 98 fi 99 100 local subcommand="$1" 101 local action= 102 if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then 103 show_help 104 exit 0 105 else 106 action=$(echo "$subcommand" | tr '-' '_') 107 shift 108 fi 109 110 if [ -z "$(declare -f "$action")" ]; then 111 echo "spreadJ: no such command: $subcommand" >&2 112 show_help 113 exit 1 114 fi 115 116 "$action" "$@" 117 } 118 119 main "$@"