test memory limit
Some checks failed
memory-limit / Build judge (push) Successful in 18s
memory-limit / Linux / gcc (push) Failing after 14s
memory-limit / Linux / clang (push) Failing after 15s
memory-limit / Windows / clang (push) Failing after 16s
memory-limit / Windows / msvc (push) Failing after 17s
Some checks failed
memory-limit / Build judge (push) Successful in 18s
memory-limit / Linux / gcc (push) Failing after 14s
memory-limit / Linux / clang (push) Failing after 15s
memory-limit / Windows / clang (push) Failing after 16s
memory-limit / Windows / msvc (push) Failing after 17s
This commit is contained in:
35
example/mem-limit/mem.jdg
Normal file
35
example/mem-limit/mem.jdg
Normal file
@@ -0,0 +1,35 @@
|
||||
// End-to-end check that memory_limit is actually enforced by the runner.
|
||||
// The solution allocates N MiB (argv[1]) and touches every page.
|
||||
//
|
||||
// - "within_limit" allocates 16 MiB under a 256 MiB cap → expected PASS
|
||||
// - "exceeds_limit" allocates 256 MiB under a 64 MiB cap → expected MLE
|
||||
//
|
||||
// The workflow runs judge --json and asserts these statuses via jq.
|
||||
|
||||
build "$CC -O2 -std=c11 -Wall -Wextra solution.c -o solution"
|
||||
build_windows "if /I \"%CC%\"==\"msvc\" (cl /nologo /O2 /W3 solution.c /Fe:solution.exe) else (%CC% -O2 -std=c11 -Wall -Wextra solution.c -o solution.exe)"
|
||||
|
||||
binary = "solution"
|
||||
timeout 10s
|
||||
|
||||
normalize_crlf = true
|
||||
|
||||
group("within_limit") {
|
||||
weight = 1.0
|
||||
memory_limit = 256M
|
||||
|
||||
test("allocate_16mb") {
|
||||
args = ["16"]
|
||||
stdout = "ok 16\n"
|
||||
}
|
||||
}
|
||||
|
||||
group("exceeds_limit") {
|
||||
weight = 0.0 // score doesn't matter — we assert the status in CI
|
||||
memory_limit = 64M
|
||||
|
||||
test("allocate_256mb") {
|
||||
args = ["256"]
|
||||
// no stdout matcher: process is expected to be killed before it prints
|
||||
}
|
||||
}
|
||||
27
example/mem-limit/solution.c
Normal file
27
example/mem-limit/solution.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <megabytes>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
long mb = strtol(argv[1], NULL, 10);
|
||||
if (mb <= 0) return 1;
|
||||
|
||||
size_t bytes = (size_t)mb * 1024 * 1024;
|
||||
char *p = (char *)malloc(bytes);
|
||||
if (!p) {
|
||||
fprintf(stderr, "malloc failed\n");
|
||||
return 2;
|
||||
}
|
||||
for (size_t i = 0; i < bytes; i += 4096) {
|
||||
p[i] = (char)(i & 0xff);
|
||||
}
|
||||
volatile char sink = p[bytes - 1];
|
||||
(void)sink;
|
||||
|
||||
printf("ok %ld\n", mb);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user