ソースを参照

fix drop in gcov coverage (#917)

Julius Pfrommer 8 年 前
コミット
27a2b77429

+ 5 - 22
.travis.yml

@@ -9,7 +9,8 @@ os:
 # - osx
 
 # use new build environment (docker)
-sudo: false
+dist: trusty
+sudo: required
 
 env:
   global:
@@ -33,16 +34,16 @@ addons:
     sources:
       # see https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
       - kalakris-cmake
-      - ubuntu-toolchain-r-test
     packages:
       - binutils-mingw-w64-i686
       - build-essential
       - clang
       - cmake
-      - gcc-4.8
       - gcc-multilib
-      - g++-4.8
       - g++-multilib
+      - valgrind
+      - check
+      - cppcheck
       - mingw-w64
       - g++-mingw-w64-x86-64
       - g++-mingw-w64-i686
@@ -72,24 +73,6 @@ cache:
     - $HOME/install
 
 before_install:
-# set paths for locally installed libs (like liburcu)
-- export LOCAL_PKG=$HOME/install
-- mkdir -p $LOCAL_PKG/lib
-- mkdir -p $LOCAL_PKG/include
-- mkdir -p $LOCAL_PKG/bin
-- export LIBRARY_PATH=$LOCAL_PKG/lib:$LIBRARY_PATH
-- export C_INCLUDE_PATH=$LOCAL_PKG/include:$C_INCLUDE_PATH
-- export CPLUS_INCLUDE_PATH=$LOCAL_PKG/include:$CPLUS_INCLUDE_PATH
-- export PKG_CONFIG_PATH=$LOCAL_PKG/lib/pkgconfig:$PKG_CONFIG_PATH
-- export PATH=$LOCAL_PKG:$LOCAL_PKG/bin:$PATH
-# set local path for python packages
-- export PATH=$PATH:$HOME/.local/bin # linux
-- export PATH=$PATH:$HOME/Library/Python #OS X
-- export PATH=$PATH:$HOME/Library/Python/2.7/bin #OS X
-# set search path for check library
-- export CHECK_INCLUDE_DIRS=$LOCAL_PKG/include/
-- export CHECK_LIBRARIES=$LOCAL_PKG/lib/
-
 - sh ./tools/travis/travis_notifications.sh
 - if [ ${TRAVIS_OS_NAME} == "linux" ]; then sh ./tools/travis/travis_linux_before_install.sh; fi
 - if [ ${TRAVIS_OS_NAME} == "osx" ]; then sh ./tools/travis/travis_osx_before_install.sh; fi

+ 1 - 1
CMakeLists.txt

@@ -49,7 +49,7 @@ option(BUILD_SHARED_LIBS "Enable building of shared libraries (dll/so)" OFF)
 if(UA_ENABLE_COVERAGE)
   set(CMAKE_BUILD_TYPE DEBUG)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
 endif()
 

+ 3 - 1
plugins/ua_network_tcp.c

@@ -330,15 +330,17 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
     struct sockaddr_in addr;
     socklen_t addrlen = sizeof(struct sockaddr_in);
     int res = getpeername(newsockfd, (struct sockaddr*)&addr, &addrlen);
+    
     if(res == 0) {
         UA_LOG_INFO(layer->logger, UA_LOGCATEGORY_NETWORK,
                     "Connection %i | New connection over TCP from %s:%d",
-            newsockfd, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
+                    newsockfd, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
     } else {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Connection %i | New connection over TCP, "
                        "getpeername failed with errno %i", newsockfd, errno);
     }
+
     memset(c, 0, sizeof(UA_Connection));
     c->sockfd = newsockfd;
     c->handle = layer;

+ 5 - 4
src/client/ua_client.c

@@ -330,8 +330,8 @@ SecureChannelHandshake(UA_Client *client, UA_Boolean renew) {
     retval = response.responseHeader.serviceResult;
     if(retval == UA_STATUSCODE_GOOD) {
         /* Response.securityToken.revisedLifetime is UInt32 we need to cast it
-           to DateTime=Int64 we take 75% of lifetime to start renewing as
-           described in standard */
+         * to DateTime=Int64 we take 75% of lifetime to start renewing as
+         *  described in standard */
         client->scRenewAt = UA_DateTime_now() +
             (UA_DateTime)(response.securityToken.revisedLifetime * (UA_Double)UA_MSEC_TO_DATETIME * 0.75);
 
@@ -341,12 +341,13 @@ SecureChannelHandshake(UA_Client *client, UA_Boolean renew) {
         UA_ByteString_deleteMembers(&client->channel->serverNonce);
         UA_ByteString_copy(&response.serverNonce, &client->channel->serverNonce);
 
-        if(renew)
+        if(renew) {
             UA_LOG_DEBUG(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "SecureChannel renewed");
-        else
+        } else {
             UA_LOG_DEBUG(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "SecureChannel opened");
+        }
     } else {
         UA_LOG_DEBUG(client->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                      "SecureChannel could not be opened / "

+ 6 - 4
src/server/ua_services_securechannel.c

@@ -10,26 +10,28 @@ void Service_OpenSecureChannel(UA_Server *server, UA_Connection *connection,
         response->responseHeader.serviceResult =
             UA_SecureChannelManager_open(&server->secureChannelManager, connection, request, response);
 
-        if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD)
+        if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
             UA_LOG_INFO(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "Connection %i | SecureChannel %i | OpenSecureChannel: Opened SecureChannel",
                          connection->sockfd, response->securityToken.channelId);
-        else
+        } else {
             UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "Connection %i | OpenSecureChannel: Opening a SecureChannel failed",
                          connection->sockfd);
+        }
     } else {
         response->responseHeader.serviceResult =
             UA_SecureChannelManager_renew(&server->secureChannelManager, connection, request, response);
 
-        if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD)
+        if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
             UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "Connection %i | SecureChannel %i | OpenSecureChannel: SecureChannel renewed",
                          connection->sockfd, response->securityToken.channelId);
-        else
+        } else {
             UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
                          "Connection %i | OpenSecureChannel: Renewing SecureChannel failed",
                          connection->sockfd);
+        }
     }
 }
 

+ 1 - 0
tests/check_types_builtin.c

@@ -410,6 +410,7 @@ START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArr
     ck_assert_int_eq((uintptr_t)dst.type, (uintptr_t)&UA_TYPES[UA_TYPES_INT32]); 
     ck_assert_int_eq(dst.arrayLength, 0);
     ck_assert_int_ne((uintptr_t)dst.data, 0);
+    assert(dst.data != NULL); /* repeat the previous argument so that clang-analyzer is happy */
     ck_assert_int_eq(*(UA_Int32 *)dst.data, 255);
     // finally
     UA_Variant_deleteMembers(&dst);

+ 4 - 71
tools/travis/travis_linux_before_install.sh

@@ -8,78 +8,11 @@ pip install --user cpp-coveralls
 pip install --user sphinx
 pip install --user sphinx_rtd_theme
 
-# Increase the environment version to force a rebuild of the packages
-# The version is writen to the cache file after every build of the dependencies
-ENV_VERSION="1"
-ENV_INSTALLED=""
-if [ -e $LOCAL_PKG/.build_env ]; then
-    echo "=== No cached build environment ==="
-    read -r ENV_INSTALLED < $LOCAL_PKG/.build_env
-fi
+wget https://launchpad.net/~lttng/+archive/ubuntu/ppa/+build/11525342/+files/liburcu-dev_0.9.x+stable+bzr1192+pack30+201612060302~ubuntu14.04.1_amd64.deb
+wget https://launchpad.net/~lttng/+archive/ubuntu/ppa/+build/11525342/+files/liburcu4_0.9.x+stable+bzr1192+pack30+201612060302~ubuntu14.04.1_amd64.deb
+sudo dpkg -i *.deb
+rm *.deb
 
-# travis caches the $LOCAL_PKG dir. If it is loaded, we don't need to reinstall the packages
-if [ "$ENV_VERSION" = "$ENV_INSTALLED" ]; then
-    echo "=== The build environment is current ==="
-    # Print version numbers
-    clang --version
-    g++ --version
-    cppcheck --version
-    valgrind --version
-    exit 0
-fi
-
-echo "=== The build environment is outdated ==="
-
-# Clean up
-rm -rf $LOCAL_PKG/*
-
-# Install newer valgrind
-echo "=== Installing valgrind ==="
-wget http://valgrind.org/downloads/valgrind-3.11.0.tar.bz2
-tar xf valgrind-3.11.0.tar.bz2
-cd valgrind-3.11.0
-./configure --prefix=$LOCAL_PKG
-make -s -j8 install
-cd ..
-
-# Install specific check version which is not yet in the apt package
-echo "=== Installing check ==="
-mkdir tmp_check
-wget http://ftp.de.debian.org/debian/pool/main/c/check/check_0.10.0-3+b1_amd64.deb
-dpkg -x check_0.10.0-3+b1_amd64.deb ./tmp_check
-# change pkg-config file path
-sed -i "s|prefix=/usr|prefix=${LOCAL_PKG}|g" ./tmp_check/usr/lib/x86_64-linux-gnu/pkgconfig/check.pc
-sed -i 's|libdir=.*|libdir=${prefix}/lib|g' ./tmp_check/usr/lib/x86_64-linux-gnu/pkgconfig/check.pc
-# move files to globally included dirs
-cp -R ./tmp_check/usr/lib/x86_64-linux-gnu/* $LOCAL_PKG/lib/
-cp -R ./tmp_check/usr/include/* $LOCAL_PKG/include/
-cp -R ./tmp_check/usr/bin/* $LOCAL_PKG/
-
-# Install specific liburcu version which is not yet in the apt package
-echo "=== Installing liburcu ==="
-mkdir tmp_liburcu
-wget https://launchpad.net/ubuntu/+source/liburcu/0.8.5-1ubuntu1/+build/6513813/+files/liburcu2_0.8.5-1ubuntu1_amd64.deb
-wget https://launchpad.net/ubuntu/+source/liburcu/0.8.5-1ubuntu1/+build/6513813/+files/liburcu-dev_0.8.5-1ubuntu1_amd64.deb
-dpkg -x liburcu2_0.8.5-1ubuntu1_amd64.deb ./tmp_liburcu
-dpkg -x liburcu-dev_0.8.5-1ubuntu1_amd64.deb ./tmp_liburcu
-# move files to globally included dirs
-cp -R ./tmp_liburcu/usr/lib/x86_64-linux-gnu/* $LOCAL_PKG/lib/
-cp -R ./tmp_liburcu/usr/include/* $LOCAL_PKG/include/
-
-# Install newer cppcheck
-echo "=== Installing cppcheck ==="
-wget https://github.com/danmar/cppcheck/archive/1.73.tar.gz -O cppcheck-1.73.tar.gz
-tar xf cppcheck-1.73.tar.gz
-cd cppcheck-1.73
-make PREFIX="$LOCAL_PKG" SRCDIR=build CFGDIR="$LOCAL_PKG/cppcheck-cfg" HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function" -j8
-make PREFIX="$LOCAL_PKG" SRCDIR=build CFGDIR="$LOCAL_PKG/cppcheck-cfg" HAVE_RULES=yes install
-cd ..
-
-# create cached flag
-echo "=== Store cache flag ==="
-echo $ENV_VERSION > $LOCAL_PKG/.build_env
-
-# Print version numbers
 echo "=== Installed versions are ==="
 clang --version
 g++ --version

+ 12 - 15
tools/travis/travis_linux_script.sh

@@ -24,6 +24,7 @@ if [ $ANALYZE = "true" ]; then
     else
         cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
             --enable=style --force --std=c++11 -j 8 \
+            --suppress=duplicateBranch \
             --suppress=incorrectStringBooleanError \
             --suppress=invalidscanf --inline-suppr \
             -I include src plugins 2> cppcheck.txt
@@ -88,20 +89,15 @@ else
     make -j8
     tar -pczf open62541-linux64.tar.gz ../../doc ../../doc_latex/open62541.pdf ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
     cp open62541-linux64.tar.gz ..
-    cp open62541.h .. # copy single file-release
-    cp open62541.c .. # copy single file-release
+    cp open62541.h ../.. # copy single file-release
+    cp open62541.c ../.. # copy single file-release
     cd .. && rm build -rf
 
-    if [ "$CC" = "gcc" ]; then
-        echo "Upgrade to gcc 4.8"
-        export CXX="g++-4.8" CC="gcc-4.8"
-    fi
-
     echo "Building the C++ example"
     mkdir -p build && cd build
-    cp ../open62541.* .
-    gcc-4.8 -std=c99 -c open62541.c
-    g++-4.8 ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
+    cp ../../open62541.* .
+    gcc -std=c99 -c open62541.c
+    g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
     cd .. && rm build -rf
 
     echo "Compile multithreaded version"
@@ -112,17 +108,18 @@ else
 
     echo "Debug build and unit tests (64 bit)"
     mkdir -p build && cd build
-    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON ..
-    make -j8 && make test ARGS="-V"
     cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
     make -j8 && make test ARGS="-V"
-    echo "Run valgrind to see if the server leaks memory (just starting up and closing..)"
     (valgrind --leak-check=yes --error-exitcode=3 ./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
+    # without valgrind
+    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON ..
+    make -j8 && make test ARGS="-V"
+    (./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
     # only run coveralls on main repo, otherwise it fails uploading the files
     echo "-> Current repo: ${TRAVIS_REPO_SLUG}"
-    if ([ "$CC" = "gcc-4.8" ] || [ "$CC" = "gcc" ]) && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
+    if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
         echo "  Building coveralls for ${TRAVIS_REPO_SLUG}"
-        coveralls --gcov /usr/bin/gcov-4.8 -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result
+        coveralls -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
     else
         echo "  Skipping coveralls since not gcc and/or ${TRAVIS_REPO_SLUG} is not the main repo"
     fi