Re: [PATCH 5/6] selftests/bpf: libarena: Add a benchmark for malloc()/calloc()

[email protected]
Newsgroups org.kernel.vger.bpf
Message-ID <49d90f8604abbf8f1e0ae7699bfbb9a02bc8edb69c5b67f8925166bfd681969f@mail.kernel.org>
> diff --git a/tools/testing/selftests/bpf/benchs/run_bench_libarena.sh b/tools/testing/selftests/bpf/benchs/run_bench_libarena.sh
> new file mode 100755
> index 000000000000..10afe4d52ebf
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/benchs/run_bench_libarena.sh
> @@ -0,0 +1,31 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +source ./benchs/run_common.sh
> +
> +set -eufo pipefail
> +
> +RUN_BENCH="./bench -d3 -q"
> +
> +summarize_libarena()
> +{
> +	local bench="$1"
> +	local summary
> +
> +	summary=$(printf '%s\n' "$2" | tail -n1)
> +	summary=${summary#Summary: }
> +	printf "%-20s %s\n" "$bench" "$summary"
> +}
> +
> +header "libarena sequential malloc\n"
                                       ^^

The argument passed to header() includes a trailing '\n' escape, but
header() in benchs/run_common.sh uses printf's %s conversion, which
copies the argument verbatim without interpreting backslash escapes:

    function header()
    {
            local len=${#1}

            printf "\n%s\n" "$1"
            for i in $(seq 1 $len); do printf '='; done
            printf '\n'
    }

So the two characters '\' and 'n' are printed literally rather than as a
newline. There is a second effect: len=${#1} counts those two extra
characters, so the '=' underline is 28 characters for a 26-character title,
leaving the rule two characters wider than the text it underlines.

header() already emits its own leading and trailing newlines, so the escape
is not needed. All 23 other header() call sites in
tools/testing/selftests/bpf/benchs/*.sh pass a bare string with no escape
(for example, run_bench_bloom_filter_map.sh:8 uses header "Bloom filter
map"), so this is the only caller that includes an escape.

Would it make sense to drop the trailing \n?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32062809860
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.