#!/usr/bin/env bash # GRADER for phase2, p2 CSCI 311 Spring 2006 # assumes: (1) that tests/ is one level higher # (2) the script is placed into the same directory # as the student directories # (3) students do not put their files into sub directories # to do: no protection against programs that hang exec_name=btree start_dir=`pwd` # student directories are up two levels, pwd=student diretory test_dir=../../tests COMPILE_POINTS=1 POINTS_FOR_TESTS=1 # if a single student directory is given from the command line # else grade all students if [ $# != 0 ] then student_directories=$@ else # count ONLY directories student_directories=`ls -F | grep \/` fi cat << END /////////////////////////////////////////////////////////// // `date | awk '{"print $1 $2 $3, $6"}'` phase1// /////////////////////////////////////////////////////////// END echo $student_directories rm -f phase1_p2_grade.csv echo "user,name,secret_id,compile,\ t01,t02,t03,t04,t05,t06,t07,\ _t01,_t02,_t03,_t04,_t05,_t06,_t07,\ ,total,files,lines,COMMENT" >> phase1_p2_grade.csv for student in $student_directories do echo -n "$student: " student=`echo $student | sed -e 's/.$//' 2> /dev/null` grade=`grep ^$student students.lst` echo `grep ^$student students.lst` points=0; # pwd will be inside the students directory if cd $student then # count the number of files num_of_files=0; for cur_file in `ls *.h *.cpp *akefile 2> /dev/null` do (( num_of_files++ )) done # count the number of lines num_of_lines=`wc -l *.h *.cpp *akefile 2> /dev/null | awk '/total/ {print $1}' 2> /dev/null` # remove old output files if any rm -f *.temp_out *.o btree # compile and then run the tests if make >& /dev/null && file $exec_name >& /dev/null then grade=${grade},$COMPILE_POINTS points=`expr $COMPILE_POINTS + $points` for test_file in $test_dir/t0[0-7]; do student_file=`basename $test_file` echo -n "$student_file " ./$exec_name < $test_file > $student_file.temp_out 2> /dev/null if diff $student_file.temp_out ${test_file}.out >& /dev/null; then echo "passed" grade=${grade},$POINTS_FOR_TESTS points=`expr $POINTS_FOR_TESTS + $points` else echo "failed" grade=${grade},0 fi done for test_file in $test_dir/_t0[0-7]; do student_file=`basename $test_file` echo -n "$student_file " ./$exec_name < $test_file > $student_file.temp_out 2> /dev/null if diff $student_file.temp_out ${test_file}.out >& /dev/null; then echo "passed" grade=${grade},$POINTS_FOR_TESTS points=`expr $POINTS_FOR_TESTS + $points` else echo "failed" grade=${grade},0 fi done # clean up rm -f *.o btree >& /dev/null else # no executable echo "$student has no executable built" # 0 points for compilation grade=${grade},0 # assign zero for each test for test_file in $test_dir/t0[0-7] $test_dir/_t0[0-7] do grade=${grade},0 done fi #add on the points #points=`expr $points / 3` grade=${grade},$points #add on the number of files grade=${grade},$num_of_files #add on the number of lines grade=${grade},$num_of_lines else echo "wtf: can't cd to student directory: $student" fi # add the comment file if [ -f COMMENT ]; then grade=${grade},`cat COMMENT` else grade="${grade},NO COMMENT" fi cd $start_dir # write to the file echo $grade >> phase1_p2_grade.csv done