Skip to content

Commit

Permalink
Merge pull request pmem#18 from marcinslusarz/codecov
Browse files Browse the repository at this point in the history
Integrate codecov.io
  • Loading branch information
Sarah Jelinek authored Jun 13, 2017
2 parents e35acc3 + 4013c8e commit e0505d6
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 57 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
- MAKE_PKG=0 OS=ubuntu OS_VER=16.04
- MAKE_PKG=0 OS=fedora OS_VER=25
- COVERITY=1 OS=ubuntu OS_VER=16.04
- COVERAGE=1 OS=ubuntu OS_VER=16.04

before_install:
- export HOST_WORKDIR=`pwd`
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ option(BUILD_TESTS "build and enable tests" ON)
option(BUILD_EXAMPLES "build examples" ON)
option(TREAT_WARNINGS_AS_ERRORS
"make the build fail on any warnings during compilation, or linking" ON)
option(EXPECT_SPURIOUS_SYSCALLS
"account for some unexpected syscalls in tests - enable while using sanitizers, gcov" OFF)

set(SYSCALL_INTERCEPT_VERSION_MAJOR 0)
set(SYSCALL_INTERCEPT_VERSION_MINOR 1)
Expand Down
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ignore:
- utils/check_license/check-license.c
- src/cpp_compile_mock.c
- src/cpp_compile_test.cc
- examples/icap.c
- examples/fork_ban.c
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

# See: https://cmake.org/Wiki/CMake/Testing_With_CTest

if(EXPECT_SPURIOUS_SYSCALLS)
add_definitions(-DEXPECT_SPURIOUS_SYSCALLS)
endif()

find_package(Threads)

include_directories(${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/test)
Expand Down
10 changes: 5 additions & 5 deletions test/hook_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ main(int argc, char *argv[])
return EXIT_FAILURE;

magic_syscall_start_log(argv[2], "1");
assert(syscall(test_magic_syscall) == test_magic_syscall_result);

assert(write(1, dummy_data, sizeof(dummy_data)) == 7);
assert(write(1, "thing", 4) == 4);
assert(write(1, dummy_data, sizeof(dummy_data)) == 7);
assert(write(hook_test_fd, dummy_data, sizeof(dummy_data)) ==
hook_test_dummy_return_value);
assert(write(hook_test_fd, "thing", 4) == -1);
assert(write(hook_test_fd, dummy_data, sizeof(dummy_data)) ==
hook_test_dummy_return_value);

assert(syscall(test_magic_syscall) == test_magic_syscall_result);
magic_syscall_stop_log();

return EXIT_SUCCESS;
Expand Down
48 changes: 46 additions & 2 deletions test/hook_test_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,55 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* hook_test_data.h -- defines some symbols/values to be used in
* hook_test.c (making syscalls) and in hook_test_preload.c (intercepting those
* same syscalls). This file defines variables with internal linkage, and
* compiler wanrs if they are not used in a TU. This is ugly usually, but
* these are really meant to be used in the two other files source files
* mentioned above.
* This header is not meant to be used anywhere else.
*/

#ifndef INTERCEPT_HOOK_TEST_DATA_H
#define INTERCEPT_HOOK_TEST_DATA_H

#include <unistd.h>
#include <stdbool.h>

/* arbitrary fd, expected not to conflict with any valid fd */
static const int hook_test_fd = 8765;

static const char dummy_data[] = "dummy_data";
static const long test_magic_syscall = 9999;
static const long test_magic_syscall_result = 7777;

static const ssize_t hook_test_dummy_return_value = 5;

static inline bool
is_spurious_syscall(long syscall_number, long arg0)
{
#ifdef EXPECT_SPURIOUS_SYSCALLS

/*
* A filter function which is aware of syscall originating
* from ASAN, gcov, etc...
*
* In regulard builds, such filtering should not be applied, and
* the hook test should look at every syscall.
* The goal of insturmented builds is not to retest the same logic as
* the test do otherwise, but rather to execute the code with the
* instrumentation in place. Therefore, it is not a problem if
* the test just allows through pretty much any syscall here.
*/
return syscall_number != SYS_write || arg0 != hook_test_fd;

#else

/* regular testing, no syscalls ignored */
(void) syscall_number;
(void) arg0;
return false;

#endif
}

#endif
44 changes: 4 additions & 40 deletions test/hook_test_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
static int hook_counter;
static bool in_hook;
static bool deinit_called;
static bool during_test;

static int
hook(long syscall_number, long arg0, long arg1, long arg2, long *result)
Expand All @@ -62,48 +61,22 @@ hook(long syscall_number, long arg0, long arg1, long arg2, long *result)
/* fallthrough */
case 2:
assert(syscall_number == SYS_write);
assert(arg0 == 1);
assert(arg0 == hook_test_fd);
assert(strcmp((void *)(intptr_t)arg1, dummy_data) == 0);
assert(arg2 == (long)sizeof(dummy_data));
*result = 7;
*result = hook_test_dummy_return_value;
return 0;

case 1:
assert(syscall_number == SYS_write);
assert(arg0 == 1);
assert(arg2 == 4);
assert(arg0 == hook_test_fd);
return 1;

default:
assert(0);
}
}

/*
* is_likely_asan_initiated
* Filters some syscalls that are normally not happening, but are made by
* ASAN code when ASAN does instrumenting.
*/
static bool
is_likely_asan_initiated(long syscall_number, long arg0)
{
switch (syscall_number) {
case SYS_mmap:
case SYS_munmap:
case SYS_ioctl:
case SYS_getpid:
case SYS_futex:
case SYS_exit_group:
return true;
case SYS_write:
if (arg0 == 2)
return true;
/* fallthrough */
default:
return false;
}
}

static int
hook_wrapper(long syscall_number,
long arg0, long arg1,
Expand All @@ -118,16 +91,7 @@ hook_wrapper(long syscall_number,
if (in_hook || deinit_called)
return 1;

if (is_likely_asan_initiated(syscall_number, arg0))
return 1;

if (syscall_number == test_magic_syscall) {
during_test = !during_test;
*result = test_magic_syscall_result;
return 0;
}

if (!during_test)
if (is_spurious_syscall(syscall_number, arg0))
return 1;

in_hook = true;
Expand Down
16 changes: 6 additions & 10 deletions test/libcintercept1.log.match
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
$(S) $(XX) -- syscall(9999, $(XX), $(XX), $(XX), $(XX), $(XX), $(XX)) = ?
$(S) $(XX) -- syscall(9999, $(XX), $(XX), $(XX), $(XX), $(XX), $(XX)) = $(N)
$(S) $(XX) -- write(1, "dummy_data\0", 11) = ?
$(S) $(XX) -- write(1, "dummy_data\0", 11) = 7
$(S) $(XX) -- write(1, "thin", 4) = ?
$(S) $(XX) -- write(1, "thin", 4) = 4
$(S) $(XX) -- write(1, "dummy_data\0", 11) = ?
$(S) $(XX) -- write(1, "dummy_data\0", 11) = 7
$(S) $(XX) -- syscall(9999, $(XX), $(XX), $(XX), $(XX), $(XX), $(XX)) = ?
$(S) $(XX) -- syscall(9999, $(XX), $(XX), $(XX), $(XX), $(XX), $(XX)) = $(N)
$(S) $(XX) -- write(8765, "dummy_data\0", 11) = ?
$(S) $(XX) -- write(8765, "dummy_data\0", 11) = 5
$(S) $(XX) -- write(8765, "thin", 4) = ?
$(S) $(XX) -- write(8765, "thin", 4) = -9
$(S) $(XX) -- write(8765, "dummy_data\0", 11) = ?
$(S) $(XX) -- write(8765, "dummy_data\0", 11) = 5
2 changes: 2 additions & 0 deletions utils/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ containerName=${DOCKER_USER}-${PROJECT}-${OS}-${OS_VER}
if [[ "$command" == "" ]]; then
if [[ $MAKE_PKG -eq 0 ]] ; then command="./run-build.sh"; fi
if [[ $MAKE_PKG -eq 1 ]] ; then command="./run-build-package.sh"; fi
if [[ $COVERAGE -eq 1 ]] ; then command="./run-coverage.sh"; ci_env=`bash <(curl -s https://codecov.io/env)`; fi
fi

WORKDIR=/${PROJECT}
Expand All @@ -79,6 +80,7 @@ WORKDIR=/${PROJECT}
# - host directory containing source mounted (-v)
# - working directory set (-w)
sudo docker run --rm --privileged=true --name=$containerName -ti \
$ci_env \
--env http_proxy=$http_proxy \
--env https_proxy=$https_proxy \
--env COMPILER=$COMPILER \
Expand Down
51 changes: 51 additions & 0 deletions utils/docker/run-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash -ex
#
# Copyright 2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# run-coverage.sh - is called inside a Docker container;
# builds syscall_intercept with the aim of collecting
# information on code coverage

cd $WORKDIR

mkdir build
cd build
CC=gcc cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_FLAGS=-coverage \
-DCMAKE_CXX_FLAGS=-coverage \
-DEXPECT_SPURIOUS_SYSCALLS=ON

make
ctest --output-on-failure
bash <(curl -s https://codecov.io/bash)
cd ..
rm -r build

0 comments on commit e0505d6

Please sign in to comment.