Truke Ktest · bus, bench and recording on one timeline · prospective manual
Ktest user manual
Ktest turns a Linux machine and the test equipment wired to it into an instrument rack you use from a browser, a script or an LLM agent.
It monitors and transmits on CAN, drives bench supplies and oscilloscopes, and records all of it, with every command anyone gave, into one open file against one clock.
Ktest is not finished. This manual describes it as it is meant to be, and marks what is not there yet.
- built works today, as described
- planned decided, not yet written
- proposed an idea put up for discussion
Contents
Conventions of this manual
$ ktestd …is a command typed in a terminal on the Linux machine that runs Ktest.- Anything not marked is built. A mark on a heading covers its whole section.
- Names such as
psu1,scope1andcan0are this manual's bench. Yours are whatever you name on the command line. - Durations are written as Go writes them:
10ms,30s,1m0s. Voltages are in V, currents in A, times on a scope in s. - The examples (
examples/in the repository) run without hardware and are referred to throughout.
1 Using Ktest
1.1 What Ktest is
Ktest is one program, ktestd, running on a Linux machine that is wired to the bench: a CAN interface, and instruments reached over the network. It owns that hardware, records everything it sees and does into one file, and serves an instrument rack to any browser. Three kinds of work that today need three unrelated tools meet in it:
| Work | What Ktest does | Status |
|---|---|---|
| Bus | monitors CAN and CAN FD, decodes with a DBC, sends single frames and kernel-paced cyclic ones, by bytes or by signal | built |
| LIN, ISO-TP, J1939 | planned | |
| Bench | drives programmable supplies and oscilloscopes over SCPI | built against simulators |
| loads, multimeters, function generators; USBTMC | planned | |
| Recording | puts all of it on one timeline, in one open format, Logb | built |
The third row is the reason Ktest exists. Bus tools do not see the bench and bench software does not see the bus, so relating a supply transient to the CAN traffic it caused is done by hand, if at all. In a Ktest recording both are in the same file against the same clock.
There are three ways to use it, and they are the same interface seen from three clients:
- The rack, in a browser: panels of knobs, gauges, plots and scope traces laid out per instrument (§1.4).
- A script: commands are plain HTTP requests, so
curl, Python or a CI job drives the bench (§1.5). - An LLM agent: the same requests, offered to a model as tools, under the same limits as everyone else (§1.6).
All three are bound by one rule: a command is answered with accepted or refused, never with state. What the command did arrives on the stream, as a record, for every client at once. That is why two browsers stay in step, a reloaded page recovers the rack, and a script and a person can watch the same bench without disagreeing about it. Part 3 explains the design.
1.2 Build and install
Ktest is written in Go and has no C dependencies. The rack's browser code is committed already built and is embedded in the binary, so Node is not needed to build or run it.
From source today
You need Linux, Go 1.25 or later, and the Logb repository checked out in the GOPATH layout next to Ktest's, because Logb has no tagged release yet and go.mod points at ../logb:
$ mkdir -p ~/go/src/github.com/rveen ~/go/src/github.com/trukeio
$ git clone https://github.com/trukeio/logb ~/go/src/github.com/trukeio/logb
$ git clone https://github.com/trukeio/ktest ~/go/src/github.com/trukeio/ktest
$ cd ~/go/src/github.com/trukeio/ktest
$ go build -o bin/ ./cmd/...
$ ls bin
canlogb dutsim ktestd logbcheck monitor-check peer-conformance psusim scopesim sublat vcanprobe
For a small ARM board, cross-compile on any machine and copy the binary over:
$ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ./cmd/ktestd ./cmd/vcanprobe
To test bus work without hardware, install can-utils (candump, canplayer, cangen) and make a virtual bus:
$ sudo modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
Rebuilding the rack
Only after changing something under web/src/:
$ cd web && npm install && npm run build # writes web/dist/, which ktestd embeds
$ npm test # the browser's Logb reader against Go's
As a service planned
The intended installation is a release binary and a systemd unit running as an ordinary user, with its configuration in one directory. Nothing of this is packaged yet. The layout it is heading for:
| Path | What it holds |
|---|---|
/usr/bin/ktestd | the daemon |
/etc/ktest/limits.json | the limits no client can loosen (§2.4) |
/etc/ktest/tokens | who may log in, as hashes (§2.5) |
/etc/ktest/panels/*.json | rack panels (§2.6) |
/run/ktest.sock | the local control socket, mode 0660 |
~/.local/state/ktestd/ | what the daemon makes for itself, such as its TLS certificate |
/var/lib/ktest/*.logb | recordings |
A Ktest Box, a small appliance with the daemon, a CAN interface and a tested configuration already on it, is the commercial form of the same thing. The software on it is the open-source one.
The machine
Any Linux machine with a SocketCAN interface works. The bench this manual is written around is an Orange Pi Zero 2 with an MCP2518FD CAN FD controller on its SPI header, under the mainline mcp251xfd driver; examples/orangepi-zero2-mcp2518fd/ has the wiring and the device tree overlay. USB adapters that speak gs_usb (CANable and its derivatives) work wherever a plain interface is enough. Vector VN hardware is not supported.
Ktest opens an interface and never configures it. Set the bit rates yourself, which is the one step that needs root:
$ sudo ip link set can0 up type can bitrate 500000 dbitrate 2000000 fd on
$ ip -details link show can0 | grep -E 'bitrate|dbitrate' # the rates it actually runs
Then run vcanprobe -i can0 once. It measures what this kernel and adapter can do (loopback, CAN FD, error frames, timestamps, cyclic pacing, drop reporting), and Ktest's timing claims hold only where the probe says so.
1.3 A first bench
examples/bench runs a whole bench with no hardware: a simulated two-channel supply, a simulated Siglent SDS1202X-E oscilloscope, a virtual CAN bus, and ktestd recording all three and serving the rack.
$ cd examples/bench
$ ./demo.sh
...
Open https://localhost:8445/ in Chrome and log in with this token:
3f9c…
The script builds the programs, makes a login token the first time, and runs until Ctrl-C, recording to demo.logb. The certificate is self-signed, so the browser warns once. Paste the token.
Behind the script is one command line, and it is the whole configuration of a bench:
$ ktestd -https :8445 -tokens tokens \
-panel rack.json -limits limits.json \
-psu psu1=127.0.0.1:5025,2 \
-scope scope1=127.0.0.1:5026,2,full=ch1 \
-o demo.logb vcan0
Things to try, in order:
- Press Take control, then Arm. The supply's widgets unlock. The scope's traces were already drawing, because reading an input needs no permission.
- Raise ch1 current limit to 0.5 A, set ch1 voltage to 5 V, and switch ch1 output on. The readouts show 5 V and 0.5 A, measured at the simulated 10 Ω load.
- Lower the current limit to 0.2 A. The supply goes into constant current and the measured voltage falls to 2 V, although the setpoint still says 5 V.
- Ask for 20 V. The request is refused, because
limits.jsoncaps the channel at 12 V. The refusal is in the recording. - Set C1 volts/div to 0.3. The scope has only 1-2-5 steps, so it holds 0.2, and the widget shows both what you asked for and what is held.
- Press STOP. Every instrument is disarmed and the supply's outputs go off. The scope is left as it is.
Afterwards, check the recording against the simulators' own transcripts, which were written by something that knows nothing of Logb:
$ bin/logbcheck -control -psu psu1=psu.log -scope scope1=scope.log demo.logb /dev/null
examples/supply-bench and examples/scope-bench are the same with one instrument each, and show more of each one's widgets.
1.4 The rack, in a browser
The rack is served by the daemon it drives, at the address given with -https. It works in any current browser on any operating system; nothing is installed on the client.
Logging in
The page asks for a token (§2.5). A token has a name and a role. view may watch and may stop; operate may also take control, arm, write and save panels.
The control bar
| Control | What it does |
|---|---|
| Take control | takes the lease of every instrument on the panel in one press. A lease is single-writer: while you hold it nobody else can write to that instrument. The page renews it; if the page dies, the lease runs out by itself after its term (30 s). |
| Arm | arms the instruments you hold. Nothing is sent or set on an instrument that is not armed. |
| STOP | disarms everything the daemon drives, stops all cyclic transmit and switches every supply output off. It needs no lease and works for a view name, because a stop that needed the lease would be out of reach exactly when its holder has hung. |
| Edit panel | turns the rack into its own editor (§2.7). |
Each instrument has a box, and the box's header says what is true of that instrument: its kind, who holds its lease, and whether it is armed. When the instruments disagree, one held by someone else or one armed and another not, the bar says how many instead of rounding it off.
The widgets
A widget that writes unlocks only when this page holds the lease and the recording says the instrument is armed. Every writing widget shows two things: the value you asked for and the value the instrument holds. They differ when an instrument clamps a setpoint to its rating or rounds it to a step it has, and the widget marks the difference instead of hiding it.
| Widget | Shows or sets | Notes |
|---|---|---|
| readout | one value, as a number with its unit | |
| gauge | one value on a scale | |
| lamp | one on/off or state value | |
| plot | several channels against time, scrolling | channels from different sources share one axis |
| scope | one oscilloscope channel, per acquisition | drawn as a min/max band, so a one-sample spike is still visible; the trigger is the dashed line |
| setpoint | a number, typed | |
| knob, slider | a number, dragged or stepped with the arrow keys | sends on release, so a drag is one decision in the recording |
| enum | one of a list of named values | shows no choice when the held value is not on the list |
| toggle | on or off | |
| button | on while held | releases when the pointer leaves, the window loses focus or the tab is hidden |
| trace table | a bus's frames as they arrive, decoded | planned |
Without a panel, the rack lists every channel the stream carries, which is a quick way to see what a new bench offers.
Replay planned
A recording carries the panel that was on screen while it was made, so opening a recording brings back the rack and plays the data through the same widgets. In replay nothing actuates: hardware bindings resolve only in live mode, and the rack will show which mode it is in where it cannot be missed. Until this is built, recordings are viewed with Logb's own viewer, logbview, which also follows a file that is still being written (logbview -follow).
1.5 Driving it from scripts
Everything the rack does, it does through HTTP requests that a script can make as well. There are two ways in:
| Listener | Flag | Who may use it |
|---|---|---|
| Unix socket | -sock /run/ktest.sock | whoever the file's owner and group admit; full control, no token |
| HTTPS | -https :8443 -tokens file | named tokens with a role; control and streams |
| HTTP | -http :8080 | anyone; the streams only, read-only, no control |
The sequence
Every script that writes goes through the same four steps: take the instrument's lease, arm it, do the work, release. Locally, with curl:
$ K="curl -s --unix-socket /run/ktest.sock"
$ $K -d '{"holder":"thermal sweep","ttl":"60s"}' http://ktest/psu/psu1/lease
{"seq":1,"token":"9b1e…","ttl":"1m0s"}
$ L="Ktest-Lease: 9b1e…"
$ $K -H "$L" -X POST http://ktest/psu/psu1/arm
$ $K -H "$L" -X PUT -d '{"value":0.5}' http://ktest/channels/psu1.ch1.i.set
$ $K -H "$L" -X PUT -d '{"value":5}' http://ktest/channels/psu1.ch1.v.set
$ $K -H "$L" -X PUT -d '{"value":true}' http://ktest/channels/psu1.ch1.out.set
{"seq":5}
$ $K -H "$L" -X PUT -d '{"ttl":"60s"}' http://ktest/psu/psu1/lease # renew before the term ends
$ $K -H "$L" -X DELETE http://ktest/psu/psu1/lease
The answer to a write is a sequence number. The same number is on the record of that decision in the instrument's control stream, so a script can find what became of request 5 in the recording.
If the script crashes, its lease runs out, and the instrument is disarmed: cyclic transmit stops, while a supply's outputs stay as they were, since cutting what a supply feeds is itself an act nobody asked for. Releasing the lease does the same. Use POST /disarm when the outputs must go off.
The bus
$ $K -d '{"holder":"bench script"}' http://ktest/bus/can0/lease
$ $K -H "$L" -X POST http://ktest/bus/can0/arm
# one frame, by identifier and bytes
$ $K -H "$L" -d '{"id":"0x123","data":"DEADBEEF"}' http://ktest/bus/can0/send
# one frame, by message and signals in physical units (needs -dbc)
$ $K -H "$L" -d '{"message":"EngineData","signals":{"EngineSpeed":3000,"Gear":"Reverse"}}' \
http://ktest/bus/can0/send
# a cyclic frame every 10 ms, paced by the kernel; PUT again to change its data
$ $K -H "$L" -X PUT -d '{"data":"0102","period":"10ms"}' http://ktest/bus/can0/cyclic/123
$ $K -H "$L" -X DELETE http://ktest/bus/can0/cyclic/123
A signal left out takes the database's start value. A value is rounded to the nearest step the signal can represent and refused outside the range the database declares. Cyclic frames are sent by the kernel (CAN_BCM), not by the daemon's loop, so their timing does not depend on how busy the daemon or the script is.
Reading results
Results are not returned by requests. They are in the stream, which is an endless HTTP response in Logb format:
$ curl -N --cacert tls-cert.pem -H 'Authorization: Bearer 3f9c…' \
https://rack:8443/stream/live > run.logb
That file is a valid recording from the moment the request starts: it opens with the schemas and the current value of every held channel, so a consumer that joins late knows that the supply was set to 12 V forty minutes ago. Read it with Logb's tools (logbdump, logbview) or its Go reader. /stream/rack is the same records uncompressed, with waveforms reduced to envelopes, which is what the browser reads.
A reader for Python, so that a notebook can take values off the live stream as arrays, is planned, as part of Logb and not of Ktest.
From Python
import requests, time
RACK = "https://rack:8443"
s = requests.Session()
s.verify = "tls-cert.pem" # the daemon's own certificate
s.headers["Authorization"] = "Bearer " + open("token").read().strip()
lease = s.post(f"{RACK}/psu/psu1/lease", json={"ttl": "60s"}).json()
s.headers["Ktest-Lease"] = lease["token"]
s.post(f"{RACK}/psu/psu1/arm").raise_for_status()
try:
s.put(f"{RACK}/channels/psu1.ch1.i.set", json={"value": 0.5})
s.put(f"{RACK}/channels/psu1.ch1.out.set", json={"value": True})
for mv in range(0, 12001, 500): # 0 to 12 V in 0.5 V steps
r = s.put(f"{RACK}/channels/psu1.ch1.v.set", json={"value": mv / 1000})
if not r.ok:
print(r.status_code, r.json()["error"])
time.sleep(1)
finally:
s.post(f"{RACK}/disarm") # outputs off, whatever happened
s.delete(f"{RACK}/psu/psu1/lease")
Over HTTPS the lease holder is the token's name and cannot be chosen, so the recording's word for who held the supply is one nobody could have typed in for someone else.
Procedures inside the daemon built
A script run by a client stops when the client does. For sequences that must survive a disconnect, such as an overnight thermal run, the daemon runs procedures itself. A procedure is written in a strict subset of Robot Framework syntax, so it parses under Robot's own parser and reads as Robot to anyone who knows it; but it runs only here, in Go, and there is no Python. Start ktestd with -procedures dir, and a procedure is a file in that directory:
*** Variables ***
${SUPPLY} psu1.ch1
@{LEVELS} 2V 4V 6V 8V
*** Test Cases ***
Ramp
[Teardown] Stress Remove ${SUPPLY}
FOR ${level} IN @{LEVELS}
Stress Apply ${SUPPLY} ${level} current=1A
Wait Until psu1.ch1.out.applied timeout=2s
Settle 300ms
${v}= Read Channel psu1.ch1.meas.v
Should Be Within ${v} ${level} 0.2V
Record Step ramp ${level} ok
END
$ $K -d '{"file":"ramp.robot","test":"Ramp"}' http://ktest/procedures/run
{"seq":1}
$ $K -X DELETE http://ktest/procedures/run # stop it; its [Teardown] still runs
Checked before it runs. A procedure is loaded whole and refused, with a sentence naming the line, if anything in it is wrong: an unknown keyword or argument name, a missing argument, a quantity in the wrong unit (Settle 5V), a variable not defined where it is used, a condition that does not type-check, a keyword that calls itself. Constructs outside the subset are refused by name: Library, Evaluate, ${{…}}, TRY/EXCEPT, GROUP, templates, Run Keyword, and the Set Test/Suite/Global Variable scopes. A WHILE must have limit=, a count or a duration.
Conditions in IF, WHILE, Should Be True and Wait Until are Ktest's expression language, the one monitors and limits use: comparisons and and, or, not over variables ($level or ${level}) and channels (psu1.ch1.meas.v > 11.5V), with units checked. A condition does no arithmetic; a value that needs computing is computed by a keyword, where it is recorded.
Keywords. Log, Fail, Set Variable and Should Be True behave as Robot's do. Ktest's own: Settle duration; Wait Until condition timeout=10s; Read Channel name; Should Be Within actual expected tolerance; Record Step point level result threshold=; Stress Apply psu1.ch1 level current= and Stress Remove psu1.ch1.
Acting. A run acts through the control plane for the name that started it. The first time it writes an instrument it takes the lease and arms it; it renews the lease while it runs and releases it at the end. Each of these is an ordinary control decision, recorded with via 3 and the starter's name, and held to the same limits and roles. An instrument someone else has leased is refused, and the run fails as refused. A stop disarms the run's instruments like any other's; the run does not arm them again, and its next write is refused.
Recorded. procedure.run holds whether a run is under way, which test from which file, and the sha256 of every file it was loaded from. procedure.step has every keyword call at its start and its end, with its arguments as resolved and its outcome (ok, nok, timeout, refused, fail, stopped). procedure.result has what Record Step records. One run is under way at a time, and it survives the client that started it disconnecting.
Locked mode. A validated procedure is validated with the daemon that ran it, so a lab under change control starts ktestd with -locked locked.json, a file of the sha256 sums its validated configuration had: the binary, the keyword library's version, limits.json, the instrument configuration (the bus, the DBC file, each -psu and -scope and the poll periods) and every procedure file. Make the file from the configuration that was validated, with the same flags and -lock-hashes added; it is written to stdout, and the daemon exits:
$ ktestd -limits limits.json -psu psu1=10.0.0.20:5025,2 -procedures procedures -lock-hashes vcan0 > locked.json
$ ktestd -limits limits.json -psu psu1=10.0.0.20:5025,2 -procedures procedures -locked locked.json vcan0
Each run is held to the file when it starts, on the very bytes it was loaded from, its resources and variable files among them. If nothing differs the run is accredited. If anything does, the run is refused with a sentence naming what differs (ramp.robot (sha256 e2d35abea965…, locked 95bc58878ab9…)), or, with "on_mismatch": "mark" in the file, it runs and is recorded as not accredited, with the same sentence. A file the lock does not list counts as differing. procedure.run records mode (locked or engineering), accredited, and lock, the sha256 of the lock file, which is also embedded in the recording. Without -locked the daemon is in engineering mode, and no run is accredited. A daemon whose binary, limits or instruments differ from its lock file says so as it starts, and still records and drives its instruments: only its runs are affected.
Not yet: YAML variable files (JSON works).
1.6 With an LLM agent
proposed Nothing in this section is built, and the names in it are placeholders. It describes how an agent is meant to fit, so that the design can be discussed before it is written.
An agent is a script that decides its next step by itself. Ktest already has what such a client needs: commands are small, typed HTTP requests; every refusal comes back as a sentence saying what was wrong and what to do; and the limits are enforced by the daemon, not by the client's good behaviour. So an agent gets no interface of its own. It gets the REST interface, wrapped as tools.
What works today
An agent that has a shell, such as Claude Code, can drive a bench with curl exactly as §1.5 shows. Give it a token of its own and the address, and tell it the channel names.
The tool server
ktest-mcp would be a small separate program that speaks the Model Context Protocol on one side and Ktest's REST and stream on the other. It holds the token, so the model never sees it.
$ ktestd -new-token agent:operate 2>&1 >>tokens | tail -n 1 > agent.token
$ claude mcp add ktest -- ktest-mcp -url https://rack:8443 \
-token-file agent.token -cacert tls-cert.pem
| Tool | What it does | Role needed |
|---|---|---|
bench | lists the instruments, their kind, who holds each and whether it is armed, and the limits in force | view |
channels | lists channels with unit and current value; for a settable one, the set and the applied account | view |
read | returns a channel over a time window, reduced to at most a few hundred points with min and max kept | view |
waveform | returns the latest acquisition of a scope channel as an envelope, with its settings and simple measurements (peak to peak, mean, frequency) | view |
take_control, release | takes or gives back an instrument's lease; the server renews it while the session lives | operate |
arm | arms an instrument the agent holds | operate |
set | writes a settable channel, then waits for the applied account and returns asked, held and measured together | operate |
send, cyclic | puts a frame or a message on the bus, once or periodically | operate |
stop | disarms everything and switches outputs off | view |
The set tool is the one place the agent's interface differs from a script's. A script is content with a sequence number. A model reasons better from the consequence, so the tool server follows the stream and answers with the three accounts after the write: "asked 12 V, the supply holds 6 V, 5.0 V measured".
What keeps it safe
- The limits file. An agent cannot ask for more than
limits.jsonallows, and no request changes that file. Set the limits for the device under test before giving an agent theoperaterole. - Its own name. The agent logs in with its own token, so every decision it takes is recorded under that name, and the rack shows its name on the instruments it holds.
- The lease. While a person holds an instrument, the agent cannot write to it, and the other way round.
- STOP. A person watching the rack can stop the bench at any time without holding anything.
- A view-only agent is useful by itself: it can watch a run, read the recording and explain what happened, and the most it can do to the bench is stop it.
Two questions are open. Whether limits should be settable per name, so that an agent can be held to a narrower range than a person. And whether arming by an agent should need a person's confirmation on the rack.
1.7 The programs
ktestd: the rack daemon
ktestd [flags] interface
Owns one CAN interface and any number of instruments, records them, serves the rack and takes commands.
| Flag | Default | Meaning |
|---|---|---|
-o file | <interface>.logb | the recording |
-dbc file | a CAN database: frames are decoded into signals beside the raw ones, and sends may name signals | |
-psu name=host:port[,channels] | a bench supply to drive; repeatable | |
-scope name=host:port[,channels][,full=ch1+ch2] | an oscilloscope to drive; repeatable. full= names the channels recorded at full rate | |
-panel file | the rack panel: served to the browser, saved to from it, embedded in the recording | |
-limits file | built in | the limits to enforce |
-procedures dir | a directory of procedures clients may ask the daemon to run (§1.5) | |
-locked file | engineering mode | with -procedures: the sums a validated configuration had; each run is accredited, refused or marked (§1.5) |
-lock-hashes | with -procedures: write the -locked file this configuration would need to stdout, and exit | |
-contract file | a DUT contract, dut-interface.json: run its monitors live, as a DUT rack (below) | |
-peer name=https://host:port,token=file,cacert=file,contract=file[,encoding=ndjson] | a DUT rack to drive, as a lab rack: its contract checked at start, its monitors mirrored, the rules of limits.json applied (below); repeatable, once for each DUT rack. encoding=ndjson reads its stream as NDJSON rather than Logb, for a DUT rack that serves only that | |
-mon-window, -mon-tick, -watermark, -mon-queue | 2 ms, 1 ms, 10 ms, 8192 | with -contract: how long a record waits for earlier ones from other clocks; how often the monitors are given the daemon's clock; how often mon.watermark is recorded; how many records may wait for the monitors |
-sock path | /run/ktest.sock | the local control socket |
-https addr | control, streams and the rack over TLS, with tokens | |
-tokens file | the names -https admits | |
-new-token name:role | make a token and exit: the token on standard error, the line that admits it on standard output | |
-tls-cert, -tls-key | self-signed | a certificate of your own |
-http addr | the streams only, read-only, unauthenticated | |
-state dir | ~/.local/state/ktestd | where the daemon keeps what it makes |
-d duration | 0 | stop after this long; 0 runs until interrupted |
-codec | zstd | compression of the recording: none, deflate, zstd |
-segment duration | 1 s | how often the recording restates its schemas and held values |
-psu-poll, -scope-poll | 100 ms, 5 ms | how often supplies are measured and scopes asked for a completed acquisition |
-scope-sign, -scope-trigger-delay | sub256, off | two readings of the Siglent programming guide that change the numbers (§3.5) |
-err, -rcvbuf, -q | on, 1 MiB, off | receive error frames; the socket receive buffer; do not report what could not be carried across |
canlogb: a CAN trace recorder
canlogb [-o file] [-dbc file] [-d duration] [-http addr] interface
Records a bus to a Logb file and can serve it live, and does nothing else. It has no control plane, so it cannot put anything on the bus and does not have to be trusted not to. Use it where a recorder is all that is wanted.
monitor-check: replay a recording through a DUT contract
monitor-check [-json] [-live] [-expect ok | -expect dev@t1,t2,...] [-tol 50ms] [-mode mode.applied] dut-interface.json recording.logb
Replays a recording through the monitors a DUT contract declares, with the same evaluator the DUT rack will run live, and prints every transition: when, which monitor, from what to what, and why (a stream's sample, a debounce running out, an input going stale). The evaluator reads no clock, so a replay gives the transitions the live run gave, to the nanosecond, and a contract can be tried on yesterday's recording before it is signed off. -expect ok fails if any monitor deviates; -expect dev@2.55,5.15 fails unless a deviation begins near each time given, and only there. -live, on a recording made by a DUT rack, fails unless the transitions the rack recorded live are the replay's, to the nanosecond, up to its last watermark and the first record a gap lost. It works on any DUT rack's recording, ktestd's or another program's. built
logbcheck: hold a recording to an independent account
logbcheck [-tx log] [-cyclic] [-control] [-psu name=transcript] [-scope name=transcript]
[-judgements] [-dutsim [point=]transcript]... [-faults faults.json [-faults-peer name]]
recording.logb candump.log
Checks a recording against references that nothing in Ktest wrote: a candump log of the bus, a simulator's transcript. -control checks every control decision against the limits the recording itself declares. Give /dev/null as the log when there is no bus reference.
On a lab rack's recording: -judgements replays every answer a DUT's monitors gave a keyword from the mirrored states, each rack's from its own; -dutsim point=transcript holds the step results recorded at a point to dutsim's account of what the DUT did, once for each DUT; -faults faults.json holds the rack's protection rules to the faults peer-conformance master put it through (§3.6): each rule taking hold within -react (250 ms) of its fault, holding, and clearing within -recover (5 s) of its end.
peer-conformance: check either side of the peer protocol
peer-conformance secondary -url https://rack:8445 -cacert rack.pem -contract dut-interface.json \
-token op.token [-other op2.token] [-view view.token] [-mode m] [-action a]
peer-conformance master [-addr 127.0.0.1:8446] [-dir conformance] [-phase 3s]
Checks a DUT rack or a lab rack against doc/peer-protocol.md, over the network, whatever program it is. secondary acts as a lab rack and makes 54 checks: tokens and roles, the contract's hashes, the protocol version, the clock, the subscription's format and record layouts, the choice of encoding by Accept and, when the rack serves NDJSON, its lines and their equivalence with the Logb, record for record, the watermark's cadence, the lease, every refusal, arming, a mode, an action and a second one refused while it runs, a lapsed lease stopping nothing; and it measures how late transitions arrive. It takes the lease and changes the mode: run it on a bench. master runs a reference DUT rack, prints the -peer settings to give the lab rack, injects five faults (abort, a frozen rack, a lost link, another contract, another protocol version), checks what a DUT rack can see of the lab rack's answers, and writes faults.json for logbcheck -faults. Either exits 1 if a check failed. built
psusim, scopesim: instruments without hardware
psusim [-addr :5025] [-channels 30:3:10,6:5:100] [-transcript file]
scopesim [-addr :5026] [-channels 'sine:amp=1,freq=1000;dc:amp=0'] [-on 1] [-transcript file]
psusim is a supply that speaks Keysight-style SCPI, clamps setpoints beyond a channel's rating and regulates into a resistive load (volts : amps : ohms per channel). scopesim is a Siglent SDS1202X-E with signals made from a description. Both keep a transcript for logbcheck.
A DUT rack: ktestd -contract
With -contract dut-interface.json, ktestd evaluates the contract's monitors live over what it records and records their states beside everything else. The contract is checked before anything is written, against the streams this daemon will record (decoded DBC messages among them), and a contract that names a channel the rack does not carry refuses the start. The contract and its resource file are embedded in the recording with their sha256.
| Stream | Holds |
|---|---|
mon.<name> | state: ok, dev, unknown, inactive or settling, held; from, the state before; cause. A transition is stamped with the sample or deadline that caused it, never with when it was evaluated |
mon.watermark | upto: every transition at or before this time has been recorded. Recorded every -watermark |
mon.gap | records the monitors lost (their queue was full) or got too late to use. Every monitor is then unknown until its inputs are known again |
The monitors run on their own goroutine and never hold up the daemon. Records reach the daemon from several clocks (the kernel stamps CAN frames, an instrument driver stamps its readings), so each record waits -mon-window for earlier ones before it is evaluated. Measured on loopback with dutsim, a transition reaches a subscriber 3.2 ms after its sample at the median and within 4.8 ms at the 99th percentile.
The subscription stream. GET /stream/sub?ch=mon.*,DutStatus serves the streams named (names or globs, comma separated), each record in a frame of its own sent the moment it is written. mon.watermark, mon.gap, mode and the recording's metadata are always included. The view role is enough. A subscriber that falls behind is disconnected; the recording is not affected. built
Modes and actions. The DUT rack has an instrument of its own, dut, leased and armed like the others (POST /dut/lease, POST /dut/arm, POST /dut/disarm). Under its lease, with it armed:
$ $K -X PUT -H "Ktest-Lease: $T" -d '{"value":"active"}' http://ktest/dut/mode # run the mode's entry action, then apply it
$ $K -X POST -H "Ktest-Lease: $T" http://ktest/dut/actions/reset # run an action
An action is a keyword of the contract's resource file, run by the daemon one at a time, with a timeout from the contract's timeouts (30 s otherwise). It may use Settle, Send Message message ${SIGNALS}, Start Cyclic message period ${SIGNALS}, Stop Cyclic message, Set Channel psu1.ch1.v.set 12V, Wait For Monitor alive state=ok timeout=10s, and Log, Fail, Set Variable, Should Be True. Signals are a dictionary from the Variables (&{RESET} Request=1), in the signal's own unit. The resource is checked when the daemon starts. What an action does goes through the control plane like any client's request, recorded with via 4 and the name that asked, and held to the limits.
The DUT goes on running when its master goes. A lapsed dut lease leaves dut armed and the DUT rack's cyclic tasks running; a lapsed bus lease stops only its holder's tasks. POST /dut/disarm or the stop ends the action under way and every task the DUT rack holds. Recorded: mode (requested and applied, held), dut.action.<name> (each run's start, and its end with its outcome), and dut.step (each keyword call). built
A lab rack: ktestd -peer
With -peer dut=https://host:8445,token=dut.token,cacert=dut.pem,contract=dut-interface.json, ktestd drives a DUT rack as an instrument; give -peer once for each DUT rack, each under a name of its own, and the streams below are recorded under each name (a.mon.alive, b.link). At start it asks the DUT rack which contract it runs (GET /dut/contract) and refuses to start unless it is this rack's copy, byte for byte, its resource included. While it runs, it holds the DUT's lease, subscribes to the DUT rack's monitors, mode and actions, and samples its clock once a second (GET /clock). It records:
| Stream | Holds |
|---|---|
dut.mon.*, dut.mode, dut.action.* | the DUT rack's records, at the time this rack received them; peer_t is the DUT rack's own time, restated marks a state restated when the subscription joined |
dut.link | connected, held; each connection, loss and refusal, with why |
dut.clock | the DUT rack's clock less this one, from the shortest of the last eight round trips, and its uncertainty: half that round trip |
rules | each rule taking hold and clearing, with its cause |
DUT keywords. A lab rack's procedures may use the DUT through these, every mode, action and monitor they name checked against the contract when the procedure loads:
| Keyword | Does |
|---|---|
DUT Set Mode active | changes the mode, and returns once it is applied and settled |
DUT Invoke reset | runs an action and returns once it has ended; fails as it did |
DUT Prepare active ready=alive | the mode, then a monitor ok |
DUT Wait For dut.mon.alive.state == "ok" | waits for a condition over the mirrored channels |
${r}= DUT Evaluate alive,speed window=2s | nok if a monitor was dev or unknown in the window, ok if none was; the window runs forward from the call, or from since= |
Verify Baseline alive,speed window=1s | fails unless every monitor stays ok |
${t}= Mark Time | this rack's clock, for since= |
${c}= Classify Recovery alive,speed since=${t} function=alive action=reset | the ISO 16750-1 functional status class, A to E, of a stress applied since ${t} and removed |
${th}= Threshold Search dip alive target=psu1.ch1 nominal=13.5V start=12V step=0.5V floor=6V | the lowest supply dip the DUT comes through, each level a step result |
DUT Snapshot alive,speed | the monitors' states, as text |
Every DUT keyword takes dut=, the DUT rack's name: DUT Set Mode active dut=a. With one DUT rack it may be left out; with several it is required, and the names a call gives are checked against that rack's contract.
A wait fails timeout, refused or link_lost; nok is a value. Every answer the monitors gave a keyword is recorded in dut.judgement, and logbcheck -judgements replays each from the mirrored states. With dutsim, logbcheck -dutsim transcript holds every step result to what the DUT did. built
The rules are in limits.json (§2.5). With several DUT racks the stress is theirs in common, so a rule holds while it holds for any of them, and its cause names the rack; every contract must declare the abort monitor. Measured with examples/two-racks: a killed DUT rack had the stress removed 3.4 ms later, as the link broke; a frozen one, 102 ms later, by its watermark's age; an abort monitor going dev, 0.6 ms after the lab rack received it. built
sublat: how late the monitors reach a subscriber
sublat [-cacert pem] [-token file] [-d 10s] https://rack:8443/stream/sub?ch=mon.*
Subscribes to /stream/sub and reports, per monitor transition and per watermark, how long after its own time it arrived: minimum, median, 90th and 99th percentile and maximum.
dutsim: a device under test without hardware
dutsim [-supply 127.0.0.1:5025] [-ch 1] [-behaviour glitch|restore|reset|never] [-vmin 9] [-vrestore 9.5]
[-boot 100ms] [-speed 3000] [-glitch-speed 0] [-period 10ms] [-poll 5ms] [-transcript file] interface
A DUT on a CAN interface, powered from a psusim channel. While it runs, it sends DutStatus (an alive counter, modulo 16), EngineData (EngineSpeed, in rpm) and DutSupply (Voltage, its supply as it last read it) every -period. It boots the first time its supply reaches -vrestore. When the supply falls below -vmin, it reacts as -behaviour says:
glitch: it keeps talking, but reports-glitch-speeduntil the supply is restored.restore: it falls silent, and boots again once the supply is restored.reset: it falls silent, and stays silent until it receives a reset frame (DutResetwithRequest= 1,cansend vcan0 700#01).never: it falls silent for good.
The frames are laid out in dut/dutsim.dbc; start ktestd with -dbc dut/dutsim.dbc to decode them. dutsim only queries the supply (MEAS:VOLT?) and never clears its error queue, which belongs to the rack that drives the supply. Its transcript is its own account of the run: every supply crossing, reset frame and change of state, with its time. built
vcanprobe: what this kernel and adapter can do
vcanprobe [-i vcan0] [-run regexp] [-list] [-json]
1.8 When ktestd refuses
A refusal is a JSON body with an error sentence and, when the decision was recorded, its seq. Refusals are recorded like everything else.
| Status | Meaning | What to do |
|---|---|---|
400 | the request is malformed: an unknown key, a bad value, overlapping widgets in a panel | read the sentence; it names the key |
401 | no token, or one this daemon does not admit | send Authorization: Bearer <token> |
403 | no lease presented; a view name asking to write; a setpoint above its limit; a cyclic period below the floor | take the lease, use an operate token, or stay inside the limits file |
404 | no such instrument, channel or cyclic task | |
409 | the instrument is not armed, or someone else holds its lease | arm it; or wait, the rack shows who holds it |
412 | a panel save from a panel no longer in force | reload and edit again |
428 | a panel save without If-Match | send the sha256 of the panel you edited |
503 | the instrument is not answering or is busy, the kernel refused the frame, or the daemon is stopping | the sentence carries the kernel's error |
The daemon also refuses to start on a configuration it cannot stand behind: a misspelt key in the limits or the panel file, a limit for a channel no instrument declares, two instruments with one name, a widget in a box that belongs to another instrument. A key that was meant to do something and would do nothing is treated as an error, not ignored.
2 Setting up a bench
2.1 Channels
Everything on a bench is a channel in one flat namespace. Panels, scripts, limits and recordings all refer to channels by name, so names are fixed early and do not change.
EngineData.EngineSpeed a bus signal, decoded by the DBC
can0.raw every frame on the bus
psu1.ch1.v.set the voltage asked for
psu1.ch1.v.applied the voltage the supply reports holding
psu1.ch1.meas.v the voltage measured at the terminals
scope1.ch1 a waveform
scope1.timebase.tdiv.set seconds per division, asked for
A controlled quantity is kept as three accounts: what was asked (set), what the instrument accepted (applied) and what happened (meas). One channel for all three would make the recording wrong the first time an instrument clamps, refuses or trips. Kept apart, a recording answers "what did we ask for, what was accepted, what happened" without inference. The figure at the top of this manual is that, for one setpoint.
| Kind of channel | Behaviour | Examples |
|---|---|---|
| held | a record only when the value changes; the last value stands until the next. Restated at every segment, so a late reader knows the value in force. | setpoints, armed state, lease holder |
| sampled | a record per sample or per frame, each with its time | bus frames, decoded signals, supply measurements |
| waveform | dense samples on a uniform axis, one run per acquisition | scope1.ch1, scope1.ch1.env |
A bus signal is named by its message today (EngineData.EngineSpeed). With a second bus the bus name will come first (can1.EngineData.EngineSpeed); that change is planned before multi-bus support.
2.2 Connecting a bus
Bring the interface up (§1.2), name it as the last argument, and give a DBC if there is one:
$ ktestd -dbc car.dbc -o run.logb can0
The bus is recorded in these streams:
| Stream | What it holds |
|---|---|
<bus>.raw | every frame, with the kernel's receive timestamp, and whether it came from this host |
<Message> | with -dbc, each message decoded into its signals in physical units |
<bus>.tx.set | each send the daemon was asked for, refused ones included |
<bus>.tx.applied | each of those frames, handed back by the kernel as sent |
<bus>.cyclic.<id> | each cyclic task: every change, with the kernel's own account of the task beside the request |
<bus>.control | every decision the control plane took for the bus |
<bus>.drops | frames the kernel reported lost, as drops and never as silence |
The DBC is embedded in the recording, so the file decodes itself later without it.
One bus per daemon today. Several buses, LIN (through a USB dongle or a Pico-based interface that carries CAN and LIN together), ISO-TP and J1939 (both through the kernel's own socket families, with no new hardware) are planned.
2.3 Connecting instruments
An instrument is named on the command line. The name is the first part of every one of its channels, so choose it for the bench and not for the model: psu1, not e36312a.
A supply
-psu psu1=192.168.1.20:5025,2 name = host:port, number of channels
SCPI over a raw TCP socket, the LXI port 5025, in the Keysight spelling (VOLT 5,(@1)) that the E36300 series and many others use.
| Channel | Writable | Meaning |
|---|---|---|
psu1.chN.v.set, .v.applied | set | voltage setpoint, asked and held |
psu1.chN.i.set, .i.applied | set | current limit, asked and held |
psu1.chN.out.set, .out.applied | set | output on or off |
psu1.chN.meas.v, .meas.i | measured at the terminals, every -psu-poll | |
psu1.chN.connected | whether the supply is answering | |
psu1.control | leases, arming, every write and refusal |
A setpoint nobody has set since the daemon started is absent from the recording, not zero. Whatever the supply's error queue said after a write is recorded beside it.
An oscilloscope
-scope scope1=192.168.1.30:5025,2,full=ch1 name = host:port, channels, full-rate channels
The Siglent SDS1202X-E dialect. The daemon arms the scope, waits for an acquisition, reads every displayed channel and starts again. Acquisition needs neither lease nor arming; changing a setting does.
| Channel | Writable | Meaning |
|---|---|---|
scope1.chN.env | each acquisition as a min/max envelope, about 3000 columns; always recorded, and what the rack draws | |
scope1.chN | every sample, in volts; only for channels named in full= | |
scope1.chN.vert.vdiv.set, .ofst.set, .on.set | set | volts per division, offset, channel displayed |
scope1.timebase.tdiv.set | set | seconds per division; the delay and memory depth likewise |
scope1.timebase.sara | the sample rate the scope chose | |
scope1.acq | one record per channel per trigger, whatever became of it, drops included |
Full rate is opt-in per channel because continuous full-rate capture should be a decision someone made, not a disk found full after an overnight run. One full-depth acquisition is 56 MB.
Status. Both drivers are built and checked against their simulators. Checking them against the real instruments, and placing a scope trigger on the recording's timeline by way of the scope's own CAN trigger, is the work in progress.
2.4 Adding an instrument
There are three cases, from a line of configuration to a new driver.
Another unit of a supported kind
Add another -psu or -scope with a new name. Each has its own lease, arming and control stream. Add its channels to the limits file and a box for it to the panel.
The same kind, another SCPI spelling
The commands a driver sends are a table, a dialect, and not code. A supply that spells things differently is a new table in psu/:
var Rigol = Dialect{
Name: "rigol",
SetVolt: ":SOUR%[1]d:VOLT %[2]s", // argument 1 is the channel, 2 the value
QueryVolt: ":SOUR%[1]d:VOLT?",
SetCurr: ":SOUR%[1]d:CURR %[2]s",
QueryCurr: ":SOUR%[1]d:CURR?",
SetOut: ":OUTP CH%[1]d,%[2]s",
QueryOut: ":OUTP? CH%[1]d",
MeasVolt: ":MEAS:VOLT? CH%[1]d",
MeasCurr: ":MEAS:CURR? CH%[1]d",
Identify: "*IDN?", Clear: "*CLS", Err: ":SYST:ERR?",
}
Today this needs a rebuild and the daemon uses the Keysight table. Choosing the dialect per instrument, -psu psu1=host:port,2,dialect=rigol, and loading dialect tables from a file without rebuilding, are planned.
A new kind of instrument planned
Electronic loads, multimeters and function generators each need a driver, and USBTMC needs a transport beside TCP. A driver is a Go package, and the supply and the scope set the pattern that a new one follows:
- Write the simulator first. It speaks the instrument's dialect, misbehaves the way the instrument does (clamps, rounds, reports errors only in its queue), and keeps a transcript of what it was told. The daemon is then built and checked before the hardware is plugged in, and the hardware later shows where the simulator was wrong.
- Write the driver as a conversation. It says what the instrument was told and what it answered. It holds no limits, no leases and no opinion about what a setpoint should be; those are the daemon's.
- Name the channels with the three accounts:
load1.ch1.i.set,.i.applied,load1.ch1.meas.v. - Give it a control stream that states its kind, so that the rack and any other reader know what
load1is without guessing from its name. - Decide what a stop does. An output goes off. An input is left alone.
- Add its limits to the limits file's vocabulary, and a rule to
logbcheckthat holds the recording to the simulator's transcript.
No new widget is needed. An instrument appears on the rack as a box of generic widgets bound to its channels, which is a panel and not code.
2.5 Limits: limits.json
The limits are the bounds no client can loosen, whatever role or lease it has. They are read once, at start. No request changes them.
{
"min_period": "1ms",
"channels": {
"psu1.ch1": {"v_max": 12, "i_max": 1},
"scope1.timebase": {"msiz_max": 700000}
}
}
| Key | Meaning | Without it |
|---|---|---|
min_period | the shortest period a cyclic frame may have, so that no task can flood the bus | 1 ms |
channels.<supply>.chN.v_max, i_max | the highest voltage setpoint and current limit a client may ask for | no limit, recorded as "none" |
channels.<scope>.timebase.msiz_max | the deepest memory a client may ask for, which bounds the size of a readout | no limit |
rules.monitoring_lost | with -peer, required: {"watermark_age": "100ms", "action": "remove_stress"}. The stress is removed when the DUT rack's link is down or its watermark is older than this, by this rack's clock | refused with -peer |
rules.dut_abort | {"monitor": "abort", "action": "remove_stress"}: the stress is removed while the DUT rack's monitor is dev | no such rule |
rules.remove_stress | the instruments removing the stress disarms, with their outputs off, as the stop does. A rule does it when it takes hold, and again for any of them armed while it holds; each time is a control decision, request 15, with the rule's name | refused with rules |
Set the limits for the device on the bench, not for the instrument: a 30 V supply feeding a 12 V module gets v_max 12. The limits in force are written into every recording, and the file is attached to it. Limits as expressions over channels are planned.
2.6 Access: tokens, roles and TLS
$ ktestd -new-token rolf:operate >> tokens # the token itself is printed on the terminal
$ ktestd -new-token display:view >> tokens
$ ktestd -https :8443 -tokens tokens can0
The tokens file holds one line per name, name role sha256. It never holds a token, so reading it admits nobody.
| Role | May |
|---|---|
view | read the streams, open the rack, and stop |
operate | also take leases, arm, write channels, transmit, and save panels |
Without -tls-cert and -tls-key the daemon makes a self-signed certificate once, keeps it in its state directory and prints its fingerprint. A script should trust that certificate (curl --cacert ~/.local/state/ktestd/tls-cert.pem) or pin its key, and not switch verification off.
The recording lists the names and roles that were admitted, never the hashes, and every control decision records who asked and through which listener.
2.7 Panels: panel.json
A panel is the layout of a rack: boxes, one per instrument, each a grid of widgets bound to channels by name. It is data. The browser builds the rack from it, and the recording carries it.
{
"title": "Bench: supply and scope",
"groups": [
{
"instrument": "psu1",
"label": "Bench supply / 30 V 3 A",
"widgets": [
{"type": "knob", "channel": "psu1.ch1.v.set", "label": "ch1 voltage",
"step": 0.1, "max": 12, "x": 0, "y": 0, "w": 2, "h": 3},
{"type": "gauge", "channel": "psu1.ch1.meas.v", "label": "ch1 measured",
"max": 12, "x": 2, "y": 0, "w": 3, "h": 3},
{"type": "toggle", "channel": "psu1.ch1.out.set", "label": "ch1 output",
"x": 5, "y": 0, "w": 2, "h": 2},
{"type": "plot", "channels": ["psu1.ch1.meas.v", "psu1.ch1.meas.i"],
"window": 20, "x": 0, "y": 3, "w": 12, "h": 4}
]
},
{
"instrument": "scope1",
"label": "Oscilloscope / SDS1202X-E",
"widgets": [
{"type": "scope", "channel": "scope1.ch1", "label": "C1",
"x": 0, "y": 0, "w": 8, "h": 5},
{"type": "setpoint", "channel": "scope1.timebase.tdiv.set", "label": "Seconds/div",
"x": 8, "y": 0, "w": 4, "h": 2}
]
}
]
}
The panel
| Key | Meaning |
|---|---|
title | shown at the top of the rack |
columns | the grid's width in cells, 1 to 48; 12 when unsaid |
groups | the boxes, drawn top to bottom in the order given |
widgets | instead of groups: one unnamed grid. A panel has one or the other. |
A group
| Key | Meaning |
|---|---|
instrument | the name the recording knows the instrument by. Every widget in the box must be bound to that instrument's channels. The box's header shows the instrument's kind, holder and arming; the kind comes from the recording and is never stated here. |
label | what the box is called on screen |
columns | this box's grid width; the panel's when unsaid |
widgets | the widgets; x and y are the box's own, so a box moves up or down without its contents being renumbered |
A widget
Every widget has type, a place (x, y, w, h in grid cells) and an optional label. Widgets lie inside the grid and clear of each other.
| Type | Bound to | Other keys |
|---|---|---|
readout | channel | |
gauge | channel | min, max: the scale; 0 to 100 when unsaid |
lamp | channel | |
plot | channels, a list | window: seconds shown |
scope | channel, a scope channel such as scope1.ch1 | |
setpoint | channel, a number that can be set | step |
knob, slider | channel, a number that can be set | min, max, step |
enum | channel, a number that can be set | options: at least two {"value": 3.3, "label": "3V3 logic"}, no value twice |
toggle, button | channel, a switch such as out.set or on.set |
A scale says what is worth asking for and enforces nothing. A knob whose scale ends at 12 V does not stop a script from asking for 20; the limits file does.
Several widgets may be bound to one channel. A knob, a typed setpoint and a preset selector on psu1.ch1.v.set all follow each other, because each reads the value back from the recording and none from another.
The panel is checked when the daemon starts, and the daemon does not start on a panel it cannot stand behind. Whether a channel exists is not checked then, since a panel is written before its streams arrive and must replay against a recording; the rack says so beside the widget.
2.8 Designing a panel in the rack
The quickest way to a panel is to start the daemon with a nearly empty one and lay it out in the browser.
$ echo '{"title": "My bench", "groups": [{"instrument": "psu1", "widgets": []}]}' > rack.json
$ ktestd -https :8443 -tokens tokens -panel rack.json -psu psu1=192.168.1.20:5025,2 can0
- Press Edit panel. The widgets go on drawing live data while you edit.
- Add puts a new widget below the rest of its box. Click it to choose its type, channel and label.
- Drag a widget to move it. Drag its lower right corner to resize it. ✕ removes it.
- Save. The panel is checked by the daemon exactly as the file is at start, written back to the
-panelfile with one widget to a line, and embedded in the recording again. Every other page showing the rack changes with it.
If two people edit at once, the second save is refused and says why, because it was edited from a panel that is no longer in force. Reload and make the change again. A view name cannot save.
Give the daemon a copy of a panel you want to keep unchanged, as the demos do with rack.json made from panel.json, since a save overwrites the file it was started with.
Moving a widget from one box into another by dragging, and adding or reordering boxes in the editor, are planned. Today a widget changes boxes by being removed and added again, and boxes are added in the file.
Some advice on layout
- One box per instrument, named as the bench names it. The header then tells you at a glance who holds what.
- Put what is measured beside what is set. A knob for the voltage next to a gauge for the measured voltage shows a current limit biting the moment it happens.
- Give every supply a lamp on
connectedand onout.applied. An output that is on should be visible from across the room. - Set a knob's or a slider's
maxto the limit inlimits.json, so the scale covers what can be asked for. - Use an
enumfor the few values that have names on this bench (3V3, 5 V, 12 V rail) and a typedsetpointfor the rest. - Use a
buttonfor anything that should be on only while someone is there holding it. It is a convenience and not an interlock; arming and STOP are the interlocks.
2.9 The recording
The recording is a Logb file: an open, MIT-licensed format for test data whose frames are self-describing, length-prefixed and checksummed. A Ktest recording is complete in itself. It contains:
| Content | Why |
|---|---|
| every channel, with its name, unit and scaling | no database is needed to read it later |
| every control decision and refusal, with who asked | the file says what was done to the bench, not only what was seen |
| the DBC, the limits and the panel, as attachments | it decodes itself, states what was allowed, and brings back the rack that watched it |
rack.panel | which panel was on screen when, with each save and who made it |
| provenance: interface and adapter, kernel and daemon versions, the timestamp source of each stream, instrument identification strings, the admitted names and the certificate's fingerprint | a measurement from 2027 should be reconstructable in 2030 |
| drops, as records | a gap that does not say it is a gap is the worst thing a recording can contain |
recording.epoch, in the metadata | every time axis counts from it, in Unix nanoseconds: what puts a record next to a clock outside the recording |
with -contract: the contract, its resource, and mon.* | what the DUT was judged by, and every judgement, live |
The file on disk and the bytes on /stream/live are the same format, so a recording cut anywhere is still readable: a reader finds the next segment and has the schemas and the held values it needs. Tools:
| Tool | From | Use |
|---|---|---|
logbview | Logb | browse a recording as plots; -follow for one still being written |
logbdump | Logb | print a recording's frames and values as text |
logbcheck | Ktest | hold a recording to an independent reference (§1.7) |
3 The design
3.1 Four properties
- The daemon owns the hardware. Connections stay open, access is leased, and a run survives the browser disconnecting.
- Everything produced is a Logb stream. The file on disk and the bytes on the wire are one format. Live view and replay share one decoder.
- Control is asymmetric. Commands go in over REST; results come back only on the stream. A widget is never the source of truth.
- Timing lives below the daemon. Cyclic transmit is configured into the kernel and timestamps are taken by it. The daemon's event loop is never what paces a bus.
The daemon is a plain user process in one static binary. It is Linux only; Windows and macOS reach it through the browser.
3.2 Commands in, results out
A request returns accepted or refused and a sequence number. It does not return state. The resulting set, applied and meas values arrive on the stream like everything else. What this buys:
- Two browsers, a script and an agent see the same bench, because there is one account of it and none of them holds a private copy.
- A page reload, or a client that connects halfway through a run, recovers the whole rack from the stream's opening segment. There is no "get current state" request that could disagree with the stream.
- Replay drives the display through the same path as live.
- The data connection is one-way, so it is an ordinary HTTP response and not a WebSocket.
curl > run.logbis a recording, a slow client slows its own connection and nothing else, and a reconnect resynchronises by itself.
The cost is at the widget, which must show an unconfirmed value as unconfirmed and commit a drag on release instead of sending every intermediate value.
3.3 Safety
The browser is an actuator, and so is a script and so is an agent. Nothing is sent by default.
| Mechanism | Rule |
|---|---|
| Limits | per channel, in the daemon, read once at start, independent of what any panel or client permits |
| Lease | one writer per instrument, with a term. A client that stops renewing loses it, so a crashed script cannot block the lab. |
| Arming | explicit, per instrument. Only an armed instrument takes writes. |
| Stop | anyone who can reach the daemon may disarm. Outputs go off; inputs are left alone. |
| Disconnect | per class. When a lease ends, cyclic transmit stops, and a supply holds its output. If the daemon itself dies, the kernel stops every cyclic task it had. |
| Identity | over the network, TLS and a named token on every request. A lease belongs to the name that took it. |
| Replay | never actuates planned |
Every one of these decisions is recorded, refusals included, so the rules can be checked afterwards against the recording. logbcheck -control does that.
3.4 Timing
Ktest is not a real-time system and does not pretend to be. Two things are delegated to the kernel:
- Cyclic transmit is
CAN_BCM. Measured on a virtual bus at a 1 ms period, its frame-to-frame jitter is 31 µs at the median and 76 µs at the 99th percentile; a userspace loop manages 166 µs and 983 µs. A cyclic task keeps no timetable: each interval runs a few tens of µs long, so over minutes the count falls slightly short of duration over period. - Receive timestamps are the kernel's. A frame that arrives without one is recorded as unstamped, never as time zero. Hardware timestamps from the controller, with the recording saying which clock each stream is on, are planned with the MCP2518FD interface.
Reacting to a frame within microseconds is not something a script or the daemon's loop will ever do. It is kernel configuration or instrument hardware. Scripts are for orchestration at human and millisecond scales: sweep a parameter, step a supply, wait for a signal.
Bus frames are never dropped silently. When the kernel reports a loss, the loss is a record. When a reader simply stalls, the kernel reports nothing, so the daemon does not take silence as proof that nothing was lost.
3.5 Waveforms
An acquisition can be 14 million samples, and a browser has about a thousand pixels across. The daemon reduces each acquisition to a min/max envelope of some 3000 columns. A spike one sample wide is still in it, which every-nth-point decimation would lose. The rack draws the envelope as a band; the recording keeps the envelope always and the full samples for the channels you name.
A sample is stored as 32-bit float volts. Storing the digitiser's 8-bit code would be four times smaller, but then every turn of the volts/div knob would change the stream's schema and with it the stream's identity, and scope1.ch1 must mean one thing for a whole session. The code is not lost: the conversion in force is recorded with every acquisition, so it can be recovered exactly.
The settings an acquisition was taken under travel with it, and the rack shows those under each trace, not whatever the instrument holds by the time it is drawn. A change of the sample interval opens a new segment in the recording, so that no sample can be decoded to the wrong position.
If the rack's stream cannot keep up, an acquisition is left out of it and recorded as a drop in scope1.acq. The recording on disk still has it.
Two readings of Siglent's programming guide disagree between its revisions: how a code above 127 becomes negative, and whether the trigger delay shifts the time axis. They are settings (-scope-sign, -scope-trigger-delay), written into every acquisition, until the instrument settles them.
3.6 Two racks: master and secondary
When one rig stresses a device and another operates and judges it, Ktest runs two daemons, and one drives the other as an instrument. The lab rack is the master: it runs the lab's procedures and applies the stress. The DUT rack is the secondary (what other systems call the slave): it powers, operates and watches the device under test, and says how the device behaved.
| Rack | Role | Started with | Runs | Changes |
|---|---|---|---|---|
| Lab rack | master | -peer, -procedures, -locked | the procedures a standard prescribes: climatic, EMC, transients, supply profiles | rarely, under the lab's change control |
| DUT rack | secondary | -contract | the DUT's modes and actions, and the monitors that judge its functions | with each DUT |
Two processes, not one, because each side is validated on its own. A new DUT changes the secondary and its contract; the master's validated procedures, binary and limits stay as they were.
The contract is the whole interface
dut-interface.json declares what the master may name: the DUT's modes, its actions and its monitors. The master never sends raw frames to the DUT and never reads the secondary's other channels. Both racks hold a copy, and the master refuses to start unless the secondary's is the same, byte for byte, its resource file included. A procedure that names a mode, action or monitor the contract lacks is refused when it loads. Every run records the contract's sha256.
Commands in, results out, between racks
The rule of §3.2 holds between the racks too. The master holds the secondary's dut lease like any client and changes modes or runs actions by REST; the answer is accepted or refused. What happened arrives on /stream/sub: one record per frame, sent the moment it is written, 4.8 ms after its sample at the 99th percentile on loopback.
The stream carries a watermark: every monitor transition up to time T has been sent. Silence alone never means the DUT was fine. DUT Evaluate waits until the watermark has passed the end of its window before it answers ok.
The secondary judges, the master decides
Monitors are expressions over the DUT's signals, evaluated on the secondary, next to the DUT and on its clock. The master mirrors their states into its own recording as dut.mon.*, and its keywords (Verify Baseline, Classify Recovery, Threshold Search) turn them into verdicts. The two clocks are tied by an offset the master estimates once a second, with its uncertainty, and a window is widened by that uncertainty so that a deviation at its edge counts against the DUT.
When the link fails
| Event | Master | Secondary |
|---|---|---|
link down, or watermark older than watermark_age | rule monitoring_lost: the stress is removed, the run fails link_lost | the DUT keeps running in its mode |
abort monitor dev | rule dut_abort: the stress is removed, the run fails | keeps judging |
| master's lease lapses | dut stays armed; the cyclic frames its modes started go on |
The rules are in the master's limits.json, read at start and beyond any client's reach. Measured with examples/two-racks: a killed secondary had the stress removed 3.4 ms later, a frozen one 102 ms later, and an abort 0.6 ms after the master received it. A run that lost its link is not resumed; a new run starts.
Each side keeps its own validation
- Master:
-lockedholds every run to the sums of its binary, library, limits, instruments and procedure files, and records it as accredited or not (§1.5). - Secondary: the contract's sha256 is in both recordings, and
monitor-check -livereplays the secondary's recording through the same monitors to the nanosecond. - Between them:
logbcheck -judgementsrecomputes every answer the monitors gave a keyword from the mirrored states.
The flags and streams of each side are in §1.7, a DUT rack and a lab rack. examples/two-racks/demo.sh runs both on one machine with a simulated DUT and supply.
The peer protocol, for other programs
Either rack may be a program other than ktestd: a lab's own test software as the master, or a supplier's DUT software as the secondary. What passes between them is specified in doc/peer-protocol.md, version 1, normatively and in two parts: what a DUT rack must do, and what a master must do. It covers the contract, the expression language, the monitors' states and the watermark, the REST interface, the subscription stream and its record layouts, clock estimation, the protection rules and versioning. ktestd states its version in GET /dut/contract and in its stream's metadata.
| Go package | For |
|---|---|
peer | a master: the connection with its contract check, lease and clock (Link), what the DUT rack streamed (View), the DUT operations (DUT) and the protection rules' verdict (Guard). ktestd -peer runs on it |
secondary | a DUT rack: Core is its behaviour, under any control plane, and ktestd -contract runs on it; Server loads the contract against the program's own streams, evaluates the monitors, records, and serves the REST interface and the subscription; the program writes its records and runs its actions. LoadTokens and SelfSigned do access as ktestd does |
contract, expr, monitor | the contract file, the expression language and the evaluator, shared by both sides |
conformance | the checks behind peer-conformance |
examples/library-rack is a DUT rack written on secondary in under 300 lines, with the simulated DUT in-process and its actions in Go; the lab rack of examples/two-racks drives it unchanged. A program written so writes each record within the server's reorder window of its time, 20 ms by default; a later one is a gap.
Several DUT racks
Several DUTs in one chamber, or on one supply, each have their own DUT rack, and one lab rack drives them all: -peer once for each, dut= on every DUT keyword, and the protection rules covering every rack. examples/two-duts runs a ktestd DUT rack and a library-rack on one supply: one dip stresses both, each DUT is classified from its own rack, and freezing either rack removes the stress.
Checking an implementation
peer-conformance (§1.7) checks either side from outside: ktestd -contract passed its 43 checks of a DUT rack before the 11 encoding checks were added, with transitions arriving 2.8 ms after their time at the 99th percentile, and ktestd -peer its 10 checks of a master. Held to the faults it was put through with logbcheck -faults, ktestd as master took its rule 21 ms after an abort, 83 ms after the DUT rack froze and at once when the link was lost, and cleared it within 20 ms of each fault's end. A DUT rack's monitors are held to the reference evaluator with monitor-check -live, on its own recording.
3.7 What Ktest is not
- Not a production end-of-line system. No operator mode, no yield reporting, no shop-floor integration.
- Not an IDE, a report generator or a requirements tool.
- Not a real-time system. Sub-millisecond deterministic response belongs to the kernel or the instrument.
- Not tied to one vendor's hardware. SocketCAN adapters and SCPI instruments; no Vector VN interfaces.
- Not automotive Ethernet. That is a separate project.
3.8 Status and roadmap
Ktest is built in milestones, each usable alone. This manual describes the whole; this table says how much of it exists (ktestd 0.4).
| Milestone | Status | |
|---|---|---|
| 1 | Record. SocketCAN in, Logb out, live view, DBC decoding | built |
| 2 | Transmit. Single and cyclic sends, by bytes or by signal; leases, arming, limits; TLS and roles | built |
| 3 | Panels. The rack, the widget set, the panel editor, the supply driver | built, except the trace table |
| 4 | Scope and waveforms. The scope driver, envelopes, the scope widget | built against the simulator |
| The real SDS1202X-E; hardware timestamps; the scope's trigger on the recording's timeline | in progress | |
| 5 | Scripting. The expression language; procedures in a Robot subset, run by the daemon | built for a single rack |
| Two racks: DUT monitors live, the subscription stream, DUT modes and actions | built | |
| Two racks: the peer driver and the daemon rules | built | |
| Two racks: DUT keywords for the master's procedures | built | |
| Locked mode | built | |
The peer protocol as a specification; libraries for either side (peer, secondary); the conformance kit | built | |
| One lab rack driving several DUT racks | built | |
ktestd -contract on secondary.Core, the DUT rack's behaviour every DUT rack built on the library shares | built | |
| An NDJSON subscription; one DUT rack running several contracts | proposed | |
| Replay in the rack; packaging as a service; more instrument kinds and dialects by configuration; USBTMC | planned | |
| Several buses; LIN; ISO-TP; J1939 | planned | |
| The agent tool server | proposed |
The design is written down in full, with its measurements and the decisions that were rejected, in doc/test-software-outline.md; the peer protocol between racks in doc/peer-protocol.md.