online-judge-tools/oj

CRLF causes WA

jellc opened this issue · 14 comments

jellc commented

Summary / 概要

output の改行コードが CRLF, expected では LF となっていて、その他の部分は一致しているようなテストケースで WA と判定されます。
なお verification-helper 内で oj test が呼ばれている状況で、全ての問題 / テストケースで同様です。

see: #685, #703

Steps to reproduce / 再現方法

  1. oj-verify run

environments:

  • version: 11.3.0 (latest)
  • OS: Windows 10
  • shell: Git Bash

Actual behavior / 実際の挙動

judge's output:
(empty)
[FAILURE] WA
input:
4 5
1 2 3 4
5 6 7 8 9

output:
5 16 34 60 70 70 59 36\r

expected:
5 16 34 60 70 70 59 36
jellc commented

library-checker の問題で軒並みダメだったのですが、aoj の問題では上手くいくことに気付きました。前者のログをよく見ると、oj の引数に '--judge-command' で これ をコンパイルして得た実行ファイルを渡していました。なのでこの issue をここに立てるのは間違いで、library-checker-problems あるいは testlib などで解決するべき問題のようです。(お騒がせしてすみません m(_ _)m)

jellc commented

やはり oj 側で fix するべき問題かもしれないと思ったので、reopen します。
コマンドプロンプトでは正しく動作しましたが、その理由についてはよくわかりません。この辺りが関係あるとは思います。おそらく actual_output はどちらの環境でも改行が CRLF となっていて、bash では expected のみ改行が LF となっているようです。

def run(self, *, actual_output: bytes, input_path: pathlib.Path, expected_output_path: Optional[pathlib.Path]) -> bool:
with tempfile.TemporaryDirectory() as tempdir:
actual_output_path = pathlib.Path(tempdir) / 'actual.out'
with open(actual_output_path, 'wb') as fh:
fh.write(actual_output)
# if you use shlex.quote, it fails on Windows. why?
command = ' '.join([
self.judge_command, # already quoted and joined command
str(input_path.resolve()),
str(actual_output_path.resolve()),
str(expected_output_path.resolve() if expected_output_path is not None else ''),
])
logger.info('$ %s', command)
info, proc = utils.exec_command(command)

kmyk commented

@jellc 正確な再現方法を教えてください。手元でやってみた限りでは再現しませんでした。

$ uname -a
Linux DESKTOP-VQVORAN 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux

$ xxd test/foo.in
00000000: 666f 6f0a                                foo.

$ xxd test/foo.out
00000000: 6261 720a                                bar.

$ xxd clrf.txt
00000000: 6261 720d 0a                             bar..

$ oj t -c 'cat clrf.txt'
[INFO] online-judge-tools 11.3.0 (+ online-judge-api-client 10.9.0)
[INFO] 1 cases found

[INFO] foo
[INFO] time: 0.017431 sec
[SUCCESS] AC

[INFO] slowest: 0.017431 sec  (for foo)
[INFO] max memory: 0.924000 MB  (for foo)
[SUCCESS] test success: 1 cases
jellc commented

WSL からはこちらのローカルでも正常に動作しました。現状 Git Bash のみで不具合が確認できています。

$ uname -a
MINGW64_NT-10.0 DESKTOP-U5PFE62 2.11.2(0.329/5/3) 2018-11-10 14:38 x86_64 Msys

$ oj-verify.exe run test/library-checker/convolution_mod.test.cpp
...
INFO:onlinejudge.service.library_checker:$ c:\python38\python.exe C:\Users\jell\AppData\Local\online-judge-tools\online-judge-tools\Cache\library-checker-problems\generate.py C:\Users\jell\AppData\Local\online-judge-tools\online-judge-tools\Cache\library-checker-problems\math\convolution_mod\info.toml --compile-checker
15:55:40 [WARNING] --compile-checker is deprecated. Checker is compiled in default
15:55:40 [INFO] Start convolution_mod
15:55:40 [INFO] generate params.h
15:55:40 [INFO] Test cases are already generated
15:55:40 [INFO] compile checker
INFO:onlinejudge_verify.verify:$ oj test -c .verify-helper\cache\76d92b494c27da93fa94d0c9530f8e8a\a.out -d .verify-helper\cache\76d92b494c27da93fa94d0c9530f8e8a\test --print-input --tle 60 --judge-command C:\Users\jell\AppData\Local\online-judge-tools\online-judge-tools\Cache\library-checker-problems\math\convolution_mod\checker
[INFO] online-judge-tools 11.3.0 (+ online-judge-api-client 10.9.0)
[INFO] 30 cases found
[WARNING] GNU time is not available: time

[INFO] example_00
[INFO] time: 0.087615 sec
[INFO] $ C:\Users\jell\AppData\Local\online-judge-tools\online-judge-tools\Cache\library-checker-problems\math\convolution_mod\checker C:\Users\jell\Library\.verify-helper\cache\76d92b494c27da93fa94d0c9530f8e8a\test\example_00.in C:\Users\jell\AppData\Local\Temp\tmp4rdlxm46\actual.out C:\Users\jell\Library\.verify-helper\cache\76d92b494c27da93fa94d0c9530f8e8a\test\example_00.out
judge's output:
(empty)
[FAILURE] WA
input:
4 5
1 2 3 4
5 6 7 8 9

output:
5 16 34 60 70 70 59 36\r

expected:
5 16 34 60 70 70 59 36
jellc commented

僕自身も cmd から実行するなどで対処できますし、実際困っている人はあまり多くないとは思います。

kmyk commented

ファイル test/library-checker/convolution_mod.test.cpp の中身も貼っておいてくれるととうれしいです。
(「再現方法を教えてください」というお願いは「あなたの環境で問題が発生することをもう一度確認してください」という意味ではなく「私の環境でその問題を発生させることを手伝ってください」という意味です)

kmyk commented

Git Bash 上でも再現しません。

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop
$ xxd crlf.txt
00000000: 6261 720d 0a                             bar..

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop
$ xxd test/foo.in
00000000: 666f 6f0a                                foo.

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop
$ xxd test/foo.out
00000000: 6261 720a                                bar.

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop
$ oj t -c 'cat crlf.txt'
[WARNING] update available for online-judge-tools: 10.1.3 -> 11.3.0
[INFO] run: $ pip3 install -U online-judge-tools
[WARNING] update available for online-judge-api-client: 10.3.0 -> 10.9.0
[INFO] run: $ pip3 install -U online-judge-api-client
[INFO] online-judge-tools 10.1.3 (+ online-judge-api-client 10.3.0)
[INFO] 1 cases found
[WARNING] GNU time is not available: time

[INFO] foo
[INFO] time: 0.014657 sec
[SUCCESS] AC

[INFO] slowest: 0.014657 sec  (for foo)
[SUCCESS] test success: 1 cases

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop
$ uname -a
MINGW64_NT-10.0-18363 DESKTOP-VQVORAN 3.1.7-340.x86_64 2021-03-26 22:17 UTC x86_64 Msys
kmyk commented

やっぱりなんだか「library-checker-problems あるいは testlib などで解決するべき問題のようです。」というので正しそうな気がします

jellc commented

テストしたソースは これ です。

kmyk commented

ありがとうございます。
試してみたのですが、少なくとも素の Git Bash ではまずコンパイルが通らないらしいです。

kimiyuki@DESKTOP-VQVORAN MINGW64 ~/Desktop/Library (master)
$ oj-verify.exe run test/library-checker/convolution_mod.test.cpp
INFO:onlinejudge_verify.config:no config file
WARNING:onlinejudge_verify.verify:failed to increase the stack size
::warning ::failed to ulimit
INFO:onlinejudge_verify.verify:verify: test\library-checker\convolution_mod.test.cpp
clang++: warning: -Wl,-stack,0x10000000: 'linker' input unused [-Wunused-command-line-argument]
In file included from C:\Users\kimiyuki\Desktop\Library\test\library-checker\convolution_mod.test.cpp:5:
C:\Users\kimiyuki\Desktop\Library\src/utils/io/istream.hpp:8:10: fatal error: 'cxxabi.h' file not found
#include <cxxabi.h>
         ^~~~~~~~~~
1 error generated.
Traceback (most recent call last):
  File "C:\Users\kimiyuki\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\onlinejudge_verify\verify.py", line 60, in verify_file
    attributes = language.list_attributes(path, basedir=pathlib.Path.cwd())
  File "C:\Users\kimiyuki\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\onlinejudge_verify\languages\cplusplus.py", line 152, in list_attributes
    macros = _cplusplus_list_defined_macros(path.resolve(), CXX=env.CXX, joined_CXXFLAGS=joined_CXXFLAGS)
  File "C:\Users\kimiyuki\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\onlinejudge_verify\languages\cplusplus.py", line 62, in _cplusplus_list_defined_macros
    data = subprocess.check_output(command)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:\\Program Files\\LLVM\\bin\\clang++.EXE', '--std=c++17', '-O2', '-Wall', '-g', '-Wl,-stack,0x10000000', '-I', 'C:\\Users\\kimiyuki\\Desktop\\Library', '-dM', '-E', 'C:\\Users\\kimiyuki\\Desktop\\Library\\test\\library-checker\\convolution_mod.test.cpp']' returned non-zero exit status 1.
::error file=test\library-checker\convolution_mod.test.cpp::failed to verify
ERROR:onlinejudge_verify.verify:1 tests failed
ERROR:onlinejudge_verify.verify:failed: test\library-checker\convolution_mod.test.cpp
kmyk commented

再現させられてはないけど、やっぱりこれは library-checker-problems あるいは testlib の問題だと思います。
Library Checker の問題なら special judge なので。

jellc commented

わざわざ色々と試していただきありがとうございます。
コンパイラの違いとかでしょうかね...?

$ type g++
g++ is /c/msys64/mingw64/bin/g++

そうですね。少なくとも testlib が \r の有無を区別していることは明らかです。

jellc commented

最新の oj + Windows 11 でふと試してみたら、なぜかこの問題が解消されてました。
お騒がせいたしました。

kmyk commented

結局よく分からないままでしたが、解消されたのはよかったです