Skip to content

Instantly share code, notes, and snippets.

@jdavis
Last active December 16, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdavis/5428033 to your computer and use it in GitHub Desktop.
Save jdavis/5428033 to your computer and use it in GitHub Desktop.
Set of simple tests for the second project of Computer Science 352 at Iowa State University.
#!/usr/bin/env sh
#
# Project 2 Tests
# Josh Davis
#
# Overview:
# A few quick and crude tests for project 2.
#
# Running:
# To run it, make sure it has the right permissions:
# chmod u+x test.sh
# Next just execute it:
# ./test.sh
#
# Output:
# If the output matches up with the tests, you should only see the following
# output:
# Running Test One...
# Test passed.
# Running Test Two...
# Test passed.
# Running Test Three...
# Test passed.
# Running Test Four...
# Test passed.
# Running Test Five...
# Test passed.
#
# A failed test will output the diff of what it should be and what it
# actually was.
#
checkResult() {
RESULT=$(diff tempShould.txt tempActual.txt)
if [[ "$RESULT" != "" ]]; then
echo Test failed.
echo
echo Should be:
cat tempShould.txt
echo Actually is:
cat tempActual.txt
echo
else
echo Test passed.
fi
}
if [ ! -f rw_test ]; then
echo Could not find ./rw_test, are you sure you have it compiled?
exit
fi
# Test One
echo Running Test One: ./rw_test 3 0 1 0 1...
cat >tempShould.txt <<- EOF
Reader thread 0 enters CS.
Reader thread 0 is exiting CS.
Writer thread 1 enters CS.
Writer thread 1 is exiting CS.
Reader thread 2 enters CS.
Reader thread 2 is exiting CS.
EOF
./rw_test 3 0 1 0 1 > tempActual.txt
checkResult
# Test Two
echo Running Test Two: ./rw_test 3 0 0 1 1...
cat >tempShould.txt <<- EOF
Reader thread 0 enters CS.
Reader thread 1 enters CS.
Reader thread 0 is exiting CS.
Reader thread 1 is exiting CS.
Writer thread 2 enters CS.
Writer thread 2 is exiting CS.
EOF
./rw_test 3 0 0 1 1 > tempActual.txt
checkResult
# Test Three
echo Running Test Three: ./rw_test 3 1 0 0 1...
cat >tempShould.txt <<- EOF
Writer thread 0 enters CS.
Writer thread 0 is exiting CS.
Reader thread 1 enters CS.
Reader thread 2 enters CS.
Reader thread 1 is exiting CS.
Reader thread 2 is exiting CS.
EOF
./rw_test 3 1 0 0 1 > tempActual.txt
checkResult
# Test Four
echo Running Test Four: ./rw_test 5 0 0 1 1 0 1...
cat >tempShould.txt <<- EOF
Reader thread 0 enters CS.
Reader thread 1 enters CS.
Reader thread 0 is exiting CS.
Reader thread 1 is exiting CS.
Writer thread 2 enters CS.
Writer thread 2 is exiting CS.
Writer thread 3 enters CS.
Writer thread 3 is exiting CS.
Reader thread 4 enters CS.
Reader thread 4 is exiting CS.
EOF
./rw_test 5 0 0 1 1 0 1 > tempActual.txt
checkResult
# Test Five
echo Running Test Five: ./rw_test 5 0 0 1 0 1 1...
cat >tempShould.txt <<- EOF
Reader thread 0 enters CS.
Reader thread 1 enters CS.
Reader thread 0 is exiting CS.
Reader thread 1 is exiting CS.
Writer thread 2 enters CS.
Writer thread 2 is exiting CS.
Writer thread 4 enters CS.
Writer thread 4 is exiting CS.
Reader thread 3 enters CS.
Reader thread 3 is exiting CS.
EOF
./rw_test 5 0 0 1 0 1 1 > tempActual.txt
checkResult
rm -f tempActual.txt
rm -f tempShould.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment