Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ A tiny judging environment for OI contest based on Lemon + LemonPlus
| Arch | 2021-07-11 | amd64 | KDE-Xorg |
| Arch | 2020-10-31 | amd64 | KDE-Wayland |
| Ubuntu | 20.04 | amd64 | GNOME 3 |
| Ubuntu | 18.04.4 | amd64 | GNOME 3 |
| NOI Linux 2(Ubuntu) | 20.04 | amd64 | GNOME 3 |
| Linux Mint | 19.3 | amd64 | Cinnamon |
| Deepin | 15.11 | amd64 | DDE |
| Deepin | 20 (1000) | amd64 | DDE |
| Debian | 10.3.0 | amd64 | LXQt; KDE-Xorg |
| Fedora | 31-1.9 | amd64 | XFCE |
| openSUSE | Leap 15.1 | amd64 | iceWM |
| openSUSE | Tumbleweed | amd64 | KDE-Xorg |
| macOS | 15.2 Beta | arm64 | Aqua |

Expand Down
10 changes: 7 additions & 3 deletions src/core/processrunner_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ ProcessRunnerResult UnixProcessRunner::run() {
argumentsList << config.outputFileName;
}

argumentsList << QString("%1").arg(extraTime);

qDebug() << argumentsList;

QString bwrapPath = QStandardPaths::findExecutable("bwrap");
Expand Down Expand Up @@ -159,6 +161,8 @@ ProcessRunnerResult UnixProcessRunner::run() {
argumentsList << config.outputFileName;
}

argumentsList << QString("%1").arg(extraTime);
Comment thread
ZnPdCo marked this conversation as resolved.
Resolved

qDebug() << argumentsList;

runner.setProcessEnvironment(config.environment);
Expand All @@ -178,9 +182,9 @@ ProcessRunnerResult UnixProcessRunner::run() {
QElapsedTimer timer;
timer.start();

// Using rlimit to limit CPU time can only be accurate to seconds,
// so here it is rounded up to an integer second.
long long killTimeLimit = (config.timeLimit + 999) / 1000 * 1000 + extraTime;
// The watcher itself enforces the wall clock (timeLimit + extraTime) and exits shortly
// after the timer fires; this loop only guards against a hung watcher, with 1s of slack.
long long killTimeLimit = 1LL * config.timeLimit + extraTime + 1000;
while (timer.elapsed() <= killTimeLimit) {
if (runner.waitForFinished(10)) {
isProgramFinishedInExtraTimeLimit = true;
Expand Down
2 changes: 2 additions & 0 deletions unix/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ file(COPY hello.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable(tle tle.c)
add_executable(add add.c)
add_executable(re re.c)
add_executable(sleep_tle sleep_tle.c)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

Expand All @@ -27,6 +28,7 @@ add_test(NAME watcher_run_sh_test COMMAND python3 scripts/run_sh.py)
add_test(NAME watcher_MLE_static_test COMMAND python3 scripts/mle_static.py)
add_test(NAME watcher_unlimit_memory_test COMMAND python3 scripts/unlimit.py)
add_test(NAME watcher_TLE_test COMMAND python3 scripts/tle.py)
add_test(NAME watcher_wall_clock_TLE_test COMMAND python3 scripts/sleep_tle.py)
add_test(NAME watcher_filename_with_space_test COMMAND python3 scripts/space.py)
add_test(NAME watcher_symlink_abs_test COMMAND python3 scripts/symlink_abs.py)
add_test(NAME watcher_symlink_rel_test COMMAND python3 scripts/symlink_rel.py)
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/mle_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pid = os.getpid()
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./mle_static", "", "", "", tmperr, "1000", "380", "1000", "380", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./mle_static", "", "", "", tmperr, "1000", "380", "1000", "380", "", "", "0"], shell=False, stdout=subprocess.PIPE)

stdout, _ = p.communicate()

Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
with open(tmpin, 'w') as f:
f.writelines(['1 1'])

p = subprocess.Popen(["./watcher_unix", "./add", "", tmpin, tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False)
p = subprocess.Popen(["./watcher_unix", "./add", "", tmpin, tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False)

time.sleep(2)
p.kill()
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tmpout = f"_tmpout_{pid}"
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./hello", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./hello", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/run_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tmpout = f"_tmpout_{pid}"
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "/bin/sh", "hello.sh", "", tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "/bin/sh", "hello.sh", "", tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/runtimeerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
pid = os.getpid()
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./re", "", "", "", tmperr, "1000", "100", "1000", "100", "", ""], shell=False)
p = subprocess.Popen(["./watcher_unix", "./re", "", "", "", tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False)

assert(p.wait() == 2)
16 changes: 16 additions & 0 deletions unix/test/scripts/sleep_tle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import subprocess
import os

pid = os.getpid()
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./sleep_tle", "", "", "", tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False)

try:
returncode = p.wait(timeout=10)
except subprocess.TimeoutExpired:
p.kill()
p.wait()
raise

assert(returncode == 3)
2 changes: 1 addition & 1 deletion unix/test/scripts/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

shutil.copy("./hello", "./he llo")

p = subprocess.Popen(["./watcher_unix", "./he llo", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./he llo", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/symlink_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

os.symlink(os.path.join(os.getcwd(), "hello"), "hello_s_abs")

p = subprocess.Popen(["./watcher_unix", "./hello_s_abs", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./hello_s_abs", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/symlink_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

os.symlink("hello", "hello_s_rel")

p = subprocess.Popen(["./watcher_unix", "./hello_s_rel", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./hello_s_rel", "", "", tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/tle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tmpout = f"_tmpout_{pid}"
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./tle", "", "", "", tmperr, "1000", "100", "1000", "100", "", ""], shell=False)
p = subprocess.Popen(["./watcher_unix", "./tle", "", "", "", tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False)

time.sleep(5)
p.kill()
Expand Down
2 changes: 1 addition & 1 deletion unix/test/scripts/unlimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tmpout = f"_tmpout_{pid}"
tmperr = f"_tmperr_{pid}"

p = subprocess.Popen(["./watcher_unix", "./mle_static", "", "", tmpout, tmperr, "1000", "-1", "1000", "-1", "", ""], shell=False, stdout=subprocess.PIPE)
p = subprocess.Popen(["./watcher_unix", "./mle_static", "", "", tmpout, tmperr, "1000", "-1", "1000", "-1", "", "", "0"], shell=False, stdout=subprocess.PIPE)

assert(p.wait() == 0)
assert(os.path.exists(tmpout))
Expand Down
6 changes: 6 additions & 0 deletions unix/test/sleep_tle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <unistd.h>

int main() {
sleep(10);
return 0;
}
Loading
Loading