diff --git a/Makefile b/Makefile index 0b990bdf..880880b9 100644 --- a/Makefile +++ b/Makefile @@ -128,9 +128,9 @@ coverage: SCRATCH_IGNORE ?= "\.update\.timestamp\|Would skip\|build/\|codex\.nims\|nimcache/\|scratch/\|vendor/\.nimble" TESTGROUND_BUILDER ?= docker:generic TESTGROUND_OPTIONS ?= --instances=2 -TESTGROUND_PLAN ?= hello_codex +TESTGROUND_PLAN ?= simple_tcp_ping TESTGROUND_RUNNER ?= local:docker -TESTGROUND_TESTCASE ?= hello +TESTGROUND_TESTCASE ?= simple_tcp_ping testground: mkdir -p scratch && rm -rf scratch/* && git clone --depth=1 "file://$${PWD}" "scratch/$$(basename $${PWD})" diff --git a/testground/simple_tcp_ping/Dockerfile b/testground/simple_tcp_ping/Dockerfile new file mode 100644 index 00000000..bf159478 --- /dev/null +++ b/testground/simple_tcp_ping/Dockerfile @@ -0,0 +1,16 @@ +FROM nimlang/nim as builder + +RUN apt update -qq && \ + DEBIAN_FRONTEND="noninteractive" apt install -yq cmake curl make + +FROM builder + +COPY . . + +RUN cd /extra/scratch/nim-codex && \ + make USE_SYSTEM_NIM=1 update + +RUN cd /extra/scratch/nim-codex && \ + make USE_SYSTEM_NIM=1 TESTGROUND_PLAN=simple_tcp_ping testground_exec + +ENTRYPOINT ["/extra/scratch/nim-codex/build/codex_testground"] diff --git a/testground/simple_tcp_ping/config.nims b/testground/simple_tcp_ping/config.nims new file mode 100644 index 00000000..0dd0e08a --- /dev/null +++ b/testground/simple_tcp_ping/config.nims @@ -0,0 +1,2 @@ +switch("define", "chronicles_sinks=textlines") +switch("define", "chronicles_log_level=NOTICE") diff --git a/testground/simple_tcp_ping/main.nim b/testground/simple_tcp_ping/main.nim new file mode 100644 index 00000000..a11ff60a --- /dev/null +++ b/testground/simple_tcp_ping/main.nim @@ -0,0 +1,44 @@ +import std/strutils, testground_sdk, chronos, stew/byteutils + +testground(client): + let + myId = await client.signalAndWait("setup", client.testInstanceCount) + myIp = client.testSubnet.split('.')[0..1].join(".") & ".1." & $myId + serverIp = client.testSubnet.split('.')[0..1].join(".") & ".1.1" + await client.updateNetworkParameter( + NetworkConf( + network: "default", + ipv4: some myIp & "/24", + enable: true, + callback_state: "network_setup", + callback_target: some client.testInstanceCount, + routing_policy: "accept_all", + ) + ) + + await client.waitForBarrier("network_setup", client.testInstanceCount) + + let + payload = client.param(string, "payload") + count = client.param(int, "count") + printResult = client.param(bool, "printResult") + if myId == 1: # server + let + server = createStreamServer(initTAddress(myIp & ":5050"), flags = {ReuseAddr}) + connection = await server.accept() + + for _ in 0 ..< count: + doAssert (await connection.write(payload.toBytes())) == payload.len + connection.close() + + else: # client + let connection = await connect(initTAddress(serverIp & ":5050")) + var buffer = newSeq[byte](payload.len) + + for _ in 0 ..< count: + await connection.readExactly(addr buffer[0], payload.len) + doAssert string.fromBytes(buffer) == payload + connection.close() + + if printResult: + client.recordMessage("Hourray " & $myId & "!") diff --git a/testground/simple_tcp_ping/manifest.toml b/testground/simple_tcp_ping/manifest.toml new file mode 100644 index 00000000..da9d8da3 --- /dev/null +++ b/testground/simple_tcp_ping/manifest.toml @@ -0,0 +1,24 @@ +name = "simple_tcp_ping" +[defaults] +builder = "docker:generic" +runner = "local:docker" + +[builders."docker:generic"] +enabled = true + +[runners."local:docker"] +enabled = true + +[[testcases]] +name= "simple_tcp_ping" +instances = { min = 2, default = 2, max = 2 } + +[testcases.params] +payload = { type = "string", default = "Hello!" } +count = { type = "int", default = 2 } +printResult = { type = "bool", default = true } + +[extra_sources] + docker_generic = [ + "../../scratch" + ]