diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f76edec..cce5885f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,7 +381,7 @@ elseif(FORMAT_TEST) endif() function(auto_test target) - if(CHECK_FOUND) + if(CHECK_FOUND AND NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND ARGV1 STREQUAL "MSVC_DONT_BUILD")) add_c_executable(auto_${target}_test auto_tests/${target}_test.c) target_link_modules(auto_${target}_test toxcore @@ -390,8 +390,10 @@ function(auto_test target) if(BUILD_TOXAV) target_link_modules(auto_${target}_test toxav) endif() - add_test(NAME ${target} COMMAND auto_${target}_test) - set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") + if(NOT ARGV1 STREQUAL "DONT_RUN") + add_test(NAME ${target} COMMAND auto_${target}_test) + set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") + endif() endif() endfunction() @@ -407,10 +409,10 @@ endif() auto_test(TCP) auto_test(conference) -auto_test(crypto) -auto_test(dht) +auto_test(crypto MSVC_DONT_BUILD) +auto_test(dht MSVC_DONT_BUILD) auto_test(encryptsave) -auto_test(messenger) +auto_test(messenger MSVC_DONT_BUILD) auto_test(network) auto_test(onion) auto_test(resource_leak) @@ -424,8 +426,8 @@ auto_test(tox_strncasecmp) auto_test(version) # TODO(iphydf): These tests are broken. The code needs to be fixed, as the # tests themselves are correct. -#auto_test(selfname_change_conference) -#auto_test(self_conference_title_change) +auto_test(selfname_change_conference DONT_RUN) +auto_test(self_conference_title_change DONT_RUN) if(BUILD_TOXAV) auto_test(toxav_basic) diff --git a/appveyor.yml b/appveyor.yml index 4b4bfb20..66453ccf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,15 +1,26 @@ +cache: +- '%APPDATA%\downloads' + install: # TODO(iphydf): Remove this when appveyor gets curl back, which it should have # according to https://www.appveyor.com/docs/how-to/download-file/. - choco install curl - refreshenv -- mkdir libsodium && cd libsodium -- curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.11-msvc.zip -o libsodium.zip -- unzip libsodium.zip +- if not exist %APPDATA%\downloads mkdir %APPDATA%\downloads +# libcheck +- if not exist %APPDATA%\downloads\check.zip curl -L https://github.com/libcheck/check/archive/0.11.0.zip -o %APPDATA%\downloads\check.zip +- unzip %APPDATA%\downloads\check.zip && cd check-0.11.0 +- if not exist "%PROGRAMFILES%\check\include\check.h" cmake . && msbuild INSTALL.vcxproj - cd .. +# libsodium +- mkdir libsodium && cd libsodium +- if not exist %APPDATA%\downloads\libsodium.zip curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.12-msvc.zip -o %APPDATA%\downloads\libsodium.zip +- unzip %APPDATA%\downloads\libsodium.zip +- cd .. +# pthreads-win32 - mkdir pthreads-win32 && cd pthreads-win32 -- curl ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip -o pthreads.zip -- unzip pthreads.zip +- if not exist %APPDATA%\downloads\pthreads.zip curl -L ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip -o %APPDATA%\downloads\pthreads.zip +- unzip %APPDATA%\downloads\pthreads.zip - cd .. before_build: @@ -18,6 +29,10 @@ before_build: build: project: INSTALL.vcxproj +# TODO(iphydf): Tests all segfault on Windows at the moment. +#test_script: +#- ctest -C Debug + branches: only: - master diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc index 244737d9..536b08c5 100644 --- a/auto_tests/Makefile.inc +++ b/auto_tests/Makefile.inc @@ -123,4 +123,5 @@ tox_strncasecmp_test_CFLAGS = $(AUTOTEST_CFLAGS) tox_strncasecmp_test_LDADD = $(AUTOTEST_LDADD) +EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h EXTRA_DIST += $(top_srcdir)/auto_tests/helpers.h diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 769ba5de..f8412832 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -4,7 +4,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/check_compat.h b/auto_tests/check_compat.h new file mode 100644 index 00000000..e4fde89f --- /dev/null +++ b/auto_tests/check_compat.h @@ -0,0 +1,8 @@ +#ifdef _MSC_VER +#define pid_t int +// #include +#endif +#include +#ifdef _MSC_VER +#undef pid_t +#endif diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 33110441..e8d7e238 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -7,7 +7,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 952b0312..2fdfb0cd 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -2,9 +2,8 @@ #include "config.h" #endif -#include "../toxcore/net_crypto.h" +#include "check_compat.h" -#include #include #include #include @@ -13,6 +12,8 @@ #include "helpers.h" +#include "../toxcore/net_crypto.h" + static void rand_bytes(uint8_t *b, size_t blen) { size_t i; diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 5533593f..c04b67e4 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -4,14 +4,16 @@ #include "config.h" #endif +#include "check_compat.h" + +#include +#include + #include "helpers.h" #include "../toxcore/DHT.c" #include "../toxcore/tox.h" -#include -#include - // These tests currently fail. static bool enable_broken_tests = false; diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 749767a0..dfe85710 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 8cff56e8..0d167b5a 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c @@ -22,6 +22,7 @@ * You should have received a copy of the GNU General Public License * along with Tox. If not, see . */ + #include #include #include diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h index e5860449..55cc1ca0 100644 --- a/auto_tests/helpers.h +++ b/auto_tests/helpers.h @@ -4,25 +4,25 @@ #include "../toxcore/tox.h" #include -#include #include +#include -#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) #include #define c_sleep(x) Sleep(x) #else #include -#define c_sleep(x) usleep(1000*(x)) +#define c_sleep(x) usleep(1000 * (x)) #endif #define DEFTESTCASE(NAME) \ TCase *tc_##NAME = tcase_create(#NAME); \ tcase_add_test(tc_##NAME, test_##NAME); \ - suite_add_tcase(s, tc_##NAME); + suite_add_tcase(s, tc_##NAME) -#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \ - DEFTESTCASE(NAME) \ - tcase_set_timeout(tc_##NAME, TIMEOUT); +#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \ + DEFTESTCASE(NAME); \ + tcase_set_timeout(tc_##NAME, TIMEOUT) static const char *tox_log_level_name(TOX_LOG_LEVEL level) { diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index bd524014..614b1057 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -14,12 +14,13 @@ #include "config.h" #endif +#include "check_compat.h" + #include "helpers.h" #include "../testing/misc_tools.c" // hex_string_to_bin #include "../toxcore/Messenger.h" -#include #include #include #include diff --git a/auto_tests/monolith_test.c b/auto_tests/monolith_test.c index d6f675a2..253d2bd3 100644 --- a/auto_tests/monolith_test.c +++ b/auto_tests/monolith_test.c @@ -1,12 +1,13 @@ /* Auto Tests: One instance. */ +#define _DARWIN_C_SOURCE +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#define _DARWIN_C_SOURCE -#define _XOPEN_SOURCE 600 #include "../other/monolith.h" int main(int argc, char *argv[]) diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 9ae1ddcb..67090f74 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index c52bbb58..a0d4f4bc 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -4,7 +4,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/resource_leak_test.c b/auto_tests/resource_leak_test.c index 3a87e245..5b25bc77 100644 --- a/auto_tests/resource_leak_test.c +++ b/auto_tests/resource_leak_test.c @@ -1,9 +1,9 @@ -#include "helpers.h" - #if defined(__AIX__) -# define _XOPEN_SOURCE 1 +#define _XOPEN_SOURCE 1 #endif +#include "helpers.h" + // See man 2 sbrk. #if _BSD_SOURCE || _SVID_SOURCE || \ (_XOPEN_SOURCE >= 500 || \ diff --git a/auto_tests/self_conference_title_change_test.c b/auto_tests/self_conference_title_change_test.c index f0896101..a91aa0b4 100644 --- a/auto_tests/self_conference_title_change_test.c +++ b/auto_tests/self_conference_title_change_test.c @@ -21,6 +21,7 @@ * along with Tox. If not, see . * */ +#define _XOPEN_SOURCE 500 #include #include @@ -30,6 +31,8 @@ #include "../toxcore/tox.h" #include "../toxencryptsave/toxencryptsave.h" +#include "helpers.h" + static const char *newtitle = "kitten over darknet"; static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, @@ -44,7 +47,6 @@ static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_nu int main(void) { uint32_t conference_number; - struct timespec sleeptime; struct Tox_Options to; Tox *t; TOX_ERR_CONFERENCE_NEW conference_err; @@ -62,11 +64,7 @@ int main(void) } tox_iterate(t, NULL); - - sleeptime.tv_sec = 0; - sleeptime.tv_nsec = tox_iteration_interval(t) * 1E6; - - nanosleep(&sleeptime, NULL); + c_sleep(tox_iteration_interval(t)); if (!tox_conference_set_title(t, conference_number, (const uint8_t *)newtitle, strlen(newtitle), &title_err)) { tox_kill(t); @@ -75,7 +73,7 @@ int main(void) } tox_iterate(t, NULL); - nanosleep(&sleeptime, NULL); + c_sleep(tox_iteration_interval(t)); tox_iterate(t, NULL); fprintf(stderr, "error: title was not changed in callback. exiting.\n"); diff --git a/auto_tests/selfname_change_conference_test.c b/auto_tests/selfname_change_conference_test.c index 340f7aa6..2536b10e 100644 --- a/auto_tests/selfname_change_conference_test.c +++ b/auto_tests/selfname_change_conference_test.c @@ -21,12 +21,15 @@ * along with Tox. If not, see . * */ +#define _XOPEN_SOURCE 500 #include #include #include #include +#include "helpers.h" + #include "../toxcore/tox.h" #include "../toxencryptsave/toxencryptsave.h" @@ -55,7 +58,6 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu int main(void) { uint32_t conference_number; - struct timespec sleeptime; struct Tox_Options to; Tox *t; TOX_ERR_CONFERENCE_NEW conference_err; @@ -73,11 +75,7 @@ int main(void) } tox_iterate(t, NULL); - - sleeptime.tv_sec = 0; - sleeptime.tv_nsec = tox_iteration_interval(t) * 1E6; - - nanosleep(&sleeptime, NULL); + c_sleep(tox_iteration_interval(t)); if (!tox_self_set_name(t, (const uint8_t *)newname, strlen(newname), &name_err)) { tox_kill(t); @@ -86,7 +84,7 @@ int main(void) } tox_iterate(t, NULL); - nanosleep(&sleeptime, NULL); + c_sleep(tox_iteration_interval(t)); tox_iterate(t, NULL); fprintf(stderr, "error: name was not changed in callback. exiting.\n"); diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c index b8950921..48f95093 100644 --- a/auto_tests/skeleton_test.c +++ b/auto_tests/skeleton_test.c @@ -2,11 +2,9 @@ #include "config.h" #endif -#include -#include +#include "check_compat.h" + #include -#include -#include #include #include "helpers.h" diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 77c611d9..510109ee 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -7,7 +7,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 1a1a715d..a34cfa8d 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -7,7 +7,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c index ce698486..1b277d96 100644 --- a/auto_tests/tox_one_test.c +++ b/auto_tests/tox_one_test.c @@ -5,7 +5,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include diff --git a/auto_tests/tox_strncasecmp_test.c b/auto_tests/tox_strncasecmp_test.c index 0acc85fe..5e0edcbd 100644 --- a/auto_tests/tox_strncasecmp_test.c +++ b/auto_tests/tox_strncasecmp_test.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index f3557226..3613b9c4 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -16,7 +16,8 @@ #include "config.h" #endif -#include +#include "check_compat.h" + #include #include #include diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 2885d8be..2b77da37 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -4,7 +4,7 @@ #include "config.h" #endif -#include "helpers.h" +#include "check_compat.h" #include #include @@ -21,6 +21,7 @@ #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "helpers.h" #define TEST_REGULAR_AV 1 #define TEST_REGULAR_A 1 diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 83a7b313..5796905c 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -4,7 +4,7 @@ #include "config.h" #endif -#include "helpers.h" +#include "check_compat.h" #include #include @@ -21,6 +21,8 @@ #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "helpers.h" + #if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) #include #endif diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 5ad332bd..b87922a9 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -35,36 +35,71 @@ pkg_use_module(SNDFILE sndfile ) ############################################################################### # -# :: For Windows and other systems lacking pkg-config. +# :: For MSVC Windows builds. +# +# These require specific installation paths of dependencies: +# - libsodium in libsodium/Win32/Release/v140/static +# - pthreads in pthreads-win32/Pre-built.2 +# - check in %PROGRAMFILES%/check # ############################################################################### -if(NOT LIBSODIUM_FOUND) - include_directories(libsodium/include) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # libsodium + # --------- find_library(LIBSODIUM_LIBRARIES - NAMES - sodium - libsodium + NAMES sodium libsodium PATHS - libsodium/Win32/Release/v140/static - libsodium/x64/Release/v140/static + "libsodium/Win32/Release/v140/static" + "libsodium/x64/Release/v140/static" ) if(LIBSODIUM_LIBRARIES) + include_directories("libsodium/include") set(LIBSODIUM_FOUND TRUE) + add_definitions(-DSODIUM_STATIC) + message("libsodium: ${LIBSODIUM_LIBRARIES}") + else() + message(FATAL_ERROR "libsodium libraries not found") endif() - add_definitions(-DSODIUM_STATIC) - message("libsodium: ${LIBSODIUM_LIBRARIES}") -endif() -if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") AND CMAKE_USE_WIN32_THREADS_INIT) - include_directories(pthreads-win32/Pre-built.2/include) - find_library(CMAKE_THREAD_LIBS_INIT - NAMES - pthreadVC2 - PATHS - pthreads-win32/Pre-built.2/lib/x86 - pthreads-win32/Pre-built.2/lib/x64 + # check + # ----- + # + # We look for the check and compat (containing clock_gettime and other POSIX + # functions not present on Windows) libraries in Program Files, since that is + # the default location where cmake installs its packages. + find_library(LIBCHECK_LIBRARIES + NAMES check libcheck + PATHS "$ENV{PROGRAMFILES}/check/lib" ) - add_definitions(-DHAVE_STRUCT_TIMESPEC) - message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}") + find_library(LIBCOMPAT_LIBRARIES + NAMES compat libcompat + PATHS "$ENV{PROGRAMFILES}/check/lib" + ) + if(LIBCHECK_LIBRARIES AND LIBCOMPAT_LIBRARIES) + include_directories("$ENV{PROGRAMFILES}/check/include") + set(CHECK_FOUND TRUE) + set(CHECK_LIBRARIES ${LIBCHECK_LIBRARIES} ${LIBCOMPAT_LIBRARIES}) + message("check: ${CHECK_LIBRARIES}") + else() + message(FATAL_ERROR "check libraries not found") + endif() + + # pthreads + # -------- + if(CMAKE_USE_WIN32_THREADS_INIT) + find_library(CMAKE_THREAD_LIBS_INIT + NAMES pthreadVC2 + PATHS + "pthreads-win32/Pre-built.2/lib/x86" + "pthreads-win32/Pre-built.2/lib/x64" + ) + if(CMAKE_THREAD_LIBS_INIT) + include_directories("pthreads-win32/Pre-built.2/include") + add_definitions(-DHAVE_STRUCT_TIMESPEC) + message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}") + else() + message(FATAL_ERROR "libpthreads libraries not found") + endif() + endif() endif() diff --git a/testing/misc_tools.c b/testing/misc_tools.c index f6e76e46..a3a89c2f 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -32,6 +32,7 @@ #include //Sleep function (x = milliseconds) +#ifndef c_sleep #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) #include #define c_sleep(x) Sleep(x) @@ -39,6 +40,7 @@ #include #define c_sleep(x) usleep(1000*(x)) #endif +#endif // You are responsible for freeing the return value! uint8_t *hex_string_to_bin(const char *hex_string)