feat: support both int & str as limit input
This commit is contained in:
		
							parent
							
								
									8164e75058
								
							
						
					
					
						commit
						a119adf80f
					
				|  | @ -2,8 +2,9 @@ from datetime import datetime | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| from typing import Any, Dict, List, Optional, Type | 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 ( | from joj3_config_generator.models.const import ( | ||||||
|     DEFAULT_CPU_LIMIT, |     DEFAULT_CPU_LIMIT, | ||||||
|     DEFAULT_FILE_LIMIT, |     DEFAULT_FILE_LIMIT, | ||||||
|  | @ -62,6 +63,16 @@ class Limit(BaseModel): | ||||||
|     stderr: int = DEFAULT_FILE_LIMIT |     stderr: int = DEFAULT_FILE_LIMIT | ||||||
|     stdout: 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): | class Stage(BaseModel): | ||||||
|     name: Optional[str] = None  # Stage name |     name: Optional[str] = None  # Stage name | ||||||
|  |  | ||||||
|  | @ -202,22 +202,9 @@ def fix_diff( | ||||||
|             if not case_stage: |             if not case_stage: | ||||||
|                 continue |                 continue | ||||||
| 
 | 
 | ||||||
|             # Ensure case_stage.limit is defined before accessing .cpu and .mem |             cpu_limit = case_stage.limit.cpu | ||||||
|             cpu_limit = ( |             clock_limit = 2 * case_stage.limit.cpu | ||||||
|                 case_stage.limit.cpu * 1_000_000_000 |             memory_limit = case_stage.limit.mem | ||||||
|                 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 |  | ||||||
|             ) |  | ||||||
|             command = case_stage.command if case_stage.command is not None else None |             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" |             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" |             stdout = case_stage.out_ if case_stage.out_ is not None else f"{case}.out" | ||||||
|  |  | ||||||
|  | @ -632,7 +632,7 @@ | ||||||
|                             }, |                             }, | ||||||
|                             "cpuLimit": 1000000000, |                             "cpuLimit": 1000000000, | ||||||
|                             "clockLimit": 2000000000, |                             "clockLimit": 2000000000, | ||||||
|                             "memoryLimit": 91224961, |                             "memoryLimit": 134217728, | ||||||
|                             "stackLimit": 0, |                             "stackLimit": 0, | ||||||
|                             "procLimit": 50, |                             "procLimit": 50, | ||||||
|                             "cpuRateLimit": 0, |                             "cpuRateLimit": 0, | ||||||
|  | @ -663,18 +663,18 @@ | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" | ||||||
|                                 }, |                                 }, | ||||||
|                                 "cpuLimit": 1000000000, |                                 "cpuLimit": 500000000, | ||||||
|                                 "clockLimit": 2000000000, |                                 "clockLimit": 1000000000, | ||||||
|                                 "memoryLimit": 95656304705536, |                                 "memoryLimit": 5242880, | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             }, |                             }, | ||||||
|                             { |                             { | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" | ||||||
|                                 }, |                                 }, | ||||||
|                                 "cpuLimit": 1000000000, |                                 "cpuLimit": 1234567890, | ||||||
|                                 "clockLimit": 2000000000, |                                 "clockLimit": 2469135780, | ||||||
|                                 "memoryLimit": 95656304705536, |                                 "memoryLimit": 9876543210, | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             } |                             } | ||||||
|                         ] |                         ] | ||||||
|  |  | ||||||
|  | @ -38,7 +38,7 @@ result-detail.mem = false | ||||||
| name = "[cq] Clang-tidy" | name = "[cq] Clang-tidy" | ||||||
| command = "run-clang-tidy-18 -header-filter=.* -quiet -load=/usr/local/lib/libcodequality.so -p h7/build h7/ex2.cpp" | 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" ] | files.import = [ "tests/homework/h7/.clang-tidy", "h7/build/compile_commands.json" ] | ||||||
| limit.stdout = 65 | limit.stdout = "4m" | ||||||
| 
 | 
 | ||||||
| parsers = [ "clangtidy", "result-detail" ] | 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" ] | 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]] | [[stages]] | ||||||
| name = "[cq] Cppcheck" | 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" | 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" ] | parsers = [ "cppcheck", "result-detail" ] | ||||||
| cppcheck.keyword = ["error", "warning", "portability", "performance", "style"] | cppcheck.keyword = ["error", "warning", "portability", "performance", "style"] | ||||||
|  | @ -78,7 +78,7 @@ result-detail.mem = false | ||||||
| name = "[joj] ex2-asan" | name = "[joj] ex2-asan" | ||||||
| command="./h7/build/ex2-asan -a" | command="./h7/build/ex2-asan -a" | ||||||
| files.import = [ "h7/build/ex2-asan" ] | files.import = [ "h7/build/ex2-asan" ] | ||||||
| limit.mem = 91224961 | limit.mem = "128m" | ||||||
| 
 | 
 | ||||||
| parsers = [ "diff", "result-detail" ] | parsers = [ "diff", "result-detail" ] | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
|  | @ -86,16 +86,16 @@ result-detail.stderr = true | ||||||
| 
 | 
 | ||||||
| # will be removed as long as the name is fixed | # will be removed as long as the name is fixed | ||||||
| case0.diff.output.score = 5 | case0.diff.output.score = 5 | ||||||
| case0.limit.cpu = 1 | case0.limit.cpu = "0.5s" | ||||||
| case0.limit.mem = 91224961 | case0.limit.mem = "5m" | ||||||
| case0.diff.output.ignorespaces = true | case0.diff.output.ignorespaces = true | ||||||
| #case0.limit.stdout = 8 | #case0.limit.stdout = 8 | ||||||
| #case0.command = "./h7/build/ex2" | #case0.command = "./h7/build/ex2" | ||||||
| case0.in = "case0.in" | case0.in = "case0.in" | ||||||
| 
 | 
 | ||||||
| case1.diff.output.score = 5 | case1.diff.output.score = 5 | ||||||
| case1.limit.cpu = 1 | case1.limit.cpu = 1234567890 | ||||||
| case1.limit.mem = 91224961 | case1.limit.mem = 9876543210 | ||||||
| case1.diff.output.ignorespaces = true | case1.diff.output.ignorespaces = true | ||||||
| #case1.limit.stdout = 8 | #case1.limit.stdout = 8 | ||||||
| #case1.command = "./h7/build/ex2" | #case1.command = "./h7/build/ex2" | ||||||
|  |  | ||||||
|  | @ -66,18 +66,18 @@ | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" | ||||||
|                                 }, |                                 }, | ||||||
|                                 "cpuLimit": 1000000000, |                                 "cpuLimit": 1, | ||||||
|                                 "clockLimit": 2000000000, |                                 "clockLimit": 2, | ||||||
|                                 "memoryLimit": 95656304705536, |                                 "memoryLimit": 91224961, | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             }, |                             }, | ||||||
|                             { |                             { | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" | ||||||
|                                 }, |                                 }, | ||||||
|                                 "cpuLimit": 1000000000, |                                 "cpuLimit": 1, | ||||||
|                                 "clockLimit": 2000000000, |                                 "clockLimit": 2, | ||||||
|                                 "memoryLimit": 95656304705536, |                                 "memoryLimit": 91224961, | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             } |                             } | ||||||
|                         ] |                         ] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user