-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts to run mutation and unit tests.
- Loading branch information
Showing
7 changed files
with
191 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
PREPROC="$SCRIPT_DIR/preproc_tut" | ||
|
||
CC="gcc" | ||
# -P: do not emit line pragmas | ||
# -CC: do not discard comments | ||
CPP="$CC -E -P -CC" | ||
|
||
CN="cn" | ||
CN_INSTALL="$OPAM_SWITCH_PREFIX/lib/cn/runtime" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This file show how we envision using the preprocessor. | ||
#define S 11111111 | ||
|
||
int puts(const char*); | ||
|
||
int some_other_fun(int x) | ||
/*@ requires true; ensures return == 1i32; @*/ | ||
{ | ||
return 0; | ||
} | ||
|
||
int inc(int x) | ||
/*@ requires 0i32 <= x && x < 10i32; ensures return < 11i32; @*/ | ||
{ | ||
#if !MUTATION(inc) | ||
return x + 1; | ||
#elif X_PLUS_2 | ||
return x + 2; | ||
#elif X_PLUS_3 | ||
return x + 3; | ||
#endif | ||
} | ||
|
||
|
||
#if CN_TEST_A | ||
int main(int argc, char* argv[]) { | ||
return inc(S); | ||
} | ||
#endif | ||
|
||
#if CN_TEST_B | ||
int main(int argc, char* argv[]) { | ||
return inc(5); | ||
} | ||
#endif | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 1 ]; then | ||
echo "USAGE: $0 CFILE" | ||
echo " Run all unit tests and mutants in a single C file." | ||
exit 1 | ||
fi | ||
|
||
FILE="$1" | ||
|
||
SCRIPT_DIR="$(dirname $0)" | ||
source "$SCRIPT_DIR/config" | ||
|
||
for UNIT_TEST in $($PREPROC --list-unit < "$FILE"); do | ||
echo $UNIT_TEST | ||
$SCRIPT_DIR/run-unit-test "$FILE" "$UNIT_TEST" | ||
done | ||
|
||
for MUTANT in $($PREPROC --list-mutants < "$FILE"); do | ||
echo $MUTANT | ||
$SCRIPT_DIR/run-mutant "$FILE" "$MUTANT" | ||
done | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "USAGE: $0 CFILE FUN_QUALIFIED_MUTANT_NAME" | ||
echo " Preprocess, and test a single mutant in a single C file." | ||
exit 1 | ||
fi | ||
|
||
SCRIPT_DIR="$(dirname $0)" | ||
source "$SCRIPT_DIR/config" | ||
|
||
CFILE="$1" | ||
FUN=$(dirname "$2") | ||
UNIT_TEST=$(basename "$2") | ||
|
||
OUT_DIR=$(mktemp -d /tmp/cn-run-mutant-XXXXXX) | ||
trap "rm -rf $OUT_DIR" EXIT | ||
|
||
cat "$CFILE" | $PREPROC --show-mutant "$UNIT_TEST" > "$OUT_DIR/$UNIT_TEST.c" | ||
|
||
pushd "$OUT_DIR" | ||
$CPP "$UNIT_TEST.c" > "$UNIT_TEST.i" | ||
mv "$UNIT_TEST.i" "$UNIT_TEST.c" | ||
$CN test "$UNIT_TEST.c" --output-dir=. --only="$FUN" --seed=0 > /dev/null | ||
RESULT=$? | ||
popd | ||
exit $RESULT | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "USAGE: $0 CFILE UNIT_TEST_NAME" | ||
echo " Preprocess, and build, a single test in a single C file." | ||
exit 1 | ||
fi | ||
|
||
SCRIPT_DIR="$(dirname $0)" | ||
source "$SCRIPT_DIR/config" | ||
|
||
CFILE="$1" | ||
UNIT_TEST="$2" | ||
|
||
OUT_DIR=$(mktemp -d /tmp/cn-run-unit-test-XXXXXX) | ||
trap "rm -rf $OUT_DIR" EXIT | ||
|
||
cat "$CFILE" | $PREPROC --show-unit "$UNIT_TEST" > "$OUT_DIR/$UNIT_TEST.c" | ||
|
||
pushd "$OUT_DIR" | ||
$CPP "$UNIT_TEST.c" > "$UNIT_TEST.i" | ||
mv "$UNIT_TEST.i" "$UNIT_TEST.c" | ||
$CN instrument --fail-fast "$UNIT_TEST.c" | ||
$CC -I "$CN_INSTALL/include" -L "$CN_INSTALL" \ | ||
"$UNIT_TEST-exec.c" -lcn -o "$UNIT_TEST" | ||
"./$UNIT_TEST" | ||
popd | ||
|
||
|
||
|