summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2017-04-16 05:57:21 -0400
committerMaxim Biro <nurupo.contributions@gmail.com>2017-04-22 15:31:25 -0400
commitc7f63737ebfff2d1948ec9d6d92295a75d75cae5 (patch)
treeffaa46d8aecb53041ed61f6be73a4743fae6d4b1 /auto_tests
parent5ed37e543825c023163adba95b99ea81d3337196 (diff)
Revert "Implement tox_loop"
This reverts commit 5ff099763b1f56414572e1c12eb2f003117db5a0.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/Makefile.inc11
-rw-r--r--auto_tests/tox_loop_test.c61
2 files changed, 34 insertions, 38 deletions
diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc
index d8d8b1eb..698064c4 100644
--- a/auto_tests/Makefile.inc
+++ b/auto_tests/Makefile.inc
@@ -1,7 +1,7 @@
1if BUILD_TESTS 1if BUILD_TESTS
2 2
3TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_loop_test tox_test dht_autotest tox_strncasecmp_test 3TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest tox_strncasecmp_test
4check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_loop_test tox_test dht_autotest tox_strncasecmp_test 4check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest tox_strncasecmp_test
5 5
6AUTOTEST_CFLAGS = \ 6AUTOTEST_CFLAGS = \
7 $(LIBSODIUM_CFLAGS) \ 7 $(LIBSODIUM_CFLAGS) \
@@ -61,13 +61,6 @@ TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
61TCP_test_LDADD = $(AUTOTEST_LDADD) 61TCP_test_LDADD = $(AUTOTEST_LDADD)
62 62
63 63
64tox_loop_test_SOURCES = ../auto_tests/tox_loop_test.c
65
66tox_loop_test_CFLAGS = $(AUTOTEST_CFLAGS)
67
68tox_loop_test_LDADD = $(AUTOTEST_LDADD)
69
70
71tox_test_SOURCES = ../auto_tests/tox_test.c 64tox_test_SOURCES = ../auto_tests/tox_test.c
72 65
73tox_test_CFLAGS = $(AUTOTEST_CFLAGS) 66tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
diff --git a/auto_tests/tox_loop_test.c b/auto_tests/tox_loop_test.c
index 7589cc4b..56e78bda 100644
--- a/auto_tests/tox_loop_test.c
+++ b/auto_tests/tox_loop_test.c
@@ -1,13 +1,15 @@
1
2
3#include "helpers.h"
4
5#include "../toxcore/tox.h"
6
1#include <check.h> 7#include <check.h>
2#include <pthread.h> 8#include <pthread.h>
9#include <stdio.h>
3#include <stdlib.h> 10#include <stdlib.h>
4#include <time.h>
5#include <unistd.h> 11#include <unistd.h>
6 12
7#include "../toxcore/tox.h"
8
9#include "helpers.h"
10
11#define TCP_RELAY_PORT 33448 13#define TCP_RELAY_PORT 33448
12/* The Travis-CI container responds poorly to ::1 as a localhost address 14/* The Travis-CI container responds poorly to ::1 as a localhost address
13 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */ 15 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
@@ -17,38 +19,38 @@
17#define TOX_LOCALHOST "127.0.0.1" 19#define TOX_LOCALHOST "127.0.0.1"
18#endif 20#endif
19 21
20typedef struct { 22struct loop_test {
21 int start_count, stop_count; 23 int start_count, stop_count;
22 pthread_mutex_t mutex; 24 pthread_mutex_t mutex;
23 Tox *tox; 25 Tox *tox;
24} loop_test; 26};
25 27
26void tox_loop_cb_start(Tox *tox, void *user_data) 28void tox_loop_cb_start(Tox *tox, void *user_data)
27{ 29{
28 loop_test *userdata = (loop_test *) user_data; 30 struct loop_test *userdata = user_data;
29 pthread_mutex_lock(&userdata->mutex); 31 pthread_mutex_lock(&userdata->mutex);
30 userdata->start_count++; 32 userdata->start_count++;
31} 33}
32 34
33void tox_loop_cb_stop(Tox *tox, void *user_data) 35void tox_loop_cb_stop(Tox *tox, void *user_data)
34{ 36{
35 loop_test *userdata = (loop_test *) user_data; 37 struct loop_test *userdata = user_data;
36 userdata->stop_count++; 38 userdata->stop_count++;
37 pthread_mutex_unlock(&userdata->mutex); 39 pthread_mutex_unlock(&userdata->mutex);
38} 40}
39 41
40void *tox_loop_worker(void *data) 42void *tox_loop_worker(void *data)
41{ 43{
42 loop_test *userdata = (loop_test *) data; 44 struct loop_test *userdata = data;
43 tox_loop(userdata->tox, data, NULL); 45 int retval = tox_loop(userdata->tox, data);
44 return NULL; 46 return (void *)retval;
45} 47}
46 48
47START_TEST(test_tox_loop) 49START_TEST(test_tox_loop)
48{ 50{
49 pthread_t worker, worker_tcp; 51 pthread_t worker1, worker2;
50 struct Tox_Options *opts = tox_options_new(NULL); 52 struct Tox_Options opts;
51 loop_test userdata; 53 struct loop_test userdata;
52 uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; 54 uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
53 int retval; 55 int retval;
54 56
@@ -56,42 +58,43 @@ START_TEST(test_tox_loop)
56 userdata.stop_count = 0; 58 userdata.stop_count = 0;
57 pthread_mutex_init(&userdata.mutex, NULL); 59 pthread_mutex_init(&userdata.mutex, NULL);
58 60
59 tox_options_set_tcp_port(opts, TCP_RELAY_PORT); 61 tox_options_default(&opts);
60 userdata.tox = tox_new(opts, NULL); 62 opts.tcp_port = TCP_RELAY_PORT;
63 userdata.tox = tox_new(&opts, 0);
61 tox_callback_loop_begin(userdata.tox, tox_loop_cb_start); 64 tox_callback_loop_begin(userdata.tox, tox_loop_cb_start);
62 tox_callback_loop_end(userdata.tox, tox_loop_cb_stop); 65 tox_callback_loop_end(userdata.tox, tox_loop_cb_stop);
63 pthread_create(&worker, NULL, tox_loop_worker, &userdata); 66 pthread_create(&worker1, NULL, tox_loop_worker, &userdata);
64 67
65 tox_self_get_dht_id(userdata.tox, dpk); 68 tox_self_get_dht_id(userdata.tox, dpk);
66 69
67 tox_options_default(opts); 70 tox_options_default(&opts);
68 loop_test userdata_tcp; 71 struct loop_test userdata_tcp;
69 userdata_tcp.start_count = 0; 72 userdata_tcp.start_count = 0;
70 userdata_tcp.stop_count = 0; 73 userdata_tcp.stop_count = 0;
71 pthread_mutex_init(&userdata_tcp.mutex, NULL); 74 pthread_mutex_init(&userdata_tcp.mutex, NULL);
72 userdata_tcp.tox = tox_new(opts, NULL); 75 userdata_tcp.tox = tox_new(&opts, 0);
73 tox_callback_loop_begin(userdata_tcp.tox, tox_loop_cb_start); 76 tox_callback_loop_begin(userdata_tcp.tox, tox_loop_cb_start);
74 tox_callback_loop_end(userdata_tcp.tox, tox_loop_cb_stop); 77 tox_callback_loop_end(userdata_tcp.tox, tox_loop_cb_stop);
75 pthread_create(&worker_tcp, NULL, tox_loop_worker, &userdata_tcp); 78 pthread_create(&worker2, NULL, tox_loop_worker, &userdata_tcp);
76 79
77 pthread_mutex_lock(&userdata_tcp.mutex); 80 pthread_mutex_lock(&userdata_tcp.mutex);
78 TOX_ERR_BOOTSTRAP error; 81 TOX_ERR_BOOTSTRAP error = 0;
79 ck_assert_msg(tox_add_tcp_relay(userdata_tcp.tox, TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "Add relay error, %i", 82 ck_assert_msg(tox_add_tcp_relay(userdata_tcp.tox, TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i",
80 error); 83 error);
81 ck_assert_msg(tox_bootstrap(userdata_tcp.tox, TOX_LOCALHOST, 33445, dpk, &error), "Bootstrap error, %i", error); 84 ck_assert_msg(tox_bootstrap(userdata_tcp.tox, TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error");
82 pthread_mutex_unlock(&userdata_tcp.mutex); 85 pthread_mutex_unlock(&userdata_tcp.mutex);
83 86
84 sleep(10); 87 sleep(10);
85 88
86 tox_loop_stop(userdata.tox); 89 tox_loop_stop(userdata.tox);
87 pthread_join(worker, (void **)&retval); 90 pthread_join(worker1, (void **)&retval);
88 ck_assert_msg(retval == 0, "tox_loop didn't return 0"); 91 ck_assert_msg(retval == 0, "tox_loop didn't return 0");
89 92
90 tox_kill(userdata.tox); 93 tox_kill(userdata.tox);
91 ck_assert_msg(userdata.start_count == userdata.stop_count, "start and stop must match"); 94 ck_assert_msg(userdata.start_count == userdata.stop_count, "start and stop must match");
92 95
93 tox_loop_stop(userdata_tcp.tox); 96 tox_loop_stop(userdata_tcp.tox);
94 pthread_join(worker_tcp, (void **)&retval); 97 pthread_join(worker2, (void **)&retval);
95 ck_assert_msg(retval == 0, "tox_loop didn't return 0"); 98 ck_assert_msg(retval == 0, "tox_loop didn't return 0");
96 99
97 tox_kill(userdata_tcp.tox); 100 tox_kill(userdata_tcp.tox);
@@ -100,9 +103,9 @@ START_TEST(test_tox_loop)
100END_TEST 103END_TEST
101 104
102#ifdef TRAVIS_ENV 105#ifdef TRAVIS_ENV
103static uint8_t timeout_mux = 20; 106uint8_t timeout_mux = 20;
104#else 107#else
105static uint8_t timeout_mux = 10; 108uint8_t timeout_mux = 10;
106#endif 109#endif
107 110
108static Suite *tox_suite(void) 111static Suite *tox_suite(void)