diff options
| author | Omar Rizwan <omar@omar.website> | 2023-06-30 18:11:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-30 18:11:12 +0000 |
| commit | 8a8a749eb2afbf6b0636c280554c32219fff1dd2 (patch) | |
| tree | a4fca4989a76d0e17c2d17ffe8ad1ad349111df2 /test | |
| parent | Left-align labels, watch for .folk.temp files (diff) | |
| parent | Fix load librt to work on folk0 also (diff) | |
| download | folk-8a8a749eb2afbf6b0636c280554c32219fff1dd2.tar.gz folk-8a8a749eb2afbf6b0636c280554c32219fff1dd2.zip | |
Merge pull request #42 from FolkComputer/osnr/camera-pipeline
Run Camera in subprocess
Diffstat (limited to 'test')
| -rw-r--r-- | test/basic.tcl | 8 | ||||
| -rw-r--r-- | test/commit.tcl | 7 | ||||
| -rw-r--r-- | test/cstructs.tcl | 23 | ||||
| -rw-r--r-- | test/joins.tcl | 7 | ||||
| -rw-r--r-- | test/negation.tcl | 6 | ||||
| -rw-r--r-- | test/perf.tcl | 12 | ||||
| -rw-r--r-- | test/process.tcl | 59 | ||||
| -rw-r--r-- | test/shm.tcl | 58 | ||||
| -rw-r--r-- | test/trie.tcl | 7 | ||||
| -rw-r--r-- | test/with-all.tcl | 11 |
10 files changed, 133 insertions, 65 deletions
diff --git a/test/basic.tcl b/test/basic.tcl index af2bb16f..c39916dd 100644 --- a/test/basic.tcl +++ b/test/basic.tcl @@ -1,9 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} proc count condition { Statements::count $condition } @@ -11,7 +5,7 @@ proc count condition { Assert programOakland has program {{this} { Claim Omar lives in "Oakland" }} -Assert when $::nodename has step count /c/ {{c} { +Assert when $::thisProcess has step count /c/ {{c} { When Omar lives in /place/ { Claim $place is a place where Omar lives } diff --git a/test/commit.tcl b/test/commit.tcl index 2a8bdaed..1cf780b8 100644 --- a/test/commit.tcl +++ b/test/commit.tcl @@ -1,10 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} - Assert programBall has program {{this} { Commit { Claim $this has a ball at x 100 y 100 } diff --git a/test/cstructs.tcl b/test/cstructs.tcl index 17f0fb41..623cd53f 100644 --- a/test/cstructs.tcl +++ b/test/cstructs.tcl @@ -1,10 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} - set cc [c create] $cc struct Name { char* first; @@ -25,3 +18,19 @@ $cc compile puts [omar] assert {[dict get [omar] name last] eq "Rizwan"} + +set cc [c create] +$cc proc plusone {int a} int { + return a + 1; +} +$cc proc dostuff {void* v} int { + return 300; +} +$cc compile +assert {[plusone 3] eq 4} + +catch {plusone Wrong} err +assert {[string match {expected integer but got "Wrong"*} $err]} + +catch {dostuff hi} err +assert {[string match {failed to convert argument from Tcl to C*} $err]} diff --git a/test/joins.tcl b/test/joins.tcl index 799abe0c..57d80300 100644 --- a/test/joins.tcl +++ b/test/joins.tcl @@ -1,10 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} - Assert Omar is a person Assert Omar lives in "New York" Assert Elmo is a person diff --git a/test/negation.tcl b/test/negation.tcl index 0067783a..501d7295 100644 --- a/test/negation.tcl +++ b/test/negation.tcl @@ -1,9 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} Assert programNegation has program code { When /nobody/ is booping { set ::booping nope diff --git a/test/perf.tcl b/test/perf.tcl index 97ee79cc..186f997c 100644 --- a/test/perf.tcl +++ b/test/perf.tcl @@ -9,22 +9,22 @@ Assert when /name/ is a /animal/ {{name animal} { Assert when /node/ has step count /c/ {{node c} {}} Assert Bob is a cat -puts "$::nodename: No additional statements:" +puts "$::thisProcess: No additional statements:" puts " [run]" for {set i 0} {$i < 100} {incr i} { Assert $i } -puts "$::nodename: Asserted 100 statements:" +puts "$::thisProcess: Asserted 100 statements:" puts " [run]" Assert Omar is a human -puts "$::nodename: Asserted 100 statements + Omar is a human:" +puts "$::thisProcess: Asserted 100 statements + Omar is a human:" puts " [run]" -puts "$::nodename: Same:" +puts "$::thisProcess: Same:" puts " [run]" -puts "$::nodename: Same:" +puts "$::thisProcess: Same:" puts " [run]" -puts "$::nodename: Same:" +puts "$::thisProcess: Same:" puts " [run]" diff --git a/test/process.tcl b/test/process.tcl index 72dcb264..c69fe26c 100644 --- a/test/process.tcl +++ b/test/process.tcl @@ -8,8 +8,7 @@ Step Assert when we are running {{} { On process { - Assert <root> claims things are good - Step + Claim things are good } When things are good { @@ -17,24 +16,70 @@ Assert when we are running {{} { } }} Step -vwait good +vwait ::good Assert when we are running {{} { - puts "Core: $::nodename" On process { set n 0 while true { incr n Commit { Claim the counter is $n } - Step + if {$n > 10} { break } } } When the counter is /n/ { if {$n > 5} { - set ::done true + set ::ok true } } }} Step -vwait done +vwait ::ok + +Assert when we are running {{} { + On process { + Claim I am in a process + When I am in a process { + Commit { Claim we were in a process } + } + } + When we were in a process { + set ::wereinaprocess true + } +}} +Step +vwait ::wereinaprocess + +Assert when we are running {{} { + On process { + Wish $::thisProcess receives statements like [list /x/ claims the main process exists] + When the main process exists { + Commit { Claim the subprocess heard that the main process exists } + } + } + Claim the main process exists + When the subprocess heard that the main process exists { + set ::heard true + } +}} +Step +vwait ::heard + +Retract when we are running /anything/ +Step + +Assert when we are running {{} { + set x done + On process { + eval [python3 [subst { + print("Claim Python is $x") + }]] + } + When Python is done { + set ::pythondone true + } +}} +Step + +vwait ::pythondone diff --git a/test/shm.tcl b/test/shm.tcl new file mode 100644 index 00000000..c3d63fc7 --- /dev/null +++ b/test/shm.tcl @@ -0,0 +1,58 @@ +Assert we are running +Assert when we are running {{} { + On process { + set cc [c create] + $cc include <sys/mman.h> + $cc include <sys/stat.h> + $cc include <fcntl.h> + $cc include <unistd.h> + $cc include <stdlib.h> + $cc proc shmMount {char* name size_t size void* addr} void { + int fd = shm_open(name, O_RDWR | O_CREAT, S_IROTH | S_IWOTH | S_IRUSR | S_IWUSR); + ftruncate(fd, size); + void* ptr = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); + if (ptr == NULL || ptr != addr) { + fprintf(stderr, "shmMount: failed"); exit(1); + } + } + $cc proc blup {} void { + void* ptr = (void*)0x280000000; + shmMount("/folk-images", 1000000000, ptr); + + char* s = (char*)ptr; + snprintf(s, 100, "Hello!"); + } + $cc compile + blup + } + + On process { + set cc [c create] + $cc include <sys/mman.h> + $cc include <sys/stat.h> + $cc include <fcntl.h> + $cc include <unistd.h> + $cc include <stdlib.h> + $cc proc shmMount {char* name size_t size void* addr} void { + int fd = shm_open(name, O_RDWR | O_CREAT, S_IROTH | S_IWOTH | S_IRUSR | S_IWUSR); + ftruncate(fd, size); + void* ptr = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); + if (ptr == NULL || ptr != addr) { + fprintf(stderr, "shmMount: failed"); exit(1); + } + } + $cc proc blup {} void { + void* ptr = (void*)0x280000000; + shmMount("/folk-images", 1000000000, ptr); + + char* s = (char*)ptr; + printf("[%s]\n", s); + } + $cc compile + blup + } +}} +Step + +after 1000 {set done true} +vwait done diff --git a/test/trie.tcl b/test/trie.tcl index 9e353d58..92ad9efa 100644 --- a/test/trie.tcl +++ b/test/trie.tcl @@ -2,13 +2,6 @@ set t [trie create] trie add t {Omar is a person} 1 trie add t {Generic is a /y/} 2 -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - return -code error "assertion failed: $condition" - } -} - assert {[trie lookup $t {Omar is a person}] eq {1}} assert {[trie lookup $t {/p/ is a person}] eq {1 2}} assert {[trie lookup $t {Omar is a /x/}] eq {1}} diff --git a/test/with-all.tcl b/test/with-all.tcl index d628a9db..27e594bd 100644 --- a/test/with-all.tcl +++ b/test/with-all.tcl @@ -1,14 +1,3 @@ -proc assert condition { - set s "{$condition}" - if {![uplevel 1 expr $s]} { - set errmsg "assertion failed: $condition" - if {[lindex $condition 1] eq "eq" && [string index [lindex $condition 0] 0] eq "$"} { - set errmsg "$errmsg\n[uplevel 1 [list set [string range [lindex $condition 0] 1 end]]] is not equal to [lindex $condition 2]" - } - return -code error $errmsg - } -} - Assert programOakland has program code { Claim Omar lives in "Oakland" } |
