Page MenuHomeFreeBSD

sysutils/zfs-stats-lite: Bump to 1.3: Fix handling of negative numbers
ClosedPublic

Authored by dteske on Sep 15 2015, 6:10 PM.

Details

Summary

Bump to 1.3: Fix handling of negative numbers

PR: ports/199255
Approved by: <your name here>

Test Plan

Some calculations from sysctl(8) regarding kstat numbers produce
negative calculations (since values can change between query of
one value and another, it is not guaranteed that all values are
going to be positive). The f_float() and f_perc() functions which
provide floating point arithmetic native to sh(1) were using the
getopts built-in to parse arguments which made it impossible to
accept negative values. Both f_float() and f_perc() have been
updated to support negative numbers, fixing the PR.

To test the f_float() function, I had inserted the following few
lines after its declaration:

f_float "$@"
retval=$?
echo "foo=[$foo]"
exit $retval

Wherein I tested many arguments:

-1 2 # -0.50
1 -2 # -0.50
-n4 -1 2 # -0.5000
-n4 1 -2 # -0.5000
-n 4 -1 2 # -0.5000
-n 4 1 -2 # -0.5000
-10 2 # -5.00
10 -2 # -5.00
-n4 -10 2 # -5.0000
-n4 10 -2 # -5.0000
-n 4 -10 2 # -5.0000
-n 4 10 -2 # -5.0000
-1 / 2 # -0.50
1 / -2 # -0.50
-n4 -1 / 2 # -0.5000
-n4 1 / -2 # -0.5000
-n 4 -1 / 2 # -0.5000
-n 4 1 / -2 # -0.5000
-10 / 2 # -5.00
10 / -2 # -5.00
-n4 -10 / 2 # -5.0000
-n4 10 / -2 # -5.0000
-n 4 -10 / 2 # -5.0000
-n 4 10 / -2 # -5.0000
-1 -2 # 0.50
-n4 -1 -2 # 0.5000
-n 4 -1 -2 # 0.5000
-10 -2 # 5.00
-n4 -10 -2 # 5.0000
-n 4 -10 -2 # 5.0000
-1 / -2 # 0.50
-n4 -1 / -2 # 0.5000
-n 4 -1 / -2 # 0.5000
-10 / -2 # 5.00
-n4 -10 / -2 # 5.0000
-n 4 -10 / -2 # 5.0000
-1 2 foo # foo=[-0.50]
1 -2 foo # foo=[-0.50]
-n4 -1 2 foo # foo=[-0.5000]
-n4 1 -2 foo # foo=[-0.5000]
-n 4 -1 2 foo # foo=[-0.5000]
-n 4 1 -2 foo # foo=[-0.5000]
-10 2 foo # foo=[-5.00]
10 -2 foo # foo=[-5.00]
-n4 -10 2 foo # foo=[-5.0000]
-n4 10 -2 foo # foo=[-5.0000]
-n 4 -10 2 foo # foo=[-5.0000]
-n 4 10 -2 foo # foo=[-5.0000]
-1 / 2 foo # foo=[-0.50]
1 / -2 foo # foo=[-0.50]
-n4 -1 / 2 foo # foo=[-0.5000]
-n4 1 / -2 foo # foo=[-0.5000]
-n 4 -1 / 2 foo # foo=[-0.5000]
-n 4 1 / -2 foo # foo=[-0.5000]
-10 / 2 foo # foo=[-5.00]
10 / -2 foo # foo=[-5.00]
-n4 -10 / 2 foo # foo=[-5.0000]
-n4 10 / -2 foo # foo=[-5.0000]
-n 4 -10 / 2 foo # foo=[-5.0000]
-n 4 10 / -2 foo # foo=[-5.0000]
-1 -2 foo # foo=[0.50]
-n4 -1 -2 foo # foo=[0.5000]
-n 4 -1 -2 foo # foo=[0.5000]
-10 -2 foo # foo=[5.00]
-n4 -10 -2 foo # foo=[5.0000]
-n 4 -10 -2 foo # foo=[5.0000]
-1 / -2 foo # foo=[0.50]
-n4 -1 / -2 foo # foo=[0.5000]
-n 4 -1 / -2 foo # foo=[0.5000]
-10 / -2 foo # foo=[5.00]
-n4 -10 / -2 foo # foo=[5.0000]
-n 4 -10 / -2 foo # foo=[5.0000]

To test the f_perc() function, I inserted the following after it:

f_perc "$@"
retval=$?
echo "foo=[$foo]"

Wherein I performed similar testing to the above.

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dteske retitled this revision from to sysutils/zfs-stats-lite: Bump to 1.3: Fix handling of negative numbers.
dteske updated this object.
dteske edited the test plan for this revision. (Show Details)
dteske added a reviewer: feld.
dteske added subscribers: shurd, emaste, adrian.
feld edited edge metadata.

looks good from here

This revision is now accepted and ready to land.Oct 14 2015, 4:24 PM
This revision was automatically updated to reflect the committed changes.