[LTP] [PATCH v7 2/4] ci: add patchwork communication script

Petr Vorel pvorel@suse.cz
Tue Apr 15 19:35:35 CEST 2025


Hi Andrea,

...
> +fetch_series() {
> +        local current_time=$(date +%s)
> +        local since_time=$(expr $current_time - $PATCHWORK_SINCE)
> +        local date=$(date -u -d @$since_time +"%Y-%m-%dT%H:%M:%SZ")
> +        local stdout=$(curl -k -G "$PATCHWORK_URL/api/events/" \
> +                --data "category=series-completed" \
> +                --data "project=ltp" \
> +                --data "state=new" \
> +                --data "since=$date" \
> +                --data "archive=no")
> +
> +        [ $? -eq 0 ] || exit 1

You may have noticed in tst_test.sh, that local variable never uses $(...).
It assign single value, but never call $(...). This is for a reason.

Try:

$ cat foo.sh
#!/bin/sh

foo()
{
    local foo=$(aasfd_command_which_fails)

    [ $? -eq 0 ] || exit 1
    echo "run after"
}

bar()
{
    local foo

    foo=$(aasfd_command_which_fails)

    [ $? -eq 0 ] || exit 1
    echo "will not run after"
}

foo
bar

---
$ bash ./foo.sh
./foo.sh: line 5: aasfd_command_which_fails: command not found
run after
./foo.sh: line 15: aasfd_command_which_fails: command not found

What happen? $? is assigned from result of local keyword,
it overwrite previous result from $(...). Note even '#!/bin/sh -e'
would not cause it to fail early.

(Deliberately test with bash to demonstrate local behaves oddly not even in dash
or 'busybox sh' but even with bash. And yes, given how many errors we caught
with this script and generate_arch.sh and generate_syscalls.sh due shell strange
syntax and behavior makes me wonder if we really want to use shell scripts for
anything longer than 5 lines.)

Kind regards,
Petr


More information about the ltp mailing list