Skip to content

Commit 637cfe5

Browse files
dpotmaneboasson
authored andcommitted
Prevent removing last struct member in fuzzer test mutations
Signed-off-by: Dennis Potman <[email protected]>
1 parent 3f6b8ec commit 637cfe5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tests/support_modules/fuzz_tools/checks/mutated.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ def check_mutation_key(log: Stream, ctx: FullContext, typename: str, num_samples
9696
mutated_ctx = FullContext(new_scope)
9797
mutated_datatype = mutated_ctx.get_datatype(typename)
9898

99-
if typename == "Zerepainam":
100-
print(mutated_ctx.idl_file)
101-
10299
if narrow_ctx.idl_file[1:] == mutated_ctx.idl_file[1:]:
103100
return True
104101

tests/support_modules/fuzz_tools/rand_idl/mutator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def scan_avoid_mutating_field(field: cn.RField):
102102
def non_valid_mutate_struct(top_scope: cn.RScope, struct: cn.RStruct, random: Random) -> cn.RStruct:
103103
if struct.extensibility in [cn.RExtensibility.NotSpecified, cn.RExtensibility.Final]:
104104
action = random.choices([1, 2], weights=[1, 1], k=1)[0]
105+
106+
if len(struct.fields) == 1:
107+
action = 1
108+
105109
if action == 1:
106110
# add a field
107111
struct.fields.append(
@@ -119,6 +123,10 @@ def non_valid_mutate_struct(top_scope: cn.RScope, struct: cn.RStruct, random: Ra
119123
# keyless struct
120124
action = 1
121125

126+
# can't remove last field
127+
if len(struct.fields) == 1 and action == 2:
128+
action = 1
129+
122130
if action == 1:
123131
# add a field in the middle
124132
if len(struct.fields) == 0:
@@ -152,7 +160,7 @@ def non_valid_mutate_struct(top_scope: cn.RScope, struct: cn.RStruct, random: Ra
152160
if struct.extensibility == cn.RExtensibility.Mutable:
153161
action = random.choices([1, 2], weights=[1, 1], k=1)[0]
154162

155-
if action == 1 and struct.in_key_path:
163+
if action == 1 and struct.in_key_path and len(struct.fields) > 1:
156164
# remove a key field
157165
for i, field in enumerate(struct.fields):
158166
if 'key' in field.annotations:

0 commit comments

Comments
 (0)