Skip to content

Commit

Permalink
Merge 2b16c04 into 13aa33a
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jul 17, 2018
2 parents 13aa33a + 2b16c04 commit 485a939
Show file tree
Hide file tree
Showing 80 changed files with 580 additions and 958 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CTestTestfile.cmake
*.pc

# Testing
/amalgamation.*
testing/data
*~

Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ matrix:
- libcv-dev # For av_test.
- libhighgui-dev # For av_test.
- libopencv-contrib-dev # For av_test.
- libsndfile1-dev # For av_test.
- portaudio19-dev # For av_test.
before_install:
# Clear bazel installation.
Expand Down
10 changes: 10 additions & 0 deletions .travis/cmake-linux
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ travis_install() {
}
}

run_static_analysis() {
export CPPFLAGS="-isystem $CACHEDIR/include"
export LDFLAGS="-L $CACHEDIR/lib"
other/analysis/run-clang
other/analysis/run-clang-analyze
}

travis_script() {
. ".travis/flags-$CC.sh"

Expand All @@ -50,6 +57,9 @@ travis_script() {

other/astyle/format-source . "$ASTYLE"

# Use () to run in a separate process so the exports are local.
(run_static_analysis)

cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
Expand Down
25 changes: 11 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if(TRACE)
endif()

if(MIN_LOGGER_LEVEL)
add_definitions(-DMIN_LOGGER_LEVEL=LOG_${MIN_LOGGER_LEVEL})
add_definitions(-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_${MIN_LOGGER_LEVEL})
endif()

option(USE_IPV6 "Use IPv6 in tests" ON)
Expand Down Expand Up @@ -360,6 +360,11 @@ unit_test(toxcore util)
#
################################################################################

add_library(misc_tools
testing/misc_tools.c
testing/misc_tools.h)
target_link_modules(misc_tools toxcore)

set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")

if(ANDROID_CPU_FEATURES)
Expand All @@ -378,7 +383,7 @@ function(auto_test target)
if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
add_executable(auto_${target}_test ${CPUFEATURES}
auto_tests/${target}_test.c)
target_link_modules(auto_${target}_test toxcore)
target_link_modules(auto_${target}_test toxcore misc_tools)
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}")
Expand All @@ -387,14 +392,6 @@ function(auto_test target)
endif()
endfunction()

if(BUILD_TOXAV)
add_definitions(-D__STDC_LIMIT_MACROS=1)
add_executable(auto_monolith_test ${CPUFEATURES}
auto_tests/monolith_test.cc)
target_link_libraries(auto_monolith_test ${toxcore_LINK_MODULES})
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
endif()

auto_test(TCP)
auto_test(bootstrap)
auto_test(conference)
Expand Down Expand Up @@ -448,7 +445,7 @@ if(DHT_BOOTSTRAP)
add_executable(DHT_bootstrap ${CPUFEATURES}
other/DHT_bootstrap.c
other/bootstrap_node_packets.c)
target_link_modules(DHT_bootstrap toxcore)
target_link_modules(DHT_bootstrap toxcore misc_tools)
endif()

option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
Expand Down Expand Up @@ -508,12 +505,12 @@ endif()

add_executable(DHT_test ${CPUFEATURES}
testing/DHT_test.c)
target_link_modules(DHT_test toxcore)
target_link_modules(DHT_test toxcore misc_tools)

add_executable(Messenger_test ${CPUFEATURES}
testing/Messenger_test.c)
target_link_modules(Messenger_test toxcore)
target_link_modules(Messenger_test toxcore misc_tools)

add_executable(random_testing ${CPUFEATURES}
testing/random_testing.cc)
target_link_modules(random_testing toxcore)
target_link_modules(random_testing toxcore misc_tools)
40 changes: 11 additions & 29 deletions auto_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
cc_library(
name = "helpers",
name = "check_compat",
testonly = True,
hdrs = [
"check_compat.h",
"helpers.h",
"run_auto_test.h",
],
hdrs = ["check_compat.h"],
)

cc_library(
name = "run_auto_test",
testonly = True,
hdrs = ["run_auto_test.h"],
)

test_sizes = {
Expand All @@ -18,32 +20,12 @@ test_sizes = {
srcs = [src],
copts = ["-Wno-sign-compare"],
deps = [
":helpers",
"//c-toxcore/other:monolith",
":check_compat",
":run_auto_test",
"//c-toxcore/testing:misc_tools",
"//c-toxcore/toxav",
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:DHT_srcs",
"//c-toxcore/toxencryptsave",
],
) for src in glob(["*_test.c"])]

cc_library(
name = "monolith",
hdrs = glob([
"*.c",
"*.h",
]),
)

cc_test(
name = "monolith_test",
size = "small",
srcs = ["monolith_test.cc"],
copts = ["-Wno-sign-compare"],
deps = [
":helpers",
":monolith",
"//c-toxcore/other:monolith",
"//c-toxcore/testing:misc_tools",
],
)
2 changes: 1 addition & 1 deletion auto_tests/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AUTOTEST_CFLAGS = \
AUTOTEST_LDADD = \
$(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \
libmisc_tools.la \
libtoxcore.la \
libtoxencryptsave.la \
$(LIBSODIUM_LIBS) \
Expand Down Expand Up @@ -115,4 +116,3 @@ tox_strncasecmp_test_LDADD = $(AUTOTEST_LDADD)


EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h
EXTRA_DIST += $(top_srcdir)/auto_tests/helpers.h
16 changes: 2 additions & 14 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "check_compat.h"

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>

#include "../testing/misc_tools.h"
#include "../toxcore/TCP_client.h"
#include "../toxcore/TCP_server.h"

#include "../toxcore/crypto_core.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/util.h"

#include "helpers.h"
#include "check_compat.h"

#define NUM_PORTS 3

Expand Down Expand Up @@ -836,8 +826,6 @@ int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

srand((unsigned int) time(nullptr));

Suite *TCP = TCP_suite();
SRunner *test_runner = srunner_create(TCP);

Expand Down
13 changes: 9 additions & 4 deletions auto_tests/bootstrap_test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "helpers.h"
#include <stdio.h>

#include "../testing/misc_tools.h"
#include "check_compat.h"

static uint8_t const key[] = {
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
Expand All @@ -29,7 +32,9 @@ int main(void)
c_sleep(ITERATION_INTERVAL);
}

assert(tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_UDP);
const TOX_CONNECTION status = tox_self_get_connection_status(tox_udp);
ck_assert_msg(status == TOX_CONNECTION_UDP,
"expected connection status to be UDP, but got %d", status);
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));

tox_kill(tox_udp);
Expand Down
4 changes: 2 additions & 2 deletions auto_tests/conference_double_invite_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdbool.h>
Expand Down
15 changes: 9 additions & 6 deletions auto_tests/conference_peer_nick_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdbool.h>
Expand Down Expand Up @@ -57,15 +57,18 @@ static void rebuild_peer_list(Tox *tox)
++conference_number) {
TOX_ERR_CONFERENCE_PEER_QUERY err;
uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer count for conference %u: err = %d", conference_number, err);

for (uint32_t peer_number = 0; peer_number < count; peer_number++) {
size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err);
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);

uint8_t *const name = malloc(size);
uint8_t *const name = (uint8_t *)malloc(size);
tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
free(name);
}
}
Expand Down
18 changes: 9 additions & 9 deletions auto_tests/conference_simple_test.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "../toxcore/tox.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include "helpers.h"
#include "../testing/misc_tools.h"
#include "../toxcore/tox.h"
#include "check_compat.h"

typedef struct State {
uint32_t id;
Expand Down Expand Up @@ -51,7 +51,7 @@ static void handle_conference_invite(Tox *tox, uint32_t friend_number, TOX_CONFE
{
TOX_ERR_CONFERENCE_JOIN err;
state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
assert(err == TOX_ERR_CONFERENCE_JOIN_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err);
fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference);
state->joined = true;
}
Expand Down Expand Up @@ -186,15 +186,15 @@ int main(void)
TOX_ERR_CONFERENCE_NEW err;
state1.conference = tox_conference_new(tox1, &err);
state1.joined = true;
assert(err == TOX_ERR_CONFERENCE_NEW_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err);
fprintf(stderr, "Created conference: id=%d\n", state1.conference);
}

{
// Invite friend.
TOX_ERR_CONFERENCE_INVITE err;
tox_conference_invite(tox1, 0, state1.conference, &err);
assert(err == TOX_ERR_CONFERENCE_INVITE_OK);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err);
fprintf(stderr, "tox1 invited tox2\n");
}

Expand Down
20 changes: 7 additions & 13 deletions auto_tests/conference_test.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/* Auto Tests: Conferences.
*/

#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "check_compat.h"

#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "../testing/misc_tools.h"
#include "../toxcore/crypto_core.h"
#include "../toxcore/tox.h"
#include "../toxcore/util.h"

#include "helpers.h"
#include "check_compat.h"

#define NUM_GROUP_TOX 5
#define GROUP_MESSAGE "Install Gentoo"
Expand Down Expand Up @@ -125,8 +119,8 @@ static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
for (unsigned i = 0; i < k - 1; ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
(k - 1), i, peer_count);
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
k - 1, i, (unsigned)peer_count);
}
}
}
Expand Down Expand Up @@ -240,8 +234,8 @@ static void test_many_group(void)
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);

ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
NUM_GROUP_TOX, i, peer_count);
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
NUM_GROUP_TOX, i, (unsigned)peer_count);

uint8_t title[2048];
size_t ret = tox_conference_get_title_size(toxes[i], 0, nullptr);
Expand Down
8 changes: 4 additions & 4 deletions auto_tests/conference_two_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//
// This test triggers a different code path than if we only allocate a single
// conference. This is the simplest test possible that triggers it.
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "../testing/misc_tools.h"
#include "../toxcore/tox.h"

#include "check_compat.h"
#include "helpers.h"

int main(void)
{
Expand Down
Loading

0 comments on commit 485a939

Please sign in to comment.