Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Dec 28, 2014
1 parent 68a5b16 commit 571a348
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*.sdf
*.status
*.tar.*
*.gcov
*.gcda
*.gcno
*.html
*~
.DS_Store
.deps
Expand Down
37 changes: 37 additions & 0 deletions .jenkins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

result=0

function run_test {
printf '\e[0;36m'
echo "running test: $command $@"
printf '\e[0m'

$command "$@"
status=$?
if [ $status -ne 0 ]; then
printf '\e[0;31m'
echo "test failed: $command $@"
printf '\e[0m'
echo
result=1
else
printf '\e[0;32m'
echo OK
printf '\e[0m'
echo
fi
return 0
}

run_test ./autogen.sh
run_test ./configure --enable-debug
run_test make
run_test tests/test.py tests/google.com
run_test tests/test.py tests/facebook.com
run_test tests/test.py tests/twitter.com

gcov src/*.c
cd src && gcovr -r . --html --html-details -o index.html

exit $result
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ compiler:
- gcc

before_script:
- pip install gcovr
- ./autogen.sh
- ./configure

script:
- make
- ./.jenkins.sh
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AC_CHECK_FUNCS([inet_ntoa memset select socket strchr strdup strrchr])

AC_ARG_ENABLE([debug],
[ --enable-debug build with additional debugging code],
[CFLAGS='-g -DDEBUG'])
[CFLAGS='-g -DDEBUG -fprofile-arcs -ftest-coverage -O0'])

AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")

Expand Down
10 changes: 10 additions & 0 deletions src/chinadns.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ static const char *help_message =

#ifdef DEBUG
#define DLOG(s...) LOG(s)
void __gcov_flush(void);
static void gcov_handler(int signum)
{
__gcov_flush();
exit(1);
}
#else
#define DLOG(s...)
#endif
Expand All @@ -165,6 +171,10 @@ int main(int argc, char **argv) {
fd_set readset, errorset;
int max_fd;

#ifdef DEBUG
signal(SIGTERM, gcov_handler);
#endif

memset(&id_addr_queue, 0, sizeof(id_addr_queue));
memset(&delay_queue, 0, sizeof(delay_queue));
if (0 != parse_args(argc, argv))
Expand Down
1 change: 1 addition & 0 deletions tests/facebook.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dig @127.0.0.1 a facebook.com
1 change: 1 addition & 0 deletions tests/google.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dig @127.0.0.1 a google.com
15 changes: 15 additions & 0 deletions tests/iplist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python

from subprocess import Popen, PIPE

if __name__ == '__main__':
result = set()
for i in range(400, 1400):
p = Popen((('dig +short @114.114.114.114 a '
'r%d-1.googlevideo.com') % i).split(),
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
output = p.stdout.read()
if output:
result.add(output.strip())
for r in result:
print r
34 changes: 34 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import os
import signal
import time
from subprocess import Popen

chinadns = ['src/chinadns', '-l', 'iplist.txt', '-c', 'chnroute.txt',
'-p', '15353', '-v']

p1 = Popen(chinadns, shell=False, bufsize=0, close_fds=True)

with open(sys.argv[-1]) as f:
dig_cmd = f.read()

time.sleep(1)

p2 = Popen(dig_cmd.split() + ['-p', '15353'], shell=False,
bufsize=0, close_fds=True)

if p2 is not None:
r = p2.wait()
if r == 0:
print 'test passed'

for p in [p1]:
try:
os.kill(p.pid, signal.SIGTERM)
except OSError:
pass

sys.exit(r)
1 change: 1 addition & 0 deletions tests/twitter.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dig @127.0.0.1 a twitter.com
1 change: 1 addition & 0 deletions tests/www.facebook.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dig @127.0.0.1 a www.facebook.com

0 comments on commit 571a348

Please sign in to comment.