aboutsummaryrefslogtreecommitdiffstats
path: root/prog/expr_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-09-11 16:04:43 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-09-11 14:55:22 +0000
commit7308f9d5a4da8ea4e2a9a0748ceb0921333c11f4 (patch)
tree3c4c0d6bdfd082e089a5514c0c06e7eabec864f9 /prog/expr_test.go
parentfd0ad8a3f899365059471f5fdefdc73082ce0777 (diff)
prog: allow deeper nesting of conditional fields patching
There is a totally valid situation when we could be recursively patching conditional fields: if by changing a field's value we insert new resource constructor calls. It's a bug to skip conditional field patching for them. Allow up to 2 nested patchConditionalFields() calls and panic if there happen to be more. Add a test that reproduces the situation described above.
Diffstat (limited to 'prog/expr_test.go')
-rw-r--r--prog/expr_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/prog/expr_test.go b/prog/expr_test.go
index aaae6a74a..74818ea55 100644
--- a/prog/expr_test.go
+++ b/prog/expr_test.go
@@ -280,3 +280,25 @@ func TestConditionalUnionFields(t *testing.T) {
assert.Greater(t, zeroU2, 0)
assert.Greater(t, nonzeroU2, 0)
}
+
+func TestNestedConditionalCall(t *testing.T) {
+ // Ensure that we reach different combinations of conditional fields.
+ target, rs, _ := initRandomTargetTest(t, "test", "64")
+ ct := target.DefaultChoiceTable()
+ r := newRand(target, rs)
+
+ for i := 0; i < 100; i++ {
+ for _, name := range []string{"test$conditional_struct_nested", "test$conditional_struct_nested2"} {
+ s := newState(target, ct, nil)
+ calls := r.generateParticularCall(s, target.SyscallMap[name])
+ p := &Prog{
+ Target: target,
+ Calls: calls,
+ }
+ err := p.checkConditions()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+}