From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 35AB15A026D; Mon, 31 Oct 2022 12:20:59 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v2 4/5] test/lib: Add "td" directive, handled by table_value() Date: Mon, 31 Oct 2022 12:20:58 +0100 Message-Id: <20221031112059.170269-5-sbrivio@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221031112059.170269-1-sbrivio@redhat.com> References: <20221031112059.170269-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 5J7BLCDBKTMLE4I7BGZEVI32HAWNBCXW X-Message-ID-Hash: 5J7BLCDBKTMLE4I7BGZEVI32HAWNBCXW X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: <> Archived-At: List-Archive: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This can be used for generic cell values with an arbitrary scale. Signed-off-by: Stefano Brivio --- test/lib/term | 28 ++++++++++++++++++++++++++++ test/lib/test | 3 +++ 2 files changed, 31 insertions(+) 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)" diff --git a/test/lib/test b/test/lib/test index 4c271a5..df32178 100755 --- a/test/lib/test +++ b/test/lib/test @@ -278,6 +278,9 @@ test_one_line() { "te") table_end ;; + "td") + table_value ${__arg} || TEST_ONE_perf_nok=1 + ;; "bw") table_value_throughput ${__arg} || TEST_ONE_perf_nok=1 ;; -- 2.35.1