Skip to content
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

SENJUN-24: add cpp practice #5

Merged
merged 4 commits into from
Feb 4, 2025
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
4 changes: 4 additions & 0 deletions cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ COPY task/run-task.sh task/CMakeLists.txt task/ut.hpp /home/code_runner/task/
RUN mkdir /home/code_runner/playground
COPY playground/run-playground.sh /home/code_runner/playground

# Directory for practice
RUN mkdir /home/code_runner/practice
COPY practice/run-practice.sh task/ut.hpp /home/code_runner/practice/

# Change access write for code_runner home directory to root recursively
RUN useradd -ms /bin/bash code_runner \
&& chown -R code_runner:code_runner /home/code_runner \
Expand Down
77 changes: 77 additions & 0 deletions cpp/practice/run-practice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
set -e

# main goes here

# column after option means required argument
while getopts f:p:o:rt opt
do
case "${opt}" in
f) project=${OPTARG}
;;
o) user_options="${OPTARG}"
;;
p) main_path=${OPTARG}
;;
r) run=${OPTARG}
;;
t) test=${OPTARG}
;;
\?) echo "Invalid option" >&2
exit
;;
esac
done

f="$(basename -- $project)"

cd /home/code_runner/practice/$f
cp /home/code_runner/practice/ut.hpp /home/code_runner/practice/$f

# configure project
if ! ( timeout 10s cmake -Bbuild -Wno-dev -GNinja > /tmp/configure.txt ); then
echo "Configure error"
cat /tmp/configure.txt
echo user_solution_error_f936a25e
exit
fi

# build cpp project
if ! ( timeout 20s cmake --build build/ -- -j4 > /tmp/build.txt ); then
echo "Build error"
cat /tmp/build.txt
echo user_solution_error_f936a25e
exit
fi


# e.g: sh run.sh -p path_to_main.py -o user_options -r
if [ ${run+x} ]; then
# run cpp project
# TODO which name for project should use here?
if ! ( timeout 5s ./build/main ); then
echo "Code execution timeout"
echo user_solution_error_f936a25e
exit
fi

echo user_code_ok_f936a25e
echo user_solution_ok_f936a25e
exit
fi

# e.g: sh run.sh -f dir_name -t
if [ ${test+x} ]; then
echo user_code_ok_f936a25e
if ! ( timeout 5s ./build/tests ); then
echo "Tests execution timeout"
echo tests_cases_error_f936a25e
exit
fi

echo user_solution_ok_f936a25e
exit
fi

# Never goes here
echo "Never should go here!"