From 71cae9a1e3dac1b23fbd2abb6df4c32e1e9e0435 Mon Sep 17 00:00:00 2001 From: wang3820 Date: Tue, 31 Oct 2023 19:25:55 -0500 Subject: [PATCH] Fixed flaky test --- .../util/TransformationProbabilities.java | 10 +++++++++- .../util/TransformationProbabilitiesTest.java | 14 +++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/generator/src/main/java/com/graphicsfuzz/generator/util/TransformationProbabilities.java b/generator/src/main/java/com/graphicsfuzz/generator/util/TransformationProbabilities.java index 9229425f2..954f3b4c5 100755 --- a/generator/src/main/java/com/graphicsfuzz/generator/util/TransformationProbabilities.java +++ b/generator/src/main/java/com/graphicsfuzz/generator/util/TransformationProbabilities.java @@ -18,6 +18,8 @@ import com.graphicsfuzz.common.util.IRandom; import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Comparator; public class TransformationProbabilities { @@ -381,7 +383,13 @@ private boolean choose(int threshold, IRandom generator) { @Override public String toString() { String result = ""; - for (Field field : this.getClass().getDeclaredFields()) { + Field[] sortedFields = this.getClass().getDeclaredFields(); + Arrays.sort(sortedFields, new Comparator() { + public int compare(Field field1, Field field2) { + return field1.getName().compareTo(field2.getName()); + } + }); + for (Field field : sortedFields) { if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) { continue; } diff --git a/generator/src/test/java/com/graphicsfuzz/generator/util/TransformationProbabilitiesTest.java b/generator/src/test/java/com/graphicsfuzz/generator/util/TransformationProbabilitiesTest.java index 4c347082b..fe1b70d07 100644 --- a/generator/src/test/java/com/graphicsfuzz/generator/util/TransformationProbabilitiesTest.java +++ b/generator/src/test/java/com/graphicsfuzz/generator/util/TransformationProbabilitiesTest.java @@ -24,20 +24,20 @@ public class TransformationProbabilitiesTest { @Test public void testToString() { - assertEquals("probSubstituteFreeVariable: 80\n" + assertEquals("probAddDeadFragColorWrites: 5\n" + + "probAddLiveFragColorWrites: 5\n" + "probDonateDeadCodeAtStmt: 5\n" + "probDonateLiveCodeAtStmt: 5\n" + + "probInjectDeadBarrierAtStmt: 5\n" + "probInjectJumpAtStmt: 5\n" - + "probWrapStmtInConditional: 5\n" + "probMutatePoint: 3\n" - + "probVectorizeStmts: 3\n" + + "probOutline: 5\n" + "probSplitLoops: 5\n" + "probStructify: 3\n" - + "probOutline: 5\n" - + "probAddLiveFragColorWrites: 5\n" - + "probAddDeadFragColorWrites: 5\n" + + "probSubstituteFreeVariable: 80\n" + "probSwitchify: 5\n" - + "probInjectDeadBarrierAtStmt: 5\n", + + "probVectorizeStmts: 3\n" + + "probWrapStmtInConditional: 5\n", TransformationProbabilities.SMALL_PROBABILITIES.toString()); }