From: <svn...@op...> - 2009-03-02 13:50:19
|
Author: bellmich Date: Mon Mar 2 14:50:12 2009 New Revision: 960 URL: http://libsyncml.opensync.org/changeset/960 Log: added workaround to make check thread safe if check is older than 0.9.7 Modified: trunk/CMakeLists.txt trunk/tests/check_sync.c trunk/tests/support.c trunk/tests/support.h Modified: trunk/CMakeLists.txt ============================================================================== --- trunk/CMakeLists.txt Thu Feb 26 13:51:11 2009 (r959) +++ trunk/CMakeLists.txt Mon Mar 2 14:50:12 2009 (r960) @@ -83,8 +83,12 @@ SET ( LIBSOUP22_MIN_VERSION "2.2.91" ) SET ( LIBSOUP24_MIN_VERSION "2.3.0.1" ) SET ( LIBWBXML2_MIN_VERSION "0.10.0" ) +SET ( CHECK_MIN_VERSION "0.9.7" ) #SET ( BLUEZ_MIN_VERSION "3.19" ) +## avoid caching of CHECK_FOUND without CHECK_MIN_VERSION +SET ( CHECK_FOUND OFF ) + FIND_PACKAGE( GLIB2 REQUIRED ) FIND_PACKAGE( GTHREAD2 REQUIRED ) FIND_PACKAGE( GOBJECT2 REQUIRED ) @@ -148,9 +152,19 @@ SET ( FATAL_ERROR_TRANSPORT "Could not find libsoup2 nor OpenObex! Please install at least one of these libraries (e.g. libsoup2-dev package)." ) ENDIF( NOT LIBSOUP2_FOUND AND NOT OPENOBEX_FOUND ) +OPTION( ENABLE_UNIT_TEST "enable unit tests" OFF ) +OPTION( THREAD_SAFE_CHECK "check is thread safe" OFF ) +IF(CHECK_FOUND) + SET( THREAD_SAFE_CHECK ON ) +ELSE(CHECK_FOUND) + ## perhaps to small version + ## these versions are not thread safe + SET ( CHECK_MIN_VERSION "" ) + FIND_PACKAGE( Check ) +ENDIF(CHECK_FOUND) IF(CHECK_FOUND) - OPTION( ENABLE_UNIT_TEST "enable unit tests" ON ) - SET( MEMORYCHECK_SUPPRESSIONS_FILE "${CMAKE_SOURCE_DIR}/tests/valgrind.supp" CACHE FILEPATH "akdnaksd" ) + SET( ENABLE_UNIT_TEST ON ) + SET( MEMORYCHECK_SUPPRESSIONS_FILE "${CMAKE_SOURCE_DIR}/tests/valgrind.supp" CACHE FILEPATH "valgrind.supp" ) INCLUDE( Testing ) ENDIF(CHECK_FOUND) @@ -214,6 +228,7 @@ SHOW_STATUS( ENABLE_TOOLS "building tools\t\t" ) SHOW_STATUS( ENABLE_TRACE "tracing tools\t\t" ) SHOW_STATUS( ENABLE_UNIT_TEST "unit tests\t\t\t" ) +SHOW_STATUS( THREAD_SAFE_CHECK "check is thread safe\t\t" CHECK_VERSION ) SHOW_STATUS( ENABLE_WBXML "WAP Binary XML\t\t" LIBWBXML2_VERSION ) SHOW_STATUS( ENABLE_HTTP "http transports\t\t" LIBSOUP2_VERSION ) SHOW_STATUS( ENABLE_OBEX "obex transports\t\t" OPENOBEX_VERSION ) Modified: trunk/tests/check_sync.c ============================================================================== --- trunk/tests/check_sync.c Thu Feb 26 13:51:11 2009 (r959) +++ trunk/tests/check_sync.c Mon Mar 2 14:50:12 2009 (r960) @@ -139,7 +139,7 @@ session_errors++; break; default: - fail("An unexpected manager event %d was received.", type); + sml_fail_unless(FALSE, "An unexpected manager event %d was received.", type); break; } @@ -315,7 +315,7 @@ sml_fail_unless(!data, NULL); sml_fail_unless(size == 0, NULL); } else { - fail("The received SyncML change type %d is unsupported.", type); + sml_fail_unless(FALSE, "The received SyncML change type %d is unsupported.", type); } if (data) Modified: trunk/tests/support.c ============================================================================== --- trunk/tests/support.c Thu Feb 26 13:51:11 2009 (r959) +++ trunk/tests/support.c Mon Mar 2 14:50:12 2009 (r960) @@ -22,6 +22,10 @@ #include <libsyncml/sml_error_internals.h> #include <libxml/parser.h> +#ifndef THREAD_SAFE_CHECK +GStaticMutex __libsyncml_check_mutex = G_STATIC_MUTEX_INIT; +#endif + /* FIXME: These settings should be controlled by the test environment. * FIXME: The hard coding of the environment creates an unreal test scenario. * FIXME: The build host environment must be changed appropriately. Modified: trunk/tests/support.h ============================================================================== --- trunk/tests/support.h Thu Feb 26 13:51:11 2009 (r959) +++ trunk/tests/support.h Mon Mar 2 14:50:12 2009 (r960) @@ -29,10 +29,29 @@ void create_case(Suite *s, const char *name, TFun function); SmlParser *start_parser(const char *data, SmlError **error); -#define sml_fail_unless(expr, ...);\ - {\ - int _result = expr;\ - fail_unless(_result, ## __VA_ARGS__);\ - if (!_result) smlAssertMsg(0, g_strdup_printf(__VA_ARGS__));\ - } +#ifdef THREAD_SAFE_CHECK + #define sml_fail_unless(expr, ...);\ + {\ + int _result = expr;\ + fail_unless(_result, ## __VA_ARGS__);\ + if (!_result) smlAssertMsg(0, g_strdup_printf(__VA_ARGS__));\ + } + +#else + + /* If check is earlier than 0.9.7 then it is not thread safe. */ + + extern GStaticMutex __libsyncml_check_mutex; + + #define sml_fail_unless(expr, ...);\ + {\ + g_static_mutex_lock(&__libsyncml_check_mutex);\ + int _result = expr;\ + fail_unless(_result, ## __VA_ARGS__);\ + if (!_result) smlAssertMsg(0, g_strdup_printf(__VA_ARGS__));\ + g_static_mutex_unlock(&__libsyncml_check_mutex);\ + } + + +#endif /* THREAD_SAFE_CHECK */ |