d57c78bc71
This is how I did it: 1. `git clone https://github.com/ooni/probe-engine internal/engine` 2. ``` (cd internal/engine && git describe --tags) v0.23.0 ``` 3. `nvim go.mod` (merging `go.mod` with `internal/engine/go.mod` 4. `rm -rf internal/.git internal/engine/go.{mod,sum}` 5. `git add internal/engine` 6. `find . -type f -name \*.go -exec sed -i 's@/ooni/probe-engine@/ooni/probe-cli/v3/internal/engine@g' {} \;` 7. `go build ./...` (passes) 8. `go test -race ./...` (temporary failure on RiseupVPN) 9. `go mod tidy` 10. this commit message Once this piece of work is done, we can build a new version of `ooniprobe` that is using `internal/engine` directly. We need to do more work to ensure all the other functionality in `probe-engine` (e.g. making mobile packages) are still WAI. Part of https://github.com/ooni/probe/issues/1335
140 lines
3.4 KiB
Go
140 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTaskStartNullPointer(t *testing.T) {
|
|
if ooniffi_task_start_(nil) != nil {
|
|
t.Fatal("expected nil result here")
|
|
}
|
|
}
|
|
|
|
func TestTaskStartInvalidJSON(t *testing.T) {
|
|
settings := cstring("{")
|
|
defer freestring(settings)
|
|
if ooniffi_task_start_(settings) != nil {
|
|
t.Fatal("expected nil result here")
|
|
}
|
|
}
|
|
|
|
func TestTaskStartIdxWrapping(t *testing.T) {
|
|
settings := cstring(`{
|
|
"assets_dir": "../testdata/oonimkall/assets",
|
|
"log_level": "DEBUG",
|
|
"name": "Example",
|
|
"options": {
|
|
"software_name": "oonimkall-test",
|
|
"software_version": "0.1.0"
|
|
},
|
|
"state_dir": "../testdata/oonimkall/state",
|
|
"temp_dir": "../testdata/oonimkall/tmp"
|
|
}`)
|
|
defer freestring(settings)
|
|
o := setmaxidx()
|
|
// do twice and see if it's idempotent
|
|
if task := ooniffi_task_start_(settings); task != nil {
|
|
t.Fatal("expected nil task here")
|
|
}
|
|
if task := ooniffi_task_start_(settings); task != nil {
|
|
t.Fatal("expected nil task here")
|
|
}
|
|
restoreidx(o)
|
|
}
|
|
|
|
func TestTaskWaitForNextEventNullPointer(t *testing.T) {
|
|
if ooniffi_task_wait_for_next_event(nil) != nil {
|
|
t.Fatal("expected nil result here")
|
|
}
|
|
}
|
|
|
|
func TestTaskIsDoneNullPointer(t *testing.T) {
|
|
if ooniffi_task_is_done(nil) == 0 {
|
|
t.Fatal("expected true-ish result here")
|
|
}
|
|
}
|
|
|
|
func TestTaskInterruptNullPointer(t *testing.T) {
|
|
ooniffi_task_interrupt(nil) // mainly: we don't crash :^)
|
|
}
|
|
|
|
func TestEventSerializationNullPointer(t *testing.T) {
|
|
if ooniffi_event_serialization_(nil) != nil {
|
|
t.Fatal("expected nil result here")
|
|
}
|
|
}
|
|
|
|
func TestEventDestroyNullPointer(t *testing.T) {
|
|
ooniffi_event_destroy(nil) // mainly: we don't crash
|
|
}
|
|
|
|
func TestTaskDestroyNullPointer(t *testing.T) {
|
|
ooniffi_task_destroy(nil) // mainly: we don't crash
|
|
}
|
|
|
|
func TestExampleNormalUsage(t *testing.T) {
|
|
settings := cstring(`{
|
|
"assets_dir": "../testdata/oonimkall/assets",
|
|
"log_level": "DEBUG",
|
|
"name": "Example",
|
|
"options": {
|
|
"software_name": "oonimkall-test",
|
|
"software_version": "0.1.0"
|
|
},
|
|
"state_dir": "../testdata/oonimkall/state",
|
|
"temp_dir": "../testdata/oonimkall/tmp"
|
|
}`)
|
|
defer freestring(settings)
|
|
task := ooniffi_task_start_(settings)
|
|
if task == nil {
|
|
t.Fatal("expected non-nil task here")
|
|
}
|
|
for ooniffi_task_is_done(task) == 0 {
|
|
event := ooniffi_task_wait_for_next_event(task)
|
|
t.Logf("%s", gostring(ooniffi_event_serialization_(event)))
|
|
ooniffi_event_destroy(event)
|
|
}
|
|
ooniffi_task_destroy(task)
|
|
}
|
|
|
|
func TestExampleInterruptAndDestroy(t *testing.T) {
|
|
settings := cstring(`{
|
|
"assets_dir": "../testdata/oonimkall/assets",
|
|
"log_level": "DEBUG",
|
|
"name": "Example",
|
|
"options": {
|
|
"software_name": "oonimkall-test",
|
|
"software_version": "0.1.0"
|
|
},
|
|
"state_dir": "../testdata/oonimkall/state",
|
|
"temp_dir": "../testdata/oonimkall/tmp"
|
|
}`)
|
|
defer freestring(settings)
|
|
task := ooniffi_task_start_(settings)
|
|
if task == nil {
|
|
t.Fatal("expected non-nil task here")
|
|
}
|
|
ooniffi_task_interrupt(task)
|
|
ooniffi_task_destroy(task)
|
|
}
|
|
|
|
func TestExampleDestroyImmediately(t *testing.T) {
|
|
settings := cstring(`{
|
|
"assets_dir": "../testdata/oonimkall/assets",
|
|
"log_level": "DEBUG",
|
|
"name": "Example",
|
|
"options": {
|
|
"software_name": "oonimkall-test",
|
|
"software_version": "0.1.0"
|
|
},
|
|
"state_dir": "../testdata/oonimkall/state",
|
|
"temp_dir": "../testdata/oonimkall/tmp"
|
|
}`)
|
|
defer freestring(settings)
|
|
task := ooniffi_task_start_(settings)
|
|
if task == nil {
|
|
t.Fatal("expected non-nil task here")
|
|
}
|
|
ooniffi_task_destroy(task)
|
|
}
|