diff options
author | irungentoo <irungentoo@gmail.com> | 2015-11-03 13:40:07 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-11-03 13:40:07 -0500 |
commit | f435e94397feb3121ef334de6873b93adaaf01dd (patch) | |
tree | 17e9c0b8cdda095e940803b34d7f95db325a981d /auto_tests/toxav_many_test.c | |
parent | a25cc96b4f2aeaca169df834e39df796ac08f1bd (diff) | |
parent | ca4214bbcfe554c5754ebc4650cbab09f507567a (diff) |
Merge branch 'new_api' of https://github.com/mannol/toxcore
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r-- | auto_tests/toxav_many_test.c | 610 |
1 files changed, 286 insertions, 324 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 6017e526..9819b694 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -2,18 +2,27 @@ | |||
2 | #include "config.h" | 2 | #include "config.h" |
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #ifndef HAVE_LIBCHECK | ||
6 | # include <assert.h> | ||
7 | |||
8 | # define ck_assert(X) assert(X); | ||
9 | # define START_TEST(NAME) void NAME () | ||
10 | # define END_TEST | ||
11 | #else | ||
12 | # include "helpers.h" | ||
13 | #endif | ||
14 | |||
5 | #include <sys/types.h> | 15 | #include <sys/types.h> |
6 | #include <stdint.h> | 16 | #include <stdint.h> |
7 | #include <string.h> | 17 | #include <string.h> |
8 | #include <stdio.h> | 18 | #include <stdio.h> |
9 | #include <check.h> | ||
10 | #include <stdlib.h> | 19 | #include <stdlib.h> |
11 | #include <time.h> | 20 | #include <time.h> |
12 | #include <assert.h> | ||
13 | 21 | ||
14 | #include <vpx/vpx_image.h> | 22 | #include <vpx/vpx_image.h> |
15 | 23 | ||
16 | #include "../toxcore/tox.h" | 24 | #include "../toxcore/tox.h" |
25 | #include "../toxcore/util.h" | ||
17 | #include "../toxcore/logger.h" | 26 | #include "../toxcore/logger.h" |
18 | #include "../toxcore/crypto_core.h" | 27 | #include "../toxcore/crypto_core.h" |
19 | #include "../toxav/toxav.h" | 28 | #include "../toxav/toxav.h" |
@@ -26,365 +35,318 @@ | |||
26 | #define c_sleep(x) usleep(1000*x) | 35 | #define c_sleep(x) usleep(1000*x) |
27 | #endif | 36 | #endif |
28 | 37 | ||
29 | pthread_mutex_t muhmutex; | ||
30 | |||
31 | typedef enum _CallStatus { | ||
32 | none, | ||
33 | InCall, | ||
34 | Ringing, | ||
35 | Ended, | ||
36 | Rejected, | ||
37 | Canceled | ||
38 | |||
39 | } CallStatus; | ||
40 | |||
41 | typedef struct _Party { | ||
42 | CallStatus status; | ||
43 | ToxAv *av; | ||
44 | int id; | ||
45 | } Party; | ||
46 | |||
47 | typedef struct _ACall { | ||
48 | pthread_t tid; | ||
49 | int idx; | ||
50 | 38 | ||
51 | Party Caller; | 39 | typedef struct { |
52 | Party Callee; | 40 | bool incoming; |
53 | } ACall; | 41 | uint32_t state; |
54 | 42 | } CallControl; | |
55 | typedef struct _Status { | ||
56 | ACall calls[3]; /* Make 3 calls for this test */ | ||
57 | } Status; | ||
58 | |||
59 | Status status_control; | ||
60 | |||
61 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | ||
62 | { | ||
63 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { | ||
64 | tox_friend_add_norequest(m, public_key, 0); | ||
65 | } | ||
66 | } | ||
67 | 43 | ||
44 | typedef struct { | ||
45 | ToxAV* AliceAV; | ||
46 | ToxAV* BobAV; | ||
47 | CallControl* AliceCC; | ||
48 | CallControl* BobCC; | ||
49 | uint32_t friend_number; | ||
50 | } thread_data; | ||
68 | 51 | ||
69 | /******************************************************************************/ | 52 | /** |
70 | void callback_recv_invite ( void *av, int32_t call_index, void *_arg ) | 53 | * Callbacks |
54 | */ | ||
55 | void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | ||
71 | { | 56 | { |
72 | Status *cast = _arg; | 57 | (void) av; |
73 | cast->calls[call_index].Callee.status = Ringing; | 58 | (void) audio_enabled; |
59 | (void) video_enabled; | ||
60 | |||
61 | printf("Handling CALL callback\n"); | ||
62 | ((CallControl*)user_data)[friend_number].incoming = true; | ||
74 | } | 63 | } |
75 | void callback_recv_ringing ( void *av, int32_t call_index, void *_arg ) | 64 | void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
76 | { | 65 | { |
77 | Status *cast = _arg; | 66 | printf("Handling CALL STATE callback: %d %p\n", state, av); |
78 | cast->calls[call_index].Caller.status = Ringing; | 67 | ((CallControl*)user_data)[friend_number].state = state; |
79 | } | 68 | } |
80 | void callback_call_ended ( void *av, int32_t call_index, void *_arg ) | 69 | void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
70 | uint16_t width, uint16_t height, | ||
71 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | ||
72 | int32_t ystride, int32_t ustride, int32_t vstride, | ||
73 | void *user_data) | ||
81 | { | 74 | { |
82 | Status *cast = _arg; | 75 | (void) av; |
83 | 76 | (void) friend_number; | |
84 | if (av == cast->calls[call_index].Caller.av) | 77 | (void) width; |
85 | cast->calls[call_index].Caller.status = Ended; | 78 | (void) height; |
86 | else | 79 | (void) y; |
87 | cast->calls[call_index].Callee.status = Ended; | 80 | (void) u; |
88 | } | 81 | (void) v; |
89 | void callback_call_started ( void *av, int32_t call_index, void *_arg ) | 82 | (void) ystride; |
90 | { | 83 | (void) ustride; |
91 | Status *cast = _arg; | 84 | (void) vstride; |
92 | 85 | (void) user_data; | |
93 | if (av == cast->calls[call_index].Caller.av) | ||
94 | cast->calls[call_index].Caller.status = InCall; | ||
95 | else | ||
96 | cast->calls[call_index].Callee.status = InCall; | ||
97 | } | 86 | } |
98 | void callback_call_canceled ( void *av, int32_t call_index, void *_arg ) | 87 | void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
88 | int16_t const *pcm, | ||
89 | size_t sample_count, | ||
90 | uint8_t channels, | ||
91 | uint32_t sampling_rate, | ||
92 | void *user_data) | ||
99 | { | 93 | { |
94 | (void) av; | ||
95 | (void) friend_number; | ||
96 | (void) pcm; | ||
97 | (void) sample_count; | ||
98 | (void) channels; | ||
99 | (void) sampling_rate; | ||
100 | (void) user_data; | ||
100 | } | 101 | } |
101 | void callback_call_rejected ( void *av, int32_t call_index, void *_arg ) | 102 | void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
102 | { | 103 | { |
103 | Status *cast = _arg; | 104 | (void) userdata; |
104 | cast->calls[call_index].Caller.status = Rejected; | 105 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
105 | } | 106 | ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); |
106 | 107 | } | |
107 | void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) | ||
108 | { | ||
109 | ck_assert_msg(0, "No answer!"); | ||
110 | } | 108 | } |
111 | 109 | ||
112 | void callback_audio (void *agent, int32_t call_idx, const int16_t *PCM, uint16_t size, void *data) | ||
113 | {} | ||
114 | |||
115 | void callback_video (void *agent, int32_t call_idx, const vpx_image_t *img, void *data) | ||
116 | {} | ||
117 | 110 | ||
118 | void register_callbacks(ToxAv *av, void *data) | 111 | /** |
112 | * Iterate helper | ||
113 | */ | ||
114 | ToxAV* setup_av_instance(Tox* tox, CallControl *CC) | ||
119 | { | 115 | { |
120 | toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data); | 116 | TOXAV_ERR_NEW error; |
121 | toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data); | 117 | |
122 | toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data); | 118 | ToxAV* av = toxav_new(tox, &error); |
123 | toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data); | 119 | ck_assert(error == TOXAV_ERR_NEW_OK); |
124 | toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data); | 120 | |
125 | toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data); | 121 | toxav_callback_call(av, t_toxav_call_cb, CC); |
126 | toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); | 122 | toxav_callback_call_state(av, t_toxav_call_state_cb, CC); |
127 | 123 | toxav_callback_video_receive_frame(av, t_toxav_receive_video_frame_cb, CC); | |
128 | 124 | toxav_callback_audio_receive_frame(av, t_toxav_receive_audio_frame_cb, CC); | |
129 | toxav_register_audio_callback(av, callback_audio, NULL); | 125 | |
130 | toxav_register_video_callback(av, callback_video, NULL); | 126 | return av; |
131 | } | 127 | } |
132 | /*************************************************************************************************/ | 128 | void* call_thread(void* pd) |
133 | |||
134 | int call_running[3]; | ||
135 | |||
136 | void *in_thread_call (void *arg) | ||
137 | { | 129 | { |
138 | #define call_print(call, what, args...) printf("[%d] " what "\n", call, ##args) | 130 | ToxAV* AliceAV = ((thread_data*) pd)->AliceAV; |
139 | 131 | ToxAV* BobAV = ((thread_data*) pd)->BobAV; | |
140 | ACall *this_call = arg; | 132 | CallControl* AliceCC = ((thread_data*) pd)->AliceCC; |
141 | uint64_t start = 0; | 133 | CallControl* BobCC = ((thread_data*) pd)->BobCC; |
142 | int step = 0; | 134 | uint32_t friend_number = ((thread_data*) pd)->friend_number; |
143 | int call_idx; | 135 | |
144 | 136 | ||
145 | const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000); | 137 | memset(AliceCC, 0, sizeof(CallControl)); |
146 | int16_t sample_payload[frame_size]; | 138 | memset(BobCC, 0, sizeof(CallControl)); |
147 | randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size); | 139 | |
148 | 140 | { /* Call */ | |
149 | uint8_t prepared_payload[RTP_PAYLOAD_SIZE]; | 141 | TOXAV_ERR_CALL rc; |
150 | 142 | toxav_call(AliceAV, friend_number, 48, 3000, &rc); | |
151 | register_callbacks(this_call->Caller.av, &status_control); | 143 | |
152 | register_callbacks(this_call->Callee.av, arg); | 144 | if (rc != TOXAV_ERR_CALL_OK) { |
153 | 145 | printf("toxav_call failed: %d\n", rc); | |
154 | /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */ | 146 | ck_assert(0); |
155 | pthread_mutex_lock(&muhmutex); | ||
156 | |||
157 | while (call_running[this_call->idx]) { | ||
158 | |||
159 | pthread_mutex_unlock(&muhmutex); | ||
160 | |||
161 | switch ( step ) { | ||
162 | case 0: /* CALLER */ | ||
163 | toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10); | ||
164 | call_print(call_idx, "Calling ..."); | ||
165 | step++; | ||
166 | break; | ||
167 | |||
168 | case 1: /* CALLEE */ | ||
169 | pthread_mutex_lock(&muhmutex); | ||
170 | |||
171 | if (this_call->Caller.status == Ringing) { | ||
172 | call_print(call_idx, "Callee answers ..."); | ||
173 | pthread_mutex_unlock(&muhmutex); | ||
174 | toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings); | ||
175 | step++; | ||
176 | start = time(NULL); | ||
177 | pthread_mutex_lock(&muhmutex); | ||
178 | } | ||
179 | |||
180 | pthread_mutex_unlock(&muhmutex); | ||
181 | break; | ||
182 | |||
183 | case 2: /* Rtp transmission */ | ||
184 | pthread_mutex_lock(&muhmutex); | ||
185 | |||
186 | if (this_call->Caller.status == InCall) { /* I think this is okay */ | ||
187 | call_print(call_idx, "Sending rtp ..."); | ||
188 | pthread_mutex_unlock(&muhmutex); | ||
189 | |||
190 | c_sleep(1000); /* We have race condition here */ | ||
191 | toxav_prepare_transmission(this_call->Callee.av, 0, 1); | ||
192 | toxav_prepare_transmission(this_call->Caller.av, call_idx, 1); | ||
193 | |||
194 | int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, RTP_PAYLOAD_SIZE, | ||
195 | sample_payload, frame_size); | ||
196 | |||
197 | if ( payload_size < 0 ) { | ||
198 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
199 | } | ||
200 | |||
201 | |||
202 | while (time(NULL) - start < 10) { /* 10 seconds */ | ||
203 | /* Both send */ | ||
204 | toxav_send_audio(this_call->Caller.av, call_idx, prepared_payload, payload_size); | ||
205 | |||
206 | toxav_send_audio(this_call->Callee.av, 0, prepared_payload, payload_size); | ||
207 | |||
208 | /* Both receive */ | ||
209 | int16_t storage[RTP_PAYLOAD_SIZE]; | ||
210 | int recved; | ||
211 | |||
212 | c_sleep(20); | ||
213 | } | ||
214 | |||
215 | step++; /* This terminates the loop */ | ||
216 | |||
217 | pthread_mutex_lock(&muhmutex); | ||
218 | toxav_kill_transmission(this_call->Callee.av, 0); | ||
219 | toxav_kill_transmission(this_call->Caller.av, call_idx); | ||
220 | pthread_mutex_unlock(&muhmutex); | ||
221 | |||
222 | /* Call over CALLER hangs up */ | ||
223 | toxav_hangup(this_call->Caller.av, call_idx); | ||
224 | call_print(call_idx, "Hanging up ..."); | ||
225 | |||
226 | pthread_mutex_lock(&muhmutex); | ||
227 | } | ||
228 | |||
229 | pthread_mutex_unlock(&muhmutex); | ||
230 | break; | ||
231 | |||
232 | case 3: /* Wait for Both to have status ended */ | ||
233 | pthread_mutex_lock(&muhmutex); | ||
234 | |||
235 | if (this_call->Caller.status == Ended) { | ||
236 | pthread_mutex_unlock(&muhmutex); | ||
237 | c_sleep(1000); /* race condition */ | ||
238 | pthread_mutex_lock(&muhmutex); | ||
239 | this_call->Callee.status = Ended; | ||
240 | call_running[this_call->idx] = 0; | ||
241 | } | ||
242 | |||
243 | pthread_mutex_unlock(&muhmutex); | ||
244 | |||
245 | break; | ||
246 | |||
247 | } | 147 | } |
248 | |||
249 | c_sleep(20); | ||
250 | |||
251 | pthread_mutex_lock(&muhmutex); | ||
252 | } | 148 | } |
253 | 149 | ||
254 | pthread_mutex_unlock(&muhmutex); | 150 | while (!BobCC->incoming) |
255 | call_print(call_idx, "Call ended successfully!"); | 151 | c_sleep(10); |
152 | |||
153 | { /* Answer */ | ||
154 | TOXAV_ERR_ANSWER rc; | ||
155 | toxav_answer(BobAV, 0, 8, 500, &rc); | ||
156 | |||
157 | if (rc != TOXAV_ERR_ANSWER_OK) { | ||
158 | printf("toxav_answer failed: %d\n", rc); | ||
159 | ck_assert(0); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | c_sleep(30); | ||
164 | |||
165 | int16_t PCM[960]; | ||
166 | uint8_t video_y[800*600]; | ||
167 | uint8_t video_u[800*600 / 2]; | ||
168 | uint8_t video_v[800*600 / 2]; | ||
169 | |||
170 | memset(PCM, 0, sizeof(PCM)); | ||
171 | memset(video_y, 0, sizeof(video_y)); | ||
172 | memset(video_u, 0, sizeof(video_u)); | ||
173 | memset(video_v, 0, sizeof(video_v)); | ||
174 | |||
175 | time_t start_time = time(NULL); | ||
176 | while(time(NULL) - start_time < 4) { | ||
177 | toxav_iterate(AliceAV); | ||
178 | toxav_iterate(BobAV); | ||
179 | |||
180 | toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, NULL); | ||
181 | toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL); | ||
182 | |||
183 | toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, NULL); | ||
184 | toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, NULL); | ||
185 | |||
186 | c_sleep(10); | ||
187 | } | ||
188 | |||
189 | { /* Hangup */ | ||
190 | TOXAV_ERR_CALL_CONTROL rc; | ||
191 | toxav_call_control(AliceAV, friend_number, TOXAV_CALL_CONTROL_CANCEL, &rc); | ||
192 | |||
193 | if (rc != TOXAV_ERR_CALL_CONTROL_OK) { | ||
194 | printf("toxav_call_control failed: %d %p %p\n", rc, AliceAV, BobAV); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | c_sleep(30); | ||
199 | |||
200 | printf ("Closing thread\n"); | ||
256 | pthread_exit(NULL); | 201 | pthread_exit(NULL); |
257 | } | 202 | } |
258 | 203 | ||
259 | 204 | ||
260 | |||
261 | |||
262 | |||
263 | START_TEST(test_AV_three_calls) | 205 | START_TEST(test_AV_three_calls) |
264 | // void test_AV_three_calls() | ||
265 | { | 206 | { |
266 | long long unsigned int cur_time = time(NULL); | 207 | Tox* Alice, *bootstrap, *Bobs[3]; |
267 | Tox *bootstrap_node = tox_new(0, 0); | 208 | ToxAV* AliceAV, *BobsAV[3]; |
268 | Tox *caller = tox_new(0, 0); | 209 | |
269 | Tox *callees[3] = { | 210 | CallControl AliceCC[3], BobsCC[3]; |
270 | tox_new(0, 0), | 211 | |
271 | tox_new(0, 0), | 212 | { |
272 | tox_new(0, 0), | 213 | TOX_ERR_NEW error; |
273 | }; | 214 | |
274 | 215 | bootstrap = tox_new(NULL, &error); | |
275 | 216 | ck_assert(error == TOX_ERR_NEW_OK); | |
276 | ck_assert_msg(bootstrap_node != NULL, "Failed to create bootstrap node"); | 217 | |
277 | 218 | Alice = tox_new(NULL, &error); | |
278 | int i = 0; | 219 | ck_assert(error == TOX_ERR_NEW_OK); |
279 | 220 | ||
280 | for (; i < 3; i ++) { | 221 | Bobs[0] = tox_new(NULL, &error); |
281 | ck_assert_msg(callees[i] != NULL, "Failed to create 3 tox instances"); | 222 | ck_assert(error == TOX_ERR_NEW_OK); |
282 | } | 223 | |
283 | 224 | Bobs[1] = tox_new(NULL, &error); | |
284 | for ( i = 0; i < 3; i ++ ) { | 225 | ck_assert(error == TOX_ERR_NEW_OK); |
285 | uint32_t to_compare = 974536; | 226 | |
286 | tox_callback_friend_request(callees[i], accept_friend_request, &to_compare); | 227 | Bobs[2] = tox_new(NULL, &error); |
287 | uint8_t address[TOX_ADDRESS_SIZE]; | 228 | ck_assert(error == TOX_ERR_NEW_OK); |
288 | tox_self_get_address(callees[i], address); | ||
289 | |||
290 | uint32_t test = tox_friend_add(caller, address, (uint8_t *)"gentoo", 7, 0); | ||
291 | ck_assert_msg( test == i, "Failed to add friend error code: %i", test); | ||
292 | } | 229 | } |
293 | 230 | ||
231 | printf("Created 5 instances of Tox\n"); | ||
232 | printf("Preparing network...\n"); | ||
233 | long long unsigned int cur_time = time(NULL); | ||
234 | |||
235 | uint32_t to_compare = 974536; | ||
236 | uint8_t address[TOX_ADDRESS_SIZE]; | ||
237 | |||
238 | tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); | ||
239 | tox_self_get_address(Alice, address); | ||
240 | |||
241 | |||
242 | ck_assert(tox_friend_add(Bobs[0], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | ||
243 | ck_assert(tox_friend_add(Bobs[1], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | ||
244 | ck_assert(tox_friend_add(Bobs[2], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | ||
245 | |||
294 | uint8_t off = 1; | 246 | uint8_t off = 1; |
295 | 247 | ||
296 | while (1) { | 248 | while (1) { |
297 | tox_iterate(bootstrap_node); | 249 | tox_iterate(bootstrap); |
298 | tox_iterate(caller); | 250 | tox_iterate(Alice); |
299 | 251 | tox_iterate(Bobs[0]); | |
300 | for (i = 0; i < 3; i ++) { | 252 | tox_iterate(Bobs[1]); |
301 | tox_iterate(callees[i]); | 253 | tox_iterate(Bobs[2]); |
302 | } | 254 | |
303 | 255 | if (tox_self_get_connection_status(bootstrap) && | |
304 | 256 | tox_self_get_connection_status(Alice) && | |
305 | if (tox_self_get_connection_status(bootstrap_node) && | 257 | tox_self_get_connection_status(Bobs[0]) && |
306 | tox_self_get_connection_status(caller) && | 258 | tox_self_get_connection_status(Bobs[1]) && |
307 | tox_self_get_connection_status(callees[0]) && | 259 | tox_self_get_connection_status(Bobs[2]) && off) { |
308 | tox_self_get_connection_status(callees[1]) && | ||
309 | tox_self_get_connection_status(callees[2]) && off) { | ||
310 | printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time); | 260 | printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time); |
311 | off = 0; | 261 | off = 0; |
312 | } | 262 | } |
313 | 263 | ||
314 | 264 | if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP && | |
315 | if (tox_friend_get_connection_status(caller, 0, 0) && | 265 | tox_friend_get_connection_status(Alice, 1, NULL) == TOX_CONNECTION_UDP && |
316 | tox_friend_get_connection_status(caller, 1, 0) && | 266 | tox_friend_get_connection_status(Alice, 2, NULL) == TOX_CONNECTION_UDP && |
317 | tox_friend_get_connection_status(caller, 2, 0) ) | 267 | tox_friend_get_connection_status(Bobs[0], 0, NULL) == TOX_CONNECTION_UDP && |
268 | tox_friend_get_connection_status(Bobs[1], 0, NULL) == TOX_CONNECTION_UDP && | ||
269 | tox_friend_get_connection_status(Bobs[2], 0, NULL) == TOX_CONNECTION_UDP) | ||
318 | break; | 270 | break; |
319 | 271 | ||
320 | c_sleep(20); | 272 | c_sleep(20); |
321 | } | 273 | } |
322 | 274 | ||
323 | printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time); | 275 | AliceAV = setup_av_instance(Alice, AliceCC); |
324 | 276 | BobsAV[0] = setup_av_instance(Bobs[0], BobsCC + 0); | |
325 | ToxAv *uniqcallerav = toxav_new(caller, 3); | 277 | BobsAV[1] = setup_av_instance(Bobs[1], BobsCC + 1); |
326 | 278 | BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); | |
327 | for (i = 0; i < 3; i ++) { | 279 | |
328 | status_control.calls[i].idx = i; | 280 | printf("Created 4 instances of ToxAV\n"); |
329 | 281 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); | |
330 | status_control.calls[i].Caller.av = uniqcallerav; | 282 | |
331 | status_control.calls[i].Caller.id = 0; | 283 | thread_data tds[3]; |
332 | status_control.calls[i].Caller.status = none; | 284 | tds[0].AliceAV = AliceAV; |
333 | 285 | tds[0].BobAV = BobsAV[0]; | |
334 | status_control.calls[i].Callee.av = toxav_new(callees[i], 1); | 286 | tds[0].AliceCC = AliceCC + 0; |
335 | status_control.calls[i].Callee.id = i; | 287 | tds[0].BobCC = BobsCC + 0; |
336 | status_control.calls[i].Callee.status = none; | 288 | tds[0].friend_number = 0; |
337 | } | 289 | |
338 | 290 | tds[1].AliceAV = AliceAV; | |
339 | pthread_mutex_init(&muhmutex, NULL); | 291 | tds[1].BobAV = BobsAV[1]; |
340 | 292 | tds[1].AliceCC = AliceCC + 1; | |
341 | for ( i = 0; i < 3; i++ ) { | 293 | tds[1].BobCC = BobsCC + 1; |
342 | call_running[i] = 1; | 294 | tds[1].friend_number = 1; |
343 | pthread_create(&status_control.calls[i].tid, NULL, in_thread_call, &status_control.calls[i]); | 295 | |
344 | } | 296 | tds[2].AliceAV = AliceAV; |
345 | 297 | tds[2].BobAV = BobsAV[2]; | |
346 | /* Now start 3 calls and they'll run for 10 s */ | 298 | tds[2].AliceCC = AliceCC + 2; |
347 | 299 | tds[2].BobCC = BobsCC + 2; | |
348 | for ( i = 0; i < 3; i++ ) | 300 | tds[2].friend_number = 2; |
349 | pthread_detach(status_control.calls[i].tid); | 301 | |
350 | 302 | pthread_t tids[3]; | |
351 | while (call_running[0] || call_running[1] || call_running[2]) { | 303 | (void) pthread_create(tids + 0, NULL, call_thread, tds + 0); |
352 | pthread_mutex_lock(&muhmutex); | 304 | (void) pthread_create(tids + 1, NULL, call_thread, tds + 1); |
353 | 305 | (void) pthread_create(tids + 2, NULL, call_thread, tds + 2); | |
354 | tox_iterate(bootstrap_node); | 306 | |
355 | tox_iterate(caller); | 307 | (void) pthread_detach(tids[0]); |
356 | tox_iterate(callees[0]); | 308 | (void) pthread_detach(tids[1]); |
357 | tox_iterate(callees[1]); | 309 | (void) pthread_detach(tids[2]); |
358 | tox_iterate(callees[2]); | 310 | |
359 | 311 | time_t start_time = time(NULL); | |
360 | for ( i = 0; i < 3; i++ ) | 312 | while (time(NULL) - start_time < 5) { |
361 | toxav_do(status_control.calls[0].Caller.av); | 313 | tox_iterate(Alice); |
362 | 314 | tox_iterate(Bobs[0]); | |
363 | toxav_do(status_control.calls[0].Callee.av); | 315 | tox_iterate(Bobs[1]); |
364 | toxav_do(status_control.calls[1].Callee.av); | 316 | tox_iterate(Bobs[2]); |
365 | toxav_do(status_control.calls[2].Callee.av); | ||
366 | |||
367 | pthread_mutex_unlock(&muhmutex); | ||
368 | c_sleep(20); | 317 | c_sleep(20); |
369 | } | 318 | } |
370 | 319 | ||
371 | toxav_kill(status_control.calls[0].Caller.av); | 320 | (void) pthread_join(tids[0], NULL); |
372 | toxav_kill(status_control.calls[0].Callee.av); | 321 | (void) pthread_join(tids[1], NULL); |
373 | toxav_kill(status_control.calls[1].Callee.av); | 322 | (void) pthread_join(tids[2], NULL); |
374 | toxav_kill(status_control.calls[2].Callee.av); | 323 | |
375 | 324 | printf ("Killing all instances\n"); | |
376 | tox_kill(bootstrap_node); | 325 | toxav_kill(BobsAV[0]); |
377 | tox_kill(caller); | 326 | toxav_kill(BobsAV[1]); |
378 | 327 | toxav_kill(BobsAV[2]); | |
379 | for ( i = 0; i < 3; i ++) | 328 | toxav_kill(AliceAV); |
380 | tox_kill(callees[i]); | 329 | tox_kill(Bobs[0]); |
381 | 330 | tox_kill(Bobs[1]); | |
331 | tox_kill(Bobs[2]); | ||
332 | tox_kill(Alice); | ||
333 | tox_kill(bootstrap); | ||
334 | |||
335 | printf("\nTest successful!\n"); | ||
382 | } | 336 | } |
383 | END_TEST | 337 | END_TEST |
384 | 338 | ||
385 | 339 | ||
386 | 340 | #ifndef HAVE_LIBCHECK | |
387 | 341 | int main(int argc, char *argv[]) | |
342 | { | ||
343 | (void) argc; | ||
344 | (void) argv; | ||
345 | |||
346 | test_AV_three_calls(); | ||
347 | return 0; | ||
348 | } | ||
349 | #else | ||
388 | Suite *tox_suite(void) | 350 | Suite *tox_suite(void) |
389 | { | 351 | { |
390 | Suite *s = suite_create("ToxAV"); | 352 | Suite *s = suite_create("ToxAV"); |
@@ -399,6 +361,9 @@ Suite *tox_suite(void) | |||
399 | 361 | ||
400 | int main(int argc, char *argv[]) | 362 | int main(int argc, char *argv[]) |
401 | { | 363 | { |
364 | (void) argc; | ||
365 | (void) argv; | ||
366 | |||
402 | Suite *tox = tox_suite(); | 367 | Suite *tox = tox_suite(); |
403 | SRunner *test_runner = srunner_create(tox); | 368 | SRunner *test_runner = srunner_create(tox); |
404 | 369 | ||
@@ -410,8 +375,5 @@ int main(int argc, char *argv[]) | |||
410 | srunner_free(test_runner); | 375 | srunner_free(test_runner); |
411 | 376 | ||
412 | return number_failed; | 377 | return number_failed; |
413 | |||
414 | // test_AV_three_calls(); | ||
415 | |||
416 | // return 0; | ||
417 | } | 378 | } |
379 | #endif | ||