SIPp / sipp

The SIPp testing tool
https://sipp.readthedocs.io
Other
916 stars 380 forks source link

(test suite) stat: illegal option -- c #710

Open ryandesign opened 6 months ago

ryandesign commented 6 months ago

When running regress/runtests on macOS, this error occurs in one test:

Testing github-#0337: stat: illegal option -- c
usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
failed (on bad-EOF bad-len)

It's happening on this line:

https://github.com/SIPp/sipp/blob/d1bdebe2e90d36f4d4bd4061b398d85b4880ac5d/regress/github-%230337/run#L13

The -c flag is unique to the GNU flavor of stat and is not available in the BSD flavor of stat that is used on BSD-derived operating systems like macOS.

The BSD stat equivalent of the GNU -c%s is -f%z.

I'm not sure if there's a more portable way of discovering a file's size. If not, I'm not sure of the best way to distinguish BSD stat from GNU stat so that the right command could be used.

ryandesign commented 6 months ago

Looks like there is a second occurrence of this code:

https://github.com/SIPp/sipp/blob/d1bdebe2e90d36f4d4bd4061b398d85b4880ac5d/regress/github-%230034/run#L23

wdoekes commented 5 months ago

I suppose one could write a stat wrapper:

get_filesize() {
    local f v
    f="$1"
    # GNU stat
    if v=$(stat -c%s "$f" 2>/dev/null) && echo "$v" | grep -q '^[0-9]\+$'; then
        echo "$v"
        return
    fi
    # BSD stat
    stat -f%z "$f"
}

Would you like to create a PR?