User Tools

Site Tools


unittest_coverage
  1. '-fprofile-arcs' '-ftest-coverage' add to Sconscript file
  2. gcov lib add to Sconscript file
  3. Build IoTivity in debug mode (scons RELEASE=0), be sure to have the debug libraries in your LD_LIBRARY_PATH
  4. ./lcov.sh -d /home/iotivity-project-dir -c -o coverage.info
  5. [genhtml –highlight –legend -output-directory out coverage.info], check cov_results in your current directory

See below the example script and SConscript modifications:

lcov.sh:

#!/bin/bash

TITLE='SceneManager'
TARGET='scene-manager'
#TEST='scene_test'

pushd `dirname $0` > /dev/null

SCRIPT_PATH=$(pwd -P)

OUTPUT_DIR=$SCRIPT_PATH/'cov_result'
WORKING_DIR='cov_temp'

mkdir $WORKING_DIR
pushd $WORKING_DIR

DIR='-d '$SCRIPT_PATH'/out/linux/x86/debug/service/'$TARGET'/src'
#BASE_DIR='-b '$SCRIPT_PATH'/service/'$TARGET'/src'
BASE_DIR='-b '$SCRIPT_PATH''

GCOV_TOOL='--gcov-tool /usr/bin/gcov-4.6'

#lcov $DIR $GCOV_TOOL $BASE_DIR -z
lcov $DIR $GCOV_TOOL -z

echo "-z"

lcov $BASE_DIR $DIR $GCOV_TOOL --output-file i.info -c -i 

echo "-i"

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/scene_list_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/scene_collection_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/scene_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/scene_action_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/remote_scene_action_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/remote_scenes_col_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/remote_scene_list_test

$SCRIPT_PATH/out/linux/x86/debug/service/$TARGET/unittests/remote_scene_test

lcov $BASE_DIR $DIR $GCOV_TOOL --output-file a.info -c -q

lcov -a i.info -a a.info -o t.info

lcov -r t.info *Test.cpp -o m.info

genhtml m.info -o $OUTPUT_DIR/$TITLE -f -s

rm *.info

popd
popd > /dev/null

Example modified SConscript:

#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# NotificationManager build script
##

Import('env')

if env.get('RELEASE'):
    env.AppendUnique(CCFLAGS = ['-Os'])
    env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
    env.AppendUnique(CCFLAGS = ['-g'])

if env.get('LOGGING'):
    env.AppendUnique(CPPDEFINES = ['TB_LOG'])

lib_env = env.Clone()
SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
scenemanager_env = lib_env.Clone()

target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
scenemanager_env.AppendUnique(CPPPATH = ['./include'])
scenemanager_env.AppendUnique(CPPPATH = ['./src'])
scenemanager_env.AppendUnique(CPPPATH = ['../../resource/csdk/connectivity/api'])
scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/include'])
scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/src/common/primitiveResource/include'])
scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/src/common/expiryTimer/include'])


scenemanager_env.PrependUnique(LIBS = [
    'rcs_client',
    'rcs_server',
    'rcs_common',
    'oc',
    'octbstack',
    'oc_logger',
    'connectivity_abstraction',
    'libcoap'
    ])

if target_os not in ['windows', 'winrt']:
    scenemanager_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
    scenemanager_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])

if target_os == 'linux':
    scenemanager_env.AppendUnique(LIBS = ['pthread'])
    

if target_os == 'android':
    scenemanager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
    scenemanager_env.AppendUnique(LIBS = ['gnustl_shared','log'])

if not env.get('RELEASE'):
    scenemanager_env.PrependUnique(LIBS = ['gcov'])
    scenemanager_env.AppendUnique(CXXFLAGS = ['--coverage'])

######################################################################
# Source files and Targets
######################################################################
SCENE_SRC_DIR = './src/' 
scenemanager_src = Glob(SCENE_SRC_DIR + '*.cpp')

if target_os in ['tizen','android'] :
    scenemanagersdk = scenemanager_env.SharedLibrary('scene_manager', scenemanager_src)
else :
    scenemanagersdk = scenemanager_env.StaticLibrary('scene_manager', scenemanager_src)

scenemanager_env.InstallTarget(scenemanagersdk, 'libscene_manager')
scenemanager_env.UserInstallTargetLib(scenemanagersdk, 'libscene_manager')
scenemanager_env.UserInstallTargetHeader('include/SceneList.h', 'service/scene-manager', 'SceneList.h')
scenemanager_env.UserInstallTargetHeader('include/SceneCollection.h', 'service/scene-manager', 'SceneCollection.h')
scenemanager_env.UserInstallTargetHeader('include/Scene.h', 'service/scene-manager', 'Scene.h')
scenemanager_env.UserInstallTargetHeader('include/SceneAction.h', 'service/scene-manager', 'SceneAction.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteSceneList.h', 'service/scene-manager', 'RemoteSceneList.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteSceneCollection.h', 'service/scene-manager', 'RemoteSceneCollection.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteScene.h', 'service/scene-manager', 'RemoteScene.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteSceneAction.h', 'service/scene-manager', 'RemoteSceneAction.h')

# Go to build Unit test
if target_os == 'linux':
    SConscript('unittests/SConscript')

# Go to build sample apps
SConscript('sampleapp/SConscript')
unittest_coverage.txt · Last modified: 2016/03/02 12:48 by Markus Jung