Removed submodules
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#
|
||||
# Simple Test Makefile
|
||||
# Mike Lam, James Madison University, August 2016
|
||||
#
|
||||
# This version of the Makefile includes support for building a test suite. The
|
||||
# recommended framework is Check (http://check.sourceforge.net/). To build and
|
||||
# run the test suite, execute the "test" target. The test suite must be located
|
||||
# in a module called "testsuite". The MODS, LIBS, and OBJS variables work as
|
||||
# they do in the main Makefile.
|
||||
#
|
||||
# To change the default build target (which executes when you just type
|
||||
# "make"), change the right-hand side of the definition of the "default"
|
||||
# target.
|
||||
#
|
||||
# By default, this makefile will build the project with debugging symbols and
|
||||
# without optimization. To change this, edit or remove the "-g" and "-O0"
|
||||
# options in CFLAGS and LDFLAGS accordingly.
|
||||
#
|
||||
# By default, this makefile build the application using the GNU C compiler,
|
||||
# adhering to the C99 standard with all warnings enabled.
|
||||
|
||||
|
||||
# application-specific settings and run target
|
||||
|
||||
EXE=../fsm
|
||||
TEST=testsuite
|
||||
MODS=public.o
|
||||
OBJS=../model.o ../effects.o private.o
|
||||
LIBS=
|
||||
|
||||
UTESTOUT=utests.txt
|
||||
ITESTOUT=itests.txt
|
||||
SCHECKOUT=style.txt
|
||||
|
||||
default: $(TEST)
|
||||
|
||||
$(EXE):
|
||||
make -C ../
|
||||
|
||||
test: utest itest style
|
||||
@echo "========================================"
|
||||
|
||||
utest: $(EXE) $(TEST)
|
||||
@echo "========================================"
|
||||
@echo " UNIT TESTS"
|
||||
@./utests.sh | tee $(UTESTOUT)
|
||||
|
||||
itest: $(EXE)
|
||||
@echo "========================================"
|
||||
@echo " INTEGRATION TESTS"
|
||||
@./integration.sh | tee $(ITESTOUT)
|
||||
|
||||
style: $(EXE)
|
||||
@echo "========================================"
|
||||
@echo " CODING STYLE CHECK"
|
||||
@./style.sh 2>/dev/null >$(SCHECKOUT)
|
||||
@cat $(SCHECKOUT)
|
||||
|
||||
# compiler/linker settings
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O0 -Wall --std=c99
|
||||
LDFLAGS=-g -O0
|
||||
|
||||
#CFLAGS+=-I/opt/local/include -Wno-gnu-zero-variadic-macro-arguments
|
||||
#CFLAGS+=-Wno-gnu-zero-variadic-macro-arguments
|
||||
#LDFLAGS+=-L/opt/local/lib
|
||||
#LDFLAGS=
|
||||
LIBS+=-lcheck -lm -lpthread
|
||||
|
||||
ifeq ($(shell uname -s),Linux)
|
||||
LIBS+=-lrt -lsubunit
|
||||
endif
|
||||
|
||||
|
||||
# build targets
|
||||
|
||||
$(TEST): $(TEST).o $(MODS) $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $(TEST) $^ $(LIBS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
clean:
|
||||
rm -rf $(TEST) $(TEST).o $(MODS) $(UTESTOUT) $(ITESTOUT) $(SCHECKOUT) outputs valgrind ckstyle
|
||||
|
||||
.PHONY: default clean test unittest inttest
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
015ebe95460b1d6fbf79df280ec3ae5fab362ae8
|
||||
@@ -0,0 +1 @@
|
||||
42ae8f1bdf52b57ad234791690bf611379fc8249
|
||||
@@ -0,0 +1 @@
|
||||
ebc846cda2557a05e691ef4d7dc7de4ee312cbd1
|
||||
@@ -0,0 +1 @@
|
||||
2fd3754d04e83c387269e26d81186b290d299f82
|
||||
@@ -0,0 +1 @@
|
||||
17611b03d098cb2d095ddac6dc39c08f66514f4e
|
||||
@@ -0,0 +1 @@
|
||||
10b932ebcb7ca5600c9b81652547ea3721854698
|
||||
@@ -0,0 +1,2 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
@@ -0,0 +1,4 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
[Command.NEWLINE -> Term]
|
||||
Execute ls with arguments { ls, (null) }
|
||||
@@ -0,0 +1,8 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
[Command.TOKEN -> Arguments]
|
||||
Appending -a to the argument list
|
||||
[Arguments.TOKEN -> Arguments]
|
||||
Appending -l to the argument list
|
||||
[Arguments.NEWLINE -> Term]
|
||||
Execute ls with arguments { ls, -a, -l, (null) }
|
||||
@@ -0,0 +1,6 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
[Command.TOKEN -> Arguments]
|
||||
Appending data to the argument list
|
||||
[Arguments.NEWLINE -> Term]
|
||||
Execute ls with arguments { ls, data, (null) }
|
||||
@@ -0,0 +1,9 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
[Command.PIPE -> Make_Pipe]
|
||||
Set up pipe
|
||||
Execute ls with arguments { ls, (null) }
|
||||
[Make_Pipe.TOKEN -> Command]
|
||||
Starting new command: head
|
||||
[Command.NEWLINE -> Term]
|
||||
Execute head with arguments { head, (null) }
|
||||
@@ -0,0 +1,15 @@
|
||||
[Init.TOKEN -> Command]
|
||||
Starting new command: ls
|
||||
[Command.TOKEN -> Arguments]
|
||||
Appending -l to the argument list
|
||||
[Arguments.PIPE -> Make_Pipe]
|
||||
Set up pipe
|
||||
Execute ls with arguments { ls, -l, (null) }
|
||||
[Make_Pipe.TOKEN -> Command]
|
||||
Starting new command: head
|
||||
[Command.TOKEN -> Arguments]
|
||||
Appending -n to the argument list
|
||||
[Arguments.TOKEN -> Arguments]
|
||||
Appending 1 to the argument list
|
||||
[Arguments.NEWLINE -> Term]
|
||||
Execute head with arguments { head, -n, 1, (null) }
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
EXE="../shell"
|
||||
|
||||
function run_test {
|
||||
|
||||
# parameters
|
||||
TAG=$1
|
||||
ARGS=$2
|
||||
|
||||
# file paths
|
||||
OUTPUT=outputs/$TAG.txt
|
||||
DIFF=outputs/$TAG.diff
|
||||
EXPECT=expected/$TAG.txt
|
||||
VALGRND=valgrind/$TAG.txt
|
||||
|
||||
# print tag format
|
||||
PTAG=$(printf '%-30s' "$TAG")
|
||||
|
||||
# check for expected text that needs to be fixed
|
||||
if [ ! -z "$(egrep "<<<<.*>>>>" "$EXPECT")" ] ; then
|
||||
echo "$PTAG FAIL ($EXPECT not correct)"
|
||||
return
|
||||
fi
|
||||
|
||||
# compare the file
|
||||
SHAOUT=$(shasum "$EXPECT" | awk '{print $1}')
|
||||
SHAEXP=$(cat "expected/.$TAG.sha")
|
||||
if [ "$SHAOUT" != "$SHAEXP" ] ; then
|
||||
echo "$PTAG FAIL ($EXPECT not correct)"
|
||||
return
|
||||
fi
|
||||
|
||||
# run test and compare output to the expected version
|
||||
$EXE "$ARGS" 2>/dev/null >"$OUTPUT"
|
||||
diff -u "$OUTPUT" "$EXPECT" >"$DIFF"
|
||||
if [ -s "$DIFF" ]; then
|
||||
|
||||
# try alternative solution (if it exists)
|
||||
EXPECT=expected/$TAG-2.txt
|
||||
if [ -e "$EXPECT" ]; then
|
||||
diff -u "$OUTPUT" "$EXPECT" >"$DIFF"
|
||||
if [ -s "$DIFF" ]; then
|
||||
echo "$PTAG FAIL (see $DIFF for details)"
|
||||
else
|
||||
echo "$PTAG pass"
|
||||
fi
|
||||
else
|
||||
echo "$PTAG FAIL (see $DIFF for details)"
|
||||
fi
|
||||
else
|
||||
echo "$PTAG pass"
|
||||
fi
|
||||
|
||||
# run valgrind
|
||||
valgrind $EXE $ARGS &>$VALGRND
|
||||
}
|
||||
|
||||
# initialize output folders
|
||||
mkdir -p outputs
|
||||
mkdir -p valgrind
|
||||
rm -f outputs/* valgrind/*
|
||||
|
||||
# run individual tests
|
||||
source itests.include
|
||||
|
||||
# check for memory leaks
|
||||
LEAK=`cat valgrind/*.txt | grep 'definitely lost' | grep -v ' 0 bytes in 0 blocks'`
|
||||
if [ -z "$LEAK" ]; then
|
||||
echo "No memory leak found."
|
||||
else
|
||||
echo "Memory leak(s) found. See files listed below for details."
|
||||
grep 'definitely lost' valgrind/*.txt | grep -v ' 0 bytes in 0 blocks' | sed -e 's/:.*$//g' | sed -e 's/^/ - /g'
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# list of integration tests
|
||||
# format: run_test <TAG> <ARGS>
|
||||
# <TAG> used as the root for all filenames (i.e., "expected/$TAG.txt")
|
||||
# <ARGS> command-line arguments to test
|
||||
|
||||
run_test INTEG_command "ls"
|
||||
run_test INTEG_execute "ls NL"
|
||||
run_test INTEG_execute_name "ls data NL"
|
||||
run_test INTEG_execute_flags "ls -a -l NL"
|
||||
run_test INTEG_pipe "ls | head NL"
|
||||
run_test INTEG_pipe_flags "ls -l | head -n 1 NL"
|
||||
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include "../effects.h"
|
||||
#include "../model.h"
|
||||
|
||||
/* nothing but starting a new cmdline */
|
||||
START_TEST (UNIT_new_cmdline)
|
||||
{
|
||||
printf ("\n======================================\n");
|
||||
printf ("UNIT TEST: new_cmdline\n\n");
|
||||
|
||||
fsm_t *fsm = cmdline_init ();
|
||||
assert (fsm != NULL);
|
||||
|
||||
handle_event (fsm, TOKEN);
|
||||
ck_assert_int_eq (fsm->state, Command);
|
||||
|
||||
free (fsm);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* a single cmdline from NEW to TRM */
|
||||
START_TEST (UNIT_exec_cmd)
|
||||
{
|
||||
printf ("\n======================================\n");
|
||||
printf ("UNIT TEST: exec_cmd\n\n");
|
||||
|
||||
fsm_t *fsm = cmdline_init ();
|
||||
assert (fsm != NULL);
|
||||
|
||||
handle_event (fsm, TOKEN);
|
||||
ck_assert_int_eq (fsm->state, Command);
|
||||
|
||||
handle_event (fsm, NEWLINE);
|
||||
ck_assert_int_eq (fsm->state, Term);
|
||||
|
||||
free (fsm);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void public_tests (Suite *s)
|
||||
{
|
||||
TCase *tc_public = tcase_create ("Public");
|
||||
tcase_add_test (tc_public, UNIT_new_cmdline);
|
||||
tcase_add_test (tc_public, UNIT_exec_cmd);
|
||||
suite_add_tcase (s, tc_public);
|
||||
}
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
STYLE="gnu"
|
||||
|
||||
IGNORE=()
|
||||
FAIL=0
|
||||
|
||||
function comp_file {
|
||||
|
||||
SRC=$1
|
||||
SRC_NAME=$2
|
||||
|
||||
# file paths
|
||||
FORMAT=ckstyle/${SRC_NAME}.$STYLE
|
||||
DIFF=ckstyle/${SRC_NAME}.diff
|
||||
|
||||
# run clang-format and compare results
|
||||
clang-format --style=$STYLE $source > $FORMAT
|
||||
diff -u $SRC $FORMAT >$DIFF
|
||||
|
||||
PTAG=$(printf '%-30s' "$SRC_NAME")
|
||||
if [ -s $DIFF ]; then
|
||||
echo "$PTAG FAIL (see $DIFF for details)"
|
||||
FAIL=1
|
||||
else
|
||||
echo "$PTAG pass"
|
||||
rm $DIFF
|
||||
fi
|
||||
rm $FORMAT
|
||||
}
|
||||
|
||||
mkdir -p ckstyle
|
||||
rm -f ckstyle/*
|
||||
|
||||
for source in $(ls ../*.c ../*.h) ; do
|
||||
SKIP=0
|
||||
src=$(basename $source)
|
||||
for ignore in ${IGNORE[*]} ; do
|
||||
if [ "$src" = "$ignore" ] ; then
|
||||
SKIP=1
|
||||
fi
|
||||
done
|
||||
if [ $SKIP = 0 ] ; then
|
||||
comp_file $source $src
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $FAIL != 0 ] ; then
|
||||
echo "Code that does not adhere to GNU standards will not be accepted."
|
||||
echo "You must fix these files before submission."
|
||||
else
|
||||
echo "Code correctly adheres to required style."
|
||||
fi
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
extern void public_tests (Suite *s);
|
||||
extern void private_tests (Suite *s);
|
||||
|
||||
Suite * test_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("Default");
|
||||
public_tests (s);
|
||||
private_tests (s);
|
||||
return s;
|
||||
}
|
||||
|
||||
void run_testsuite ()
|
||||
{
|
||||
Suite *s = test_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
srunner_free (sr);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
srand((unsigned)time(NULL));
|
||||
run_testsuite ();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
OUTPUT=utests.output
|
||||
|
||||
./testsuite > "$OUTPUT" 2>/dev/null
|
||||
|
||||
if [ ! -s "$OUTPUT" ] ; then
|
||||
echo "UNIT FAIL (testsuite produced no output)"
|
||||
rm -f "$OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat "$OUTPUT" | awk '/Failures/,0'
|
||||
|
||||
percent=$(cat "$OUTPUT" | grep Failures | cut -d':' -f1)
|
||||
rm -f "$OUTPUT"
|
||||
[ "$percent" = "100%" ] && exit 0
|
||||
|
||||
echo "(run ./testsuite in tests directory for more information)"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user