From 56fc68215221f3f5904fb1c42cd9dcd47bff8de0 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Wed, 30 Mar 2011 13:09:47 +0300 Subject: [PATCH] Changes: add coverage enablers to the code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RevBy: Pertti Kellomäki Details: explicitly flush the coverage data to disk in a few key locations --- CMakeLists.txt | 6 +-- src/common/coverage.h | 43 +++++++++++++++++++ src/common/eventhandler.cpp | 13 +++++- src/ebooster/ebooster.cpp | 2 + src/launcherlib/booster.cpp | 6 +++ src/launcherlib/daemon.cpp | 6 +++ src/launcherlib/logger.cpp | 1 + src/qdeclarativebooster/mdeclarativecache.cpp | 20 +++++++++ 8 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/common/coverage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 408247e..aa28760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,9 +86,9 @@ add_definitions(-DDEBUG_LOGGING_DISABLED) # Build with test coverage switch if BUILD_COVERAGE environment variable is set if ($ENV{BUILD_COVERAGE}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs") - set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -ftest-coverage -fprofile-arcs") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -DWITH_COVERAGE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -DWITH_COVERAGE") + set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} --coverage") endif ($ENV{BUILD_COVERAGE}) # Sub build: applauncherd diff --git a/src/common/coverage.h b/src/common/coverage.h new file mode 100644 index 0000000..cc91b25 --- /dev/null +++ b/src/common/coverage.h @@ -0,0 +1,43 @@ +/*************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of applauncherd +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef COVERAGE_H +#define COVERAGE_H + +#ifdef WITH_COVERAGE +#ifdef __cplusplus +extern "C" void __gcov_flush(void); +extern "C" pid_t __gcov_fork(void); +extern "C" int __gcov_execv(const char *path, char *const argv[]); +extern "C" int __gcov_execve(const char *path, char *const argv[], + char *const envp[]); +#endif // __cplusplus + +#define _exit(status) { \ + __gcov_flush(); \ + _exit(status); \ + } + +#define fork() __gcov_fork() +#define execv(path, argv) __gcov_execv((path), (argv)) +#define execve(path, argv, envp) __gcov_execve((path), (argv), (envp)) + +#endif // WITH_COVERAGE + +#endif // COVERAGE_H diff --git a/src/common/eventhandler.cpp b/src/common/eventhandler.cpp index ebc58b1..8057a7a 100644 --- a/src/common/eventhandler.cpp +++ b/src/common/eventhandler.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "coverage.h" int EventHandler::m_sighupFd[2]; struct sigaction EventHandler::m_oldSigAction; @@ -89,9 +90,13 @@ void EventHandler::accept() void EventHandler::notifyThemeChange() { +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif + // only MApplication is connected to this signal MApplication::quit(); - ::_exit(EXIT_SUCCESS); + _exit(EXIT_SUCCESS); } // @@ -109,12 +114,16 @@ void EventHandler::hupSignalHandler(int) void EventHandler::handleSigHup() { +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif + if (m_type == MEventHandler) MApplication::quit(); else if (m_type == QEventHandler) QApplication::quit(); - ::_exit(EXIT_SUCCESS); + _exit(EXIT_SUCCESS); } bool EventHandler::setupUnixSignalHandlers() diff --git a/src/ebooster/ebooster.cpp b/src/ebooster/ebooster.cpp index 944ad6c..fe911e4 100644 --- a/src/ebooster/ebooster.cpp +++ b/src/ebooster/ebooster.cpp @@ -26,6 +26,8 @@ #include #endif +#include "coverage.h" + const string EBooster::m_socketId = "/tmp/booste"; const string EBooster::m_temporaryProcessName = "booster-e"; diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index 4742497..6c1a8ed 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -57,6 +57,8 @@ namespace } #endif // HAVE_CREDS +#include "coverage.h" + static const int FALLBACK_GID = 126; static gid_t getGroupId(const char *name, gid_t fallback) @@ -481,6 +483,10 @@ int Booster::launchProcess() // Load the application and find out the address of main() void* handle = loadMain(); +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif + // Jump to main() const int retVal = m_appData->entry()(m_appData->argc(), const_cast(m_appData->argv())); m_appData->deleteArgv(); diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index f99f74d..9562633 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -38,6 +38,8 @@ #include #include +#include "coverage.h" + Daemon * Daemon::m_instance = NULL; int Daemon::m_lockFd = -1; const int Daemon::m_boosterSleepTime = 2; @@ -766,4 +768,8 @@ Daemon::~Daemon() { delete m_socketManager; delete m_singleInstance; + +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif } diff --git a/src/launcherlib/logger.cpp b/src/launcherlib/logger.cpp index e89fb95..36ffec6 100644 --- a/src/launcherlib/logger.cpp +++ b/src/launcherlib/logger.cpp @@ -24,6 +24,7 @@ #include #include +#include "coverage.h" bool Logger::m_isOpened = false; bool Logger::m_debugMode = false; diff --git a/src/qdeclarativebooster/mdeclarativecache.cpp b/src/qdeclarativebooster/mdeclarativecache.cpp index e92af2a..cf18aaa 100644 --- a/src/qdeclarativebooster/mdeclarativecache.cpp +++ b/src/qdeclarativebooster/mdeclarativecache.cpp @@ -27,6 +27,8 @@ #include #endif +#include "coverage.h" + MDeclarativeCachePrivate * const MDeclarativeCache::d_ptr = new MDeclarativeCachePrivate; const int MDeclarativeCachePrivate::ARGV_LIMIT = 32; @@ -45,6 +47,10 @@ MDeclarativeCachePrivate::~MDeclarativeCachePrivate() { delete qDeclarativeViewInstance; delete[] initialArgv; + +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif } void MDeclarativeCachePrivate::populate() @@ -128,6 +134,11 @@ QApplication* MDeclarativeCachePrivate::qApplication(int &argc, char **argv) } } + +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif + return qApplicationInstance; } @@ -140,6 +151,11 @@ QDeclarativeView* MDeclarativeCachePrivate::qDeclarativeView() } else { returnValue = new QDeclarativeView(); } + +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif + return returnValue; } @@ -166,6 +182,10 @@ QString MDeclarativeCachePrivate::applicationFilePath() void MDeclarativeCache::populate() { d_ptr->populate(); + +#ifdef WITH_COVERAGE + __gcov_flush(); +#endif } QApplication* MDeclarativeCache::qApplication(int &argc, char **argv)