Skip to content

Commit

Permalink
feat: add more real world tests (#477)
Browse files Browse the repository at this point in the history
* Add euc / oob / shf / stp examples

These examples are not yet complete, however, as they require test
traces as well.

* Add MMIO example

Again, this is not yet complete because we don't have traces for it.

* Add real-world traces

These are based off the unit tests used for the linea-tracer.

This second batch of traces are appended and include traces taken from
the replay tests.
  • Loading branch information
DavePearce authored Dec 21, 2024
1 parent 01aa174 commit d1958a1
Show file tree
Hide file tree
Showing 24 changed files with 28,805 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lint:
.PHONY: test
test:
@echo ">>> Running Unit Tests..."
go test -v -race ./...
go test --timeout 0 -v ./...

.PHONY: qtest
qtest:
Expand Down
9 changes: 7 additions & 2 deletions pkg/sexp/translator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sexp

import "fmt"
import (
"fmt"
"reflect"
)

// SymbolRule is a symbol generator is responsible for converting a terminating
// expression (i.e. a symbol) into an expression type T. For
Expand Down Expand Up @@ -265,7 +268,9 @@ func translateSExp[T comparable](p *Translator[T], s SExp) (T, []SyntaxError) {
}
}
// This should be unreachable.
return empty, p.SyntaxErrors(s, "invalid s-expression")
typeof := reflect.TypeOf(s)
// But, if it is reached ... produce a nice error :)
return empty, p.SyntaxErrors(s, fmt.Sprintf("invalid s-expression (%s)", typeof))
}

// Translate a list of S-Expressions into a unary, binary or n-ary
Expand Down
38 changes: 36 additions & 2 deletions pkg/test/valid_corset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,11 @@ func Test_PureFun_08(t *testing.T) {
Check(t, false, "purefun_08")
}

/* #479
func Test_PureFun_09(t *testing.T) {
Check(t, false, "purefun_0")
}
*/
// ===================================================================
// For Loops
// ===================================================================
Expand Down Expand Up @@ -764,8 +769,8 @@ func TestSlow_BinStatic(t *testing.T) {
Check(t, true, "bin-static")
}

func TestSlow_BinDynamic(t *testing.T) {
Check(t, true, "bin-dynamic")
func TestSlow_Bin(t *testing.T) {
Check(t, true, "bin")
}

func TestSlow_Wcp(t *testing.T) {
Expand All @@ -776,6 +781,28 @@ func TestSlow_Wcp(t *testing.T) {
Check(t, true, "mxp")
}
*/
/*
func TestSlow_Shf(t *testing.T) {
Check(t, true, "shf")
}
*/
func TestSlow_Euc(t *testing.T) {
Check(t, true, "euc")
}

/*
func TestSlow_Oob(t *testing.T) {
Check(t, true, "oob")
}
*/
func TestSlow_Stp(t *testing.T) {
Check(t, true, "stp")
}

/* func TestSlow_Mmio(t *testing.T) {
Check(t, true, "mmio")
}
*/
// ===================================================================
// Test Helpers
// ===================================================================
Expand Down Expand Up @@ -808,14 +835,17 @@ func Check(t *testing.T, stdlib bool, test string) {
// Check valid traces are accepted
accepts_file := fmt.Sprintf("%s/%s.%s", TestDir, test, "accepts")
accepts := ReadTracesFile(accepts_file)
ntests := len(accepts)
CheckTraces(t, accepts_file, true, true, accepts, schema)
// Check invalid traces are rejected
rejects_file := fmt.Sprintf("%s/%s.%s", TestDir, test, "rejects")
rejects := ReadTracesFile(rejects_file)
ntests += len(rejects)
CheckTraces(t, rejects_file, false, true, rejects, schema)
// Check expanded traces are rejected
expands_file := fmt.Sprintf("%s/%s.%s", TestDir, test, "expanded")
expands := ReadTracesFile(expands_file)
ntests += len(expands)
CheckTraces(t, expands_file, false, false, expands, schema)
// Check auto-generated valid traces (if applicable)
auto_accepts_file := fmt.Sprintf("%s/%s.%s", TestDir, test, "auto.accepts")
Expand All @@ -827,6 +857,10 @@ func Check(t *testing.T, stdlib bool, test string) {
if auto_rejects := ReadTracesFileIfExists(auto_rejects_file); auto_rejects != nil {
CheckTraces(t, auto_rejects_file, false, true, auto_rejects, schema)
}
//
if ntests == 0 {
panic(fmt.Sprintf("missing any tests for %s", test))
}
}

// Check a given set of tests have an expected outcome (i.e. are
Expand Down
3,727 changes: 3,709 additions & 18 deletions testdata/add.accepts

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions testdata/bin-dynamic.accepts

This file was deleted.

Empty file removed testdata/bin-dynamic.rejects
Empty file.
2,000 changes: 2,000 additions & 0 deletions testdata/bin.accepts

Large diffs are not rendered by default.

File renamed without changes.
6,648 changes: 6,648 additions & 0 deletions testdata/euc.accepts

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions testdata/euc.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(module euc)

(defcolumns
(IOMF :binary@prove)
(CT :i8)
(CT_MAX :i8)
(DIVIDEND :i64)
(DIVISOR :i64)
(QUOTIENT :i64)
(REMAINDER :i64)
(CEIL :i64)
(DONE :binary)
(DIVISOR_BYTE :byte@prove)
(QUOTIENT_BYTE :byte@prove)
(REMAINDER_BYTE :byte@prove))

(defconst
MMEDIUM 8)

(module euc)

(defconst
MAX_INPUT_LENGTH MMEDIUM)

(defconstraint first-row (:domain {0})
(vanishes! IOMF))

(defconstraint heartbeat ()
(if-zero IOMF
(begin (vanishes! DONE)
(vanishes! (next CT)))
(begin (eq! (next IOMF) 1)
(if-zero (- CT_MAX CT)
(begin (eq! DONE 1)
(vanishes! (next CT)))
(begin (vanishes! DONE)
(will-inc! CT 1))))))

(defconstraint ctmax ()
(eq! (~ (- CT MAX_INPUT_LENGTH))
1))

(defconstraint counter-constancies ()
(counter-constancy CT CT_MAX))

(defconstraint byte-decomposition ()
(begin (byte-decomposition CT DIVISOR DIVISOR_BYTE)
(byte-decomposition CT QUOTIENT QUOTIENT_BYTE)
(byte-decomposition CT REMAINDER REMAINDER_BYTE)))

(defconstraint result (:guard DONE)
(begin (eq! DIVIDEND
(+ (* DIVISOR QUOTIENT) REMAINDER))
(if-zero (* DIVIDEND REMAINDER)
(eq! CEIL QUOTIENT)
(eq! CEIL (+ QUOTIENT 1)))))
Loading

0 comments on commit d1958a1

Please sign in to comment.