summaryrefslogtreecommitdiff
path: root/chapter16/src/test/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-10-18 15:41:32 -0700
committerCliff Click <cliffc@acm.org>2024-10-21 08:52:01 -0700
commit10db4b4946b917d9383db0464c50a49acb7d6baf (patch)
tree763406852d733e7c011a8529cf2e5407876218b8 /chapter16/src/test/java/com
parentc4c8ee708c6948dcfa41be61eb96e744d5c6d3f8 (diff)
downloadSimple-10db4b4946b917d9383db0464c50a49acb7d6baf.tar.gz
Simple-10db4b4946b917d9383db0464c50a49acb7d6baf.zip
fuzzer bug fixes
ignore temps made during constructing and/or/xor honor TypeInteger.TOP; TypeInteger.nonZero works with zero NotNode keeps precision. Scope lazy phis of narrow ints auto-widen
Diffstat (limited to 'chapter16/src/test/java/com')
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java18
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java33
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java41
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java51
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/FuzzerWrap.java14
5 files changed, 136 insertions, 21 deletions
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index a064e8e4..d6278b76 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -515,4 +515,22 @@ return v;
StopNode stop = parser.parse().iterate();
//assertEquals("return new S;", stop.toString());
}
+
+ @Test
+ public void testScheduleUse() {
+ Parser parser = new Parser(
+"""
+int v0=0;
+while(0>=0) {
+ u1 v1=0;
+ v1=v0;
+ if(v1*0)
+ v0=-v1;
+}
+return 0;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
+
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
index ea577c6b..7d7bb25a 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
@@ -166,6 +166,39 @@ return arg;
}
@Test
+ public void testCloneAnd() {
+ Parser parser = new Parser("""
+int v0=0;
+u32 v1 = 1&(1<<arg)&(1<<arg);
+while(arg) v1=-v0;
+while(v1) break;
+return v1;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return (Phi(Loop18,((1<<arg)&1),0)&Phi(Loop,Shl,4294967295));", stop.toString());
+ assertEquals(1L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testAndHigh() {
+ Parser parser = new Parser("""
+int v0=0;
+if(0&0>>>0) {
+ while(0) {
+ u8 v1=0;
+ v0=0>>>0;
+ v1=arg;
+ while(v1+0) {}
+ }
+}
+return v0;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
public void testTypes() {
Parser parser = new Parser(
"""
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
index 93a9c85c..55486124 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
@@ -325,4 +325,45 @@ return is[1];
catch( NegativeArraySizeException e ) { assertEquals("-1",e.getMessage()); }
}
+ @Test
+ public void testProgress() {
+ Parser parser = new Parser("""
+i8 v1=0&0;
+u8 v2=0;
+byte v4=0;
+if(0) {}
+while(v2<0) {
+ v4=0-v1;
+ break;
+}
+int v5=0&0;
+while(v5+(0&0)) {
+ int v7=0&0;
+ while(v7)
+ v4=0>>>v5;
+ while(v1)
+ return 0;
+}
+return v1;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testSharpNot() {
+ Parser parser = new Parser(
+"""
+if(0>>0) {}
+while(0) {}
+u32 v7=0;
+int v8=0;
+while(0<--1>>>---(v7*0==v8)) {}
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
+
+
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
index 6878a836..7cd1604b 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
@@ -3,31 +3,15 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.StopNode;
import org.junit.Test;
-import org.junit.Ignore;
-
-import java.awt.*;
-import java.nio.charset.StandardCharsets;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-/**
- struct S {
- int x; // default init of 0
- S? x; // default init of null
- int !x; // final init required in constructor
- S x; // init required in constructor
- int !x=17; // final init done now, not in constructor
- S x = ...;// init done now, not in constructor
- };
-
- */
-
public class Chapter16Test {
@Test
public void testJig() {
- Parser parser = new Parser("""
+ Parser parser = new Parser(
+"""
return 3.14;
""");
StopNode stop = parser.parse().iterate();
@@ -35,6 +19,7 @@ return 3.14;
assertEquals(3.14, Evaluator.evaluate(stop, 0));
}
+
@Test
public void testMulti0() {
Parser parser = new Parser(
@@ -157,5 +142,35 @@ return next.i;
assertEquals(2L, Evaluator.evaluate(stop, 3));
}
+ @Test
+ public void testLinkedList2() {
+ Parser parser = new Parser(
+"""
+struct LLI { LLI? next; int i; };
+LLI? head = null;
+while( arg ) {
+ head = new LLI {
+ next=head;
+ // Any old code in the constructor
+ int tmp=arg;
+ while( arg > 10 ) {
+ tmp = tmp + arg;
+ arg = arg - 1;
+ }
+ i=tmp;
+ };
+ arg = arg-1;
+}
+if( !head ) return 0;
+LLI? next = head.next;
+if( !next ) return 1;
+return next.i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("Stop[ return 0; return 1; return .i; ]", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ assertEquals(1L, Evaluator.evaluate(stop, 1));
+ assertEquals(2L, Evaluator.evaluate(stop, 11));
+ }
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter16/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index 699711fc..eaeed8e2 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -1,10 +1,9 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.fuzzer.Fuzzer;
-import org.junit.Test;
+import java.util.Random;
import org.junit.Ignore;
-
-
+import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
@@ -25,6 +24,15 @@ public class FuzzerWrap {
@Test
+ public void fuzzPeepsSmall() {
+ Random R = new Random(System.currentTimeMillis());
+ var fuzzer = new Fuzzer();
+ for (int i=0; i<100; i++)
+ fuzzer.fuzzPeeps(R.nextLong());
+ assertTrue(fuzzer.noExceptions());
+ }
+
+ @Test
@Ignore
public void fuzzPeepTiming() {
var fuzzer = new Fuzzer();