[
https://issues.apache.org/jira/browse/YUNIKORN-1403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17733787#comment-17733787
]
Simon Blessenohl commented on YUNIKORN-1403:
--------------------------------------------
I haven't written a lot of Go in a while, so thanks for bearing with me while I
work on this!
The reproducer you posted has
{code:java}
absResValue := int64(div) * 100{code}
In contrast, the [YuniKorn
code|https://github.com/apache/yunikorn-core/blob/a6a90bb0408a3004592f06d8a79335ac326dcfe4/pkg/common/resources/resources.go#L956]
has
{noformat}
absResValue = int64(div * 100){noformat}
Is this mismatch intended? Or did I get confused here? If not, then I wonder
whether the output of the reproducer is indicative of what happens in the
YuniKorn code. Altering the reproducer to match the YuniKorn code (see
[https://go.dev/play/p/QbbSklDg_b1]) yields these results on the playground:
{code:java}
inputs:
9223372036854775807
1
div in float64: 9223372036854775808.000000
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: true
abs > 0: false
=================================
inputs:
9223372036854775807
-1
div in float64: -9223372036854775808.000000
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: false
abs > 0: false
=================================
inputs:
-9223372036854775808
1
div in float64: -9223372036854775808.000000
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: false
abs > 0: false
=================================
inputs:
-9223372036854775808
-1
div in float64: 9223372036854775808.000000
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: true
abs > 0: false
=================================
inputs:
9223372036854775807
0
div in float64: +Inf
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: true
abs > 0: false
=================================
inputs:
-9223372036854775808
0
div in float64: -Inf
div in int64: -9223372036854775808
absResValue: -9223372036854775808
div > 0: false
abs > 0: false
================================= {code}
As far as I see, the negative overflows are gone. I tried a few other things
but, as I said in my MR, I still fail to come up with a test case that
exercises the negative overflow handling in YuniKorn (on Intel with Go 1.20),
even when I relax the condition to
{code:java}
if absResValue >= 0 && div < 0 { {code}
If you have another idea for inputs that would provoke a negative overflow in
YuniKorn, do let me know!
> CalculateAbsUsedCapacity: overflow unit tests
> ---------------------------------------------
>
> Key: YUNIKORN-1403
> URL: https://issues.apache.org/jira/browse/YUNIKORN-1403
> Project: Apache YuniKorn
> Issue Type: Improvement
> Components: core - common, test - unit
> Reporter: Wilfred Spiegelenburg
> Priority: Major
> Labels: newbie, pull-request-available
>
> CalculateAbsUsedCapacity is guarded against positive and negative overflow.
> The postive case is unit tested. The negative case is not unit tested.
> Need to add a test case for te negative side:
> {code}
> // protect against negative integer overflow
> if absResValue > 0 && div < 0 {
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]