[SOLVED] CS Java mips assembly #! /bin/bash

30 $

File Name: CS_Java_mips_assembly_#!_/bin/bash.zip
File Size: 320.28 KB

5/5 - (1 vote)

#! /bin/bash

# Occasionally, students use UTF-8 characters in their source code (usually
# without knowing it).We might as well support it.
export LC_ALL=en_US.UTF-8

# Java figures out the proper student .java files that are required but we
# need a little help for C and assembly.If you leave either of these blank,
# then this type of testing simply wont work.
C_SRC=
S_SRC=asm2.s

JAVA_SRCS=$(ls -1 *.java 2>/dev/null | grep -v -i -E ^Test_ | grep -v -E Base.java$)
if [[ $JAVA_SRCS != ]]
then
echo Compiling all of the Java sources your code, plus all of the testcases
javac *.java
fi

if [[ ${S_SRC} != ]]
then
if [[ ! -f Mars4.5la.jar ]]
then
echo Cannot find the Mars JAR file Mars4.5la.jar.Please copy the JAR file into the same directoy as the grading script and name it Mars4.5la.jar .
exit 1
fi
fi

attempts=0
pass=0

# this variable can be increased, to apply various penalties for breaking
# the rules!
penaltyDivisor=1

failList=

# if we have C or Java sources, check for any + operators in it but make
# sure to exclude testcases.
if [[ ${C_SRC} != || ${JAVA_SRCS} != ]]
then
if [[ $(grep -E [^+][+][^+] ${C_SRC} ${JAVA_SRCS}) != ]]
then
echo
echo ERROR: The grading script found that you used + or += in your C or Java code your grade will be cut in half.

echo BEGIN MATCHED LINES
grep -E [^+][+][^+] ${C_SRC} ${JAVA_SRCS}
echo END MATCHED LINES

penaltyDivisor=$(( penaltyDivisor*2 ))
fi
fi

if [[ ${S_SRC} != ]]
then
if [[ ! -x mips_checker.pl ]]
then
echo ERROR: The script mips_checker.pl either is not in the current directory, or is not executable.Please fix this.Until you do, this script will cut your score in half.

penaltyDivisor=$(( penaltyDivisor*2 ))
elif [[ $(./mips_checker.pl < ${S_SRC} 2>&1) != ]]
then
echo ERROR: mips_checker.pl reported some invalid instructions in your program your grade will be cut in half.
echo BEGIN mips_checker.pl
./mips_checker.pl < ${S_SRC} 2>&1
echo END mips_checker.pl

penaltyDivisor=$(( penaltyDivisor*2 ))
fi
fi

echo
echo ************* Running the testcases *************
echo

for TESTCASE in $(ls -1 Test_*.java test_*.[cs] 2>/dev/null)
do
attempts=$(( attempts+1 ))

BASE=$(echo $TESTCASE | rev | cut -f2- -d. | rev)
TYPE=$(echo $TESTCASE | rev | cut -f1-d. | rev)

if [[ ! -f $BASE.out ]]
then
echo ******************************
echo * TESTCASE $TESTCASE FAILED
echo ******************************
echo ERROR: The testcase file $TESTCASE was found, but could not find a matching output file $BASE.out’

failList=$failList
* $TESTCASE
continue
fi

# how long is the output example?Well use this to calculate exactly how
# much output well save.
lines=$(wc -l $BASE.out | awk {print $1})
lines=$(( lines*2 + 10 ))

# run the testcase.Save the file into a temporary file.Of course, each
# different type of testcase is run in a different way.
if [[ $TYPE = s ]]
then
# we use head and tail to remove the stuff that Mars adds to the program
# (2 lines at the head, 1 at the tail).We then, later, use *ANOTHER*
# head operation to limit user data if the user generates far too much
# data.
#
# BUGFIX: grep out lines which are printed by Mars on Windows.Irritating.
timeout 15s java -jar Mars4.5la.jar sm ${S_SRC} $BASE.s 2>$BASE.stderr.unfiltered | cut -c-1000 | tail -n+3 | head -n-1 | head -n$lines > $BASE.student_output

# BUGFIX ON THE BUGFIX: Not all bash installs support the redirection
# syntax I used.Do something simpler.
cat $BASE.stderr.unfiltered | grep -v java.util.prefs.WindowsPreferences | grep -v Could not open/create prefs > $BASE.stderr
rm $BASE.stderr.unfiltered

elif [[ $TYPE = java ]]
then
timeout 15s java $BASE 2>$BASE.stderr | cut -c-1000 | head -n$lines > $BASE.student_output

elif [[ $TYPE = c ]]
then
echo Compiling the testcase $TESTCASE, and linking it to ${C_SRC}
gcc -g -std=gnu99 ${C_SRC} $BASE.c -o $BASE

RC=$?
if [[ $RC != 0 ]]
then
echo
echo ******************************
echo * TESTCASE $TESTCASE FAILED
echo ******************************
echo ERROR: The compilation process had a non-zero return code $RC.

continue
fi

{
timeout 5s ./$BASE >(cut -c-1000 | head -n$lines) 2>$BASE.stderr

RC=$?
if [[ $RC != 0 ]]
then
echo
echo ERROR return code was: $RC
fi
} > $BASE.student_output

else
echo ERROR: The file extension $TYPE is not a recognized testcase type. | tee $BASE.student_output

failList=$failList
* $TESTCASE
continue
fi

if [[ -s $BASE.stderr || $(diff $BASE.student_output $BASE.out 2>&1) != ]]
then
echo ******************************
echo * TESTCASE $TESTCASE FAILED
echo ******************************
echo

if [[ -s $BASE.stderr ]]
then
echo stderr
cat $BASE.stderr
echo END stderr
else
rm $BASE.stderr

echo diff OUTPUT
diff $BASE.out $BASE.student_output
echo END diff
echo
fi

failList=$failList
* $TESTCASE

else
echo ******************************
echo * Testcase $TESTCASE passed
echo ******************************

rm $BASE.student_output $BASE.stderr
pass=$(( pass+1 ))

echo
fi
done

MAX_AUTO_SCORE=70

echo
echo *******************************************
echo *OVERALL REPORT
echo * attempts: $attempts
echo * passed: $pass
echo *

if [[ $penaltyDivisor != 1 ]]
then
echo * penaltyDivisor: $penaltyDivisor(see above)
fi

echo * score:$(( MAX_AUTO_SCORE * pass / attempts / penaltyDivisor ))
echo *(out of $MAX_AUTO_SCORE possible)

if [[ $failList != ]]
then
echo *
echo * failed:$failList
echo *
fi

echo *******************************************

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS Java mips assembly #! /bin/bash
30 $