Files
judge/example/c-sum/README.md
2026-04-05 18:20:42 +03:00

1.7 KiB

c-sum — cross-platform C example

Minimal example: a C program that reads N then N integers and prints their sum. Tested with judge across gcc / clang / MSVC on Linux / Windows, with optional valgrind and sanitizer runs.

Files

  • solution.c — student-facing solution (could be what the student submits)
  • sum.jdg — judge test suite
  • .gitea/workflows/judge.yml — Gitea CI matrix

Run locally

# Linux / macOS
CC=gcc   judge sum.jdg .
CC=clang judge sum.jdg .

# With valgrind
judge sum.jdg . --wrapper="valgrind --error-exitcode=99 --leak-check=full -q"

# With ASan+UBSan build
CC=clang CFLAGS="-O1 -g -fsanitize=address,undefined" judge sum.jdg .

On Windows (inside an MSVC dev cmd shell), build_windows kicks in and produces solution.exe, which the runner auto-detects.

Notes about the .jdg

  • normalize_crlf = true — Windows printf emits \r\n; we strip \r before matching so the same expected outputs work on both platforms.
  • trim_trailing_ws = true — forgives trailing spaces a student's output might pick up (rare but annoying to debug).
  • binary = "solution" — the runner tries solution first, then solution.exe on Windows automatically.
  • Per-group scoring = all_or_none on stress gives weight only if every stress test passes.

Adapting the Gitea workflow

  • runs-on: ${{ matrix.toolchain.system }}-Runner assumes you have self-hosted Gitea runners labelled Linux-Runner / Windows-Runner (same naming as your existing fixed_floating pipeline).
  • secrets.VAR_TOKEN is only needed when pulling a student repo from a private org.
  • The summary job shells grep over the JSON; swap to jq if available on your runners.