Skip to content

Commit

Permalink
Remove libcheck from the dependencies.
Browse files Browse the repository at this point in the history
We're not gaining much from this library, and it's a burden, especially
for windows development.
  • Loading branch information
iphydf committed Feb 6, 2018
1 parent 2126e50 commit ecc33ad
Show file tree
Hide file tree
Showing 27 changed files with 112 additions and 166 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -17,7 +17,6 @@ matrix:
- avsm
packages:
- aspcud # For Opam
- check # For tests.
- libconfig-dev # For tox-bootstrapd.
- libcv-dev # For av_test.
- libhighgui-dev # For av_test.
Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Expand Up @@ -492,32 +492,31 @@ elseif(FORMAT_TEST)
endif()

function(auto_test target)
if(CHECK_FOUND AND NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
if(NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
add_executable(auto_${target}_test auto_tests/${target}_test.c)
target_link_modules(auto_${target}_test
toxcore
toxcrypto
toxmessenger
toxnetcrypto
${CHECK_LIBRARIES})
toxnetcrypto)
if(NOT ARGV1 STREQUAL "DONT_RUN")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
endif()
endif()
endfunction()

if(BUILD_TOXAV AND CHECK_FOUND)
if(BUILD_TOXAV)
add_definitions(-D__STDC_LIMIT_MACROS=1)
add_executable(auto_monolith_test
auto_tests/monolith_test.cpp
${ANDROID_CPU_FEATURES})
target_link_modules(auto_monolith_test
${CHECK_LIBRARIES}
${toxcore_PKGCONFIG_LIBS}
${LIBSODIUM_LIBRARIES}
${OPUS_LIBRARIES}
${VPX_LIBRARIES}
${toxcore_PKGCONFIG_LIBS})
${CMAKE_THREAD_LIBS_INIT})
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)

if(ANDROID_CPU_FEATURES)
Expand Down
2 changes: 0 additions & 2 deletions INSTALL.md
Expand Up @@ -168,7 +168,6 @@ Build the container image based on the Dockerfile. The following options are ava
| SUPPORT_ARCH_i686 | Support building 32-bit toxcore. | "true" or "false" (case sensitive). | true |
| SUPPORT_ARCH_x86_64 | Support building 64-bit toxcore. | "true" or "false" (case sensitive). | true |
| SUPPORT_TEST | Support running toxcore automated tests. | "true" or "false" (case sensitive). | false |
| VERSION_CHECK | Version of libcheck. Needed only when SUPPORT_TEST is enabled. | Git branch name. | 0.12.0 |
| VERSION_OPUS | Version of libopus to build toxcore with. | Git branch name. | v1.2.1 |
| VERSION_SODIUM | Version of libsodium to build toxcore with. | Git branch name. | 1.0.16 |
| VERSION_VPX | Version of libvpx to build toxcore with. | Git branch name. | v1.6.1 |
Expand All @@ -179,7 +178,6 @@ Example of building a container image with options
cd other/docker/windows
docker build \
--build-arg SUPPORT_TEST=true \
--build-arg VERSION_CHECK=0.11.0 \
-t toxcore \
.
```
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Expand Up @@ -7,11 +7,6 @@ install:
- choco install curl
- refreshenv
- 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
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/BUILD.bazel
Expand Up @@ -22,7 +22,6 @@ cc_library(
"//c-toxcore/toxav",
"//c-toxcore/toxcore",
"//c-toxcore/toxencryptsave",
"@check",
],
) for src in glob(["*_test.c"])]

Expand All @@ -47,6 +46,5 @@ cc_test(
":monolith",
"//c-toxcore/other:monolith",
"//c-toxcore/testing:misc_tools",
"@check",
],
)
6 changes: 2 additions & 4 deletions auto_tests/Makefile.inc
Expand Up @@ -5,8 +5,7 @@ check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test on

AUTOTEST_CFLAGS = \
$(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS) \
$(CHECK_CFLAGS)
$(NACL_CFLAGS)

AUTOTEST_LDADD = \
$(LIBSODIUM_LDFLAGS) \
Expand All @@ -15,8 +14,7 @@ AUTOTEST_LDADD = \
libtoxencryptsave.la \
$(LIBSODIUM_LIBS) \
$(NACL_OBJECTS) \
$(NACL_LIBS) \
$(CHECK_LIBS)
$(NACL_LIBS)



Expand Down
74 changes: 66 additions & 8 deletions auto_tests/check_compat.h
@@ -1,8 +1,66 @@
#ifdef _MSC_VER
#define pid_t int
// #include <libcompat.h>
#endif
#include <check.h>
#ifdef _MSC_VER
#undef pid_t
#endif
#ifndef CHECK_COMPAT_H
#define CHECK_COMPAT_H

#include "../toxcore/ccompat.h"

#include <stdbool.h>
#include <stdio.h>

#define START_TEST(name) static void name(void)
#define END_TEST

#define DEFTESTCASE(NAME) test_##NAME()
#define DEFTESTCASE_SLOW(NAME, TIMEOUT) test_##NAME()

typedef struct Suite Suite;
typedef struct SRunner SRunner;
enum SRunMode { CK_NORMAL };

Suite *suite_create(const char *title)
{
printf("Running test suite: %s\n", title);
return nullptr;
}

SRunner *srunner_create(Suite *s)
{
return nullptr;
}

void srunner_free(SRunner *s)
{
}

void srunner_run_all(SRunner *r, int mode)
{
}

int srunner_ntests_failed(SRunner *r)
{
return 0;
}

#define ck_assert(ok) do { \
if (!(ok)) { \
fprintf(stderr, "%s:%d: failed `%s'\n", __FILE__, __LINE__, #ok); \
exit(EXIT_FAILURE); \
} \
} while (0)

#define ck_assert_msg(ok, ...) do { \
if (!(ok)) { \
fprintf(stderr, "%s:%d: failed `%s': ", __FILE__, __LINE__, #ok); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(EXIT_FAILURE); \
} \
} while (0)

#define ck_abort_msg(...) do { \
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(EXIT_FAILURE); \
} while (0)

#endif // CHECK_COMPAT_H
2 changes: 1 addition & 1 deletion auto_tests/dht_test.c
Expand Up @@ -684,7 +684,7 @@ START_TEST(test_dht_create_packet)
ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet.");
ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet.");
ck_assert_msg(length == 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE,
"Invalid size. Should be %d got %d", sizeof(pkt), length);
"Invalid size. Should be %u got %d", (unsigned)sizeof(pkt), length);

printf("Create Packet Successful!\n");
}
Expand Down
9 changes: 0 additions & 9 deletions auto_tests/helpers.h
Expand Up @@ -17,15 +17,6 @@
#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)

#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
DEFTESTCASE(NAME); \
tcase_set_timeout(tc_##NAME, TIMEOUT)

static const char *tox_log_level_name(TOX_LOG_LEVEL level)
{
switch (level) {
Expand Down
26 changes: 14 additions & 12 deletions auto_tests/messenger_test.c
Expand Up @@ -249,8 +249,8 @@ START_TEST(test_dht_state_saveloadsave)
DHT_save(m->dht, buffer + extra);

for (i = 0; i < extra; i++) {
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i);
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", (unsigned)i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", (unsigned)i);
}

int res = DHT_load(m->dht, buffer + extra, size);
Expand All @@ -263,11 +263,12 @@ START_TEST(test_dht_state_saveloadsave)
uint8_t *ptr = buffer + extra + offset;
sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
ck_assert_msg(res == 0, msg);
ck_assert_msg(res == 0, "%s", msg);
}

size_t size2 = DHT_size(m->dht);
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", (unsigned)size,
(unsigned)size2);

VLA(uint8_t, buffer2, size2);
DHT_save(m->dht, buffer2);
Expand All @@ -291,8 +292,8 @@ START_TEST(test_messenger_state_saveloadsave)
messenger_save(m, buffer + extra);

for (i = 0; i < extra; i++) {
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from messenger_save() @%u", i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from messenger_save() @%u", i);
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from messenger_save() @%u", (unsigned)i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from messenger_save() @%u", (unsigned)i);
}

int res = messenger_load(m, buffer + extra, size);
Expand All @@ -305,11 +306,12 @@ START_TEST(test_messenger_state_saveloadsave)
uint8_t *ptr = buffer + extra + offset;
sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
ck_assert_msg(res == 0, msg);
ck_assert_msg(res == 0, "%s", msg);
}

size_t size2 = messenger_size(m);
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u",
(unsigned)size, (unsigned)size2);

VLA(uint8_t, buffer2, size2);
messenger_save(m, buffer2);
Expand Down Expand Up @@ -346,10 +348,6 @@ static Suite *messenger_suite(void)

int main(int argc, char *argv[])
{
Suite *messenger = messenger_suite();
SRunner *test_runner = srunner_create(messenger);
int number_failed = 0;

friend_id = hex_string_to_bin(friend_id_str);
good_id_a = hex_string_to_bin(good_id_a_str);
good_id_b = hex_string_to_bin(good_id_b_str);
Expand All @@ -374,6 +372,10 @@ int main(int argc, char *argv[])
"the tests will continue now...\n\n", stderr);
}

Suite *messenger = messenger_suite();
SRunner *test_runner = srunner_create(messenger);
int number_failed = 0;

srunner_run_all(test_runner, CK_NORMAL);
number_failed = srunner_ntests_failed(test_runner);

Expand Down
8 changes: 4 additions & 4 deletions auto_tests/network_test.c
Expand Up @@ -38,7 +38,7 @@ START_TEST(test_addr_resolv_localhost)

int res = addr_resolve(localhost, &ip, nullptr);

ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
ck_assert_msg(res > 0, "Resolver failed: %u, %s", errno, strerror(errno));

char ip_str[IP_NTOA_LEN];
ck_assert_msg(ip.family == TOX_AF_INET, "Expected family TOX_AF_INET, got %u.", ip.family);
Expand All @@ -54,7 +54,7 @@ START_TEST(test_addr_resolv_localhost)
localhost_split = 1;
}

ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
ck_assert_msg(res > 0, "Resolver failed: %u, %s", errno, strerror(errno));

ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family);
IP6 ip6_loopback = get_ip6_loopback();
Expand All @@ -71,7 +71,7 @@ START_TEST(test_addr_resolv_localhost)
IP extra;
ip_reset(&extra);
res = addr_resolve(localhost, &ip, &extra);
ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
ck_assert_msg(res > 0, "Resolver failed: %u, %s", errno, strerror(errno));

#if USE_IPV6
ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family);
Expand Down Expand Up @@ -149,7 +149,7 @@ START_TEST(test_ip_equal)

ip2.ip6.uint8[15]++;
res = ip_equal(&ip1, &ip2);
ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET6, ::1}, {TOX_AF_INET6, ::2} ): expected result 0, got %res.", res);
ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET6, ::1}, {TOX_AF_INET6, ::2} ): expected result 0, got %u.", res);
}
END_TEST

Expand Down
2 changes: 1 addition & 1 deletion auto_tests/onion_test.c
Expand Up @@ -449,7 +449,7 @@ START_TEST(test_announce)

for (i = 0; i < NUM_ONIONS; ++i) {
onions[i] = new_onions(i + 34655);
ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u");
ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i);
}

IP ip = get_loopback();
Expand Down
10 changes: 2 additions & 8 deletions auto_tests/tox_many_tcp_test.c
Expand Up @@ -259,21 +259,15 @@ START_TEST(test_many_clients_tcp_b)
END_TEST


#ifdef TRAVIS_ENV
static const uint8_t timeout_mux = 20;
#else
static const uint8_t timeout_mux = 10;
#endif

static Suite *tox_suite(void)
{
Suite *s = suite_create("Tox many tcp");

/* Each tox connects to a single tox TCP */
DEFTESTCASE_SLOW(many_clients_tcp, 4 * timeout_mux);
DEFTESTCASE(many_clients_tcp);

/* Try to make a connection to each "older sibling" tox instance via TCP */
DEFTESTCASE_SLOW(many_clients_tcp_b, 8 * timeout_mux);
DEFTESTCASE(many_clients_tcp_b);

return s;
}
Expand Down
8 changes: 1 addition & 7 deletions auto_tests/tox_many_test.c
Expand Up @@ -139,17 +139,11 @@ START_TEST(test_many_clients)
}
END_TEST

#ifdef TRAVIS_ENV
static const uint8_t timeout_mux = 20;
#else
static const uint8_t timeout_mux = 10;
#endif

static Suite *tox_suite(void)
{
Suite *s = suite_create("Tox");

DEFTESTCASE_SLOW(many_clients, 8 * timeout_mux);
DEFTESTCASE(many_clients);

return s;
}
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/tox_strncasecmp_test.c
Expand Up @@ -29,7 +29,7 @@ void verify(const char *s1, const char *s2, size_t n, Comparison expected)

ck_assert_msg(actual == expected,
"tox_strncasecmp(\"%s\", \"%s\", %u) == %s, but expected %s.",
s1, s2, n, Comparison_Str[actual], Comparison_Str[expected]);
s1, s2, (unsigned)n, Comparison_Str[actual], Comparison_Str[expected]);
}

START_TEST(test_general)
Expand Down

0 comments on commit ecc33ad

Please sign in to comment.