Skip to content

Commit

Permalink
Add code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
albfan committed Nov 2, 2015
1 parent fd0f810 commit 2b69d16
Show file tree
Hide file tree
Showing 31 changed files with 231 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.gcno
*.gcda
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: c

compiler:
- clang
- gcc

env:
- CC_FLAGS="-O3 -Wall -std=c99 -D_BSD_SOURCE -D_XOPEN_SOURCE=500"
- COVERAGE=yes CC_FLAGS="-O3 -Wall --coverage -std=c99 -D_BSD_SOURCE -D_XOPEN_SOURCE=500"

before_install:
- pip install --user cpp-coveralls
- sudo apt-get update -qq
- sudo apt-get install -qq libc6-dev-i386

script:
- ./compile.sh
- cd t
- ./suite.sh
- cd ..

after_success:
- if [ x"$COVERAGE" = "xyes" ]; then ~/.local/bin/coveralls -b $PWD ; fi
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# fsnotifier
[![Coverage Status](https://coveralls.io/repos/albfan/fsnotifier/badge.svg?branch=master&service=github)](https://coveralls.io/github/albfan/fsnotifier?branch=master) [![Build Status](https://travis-ci.org/albfan/fsnotifier.svg?branch=master)](https://travis-ci.org/albfan/fsnotifier)

File watcher

Expand Down
12 changes: 12 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
COMPILER=clang
#COMPILER=gcc
echo "compiling 32-bit version"
$COMPILER -m32 $CC_FLAGS -o fsnotifier main.c inotify.c util.c
if [ $? -eq 0 ] ; then
echo "compiling 64-bit version"
$COMPILER -m64 $CC_FLAGS -o fsnotifier64 main.c inotify.c util.c
if [ $? -eq 0 ] ; then
chmod 755 fsnotifier fsnotifier64
fi
fi
3 changes: 3 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
export CC_FLAGS="-O3 -Wall --coverage -std=c99 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=500"
./compile.sh
10 changes: 1 addition & 9 deletions debug.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#!/bin/sh
CC_FLAGS="-O0 -g -Wall -std=c99 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=500"
echo "compiling 32-bit version"
clang -m32 $CC_FLAGS -o fsnotifier main.c inotify.c util.c
if [ $? -eq 0 ] ; then
echo "compiling 64-bit version"
clang -m64 $CC_FLAGS -o fsnotifier64 main.c inotify.c util.c
if [ $? -eq 0 ] ; then
chmod 755 fsnotifier fsnotifier64
fi
fi
./compile.sh
10 changes: 1 addition & 9 deletions make.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#!/bin/sh
CC_FLAGS="-O3 -Wall -std=c99 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=500"
echo "compiling 32-bit version"
clang -m32 $CC_FLAGS -o fsnotifier main.c inotify.c util.c
if [ $? -eq 0 ] ; then
echo "compiling 64-bit version"
clang -m64 $CC_FLAGS -o fsnotifier64 main.c inotify.c util.c
if [ $? -eq 0 ] ; then
chmod 755 fsnotifier fsnotifier64
fi
fi
./compile.sh
18 changes: 18 additions & 0 deletions report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# compile with coverage support
.coverage.sh

# run test suite
cd t
./suite.sh
cd ..

# txt report
gcov -abcfu *.c
#cat *.gcov

# html report
lcov --directory . --capture --output-file app.info
genhtml --output-directory cov_html app.info
#xdg-open cov_html/index.html
1 change: 1 addition & 0 deletions t/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test*.out
22 changes: 20 additions & 2 deletions t/suite.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/bin/bash

./test1.sh | sed 's+'$PWD'/++' > test1.out
function colorecho() {
echo -e "\x1b[$1m$2\x1b[m"
}

diff test1.ok test1.out
for test in $(ls test*.sh | sort --version-sort)
do
basename_test=$(basename ${test} .sh)
title=$(grep "###" $test | sed 's/^###\s*//')
tmpdir=$(mktemp -d "${basename_test}.XXX")
cd ${tmpdir}
../${test} | sed 's+'$PWD'/++' > ../${basename_test}.out
cd ..
rm -rf ${tmpdir}
diff ${basename_test}.ok ${basename_test}.out
if [ "$?" == 0 ]
then
echo $(colorecho 34 ${basename_test}) "${title}" $(colorecho 32 ok)
else
echo $(colorecho 34 ${basename_test}) "${title}" $(colorecho 31 ko)
fi
done
18 changes: 8 additions & 10 deletions t/test1.ok
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
UNWATCHEABLE
#
CREATE
test1/foo
foo
CHANGE
test1/foo
foo
STATS
test1/foo
foo
CHANGE
test1/foo
foo
DELETE
test1/foo
foo
CREATE
test1/bar
bar
CHANGE
test1/bar
bar
DELETE
test1/bar
DELETE
test1
bar
20 changes: 0 additions & 20 deletions t/test1.out

This file was deleted.

8 changes: 2 additions & 6 deletions t/test1.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@

trap 'kill $(jobs -p)' EXIT

mkdir test1
### basic operations

../fsnotifier64 --background --roots $PWD/test1 &
../../fsnotifier64 --background --roots $PWD &

sleep 1

cd test1
touch foo
echo foobar > foo
mv foo bar
rm bar

sleep 1

cd ..
rm -rf test1
1 change: 1 addition & 0 deletions t/test10.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fsnotifier 20130715.1353
5 changes: 5 additions & 0 deletions t/test10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

### show --help

../../fsnotifier64 --version

10 changes: 10 additions & 0 deletions t/test2.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
UNWATCHEABLE
#
UNWATCHEABLE
#
UNWATCHEABLE
#
UNWATCHEABLE
#
UNWATCHEABLE
#
12 changes: 12 additions & 0 deletions t/test2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

trap 'kill $(jobs -p)' EXIT

### log level configuration

../../fsnotifier64 --background --roots $PWD --log-level debug &
../../fsnotifier64 --background --roots $PWD --log-level info &
../../fsnotifier64 --background --roots $PWD --log-level warning &
../../fsnotifier64 --background --roots $PWD --log-level error &
../../fsnotifier64 --background --roots $PWD --log-level off &

sleep 3
8 changes: 8 additions & 0 deletions t/test3.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
info: started (self-test mode) (v.20130715.1353)
debug: inotify fd: 4
info: updating roots (curr:0, new:1)
info: registering root:
debug: watching : 1
info: unregistering root:
debug: unwatching : 1 ()
info: finished (0)
10 changes: 10 additions & 0 deletions t/test3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

### self test

../../fsnotifier64 --selftest |& \
sed 's/^fsnotifier\[[0-9]\+\] //' | \
sed 's+'$PWD'++' | \
sed 's+\(debug: unwatching : 1 (\).*)+\1)+' | \
sed '/mtab/d' | \
sed '/inotify watch descriptors/d'

2 changes: 2 additions & 0 deletions t/test4.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unrecognized option: --wrong-option
Try 'fsnotifier --help' for more information.
4 changes: 4 additions & 0 deletions t/test4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### wrong options

../../fsnotifier64 --wrong-option &
1 change: 1 addition & 0 deletions t/test5.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
running in background needs the --roots option to be set
4 changes: 4 additions & 0 deletions t/test5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### --background option needs --roots option

../../fsnotifier64 --background &
2 changes: 2 additions & 0 deletions t/test6.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unrecognized option: background
Try 'fsnotifier --help' for more information.
4 changes: 4 additions & 0 deletions t/test6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### watch / is not allowed

../../fsnotifier64 --roots / background &
8 changes: 8 additions & 0 deletions t/test7.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
UNWATCHEABLE
#
DELETE
temp/temp
CREATE
temp/temp
CHANGE
temp/temp
16 changes: 16 additions & 0 deletions t/test7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

trap 'kill $(jobs -p)' EXIT

### remove and restore root

mkdir -p temp/temp

../../fsnotifier64 --background --roots $PWD/temp/temp --log-level debug &

sleep 2

rmdir temp/temp
mkdir temp/temp

sleep 2

3 changes: 3 additions & 0 deletions t/test8.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UNWATCHEABLE
#
RESET
17 changes: 17 additions & 0 deletions t/test8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

trap 'kill $(jobs -p)' EXIT

### reset event

mkdir mnt
sudo mount -ttmpfs none mnt

../../fsnotifier64 --background --roots $PWD/mnt --log-level debug &

sleep 2

sudo fuser -vm mnt
sudo umount -f mnt

sleep 2

27 changes: 27 additions & 0 deletions t/test9.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fsnotifier - IntelliJ IDEA companion program for watching and reporting file and directory structure modifications.

fsnotifier utilizes "user" facility of syslog(3) - messages usually can be found in /var/log/user.log.
Verbosity is regulated via FSNOTIFIER_LOG_LEVEL environment variable, possible values are: debug, info, warning, error, off; default is warning.

Options:
--selftest perform some self-diagnostics (output will be logged and printed to console).
--log-level Explicit set of log level.
--roots Paths to inspect. Values separated by comma. Relative or absolute.
--background execute in background. Do not read input.
--version fsnotifier version.
--help Show this help.

Usage:
$ ./fsnotifier
ROOTS
<path to watch>
#

From here file changes comes as a two line events

EVENT
file/path/changed

Events:
CREATE, CHANGE, STATS, DELETE, RESET

5 changes: 5 additions & 0 deletions t/test9.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

### show --help

../../fsnotifier64 --help

0 comments on commit 2b69d16

Please sign in to comment.