feat: support both int & str as limit input
All checks were successful
build / build (pull_request) Successful in 2m19s
build / build (push) Successful in 2m21s

This commit is contained in:
张泊明518370910136 2025-03-02 04:01:01 -05:00
parent 8164e75058
commit a119adf80f
GPG Key ID: D47306D7062CDA9D
5 changed files with 35 additions and 37 deletions

View File

@ -2,8 +2,9 @@ from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional, Type
from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field, field_validator, model_validator
from joj3_config_generator.models.common import Memory, Time
from joj3_config_generator.models.const import (
DEFAULT_CPU_LIMIT,
DEFAULT_FILE_LIMIT,
@ -62,6 +63,16 @@ class Limit(BaseModel):
stderr: int = DEFAULT_FILE_LIMIT
stdout: int = DEFAULT_FILE_LIMIT
@field_validator("cpu", mode="before")
@classmethod
def ensure_time(cls, v: Any) -> Time:
return Time(v)
@field_validator("mem", "stdout", "stderr", mode="before")
@classmethod
def ensure_mem(cls, v: Any) -> Memory:
return Memory(v)
class Stage(BaseModel):
name: Optional[str] = None # Stage name

View File

@ -202,22 +202,9 @@ def fix_diff(
if not case_stage:
continue
# Ensure case_stage.limit is defined before accessing .cpu and .mem
cpu_limit = (
case_stage.limit.cpu * 1_000_000_000
if case_stage.limit and case_stage.limit.cpu is not None
else 0
)
clock_limit = (
2 * case_stage.limit.cpu * 1_000_000_000
if case_stage.limit and case_stage.limit.cpu is not None
else 0
)
memory_limit = (
case_stage.limit.mem * 1_024 * 1_024
if case_stage.limit and case_stage.limit.mem is not None
else 0
)
cpu_limit = case_stage.limit.cpu
clock_limit = 2 * case_stage.limit.cpu
memory_limit = case_stage.limit.mem
command = case_stage.command if case_stage.command is not None else None
stdin = case_stage.in_ if case_stage.in_ is not None else f"{case}.in"
stdout = case_stage.out_ if case_stage.out_ is not None else f"{case}.out"

View File

@ -632,7 +632,7 @@
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 91224961,
"memoryLimit": 134217728,
"stackLimit": 0,
"procLimit": 50,
"cpuRateLimit": 0,
@ -663,18 +663,18 @@
"stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case0.in"
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 95656304705536,
"cpuLimit": 500000000,
"clockLimit": 1000000000,
"memoryLimit": 5242880,
"procLimit": 50
},
{
"stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case1.in"
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 95656304705536,
"cpuLimit": 1234567890,
"clockLimit": 2469135780,
"memoryLimit": 9876543210,
"procLimit": 50
}
]

View File

@ -38,7 +38,7 @@ result-detail.mem = false
name = "[cq] Clang-tidy"
command = "run-clang-tidy-18 -header-filter=.* -quiet -load=/usr/local/lib/libcodequality.so -p h7/build h7/ex2.cpp"
files.import = [ "tests/homework/h7/.clang-tidy", "h7/build/compile_commands.json" ]
limit.stdout = 65
limit.stdout = "4m"
parsers = [ "clangtidy", "result-detail" ]
clangtidy.keyword = [ "codequality-unchecked-malloc-result", "codequality-no-global-variables", "codequality-no-header-guard", "codequality-no-fflush-stdin", "readability-function-size", "readability-duplicate-include", "readability-identifier-naming", "readability-redundant", "readability-misleading-indentation", "readability-misplaced-array-index", "cppcoreguidelines-init-variables", "bugprone-suspicious-string-compare", "google-global-names-in-headers", "clang-diagnostic", "clang-analyzer", "misc", "performance", "portability" ]
@ -51,7 +51,7 @@ result-detail.mem = false
[[stages]]
name = "[cq] Cppcheck"
command = "cppcheck --template='{\"file\":\"{file}\",\"line\":{line}, \"column\":{column}, \"severity\":\"{severity}\", \"message\":\"{message}\", \"id\":\"{id}\"}' --force --enable=all --suppress=missingIncludeSystem --quiet h7/ex2.cpp"
limit.stderr = 65
limit.stderr = "8m"
parsers = [ "cppcheck", "result-detail" ]
cppcheck.keyword = ["error", "warning", "portability", "performance", "style"]
@ -78,7 +78,7 @@ result-detail.mem = false
name = "[joj] ex2-asan"
command="./h7/build/ex2-asan -a"
files.import = [ "h7/build/ex2-asan" ]
limit.mem = 91224961
limit.mem = "128m"
parsers = [ "diff", "result-detail" ]
result-detail.exitstatus = true
@ -86,16 +86,16 @@ result-detail.stderr = true
# will be removed as long as the name is fixed
case0.diff.output.score = 5
case0.limit.cpu = 1
case0.limit.mem = 91224961
case0.limit.cpu = "0.5s"
case0.limit.mem = "5m"
case0.diff.output.ignorespaces = true
#case0.limit.stdout = 8
#case0.command = "./h7/build/ex2"
case0.in = "case0.in"
case1.diff.output.score = 5
case1.limit.cpu = 1
case1.limit.mem = 91224961
case1.limit.cpu = 1234567890
case1.limit.mem = 9876543210
case1.diff.output.ignorespaces = true
#case1.limit.stdout = 8
#case1.command = "./h7/build/ex2"

View File

@ -66,18 +66,18 @@
"stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case0.in"
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 95656304705536,
"cpuLimit": 1,
"clockLimit": 2,
"memoryLimit": 91224961,
"procLimit": 50
},
{
"stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case1.in"
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 95656304705536,
"cpuLimit": 1,
"clockLimit": 2,
"memoryLimit": 91224961,
"procLimit": 50
}
]