Skip to content

sipp-rs: take a time unit on -rp, -d and -recv_timeout - #1296

Merged
orgads merged 1 commit into
SIPp:masterfrom
AspieCoder1:rust-time-options
Nov 30, 2026
Merged

orgads merged 1 commit into
SIPp:masterfrom
AspieCoder1:rust-time-options

Conversation

@AspieCoder1

@AspieCoder1 AspieCoder1 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

SIPp parses -rp, -d and -recv_timeout as times with a default unit of milliseconds, so -rp 5s means five seconds. sipp-rs's own -h text gives -r 10 -rp 5s as an example. sipp-rs parsed these three as plain integers, so a SIPp command line that uses a unit fails before sending anything:

$ sipp-rs -sn uac -r 10 -rp 5s 127.0.0.1
-rp, "5s" is not a valid integer!

This PR parses the three options with duration_ms(), which -T2, -deadcall_wait, -reconnect_sleep and the other millisecond options already use. A bare number still means milliseconds, so existing command lines are unaffected. I compared every option src/sipp.cpp declares as SIPP_OPTION_TIME_* with its sipp-rs parser, and these were the only three still taking an integer. -send_timeout and the -watchdog_* thresholds are accepted and ignored, so they never reject a unit.

Tests: regress/github-#1296 runs each option with 2000, 5s, 250ms and 1m, and checks that 5x fails with SIPp's -rp, "5x" is not a valid time!. It runs against both binaries and fails on sipp-rs master with the error above. millisecond_options_take_a_unit checks the parsed values. cargo test --workspace --locked passes.

A bad value for any time option now fails with get_time()'s message instead of sipp-rs's own wording, so the shell test can share the check with C.

No help text or docs change: the help already describes this behaviour.

🤖 Generated with Claude Code

@orgads

orgads commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Thanks, this looks good: get_time(..., 1) in C and duration_ms() agree on the units, the truncation and the default.

One suggestion: the shell tests in regress/ run against both binaries (rust/regress.sh runs them with SIPP=sipp-rs), so this could also be covered by a regression test shared with C, as github-#1243 does for -m. For that, the error text would need to match C's. All the callers of duration() and duration_ms() parse command-line options, so both error arms in duration() can use get_time()'s wording, which gives every time option C's message at once:

let bad = || format!("{opt}, \"{v}\" is not a valid time!");
let n: f64 = v[..split].parse().map_err(|_| bad())?;
// ...
_ => return Err(bad()),

Then regress/github-#1296/run:

#!/bin/sh
# This regression test is a part of SIPp.
# -rp, -d and -recv_timeout take a time unit, milliseconds by default,
# and refuse an unknown one.
. "`dirname "$0"`/../functions"; init

for opt in -rp -d -recv_timeout; do
    for v in 2000 5s 250ms 1m; do
        out=`sippfg -sn uac -i 127.0.0.1 -p 24500 -m 1 -timeout 1s \
            $opt $v 127.0.0.1:24501 2>&1`
        test $? = 255 && fail "$opt $v refused: $out"
    done
    out=`sippfg -sn uac -i 127.0.0.1 -p 24500 $opt 5x 127.0.0.1:24501 2>&1`
    case $out in
        *"$opt, \"5x\" is not a valid time!"*) ;;
        *) fail "$opt 5x: $out" ;;
    esac
done
ok

It passes with C SIPp and fails with sipp-rs on master (-rp 5s refused: -rp, "5s" is not a valid integer!). A timed-out run exits with 1 on both, so 255 is only the option error. It takes about 12 seconds. The shell test can only show that a unit is accepted, so keep millisecond_options_take_a_unit for the values; the 5x half of it could move to this test.

Minor: the second commit only extends the test, so it could be squashed into the first.

SIPp parses these as times whose default unit is milliseconds, so
"-rp 5s" means five seconds; sipp-rs's own help gives "-r 10 -rp 5s" as
an example. sipp-rs parsed them as plain integers and exited with
'-rp, "5s" is not a valid integer!', so a command line that works with
SIPp fails before sending anything. They now go through duration_ms(),
as -T2, -deadcall_wait and the other millisecond options already do. A
bare number still means milliseconds.

A bad time now fails with get_time()'s message, '<opt>, "<v>" is not a
valid time!', for every time option, so regress/github-#1296 can check
the error against both SIPp and sipp-rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AspieCoder1

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all three done and squashed into one commit:

  • Both error arms in duration() now use get_time()'s wording, so every time option fails with C's <opt>, "<v>" is not a valid time!. Nothing else in rust/, regress/ or the docs matched the old text.
  • Added regress/github-#1296/run as you wrote it. It passes with the fix and fails on sipp-rs master with -rp 5s refused: … -rp, "5s" is not a valid integer!.
  • Moved the 5x check into that test, and kept millisecond_options_take_a_unit for the parsed values.

@orgads
orgads merged commit 1c96bb1 into SIPp:master Nov 30, 2026
11 checks passed
@orgads

orgads commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants