aboutgitcodebugslistschat
path: root/test/lib/term
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-10-31 10:41:40 +0100
committerStefano Brivio <sbrivio@redhat.com>2022-11-04 12:01:18 +0100
commitce2a0a5bb45b23a28ac9b125bd67a4678c009231 (patch)
tree312b2bc23fe5f0da9adc05439f1c8df103f665e3 /test/lib/term
parentbfd311aec786ce0b7d3b8bbaf37147aa1ba9ec08 (diff)
downloadpasst-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar.gz
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar.bz2
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar.lz
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar.xz
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.tar.zst
passt-ce2a0a5bb45b23a28ac9b125bd67a4678c009231.zip
test/lib: Add "td" directive, handled by table_value()
This can be used for generic cell values with an arbitrary scale. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'test/lib/term')
-rwxr-xr-xtest/lib/term28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/lib/term b/test/lib/term
index 1b42df8..8515c50 100755
--- a/test/lib/term
+++ b/test/lib/term
@@ -552,6 +552,34 @@ table_end() {
info_n "\n${__buf}'\n"
}
+# table_value() - Print generic table value in its own cell
+# $1: Value, can be '-' to indicate a filler
+# $2: Scale, exponent of 10
+# $3: Error value, scaled: if value is less than this, print in red
+# $4: Warning value, scaled: if value is less than this, print in yellow
+table_value() {
+ [ "${1}" = "-" ] && table_cell 1 "-" && perf_td 0 "" && return 0
+ if [ "${2}" != "0" ]; then
+ __v="$(echo "scale=1; x=( ${1} + 10^$((${2} - 1)) / 2 ) / 10^${2}; if ( x < 1 && x > 0 ) print 0; x" | bc -l)"
+ else
+ __v="${1}"
+ fi
+ perf_td 0 "${__v}"
+
+ __red="${3}"
+ __yellow="${4}"
+ if [ "$(echo "${__v} < ${__red}" | bc -l)" = "1" ]; then
+ table_cell ${#__v} "${PR_RED}${__v}${PR_NC}"
+ return 1
+ elif [ "$(echo "${__v} < ${__yellow}" | bc -l)" = "1" ]; then
+ table_cell ${#__v} "${PR_YELLOW}${__v}${PR_NC}"
+ return 1
+ else
+ table_cell ${#__v} "${PR_GREEN}${__v}${PR_NC}"
+ return 0
+ fi
+}
+
table_value_throughput() {
[ "${1}" = "-" ] && table_cell 1 "-" && perf_td 0 "" && return 0
__v="$(echo "scale=1; x=( ${1} + 10^8 / 2 ) / 10^9; if ( x < 1 && x > 0 ) print 0; x" | bc -l)"