Add led_ring, find_me, restart, and ota_progress steps plus uart_cmds scenario. Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package autotest
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// Scenario is an ordered list of steps run against a bench Config.
|
|
type Scenario struct {
|
|
ID string `json:"id"`
|
|
Description string `json:"description,omitempty"`
|
|
ConfigID string `json:"config"`
|
|
Steps []Step `json:"steps"`
|
|
}
|
|
|
|
type Step struct {
|
|
Name string `json:"name,omitempty"`
|
|
Command string `json:"command,omitempty"`
|
|
DelayMS int `json:"delay_ms,omitempty"`
|
|
Input json.RawMessage `json:"input,omitempty"`
|
|
Expect Expect `json:"expect,omitempty"`
|
|
}
|
|
|
|
type Expect struct {
|
|
// version
|
|
Version *uint32 `json:"version,omitempty"`
|
|
VersionMin *uint32 `json:"version_min,omitempty"`
|
|
GitHash string `json:"git_hash,omitempty"`
|
|
|
|
// clients
|
|
MinClients *int `json:"min_clients,omitempty"`
|
|
MaxClients *int `json:"max_clients,omitempty"`
|
|
ClientCount *int `json:"client_count,omitempty"`
|
|
Slave string `json:"slave,omitempty"`
|
|
Slaves []string `json:"slaves,omitempty"`
|
|
Available *bool `json:"available,omitempty"`
|
|
MAC string `json:"mac,omitempty"`
|
|
|
|
// deadzone
|
|
Deadzone *uint32 `json:"deadzone,omitempty"`
|
|
Success *bool `json:"success,omitempty"`
|
|
SlavesUpdated *uint32 `json:"slaves_updated,omitempty"`
|
|
SlavesUpdatedMin *uint32 `json:"slaves_updated_min,omitempty"`
|
|
|
|
// unicast_test
|
|
Seq *uint32 `json:"seq,omitempty"`
|
|
|
|
// led_ring
|
|
Mode *uint32 `json:"mode,omitempty"`
|
|
Progress *uint32 `json:"progress,omitempty"`
|
|
Digit *uint32 `json:"digit,omitempty"`
|
|
|
|
// ota_slave_progress
|
|
Active *bool `json:"active,omitempty"`
|
|
}
|
|
|
|
func LoadScenario(path string) (*Scenario, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var sc Scenario
|
|
if err := json.Unmarshal(data, &sc); err != nil {
|
|
return nil, fmt.Errorf("parse scenario: %w", err)
|
|
}
|
|
if sc.ID == "" {
|
|
return nil, fmt.Errorf("scenario: id is required")
|
|
}
|
|
if sc.ConfigID == "" {
|
|
return nil, fmt.Errorf("scenario %q: config is required", sc.ID)
|
|
}
|
|
if len(sc.Steps) == 0 {
|
|
return nil, fmt.Errorf("scenario %q: no steps", sc.ID)
|
|
}
|
|
return &sc, nil
|
|
}
|