-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(watcher_unix): Refactor & Add test for watcher_unix (#218)
* add test for watcher_unix * fix watcher_unix * add test for watcher_unix * resolve comments * add comment for parse fileName * refactor watcher_unix * add unlimited memory & TLE test * fix macos build * format code * no need to resolve symlink * add testcases * minor fix * minor fix (consistent) * remove duplicate include * add more testcases for watcher_unix * rename RE test
- Loading branch information
Showing
23 changed files
with
441 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Watcher for Linux Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
paths: [ "unix/**" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
paths: [ "unix/**" ] | ||
workflow_dispatch: | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Release | ||
|
||
jobs: | ||
build: | ||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. | ||
# You can convert this to a matrix build if you need cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Configure CMake | ||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. | ||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type | ||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} unix/test | ||
|
||
- name: Build | ||
# Build your program with the given configuration | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: ctest --verbose -C ${{env.BUILD_TYPE}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Watcher for MacOS Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
paths: [ "unix/**" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
paths: [ "unix/**" ] | ||
workflow_dispatch: | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Release | ||
|
||
jobs: | ||
build: | ||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. | ||
# You can convert this to a matrix build if you need cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
runs-on: macos-13 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Configure CMake | ||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. | ||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type | ||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} unix/test | ||
|
||
- name: Build | ||
# Build your program with the given configuration | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: ctest --verbose -C ${{env.BUILD_TYPE}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
cmake_minimum_required(VERSION 3.10.0) | ||
|
||
project(lemon_watcher_unix_test) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
if(APPLE) | ||
add_executable(watcher_unix ${CMAKE_CURRENT_SOURCE_DIR}/../watcher_unix.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../watcher_macos.mm) | ||
else() | ||
add_executable(watcher_unix ${CMAKE_CURRENT_SOURCE_DIR}/../watcher_unix.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../watcher_linux.cpp) | ||
endif() | ||
|
||
add_executable(hello hello.c) | ||
add_executable(mle_static mle_static.c) | ||
file(COPY hello.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
add_executable(tle tle.c) | ||
add_executable(add add.c) | ||
add_executable(re re.c) | ||
|
||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
enable_testing() | ||
add_test(NAME watcher_run_c_test COMMAND python3 scripts/run.py) | ||
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_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) | ||
add_test(NAME watcher_redirect_IO_test COMMAND python3 scripts/redirect.py) | ||
add_test(NAME watcher_RE_test COMMAND python3 scripts/runtimeerr.py) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
int a, b; | ||
|
||
scanf("%d%d", &a, &b); | ||
printf("%d\n", a + b); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
printf("Hello World!\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo "Hello World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
|
||
int a[100000000]; | ||
// 400 MB | ||
|
||
int main() { | ||
puts("Hello World!"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int main() { | ||
int *x = (void *)0; | ||
return *x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import subprocess | ||
|
||
cmd = "\"%s\" %s" % ("./mle_static", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "380"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
assert(stdout[0] == 48) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import subprocess | ||
import os | ||
import time | ||
|
||
with open('_tmpin', 'w') as f: | ||
f.writelines(['1 1']) | ||
|
||
cmd = "\"%s\" %s" % ("./add", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "_tmpin", "_tmpout", "_tmperr", "1000", "100"], shell=False) | ||
|
||
time.sleep(2) | ||
p.kill() | ||
|
||
assert(p.returncode == 0) | ||
|
||
assert(os.path.exists('_tmpout')) | ||
with open('_tmpout', 'r') as f: | ||
assert(f.read() == "2\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import subprocess | ||
|
||
cmd = "\"%s\" %s" % ("./hello", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import subprocess | ||
|
||
cmd = "\"%s\" %s" % ("/bin/bash", "hello.sh") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import subprocess | ||
import time | ||
|
||
cmd = "\"%s\" %s" % ("./re", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False) | ||
|
||
assert(p.wait() == 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import subprocess | ||
import shutil | ||
|
||
shutil.copy("./hello", "./he llo") | ||
|
||
cmd = "\"%s\" %s" % ("./he llo", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import subprocess | ||
import os | ||
|
||
if os.path.exists("hello_s_abs"): | ||
os.remove("hello_s_abs") | ||
|
||
os.symlink(os.path.join(os.getcwd(), "hello"), "hello_s_abs") | ||
|
||
cmd = "\"%s\" %s" % ("./hello_s_abs", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import subprocess | ||
import os | ||
|
||
if os.path.exists("hello_s_rel"): | ||
os.remove("hello_s_rel") | ||
|
||
os.symlink("hello", "hello_s_rel") | ||
|
||
cmd = "\"%s\" %s" % ("./hello_s_rel", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import subprocess | ||
import time | ||
|
||
cmd = "\"%s\" %s" % ("./tle", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "100"], shell=False) | ||
|
||
time.sleep(5) | ||
p.kill() | ||
|
||
assert(p.returncode == 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import subprocess | ||
|
||
cmd = "\"%s\" %s" % ("./mle_static", "") | ||
p = subprocess.Popen(["./watcher_unix", cmd, "", "", "_tmperr", "1000", "-1"], shell=False, stdout=subprocess.PIPE) | ||
|
||
stdout, _ = p.communicate() | ||
|
||
assert(p.wait() == 0) | ||
out_str = stdout.decode() | ||
assert(out_str.split('\n')[0] == 'Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int main() { | ||
while (1) | ||
; | ||
return 0; | ||
} |
Oops, something went wrong.