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