-
Notifications
You must be signed in to change notification settings - Fork 1
Add per-case test timeout via oj --tle #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
240080e
ce00cf3
4880a23
b54e775
dc4a013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,7 +132,26 @@ OJ_SFLAGS = -l 6077 | |
| endif | ||
|
|
||
| OJ = oj | ||
| OJ_TFLAGS = -c '$(RUN_TEST)' --ignore-spaces-and-newline | ||
| # Per-case time limit, a positive integer number of seconds. AtCoder's | ||
| # standard limit is 2s, but the dev container can be slower than the judge, | ||
| # so allow extra headroom to avoid false TLE. Override per task with e.g. | ||
| # `OJ_TLE=2 am t .java`. | ||
| OJ_TLE ?= 4 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Makefile 側で簡単なガードを入れることを検討してください。例えば: ifneq ($(filter-out $(OJ_TLE),$(shell echo '$(OJ_TLE)' | grep -E '^[1-9][0-9]*$')),)
$(error OJ_TLE must be a positive integer, got: $(OJ_TLE))
endifあるいは、CLAUDE.md のコメントに「正の整数で指定」と記載されているので、少なくともドキュメントに「不正な値を渡した場合の動作は未定義」と明記するだけでも親切です。現状では
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ご指摘ありがとうございます。makefile にガードを追加しました(4880a23)。
ifeq ($(shell echo '$(OJ_TLE)' | grep -Eq '^[1-9][0-9]*$$' && echo ok),)
$(error OJ_TLE must be a positive integer number of seconds, got: '$(OJ_TLE)')
endifコンテナで動作確認済みです:
これにより |
||
| # Fail fast on a non-positive-integer OJ_TLE instead of handing a bad value to | ||
| # oj (e.g. OJ_TLE=0 would make every case TLE, OJ_TLE=abc errors deep in oj). | ||
| # Validate with Make built-ins only (no shell), so a value containing quotes or | ||
| # shell metacharacters cannot break or inject into a command. | ||
| # Strip every digit: a non-empty remainder means a non-digit char is present. | ||
| OJ_TLE_NONDIGIT := $(strip $(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(OJ_TLE)))))))))))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
より明確にするには、 OJ_TLE_NONDIGIT := $(strip $(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(OJ_TLE))))))))))))これにより「全桁を除去した残りが空でなければ非数字文字あり」というロジックが名前と一致し、
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 恐れ入りますが、こちらは事実誤認かと思います。現行の OJ_TLE_NONDIGIT := $(strip $(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(OJ_TLE))))))))))))ご提示いただいた「修正版」コードは現行コードと完全に同一です。したがって「Strip every digit」というコメントと実装は一致しており、変更は不要です。 役割分担としては、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW] Make では
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ご指摘ありがとうございます。評価順への依存はご指摘の通りですが、 |
||
| # Strip zeros: an empty remainder means the value is empty or all-zero. | ||
| OJ_TLE_NONZERO := $(strip $(subst 0,,$(OJ_TLE))) | ||
| ifneq ($(OJ_TLE_NONDIGIT),) | ||
| $(error OJ_TLE must be a positive integer number of seconds, got: '$(OJ_TLE)') | ||
| endif | ||
| ifeq ($(OJ_TLE_NONZERO),) | ||
| $(error OJ_TLE must be a positive integer number of seconds, got: '$(OJ_TLE)') | ||
| endif | ||
| OJ_TFLAGS = -c '$(RUN_TEST)' --ignore-spaces-and-newline --tle $(OJ_TLE) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ [LOW] また、
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ご指摘ありがとうございます。2点とも対応しました(ce00cf3)。
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
つまり
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ご指摘の通りです。 誤った理由のコメントを残すより削除する方が良いと判断し、当該コメントを削除しました(b54e775)。 ※ 先の LOW スレッドで「 |
||
| OJ_TFLAGS_FLOAT = -e 1e-6 | ||
|
|
||
| TASK:=$$(basename $(CURDIR)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ [LOW] ドキュメントの記述「秒数は正の整数で指定」は正確で良いですが、
OJ_TLEに非常に大きな値(例:OJ_TLE=99999)を指定した場合の挙動についても一言触れると、ユーザーが誤って極端な値を設定した際の混乱を防げます。現状の実装ではojにそのまま渡されるため、oj側の制限に依存することになります。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ご提案ありがとうございます。巨大値(例:
OJ_TLE=99999)はojにそのまま渡され、単に各ケースの待ち時間が長くなるだけで挙動は自明です。ドキュメントが過度に冗長になるのを避けるため、ここは追記せず現状維持とさせてください。