diff --git a/MIDTERM/basic/basic_bg b/MIDTERM/basic/basic_bg new file mode 100644 index 0000000000000000000000000000000000000000..4346c8e733e36a7c3322497b3c3f8cc2da026e7c --- /dev/null +++ b/MIDTERM/basic/basic_bg @@ -0,0 +1 @@ +sleep 8 & diff --git a/MIDTERM/basic/basic_cd_arg b/MIDTERM/basic/basic_cd_arg new file mode 100644 index 0000000000000000000000000000000000000000..16911eace3e7965f5945aa452e706180f6ea2255 --- /dev/null +++ b/MIDTERM/basic/basic_cd_arg @@ -0,0 +1,2 @@ +cd /bin +pwd diff --git a/MIDTERM/basic/basic_cd_arg_space b/MIDTERM/basic/basic_cd_arg_space new file mode 100644 index 0000000000000000000000000000000000000000..7437054441e6389f094870d6de0c1ce3d0071284 --- /dev/null +++ b/MIDTERM/basic/basic_cd_arg_space @@ -0,0 +1,2 @@ + cd /bin +pwd diff --git a/MIDTERM/basic/basic_echo b/MIDTERM/basic/basic_echo new file mode 100644 index 0000000000000000000000000000000000000000..ff0e12ec692f04bfb2a5e641fa37f563a4b91cf5 --- /dev/null +++ b/MIDTERM/basic/basic_echo @@ -0,0 +1 @@ +echo Hello World diff --git a/MIDTERM/basic/basic_error b/MIDTERM/basic/basic_error new file mode 100644 index 0000000000000000000000000000000000000000..0827df83532c725f315cbc7f81074bc4afdc8f9e --- /dev/null +++ b/MIDTERM/basic/basic_error @@ -0,0 +1 @@ +not_a_command diff --git a/MIDTERM/basic/basic_error.output b/MIDTERM/basic/basic_error.output new file mode 100644 index 0000000000000000000000000000000000000000..3f183721b6352082978098a165466b05beab6a45 --- /dev/null +++ b/MIDTERM/basic/basic_error.output @@ -0,0 +1 @@ +An error has occurred diff --git a/MIDTERM/basic/basic_exit b/MIDTERM/basic/basic_exit new file mode 100644 index 0000000000000000000000000000000000000000..10dc2a42ba9a1ee28ccdf9e470ffa4212c87505b --- /dev/null +++ b/MIDTERM/basic/basic_exit @@ -0,0 +1,2 @@ +exit +echo "You should't see this" diff --git a/MIDTERM/basic/basic_help b/MIDTERM/basic/basic_help new file mode 100644 index 0000000000000000000000000000000000000000..a87bf4349919819fcc5cad8e599336fa52f08acc --- /dev/null +++ b/MIDTERM/basic/basic_help @@ -0,0 +1 @@ +help diff --git a/MIDTERM/basic/basic_help.output b/MIDTERM/basic/basic_help.output new file mode 100644 index 0000000000000000000000000000000000000000..950555eaa38f9c1e4227225f033f9c66f2cea36a --- /dev/null +++ b/MIDTERM/basic/basic_help.output @@ -0,0 +1,6 @@ +> cd +pwd +wait +exit +help +> diff --git a/MIDTERM/basic/basic_pwd b/MIDTERM/basic/basic_pwd new file mode 100644 index 0000000000000000000000000000000000000000..f748bdd051994e9fa832a7bd7b4fc59ef5e99cbe --- /dev/null +++ b/MIDTERM/basic/basic_pwd @@ -0,0 +1 @@ +pwd diff --git a/MIDTERM/basic/basic_wait b/MIDTERM/basic/basic_wait new file mode 100644 index 0000000000000000000000000000000000000000..6addaedf94a6cb7793a324fe503d62a7241ade6b --- /dev/null +++ b/MIDTERM/basic/basic_wait @@ -0,0 +1,3 @@ +sleep 3 & +wait +echo Bye diff --git a/MIDTERM/basic/basic_wait.conf b/MIDTERM/basic/basic_wait.conf new file mode 100644 index 0000000000000000000000000000000000000000..0efd67f9502e63cb033cb651e65e025b6e3a5cb2 --- /dev/null +++ b/MIDTERM/basic/basic_wait.conf @@ -0,0 +1 @@ +2 4 diff --git a/MIDTERM/batch/batch_lv1 b/MIDTERM/batch/batch_lv1 new file mode 100644 index 0000000000000000000000000000000000000000..56e32d2352ac17ed3f66f2a87f5209dc735c156f --- /dev/null +++ b/MIDTERM/batch/batch_lv1 @@ -0,0 +1,32 @@ +echo placeholder +echo '\.Who..............................................' +echo '.\.Is..............................................' +echo '..\.Dr.............................................' +echo '...\.Oscar.........................................' +echo '....\.Jose.........................................' +echo '.....\.Tsalapatis..................................' +echo '......|.............................___............' +echo '......|.........................,-""...`...........' +echo '......|.......................,`.._...@.)`-._......' +echo '......|....................../..,`.`-._<.===--.....' +echo '......|...................../../...................' +echo '......|..................../..;....................' +echo '......|........_........../...;....................' +echo '..(`._|..._.-"".""--..__,`....|....................' +echo '..<_..`-""....................\\...................' +echo '...<`-..........................:..................' +echo '....(__...<__...................;..................' +echo '......`-....`-.__......._.`..../...................' +echo '......|..\......`-.__,-`...._,`....................' +echo '......|...`._....,..../__,-`.......................' +echo '......|......""._\__,`<.<____......................' +echo '......|.........|.|..`----.`.......................' +echo '......|.........|.|........\.`.....................' +echo '......|.........;.|___......\-``...................' +echo '......|.........\...--<............................' +echo '......|..........`.`.<.............................' +echo '......|............`-`.............................' +echo '.......Fig.1..Dr.Oscar.Jose.Tsalapatis.............' +echo '....................Now............................' +echo '....................You............................' +echo '...................Knew............................' diff --git a/MIDTERM/batch/batch_lv99 b/MIDTERM/batch/batch_lv99 new file mode 100644 index 0000000000000000000000000000000000000000..a0420b59f1d4ebb748c11a224153c0cb07e6b267 --- /dev/null +++ b/MIDTERM/batch/batch_lv99 @@ -0,0 +1,12 @@ + echo This will be replaced by a random key +pwd + ls + cd /lib + pwd + sleep 3 & + wait + ls + cd /usr + pwd + ls -al + fdalsjfklajsd -adsf -sadfqwefs hasdkjfhasldfhqruf cxv diff --git a/MIDTERM/batch/batch_lv99.conf b/MIDTERM/batch/batch_lv99.conf new file mode 100644 index 0000000000000000000000000000000000000000..ebcee1a506db729ea7b0e0b6e9b0be36806d16bd --- /dev/null +++ b/MIDTERM/batch/batch_lv99.conf @@ -0,0 +1 @@ +3 4 diff --git a/MIDTERM/run.sh b/MIDTERM/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..14e055838a6fa187ac689eaf696d1afc3e950fee --- /dev/null +++ b/MIDTERM/run.sh @@ -0,0 +1,214 @@ +#!/bin/bash + +# These functions exist to stop students from using shells within their own +# shell to execute a program. We remove execution ability and use sudo to move +# to another user to then run the program +move_away() +{ + chmod 500 /bin/sh + chmod 500 /bin/bash +} + +move_back() +{ + chmod 555 /bin/sh + chmod 555 /bin/bash +} + +source /helpers.sh + +LOG=$LOGS/test_public.log +ASSIGNMENTDIR=/assignments/MIDTERM/ + +if [ ! -d /kernel ]; +then + unpack_kernel +fi + +echo "Building assignment..." +cd /kernel +chmod a+rw . + +COMPILE=$LOGS/compile.log +touch $COMPILE +truncate -s 0 $COMPILE +rm myshell > /dev/null 2> /dev/null || true +gcc main.c -o myshell -pthread >> $COMPILE 2>> $COMPILE + +touch $LOG +truncate -s 0 $LOG + +if test -f "myshell"; +then + echo "Build succeeded." +else + echo "Build failed." + exit +fi + +time_start=0 +time_stop=0 + +# Go through basic tests +# In each of these we are essentially only testing commands with output to stdout + +# This is a way to stop students from trying to use the sh command, we search for this command to be used +# afterwords +echo "Testing basic..." +for f in $ASSIGNMENTDIR/basic/* +do + if echo "$f" | grep -q ".conf" || echo "$f" | grep -q ".output" + then + continue + fi + + output=0 + if test -f "${f}.output" + then + output=1 + fi + + duration_min=0 + duration=1 + if test -f "${f}.conf" + then + duration_min=$(cat "${f}.conf" | cut -d' ' -f1) + duration=$(cat "${f}.conf" | cut -d' ' -f2-) + fi + + bname=$(basename $f) + echo " -> ${bname}..." + + echo ">SPLIT<" >> $LOG + echo ">TEST=$bname<" >> $LOG + echo ">Program Output<" >> $LOG + move_away + time_start=$(date +%s) + sudo -u user timeout "${duration}s" ./myshell < $f >> $LOG 2>> $LOG + time_stop=$(date +%s) + move_back + + echo "" >> $LOG + echo ">Expected Output<" >> $LOG + if [ "$output" = 0 ]; + then + bash $f >> $LOG 2>> $LOG + else + cat "${f}.output" >> $LOG + fi + echo ">Start Time<" >> $LOG + echo $time_start >> $LOG + echo ">Stop Time<" >> $LOG + echo $time_stop >> $LOG + echo ">Target Time Min<" >> $LOG + echo $duration_min >> $LOG + echo ">Target Time Max<" >> $LOG + echo $duration >> $LOG +done + +# Go through stderr print test +echo "Testing stderr..." +for f in $ASSIGNMENTDIR/stderr/* +do + if echo "$f" | grep -q ".conf" || echo "$f" | grep -q ".output" + then + continue + fi + + output=0 + if test -f "${f}.output" + then + output=1 + fi + + duration_min=0 + duration=1 + if test -f "${f}.conf" + then + duration_min=$(cat "${f}.conf" | cut -d' ' -f1) + duration=$(cat "${f}.conf" | cut -d' ' -f2-) + fi + + bname=$(basename $f) + echo " -> ${bname}..." + + echo ">SPLIT<" >> $LOG + echo ">TEST=$bname<" >> $LOG + echo ">Program Output<" >> $LOG + move_away + time_start=$(date +%s) + sudo -u user timeout "${duration}s" ./myshell < $f >> /dev/null 2>> $LOG + time_stop=$(date +%s) + move_back + + echo "" >> $LOG + echo ">Expected Output<" >> $LOG + if [ "$output" = 0 ]; + then + bash $f >> /dev/null 2>> $LOG + else + cat "${f}.output" >> $LOG + fi + echo ">Start Time<" >> $LOG + echo $time_start >> $LOG + echo ">Stop Time<" >> $LOG + echo $time_stop >> $LOG + echo ">Target Time Min<" >> $LOG + echo $duration_min >> $LOG + echo ">Target Time Max<" >> $LOG + echo $duration >> $LOG +done + + +# Go through batch mode test specifically for this shell +echo "Testing batch..." +for f in $ASSIGNMENTDIR/batch/* +do + if echo "$f" | grep -q ".conf" || echo "$f" | grep -q ".output" + then + continue + fi + + duration_min=0 + duration=1 + if test -f "${f}.conf" + then + duration_min=$(cat "${f}.conf" | cut -d' ' -f1) + duration=$(cat "${f}.conf" | cut -d' ' -f2-) + fi + + # replace the string in first echo by a random key + cp $f "${f}.test" + echok="echo K$((1 + $RANDOM % 30000))" + sed -i "1s/.*/$echok/" "${f}.test" + + bname=$(basename $f) + echo " -> ${bname}..." + + echo ">SPLIT<" >> $LOG + echo ">TEST=$bname<" >> $LOG + echo ">Program Output<" >> $LOG + move_away + time_start=$(date +%s) + sudo -u user timeout "${duration}s" ./myshell "$f.test" >> $LOG 2>> $LOG + time_stop=$(date +%s) + move_back + + echo ">Expected Output<" >> $LOG + bash < "$f.test" >> $LOG 2>> $LOG + + echo ">Start Time<" >> $LOG + echo $time_start >> $LOG + echo ">Stop Time<" >> $LOG + echo $time_stop >> $LOG + echo ">Target Time Min<" >> $LOG + echo $duration_min >> $LOG + echo ">Target Time Max<" >> $LOG + echo $duration >> $LOG + + rm "${f}.test" +done + + +exit 0 + diff --git a/MIDTERM/stderr/stderr_error b/MIDTERM/stderr/stderr_error new file mode 100644 index 0000000000000000000000000000000000000000..0827df83532c725f315cbc7f81074bc4afdc8f9e --- /dev/null +++ b/MIDTERM/stderr/stderr_error @@ -0,0 +1 @@ +not_a_command diff --git a/MIDTERM/stderr/stderr_error.output b/MIDTERM/stderr/stderr_error.output new file mode 100644 index 0000000000000000000000000000000000000000..3f183721b6352082978098a165466b05beab6a45 --- /dev/null +++ b/MIDTERM/stderr/stderr_error.output @@ -0,0 +1 @@ +An error has occurred diff --git a/MIDTERM/stderr/stderr_formaterr b/MIDTERM/stderr/stderr_formaterr new file mode 100644 index 0000000000000000000000000000000000000000..5a95cd90b80f304e7d1a10a5d1de0b23688d02c0 --- /dev/null +++ b/MIDTERM/stderr/stderr_formaterr @@ -0,0 +1 @@ +cd /root /root /root cdedf diff --git a/MIDTERM/stderr/stderr_formaterr.output b/MIDTERM/stderr/stderr_formaterr.output new file mode 100644 index 0000000000000000000000000000000000000000..3f183721b6352082978098a165466b05beab6a45 --- /dev/null +++ b/MIDTERM/stderr/stderr_formaterr.output @@ -0,0 +1 @@ +An error has occurred diff --git a/MIDTERM/stderr/stderr_noerror b/MIDTERM/stderr/stderr_noerror new file mode 100644 index 0000000000000000000000000000000000000000..2f08be9a02925b5c016904e19fbd5e8d057ae756 --- /dev/null +++ b/MIDTERM/stderr/stderr_noerror @@ -0,0 +1 @@ +echo hello diff --git a/MIDTERM/verify.py b/MIDTERM/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..beb145e85b0b32ff6cd7d0fffb2ebb50b656856a --- /dev/null +++ b/MIDTERM/verify.py @@ -0,0 +1,116 @@ +import subprocess +import traceback + +TYPE_BASIC = "basic" +BASIC_GRADE_PER = 1.0 +BASIC_NUM = 9 + +TYPE_STDERR = "stderr" +STDERR_GRADE_PER = 1.0 +STDERR_NUM = 3 + +TYPE_BATCH = "batch" +BATCH_GRADE_PER = 1.0 +BATCH_NUM = 2 + +DEBUG=False + +title_str = [ + ">Expected Output<", + ">Start Time<", + ">Stop Time<", + ">Target Time Min<", + ">Target Time Max<" +] + +def mark(tests, helpers, t_type, grade_per, debug=False): + try: + grade = 0 + cmts = set() + tests = [t for t in tests if t_type in t.name] + if len(tests) == 0: + cmts.add(f"Compilation error") + return (f"{t_type} Tests", grade, ",".join(cmts)) + + for t in tests: + # get the lines from the output + r = t.results().strip().split("\n") + + for i, strout in enumerate(r): + if t_type == TYPE_BATCH: + if ("command not found" in strout) and ("bash: line" in strout): + r[i] = "An error has occurred" + + for title in title_str: + if title in strout: + r[i] = title + break + + # compose program output + # remove all > and spaces + idx = r.index(">Expected Output<") + prog_output = ''.join(r[1:idx]) + prog_output = prog_output.replace(" ", "") + prog_output = prog_output.replace(">", "") + prog_output = prog_output.replace("\"", "") + prog_output = prog_output.replace("\'", "") + + idx2 = r.index(">Start Time<") + exp_output = ''.join(r[idx+1:idx2]) + exp_output = exp_output.replace(" ", "") + exp_output = exp_output.replace(">", "") + exp_output = exp_output.replace("\"", "") + exp_output = exp_output.replace("\'", "") + + start_time = int(r[idx2+1]) + + idx2 = r.index(">Stop Time<") + stop_time = int(r[idx2+1]) + + idx2 = r.index(">Target Time Min<") + target_time_min = int(r[idx2+1]) + + idx2 = r.index(">Target Time Max<") + target_time_max = int(r[idx2+1]) + + if debug: + print("=================") + print(f"[Program output] {prog_output}") + print(f"[Expected output] {exp_output}") + print(f"[Start time] {start_time}") + print(f"[Stop time] {stop_time}") + print(f"[Target time min] {target_time_min}") + print(f"[Target time max] {target_time_max}") + + time_used = stop_time - start_time + if time_used > target_time_max or time_used < target_time_min: + cmts.add(f"Time limit exceed {t.name}(check wait impl)") + continue + + if prog_output != exp_output: + cmts.add(f"Wrong output {t.name}") + continue + + grade += grade_per + except: + if DEBUG: + print(traceback.format_exc()) + cmts.add("Cannot parse assignment log - likely an error in your assignment. Ensure that your shell is correctly formated.") + + return (f"{t_type} Tests", grade, ",".join(cmts)) + +def basic(tests, helpers): + return mark(tests, helpers, TYPE_BASIC, BASIC_GRADE_PER, DEBUG) + +def stderr(tests, helpers): + return mark(tests, helpers, TYPE_STDERR, STDERR_GRADE_PER, DEBUG) + +def batch(tests, helpers): + return mark(tests, helpers, TYPE_BATCH, BATCH_GRADE_PER, DEBUG) + + +RUBRIC = { + basic: BASIC_GRADE_PER * BASIC_NUM, + stderr: STDERR_GRADE_PER * STDERR_NUM, + batch: BATCH_GRADE_PER * BATCH_NUM +}