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