fixes
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/Mond1c/judge/dsl"
|
||||
)
|
||||
|
||||
func expandPattern(pattern *dsl.Pattern, groupTimeout interface{ IsZero() bool }) ([]*dsl.Test, error) {
|
||||
func expandPattern(pattern *dsl.Pattern) ([]*dsl.Test, error) {
|
||||
if pattern.IsDirMode() {
|
||||
return expandDirPattern(pattern)
|
||||
}
|
||||
@@ -105,11 +105,11 @@ func expandDirPattern(pattern *dsl.Pattern) ([]*dsl.Test, error) {
|
||||
}
|
||||
|
||||
func splitGlob(pattern string) (prefix, suffix string) {
|
||||
idx := strings.Index(pattern, "*")
|
||||
if idx < 0 {
|
||||
before, after, found := strings.Cut(pattern, "*")
|
||||
if !found {
|
||||
return pattern, ""
|
||||
}
|
||||
return pattern[:idx], pattern[idx+1:]
|
||||
return before, after
|
||||
}
|
||||
|
||||
func extractWildcard(path, prefix, suffix string) string {
|
||||
|
||||
@@ -44,9 +44,8 @@ type TestResult struct {
|
||||
ActualCode int
|
||||
}
|
||||
|
||||
func (r *TestResult) fail(msg string, args ...any) {
|
||||
func (r *TestResult) addFailure(msg string, args ...any) {
|
||||
r.Failures = append(r.Failures, fmt.Sprintf(msg, args...))
|
||||
r.Status = StatusFail
|
||||
}
|
||||
|
||||
type GroupResult struct {
|
||||
|
||||
@@ -15,14 +15,12 @@ import (
|
||||
"github.com/Mond1c/judge/dsl"
|
||||
)
|
||||
|
||||
// MaxOutputBytes caps stdout/stderr captured from the solution process.
|
||||
// Prevents runaway student programs from OOM-ing the judge host.
|
||||
const MaxOutputBytes = 16 * 1024 * 1024 // 16 MiB
|
||||
const MaxOutputBytes = 16 * 1024 * 1024
|
||||
|
||||
type Config struct {
|
||||
WorkDir string
|
||||
BinaryName string
|
||||
Wrapper string // CLI override, wins over DSL wrapper
|
||||
Wrapper string
|
||||
}
|
||||
|
||||
type Runner struct {
|
||||
@@ -47,7 +45,6 @@ func New(f *dsl.File, cfg Config) *Runner {
|
||||
return &Runner{file: f, cfg: cfg, binary: resolveBinary(absWork, name)}
|
||||
}
|
||||
|
||||
// resolveBinary picks <work>/name, falling back to <work>/name.exe on Windows.
|
||||
func resolveBinary(workDir, name string) string {
|
||||
primary := filepath.Join(workDir, name)
|
||||
if runtime.GOOS == "windows" && !strings.HasSuffix(strings.ToLower(name), ".exe") {
|
||||
@@ -90,7 +87,6 @@ func (r *Runner) Run() *SuiteResult {
|
||||
return result
|
||||
}
|
||||
|
||||
// After build, re-resolve binary (the exe may have been produced just now).
|
||||
r.binary = resolveBinary(r.cfg.WorkDir, filepath.Base(r.binary))
|
||||
|
||||
for _, g := range r.file.Groups {
|
||||
@@ -102,7 +98,6 @@ func (r *Runner) Run() *SuiteResult {
|
||||
return result
|
||||
}
|
||||
|
||||
// buildCommand picks the most specific build command for this OS.
|
||||
func (r *Runner) buildCommand() string {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
@@ -148,8 +143,6 @@ func (r *Runner) build() (string, error) {
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
// shellCommand runs a command string through the platform's shell so env vars
|
||||
// like $CC expand naturally from the CI matrix.
|
||||
func shellCommand(ctx context.Context, cmdline string) *exec.Cmd {
|
||||
if runtime.GOOS == "windows" {
|
||||
return exec.CommandContext(ctx, "cmd", "/C", cmdline)
|
||||
@@ -166,7 +159,7 @@ func (r *Runner) runGroup(g *dsl.Group) *GroupResult {
|
||||
tests := g.Tests
|
||||
|
||||
if g.Pattern != nil {
|
||||
expanded, err := expandPattern(g.Pattern, &zeroChecker{})
|
||||
expanded, err := expandPattern(g.Pattern)
|
||||
if err != nil {
|
||||
gr.Tests = append(gr.Tests, &TestResult{
|
||||
Name: "pattern_expand",
|
||||
@@ -177,16 +170,6 @@ func (r *Runner) runGroup(g *dsl.Group) *GroupResult {
|
||||
gr.Score = 0
|
||||
return gr
|
||||
}
|
||||
for _, t := range expanded {
|
||||
if t.Timeout == 0 {
|
||||
t.Timeout = g.Timeout
|
||||
}
|
||||
for k, v := range g.Env {
|
||||
if _, ok := t.Env[k]; !ok {
|
||||
t.Env[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
tests = append(tests, expanded...)
|
||||
}
|
||||
|
||||
@@ -234,7 +217,7 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
tmpDir, err := os.MkdirTemp("", "judge-test-*")
|
||||
if err != nil {
|
||||
tr.Status = StatusRuntimeError
|
||||
tr.Failures = append(tr.Failures, fmt.Sprintf("failed to create temp dir: %v", err))
|
||||
tr.addFailure("failed to create temp dir: %v", err)
|
||||
return tr
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
@@ -242,11 +225,13 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
for name, content := range t.InFiles {
|
||||
path := filepath.Join(tmpDir, name)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
tr.fail("mkdir for file %q: %v", name, err)
|
||||
tr.Status = StatusRuntimeError
|
||||
tr.addFailure("mkdir for file %q: %v", name, err)
|
||||
return tr
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
tr.fail("write input file %q: %v", name, err)
|
||||
tr.Status = StatusRuntimeError
|
||||
tr.addFailure("write input file %q: %v", name, err)
|
||||
return tr
|
||||
}
|
||||
}
|
||||
@@ -259,7 +244,6 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
// Wrapper precedence: CLI flag > test > group (already copied into test).
|
||||
wrapper := r.cfg.Wrapper
|
||||
if wrapper == "" {
|
||||
wrapper = t.Wrapper
|
||||
@@ -269,8 +253,6 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
cmd.Dir = tmpDir
|
||||
|
||||
cmd.Env = os.Environ()
|
||||
// Force C locale so numeric formatting (decimal separator, etc.) is stable
|
||||
// across runners. Student code can still override via test env.
|
||||
cmd.Env = append(cmd.Env, "LC_ALL=C", "LANG=C")
|
||||
for k, v := range t.Env {
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
|
||||
@@ -293,12 +275,12 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
tr.ActualStderr = normalizeOutput(stderr.String(), r.file)
|
||||
|
||||
if stdout.truncated || stderr.truncated {
|
||||
tr.fail("output truncated at %d bytes (possible runaway output)", MaxOutputBytes)
|
||||
tr.addFailure("output truncated at %d bytes (possible runaway output)", MaxOutputBytes)
|
||||
}
|
||||
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
tr.Status = StatusTLE
|
||||
tr.Failures = append(tr.Failures, fmt.Sprintf("time limit exceeded (%v)", timeout))
|
||||
tr.addFailure("time limit exceeded (%v)", timeout)
|
||||
return tr
|
||||
}
|
||||
|
||||
@@ -308,46 +290,43 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
||||
actualCode = exitErr.ExitCode()
|
||||
} else {
|
||||
tr.Status = StatusRuntimeError
|
||||
tr.fail("runtime error: %v", runErr)
|
||||
tr.addFailure("runtime error: %v", runErr)
|
||||
return tr
|
||||
}
|
||||
}
|
||||
tr.ActualCode = actualCode
|
||||
|
||||
if t.ExitCode != nil && actualCode != *t.ExitCode {
|
||||
tr.fail("exit code: expected %d, got %d", *t.ExitCode, actualCode)
|
||||
tr.addFailure("exit code: expected %d, got %d", *t.ExitCode, actualCode)
|
||||
}
|
||||
|
||||
for _, f := range applyMatcher("stdout", t.Stdout, tr.ActualStdout) {
|
||||
tr.fail("%s", f)
|
||||
tr.addFailure("%s", f)
|
||||
}
|
||||
for _, f := range applyMatcher("stderr", t.Stderr, tr.ActualStderr) {
|
||||
tr.fail("%s", f)
|
||||
tr.addFailure("%s", f)
|
||||
}
|
||||
|
||||
for name, expected := range t.OutFiles {
|
||||
path := filepath.Join(tmpDir, name)
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
tr.fail("output file %q not found: %v", name, err)
|
||||
tr.addFailure("output file %q not found: %v", name, err)
|
||||
continue
|
||||
}
|
||||
actual := normalizeOutput(string(content), r.file)
|
||||
for _, f := range applyMatcher(fmt.Sprintf("file(%s)", name), dsl.ExactMatcher{Value: expected}, actual) {
|
||||
tr.fail("%s", f)
|
||||
tr.addFailure("%s", f)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tr.Failures) > 0 {
|
||||
if tr.Status == StatusPass && len(tr.Failures) > 0 {
|
||||
tr.Status = StatusFail
|
||||
}
|
||||
|
||||
return tr
|
||||
}
|
||||
|
||||
// buildExecCmd creates an exec.Cmd for the solution, optionally prefixed with
|
||||
// a wrapper (gdb, valgrind, qemu, ...). Wrapper is a shell string so users can
|
||||
// pass flags like "valgrind --error-exitcode=99 --leak-check=full".
|
||||
func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *exec.Cmd {
|
||||
if wrapper == "" {
|
||||
return exec.CommandContext(ctx, binary, args...)
|
||||
@@ -358,7 +337,6 @@ func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *e
|
||||
return exec.CommandContext(ctx, full[0], full[1:]...)
|
||||
}
|
||||
|
||||
// normalizeOutput applies the file-level CRLF / trailing-WS rules.
|
||||
func normalizeOutput(s string, f *dsl.File) string {
|
||||
if f.NormalizeCRLF {
|
||||
s = strings.ReplaceAll(s, "\r\n", "\n")
|
||||
@@ -374,8 +352,6 @@ func normalizeOutput(s string, f *dsl.File) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// cappedBuffer stops writing once limit bytes are captured, but keeps draining
|
||||
// the source so the child process doesn't block on a full pipe.
|
||||
type cappedBuffer struct {
|
||||
buf bytes.Buffer
|
||||
limit int
|
||||
@@ -386,7 +362,7 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
|
||||
room := c.limit - c.buf.Len()
|
||||
if room <= 0 {
|
||||
c.truncated = true
|
||||
return len(p), nil // pretend we wrote, to keep the pipe flowing
|
||||
return len(p), nil
|
||||
}
|
||||
if len(p) > room {
|
||||
c.buf.Write(p[:room])
|
||||
@@ -399,7 +375,3 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
|
||||
func (c *cappedBuffer) String() string { return c.buf.String() }
|
||||
|
||||
var _ io.Writer = (*cappedBuffer)(nil)
|
||||
|
||||
type zeroChecker struct{}
|
||||
|
||||
func (z *zeroChecker) IsZero() bool { return true }
|
||||
|
||||
Reference in New Issue
Block a user