Repository navigation
Expand file tree
/
Copy pathveldt.rkt
More file actions
256 lines (218 loc) · 9.2 KB
/
Copy pathveldt.rkt
File metadata and controls
256 lines (218 loc) · 9.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#lang racket/base
;; veldt.rkt — main entry point
;;
;; Usage:
;; racket veldt.rkt run [--tasks <id,...>] [--language <lang>] [--max N]
;; racket veldt.rkt run-ocaml [--tasks <id,...>] [--max N]
;; racket veldt.rkt list [--plt-only]
;; racket veldt.rkt status
;; racket veldt.rkt cleanup
(require racket/cmdline
racket/string
racket/list
racket/format
racket/path
racket/vector
json
"lib/tasks.rkt"
"lib/orchestrator.rkt"
"lib/orchestrator-ocaml.rkt"
"lib/vers.rkt"
"lib/run-log.rkt")
(define project-dir
(path->string (simplify-path
(path->complete-path (current-directory)))))
;; ── Parse subcommand first, then flags ──────────────────────────────
(define (main)
(define args (vector->list (current-command-line-arguments)))
(when (null? args)
(eprintf "Usage: racket veldt.rkt {run|run-ocaml|list|status|cleanup} [options]\n")
(exit 1))
(define subcmd (car args))
(define rest-args (list->vector (cdr args)))
(cond
[(equal? subcmd "run") (cmd-run rest-args)]
[(equal? subcmd "run-ocaml") (cmd-run-ocaml rest-args)]
[(equal? subcmd "list") (cmd-list rest-args)]
[(equal? subcmd "status") (cmd-status)]
[(equal? subcmd "cleanup") (cmd-cleanup)]
[(or (equal? subcmd "--help") (equal? subcmd "-h"))
(printf "Usage: racket veldt.rkt {run|run-ocaml|list|status|cleanup} [options]\n\n")
(printf "Subcommands:\n")
(printf " run Run ProgramBench tasks (Go implementation)\n")
(printf " run-ocaml Run PLT tasks only (OCaml implementation)\n")
(printf " list List all tasks (--plt-only for PLT tasks)\n")
(printf " status Show running VMs\n")
(printf " cleanup Delete all running VMs\n")
(printf "\nFor run options: racket veldt.rkt run --help\n")
(printf "For run-ocaml options: racket veldt.rkt run-ocaml --help\n")]
[else
(eprintf "Unknown subcommand: ~a\n" subcmd)
(eprintf "Usage: racket veldt.rkt {run|run-ocaml|list|status|cleanup}\n")
(exit 1)]))
;; ── Run subcommand (Go, original) ──────────────────────────────────
(define (cmd-run argv)
(define p-golden (make-parameter "c2835f61-63ff-48e8-b934-2c6186e0b739"))
(define p-tasks (make-parameter #f))
(define p-lang (make-parameter #f))
(define p-diff (make-parameter #f))
(define p-max (make-parameter #f))
(define p-recon-timeout (make-parameter 900))
(define p-impl-timeout (make-parameter 3600))
(command-line
#:program "veldt run"
#:argv argv
#:once-each
["--golden" commit "Golden VM commit ID"
(p-golden commit)]
["--tasks" ids "Comma-separated task instance IDs"
(p-tasks (string-split ids ","))]
["--language" lang "Filter by language (go, rs, c, cpp)"
(p-lang lang)]
["--difficulty" diff "Filter by difficulty (easy, medium, hard)"
(p-diff diff)]
["--max" n "Maximum number of tasks"
(p-max (string->number n))]
["--recon-timeout" n "Recon timeout in seconds (default: 900)"
(p-recon-timeout (string->number n))]
["--impl-timeout" n "Impl timeout in seconds (default: 3600)"
(p-impl-timeout (string->number n))]
#:args ()
(void))
(define all-tasks (load-tasks project-dir))
(when (null? all-tasks)
(error 'veldt "no tasks in config/tasks.json"))
(define tasks
(filter-tasks all-tasks
#:ids (p-tasks)
#:language (p-lang)
#:difficulty (p-diff)
#:max-count (p-max)))
(when (null? tasks)
(error 'veldt "no tasks match filters"))
(printf "veldt: ~a tasks selected\n" (length tasks))
(for ([t (in-list tasks)])
(printf " ~a (~a, ~a)\n"
(pb-task-instance-id t) (pb-task-language t) (pb-task-difficulty t)))
(printf "\n")
(define results
(run-veldt tasks
#:golden-commit (p-golden)
#:recon-timeout (p-recon-timeout)
#:impl-timeout (p-impl-timeout)))
(print-results results))
;; ── Run-OCaml subcommand ────────────────────────────────────────────
(define (cmd-run-ocaml argv)
(define p-golden (make-parameter #f))
(define p-tasks (make-parameter #f))
(define p-max (make-parameter #f))
(define p-recon-timeout (make-parameter 900))
(define p-impl-timeout (make-parameter 3600))
(define p-all (make-parameter #f))
(command-line
#:program "veldt run-ocaml"
#:argv argv
#:once-each
["--golden" commit "Golden VM commit ID (required — must have OCaml)"
(p-golden commit)]
["--tasks" ids "Comma-separated task instance IDs (default: PLT tasks only)"
(p-tasks (string-split ids ","))]
["--max" n "Maximum number of tasks"
(p-max (string->number n))]
["--recon-timeout" n "Recon timeout in seconds (default: 900)"
(p-recon-timeout (string->number n))]
["--impl-timeout" n "Impl timeout in seconds (default: 3600)"
(p-impl-timeout (string->number n))]
["--all" "Run all tasks (non-PLT tasks will be skipped by the orchestrator)"
(p-all #t)]
#:args ()
(void))
(unless (p-golden)
(eprintf "error: --golden is required for run-ocaml (must be an OCaml-enabled golden image)\n")
(eprintf "Build one with: bash scripts/build-golden-vm-ocaml.sh\n")
(exit 1))
(define all-tasks (load-tasks project-dir))
(when (null? all-tasks)
(error 'veldt "no tasks in config/tasks.json"))
;; Task selection: specific IDs, all tasks, or orchestrator default
(define tasks
(cond
[(p-tasks)
(filter-tasks all-tasks #:ids (p-tasks) #:max-count (p-max))]
[(p-all)
(let ([ts all-tasks])
(if (p-max) (take ts (min (p-max) (length ts))) ts))]
[else
(let ([ts (ocaml-default-tasks all-tasks)])
(if (p-max) (take ts (min (p-max) (length ts))) ts))]))
(when (null? tasks)
(error 'veldt "no tasks match filters"))
;; Let the orchestrator module describe what it will do
(ocaml-describe-tasks tasks (current-output-port))
(printf "\n")
(define results
(run-veldt-ocaml tasks (p-golden)
#:recon-timeout (p-recon-timeout)
#:impl-timeout (p-impl-timeout)))
(print-results results))
;; ── List ────────────────────────────────────────────────────────────
(define (cmd-list argv)
(define p-plt-only (make-parameter #f))
(command-line
#:program "veldt list"
#:argv argv
#:once-each
["--plt-only" "Show only PLT tasks"
(p-plt-only #t)]
#:args ()
(void))
(define all-tasks (load-tasks project-dir))
(cond
[(p-plt-only)
;; Delegate entirely to the OCaml orchestrator module
(ocaml-list-plt-tasks all-tasks (current-output-port))]
[else
(printf "~a tasks\n\n" (length all-tasks))
(for ([t (in-list all-tasks)])
(printf " ~a ~a ~a\n"
(~a (pb-task-instance-id t) #:min-width 50)
(~a (pb-task-language t) #:min-width 8)
(pb-task-difficulty t)))]))
;; ── Status ──────────────────────────────────────────────────────────
(define (cmd-status)
(define vms (vers-status/all))
(printf "~a running VMs:\n" (length vms))
(for ([vid (in-list vms)])
(printf " ~a\n" vid)))
;; ── Cleanup ─────────────────────────────────────────────────────────
(define (cmd-cleanup)
(define vms (vers-status/all))
(printf "deleting ~a VMs...\n" (length vms))
(for ([vid (in-list vms)])
(printf " ~a..." vid)
(vers-delete vid)
(printf " ✓\n"))
(printf "done.\n"))
;; ── Result printing ─────────────────────────────────────────────────
(define (print-results results)
(printf "\n═══ Results ═══\n")
(for ([r (in-list results)])
(define status (hash-ref r 'status "?"))
(define icon (cond [(equal? status "PASS") "✓"]
[(equal? status "SKIPPED") "⊘"]
[(equal? status "FAIL") "✗"]
[else "?"]))
(printf "~a ~a ~a (~as)\n"
icon status
(hash-ref r 'instance_id "?")
(hash-ref r 'elapsed_seconds 0)))
(define pass-count
(count (λ (r) (equal? (hash-ref r 'status "") "PASS")) results))
(define skip-count
(count (λ (r) (equal? (hash-ref r 'status "") "SKIPPED")) results))
(define total (- (length results) skip-count))
(printf "\n~a/~a passed~a\n"
pass-count total
(if (> skip-count 0) (format " (~a skipped)" skip-count) "")))
;; ── Go ──────────────────────────────────────────────────────────────
(main)