Skip to content

Commit

Permalink
JACOBIN-632 Added unit test for IINC overflow logic
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Dec 31, 2024
1 parent 33acc39 commit 9db34ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/buildno.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

package config

var BuildNo = 3391
var BuildNo = 3392
18 changes: 18 additions & 0 deletions src/jvm/interpreter_II-LD_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ func TestNewIincNeg(t *testing.T) {
}
}

func TestIincOverflow(t *testing.T) {
f := newFrame(opcodes.IINC)
f.Locals = append(f.Locals, zero)
f.Locals = append(f.Locals, int64(0x7FFFFFFF)) // initialize local variable[1] to max int
f.Meth = append(f.Meth, 1) // increment local variable[1]
f.Meth = append(f.Meth, 1) // increment it by 1
fs := frames.CreateFrameStack()
fs.PushFront(&f) // push the new frame
interpret(fs)
if f.TOS != -1 {
t.Errorf("Top of stack, expected -1, got: %d", f.TOS)
}
value := int32(f.Locals[1].(int64))
if value != -2147483648 {
t.Errorf("IINC: Expected popped value to be -2147483648, got: %d", value)
}
}

// ILOAD: test load of int in locals[index] on to stack
func TestNewIload(t *testing.T) {
f := newFrame(opcodes.ILOAD)
Expand Down

0 comments on commit 9db34ea

Please sign in to comment.