xref: /netbsd-src/crypto/external/bsd/openssl/dist/test/asynctest.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1c7da899bSchristos /*
2*b0d17251Schristos  * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
3c7da899bSchristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5c7da899bSchristos  * this file except in compliance with the License.  You can obtain a copy
6c7da899bSchristos  * in the file LICENSE in the source distribution or at
7c7da899bSchristos  * https://www.openssl.org/source/license.html
8c7da899bSchristos  */
9c7da899bSchristos 
10c7da899bSchristos #ifdef _WIN32
11c7da899bSchristos # include <windows.h>
12c7da899bSchristos #endif
13c7da899bSchristos 
14c7da899bSchristos #include <stdio.h>
15c7da899bSchristos #include <string.h>
16c7da899bSchristos #include <openssl/async.h>
17c7da899bSchristos #include <openssl/crypto.h>
18c7da899bSchristos 
19c7da899bSchristos static int ctr = 0;
20c7da899bSchristos static ASYNC_JOB *currjob = NULL;
21c7da899bSchristos 
only_pause(void * args)22c7da899bSchristos static int only_pause(void *args)
23c7da899bSchristos {
24c7da899bSchristos     ASYNC_pause_job();
25c7da899bSchristos 
26c7da899bSchristos     return 1;
27c7da899bSchristos }
28c7da899bSchristos 
add_two(void * args)29c7da899bSchristos static int add_two(void *args)
30c7da899bSchristos {
31c7da899bSchristos     ctr++;
32c7da899bSchristos     ASYNC_pause_job();
33c7da899bSchristos     ctr++;
34c7da899bSchristos 
35c7da899bSchristos     return 2;
36c7da899bSchristos }
37c7da899bSchristos 
save_current(void * args)38c7da899bSchristos static int save_current(void *args)
39c7da899bSchristos {
40c7da899bSchristos     currjob = ASYNC_get_current_job();
41c7da899bSchristos     ASYNC_pause_job();
42c7da899bSchristos 
43c7da899bSchristos     return 1;
44c7da899bSchristos }
45c7da899bSchristos 
change_deflt_libctx(void * args)46*b0d17251Schristos static int change_deflt_libctx(void *args)
47*b0d17251Schristos {
48*b0d17251Schristos     OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
49*b0d17251Schristos     OSSL_LIB_CTX *oldctx, *tmpctx;
50*b0d17251Schristos     int ret = 0;
51*b0d17251Schristos 
52*b0d17251Schristos     if (libctx == NULL)
53*b0d17251Schristos         return 0;
54*b0d17251Schristos 
55*b0d17251Schristos     oldctx = OSSL_LIB_CTX_set0_default(libctx);
56*b0d17251Schristos     ASYNC_pause_job();
57*b0d17251Schristos 
58*b0d17251Schristos     /* Check the libctx is set up as we expect */
59*b0d17251Schristos     tmpctx = OSSL_LIB_CTX_set0_default(oldctx);
60*b0d17251Schristos     if (tmpctx != libctx)
61*b0d17251Schristos         goto err;
62*b0d17251Schristos 
63*b0d17251Schristos     /* Set it back again to continue to use our own libctx */
64*b0d17251Schristos     oldctx = OSSL_LIB_CTX_set0_default(libctx);
65*b0d17251Schristos     ASYNC_pause_job();
66*b0d17251Schristos 
67*b0d17251Schristos     /* Check the libctx is set up as we expect */
68*b0d17251Schristos     tmpctx = OSSL_LIB_CTX_set0_default(oldctx);
69*b0d17251Schristos     if (tmpctx != libctx)
70*b0d17251Schristos         goto err;
71*b0d17251Schristos 
72*b0d17251Schristos     ret = 1;
73*b0d17251Schristos  err:
74*b0d17251Schristos     OSSL_LIB_CTX_free(libctx);
75*b0d17251Schristos     return ret;
76*b0d17251Schristos }
77*b0d17251Schristos 
78*b0d17251Schristos 
79c7da899bSchristos #define MAGIC_WAIT_FD   ((OSSL_ASYNC_FD)99)
waitfd(void * args)80c7da899bSchristos static int waitfd(void *args)
81c7da899bSchristos {
82c7da899bSchristos     ASYNC_JOB *job;
83c7da899bSchristos     ASYNC_WAIT_CTX *waitctx;
84c7da899bSchristos     job = ASYNC_get_current_job();
85c7da899bSchristos     if (job == NULL)
86c7da899bSchristos         return 0;
87c7da899bSchristos     waitctx = ASYNC_get_wait_ctx(job);
88c7da899bSchristos     if (waitctx == NULL)
89c7da899bSchristos         return 0;
90c7da899bSchristos 
91c7da899bSchristos     /* First case: no fd added or removed */
92c7da899bSchristos     ASYNC_pause_job();
93c7da899bSchristos 
94c7da899bSchristos     /* Second case: one fd added */
95c7da899bSchristos     if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, MAGIC_WAIT_FD, NULL, NULL))
96c7da899bSchristos         return 0;
97c7da899bSchristos     ASYNC_pause_job();
98c7da899bSchristos 
99c7da899bSchristos     /* Third case: all fd removed */
100c7da899bSchristos     if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))
101c7da899bSchristos         return 0;
102c7da899bSchristos     ASYNC_pause_job();
103c7da899bSchristos 
104c7da899bSchristos     /* Last case: fd added and immediately removed */
105c7da899bSchristos     if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, MAGIC_WAIT_FD, NULL, NULL))
106c7da899bSchristos         return 0;
107c7da899bSchristos     if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))
108c7da899bSchristos         return 0;
109c7da899bSchristos 
110c7da899bSchristos     return 1;
111c7da899bSchristos }
112c7da899bSchristos 
blockpause(void * args)113c7da899bSchristos static int blockpause(void *args)
114c7da899bSchristos {
115c7da899bSchristos     ASYNC_block_pause();
116c7da899bSchristos     ASYNC_pause_job();
117c7da899bSchristos     ASYNC_unblock_pause();
118c7da899bSchristos     ASYNC_pause_job();
119c7da899bSchristos 
120c7da899bSchristos     return 1;
121c7da899bSchristos }
122c7da899bSchristos 
test_ASYNC_init_thread(void)12313d40330Schristos static int test_ASYNC_init_thread(void)
124c7da899bSchristos {
125c7da899bSchristos     ASYNC_JOB *job1 = NULL, *job2 = NULL, *job3 = NULL;
126c7da899bSchristos     int funcret1, funcret2, funcret3;
127c7da899bSchristos     ASYNC_WAIT_CTX *waitctx = NULL;
128c7da899bSchristos 
129c7da899bSchristos     if (       !ASYNC_init_thread(2, 0)
130c7da899bSchristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
131c7da899bSchristos             || ASYNC_start_job(&job1, waitctx, &funcret1, only_pause, NULL, 0)
132c7da899bSchristos                 != ASYNC_PAUSE
133c7da899bSchristos             || ASYNC_start_job(&job2, waitctx, &funcret2, only_pause, NULL, 0)
134c7da899bSchristos                 != ASYNC_PAUSE
135c7da899bSchristos             || ASYNC_start_job(&job3, waitctx, &funcret3, only_pause, NULL, 0)
136c7da899bSchristos                 != ASYNC_NO_JOBS
137c7da899bSchristos             || ASYNC_start_job(&job1, waitctx, &funcret1, only_pause, NULL, 0)
138c7da899bSchristos                 != ASYNC_FINISH
139c7da899bSchristos             || ASYNC_start_job(&job3, waitctx, &funcret3, only_pause, NULL, 0)
140c7da899bSchristos                 != ASYNC_PAUSE
141c7da899bSchristos             || ASYNC_start_job(&job2, waitctx, &funcret2, only_pause, NULL, 0)
142c7da899bSchristos                 != ASYNC_FINISH
143c7da899bSchristos             || ASYNC_start_job(&job3, waitctx, &funcret3, only_pause, NULL, 0)
144c7da899bSchristos                 != ASYNC_FINISH
145c7da899bSchristos             || funcret1 != 1
146c7da899bSchristos             || funcret2 != 1
147c7da899bSchristos             || funcret3 != 1) {
148c7da899bSchristos         fprintf(stderr, "test_ASYNC_init_thread() failed\n");
149c7da899bSchristos         ASYNC_WAIT_CTX_free(waitctx);
150c7da899bSchristos         ASYNC_cleanup_thread();
151c7da899bSchristos         return 0;
152c7da899bSchristos     }
153c7da899bSchristos 
154c7da899bSchristos     ASYNC_WAIT_CTX_free(waitctx);
155c7da899bSchristos     ASYNC_cleanup_thread();
156c7da899bSchristos     return 1;
157c7da899bSchristos }
158c7da899bSchristos 
test_callback(void * arg)159*b0d17251Schristos static int test_callback(void *arg)
160*b0d17251Schristos {
161*b0d17251Schristos     printf("callback test pass\n");
162*b0d17251Schristos     return 1;
163*b0d17251Schristos }
164*b0d17251Schristos 
test_ASYNC_callback_status(void)165*b0d17251Schristos static int test_ASYNC_callback_status(void)
166*b0d17251Schristos {
167*b0d17251Schristos     ASYNC_WAIT_CTX *waitctx = NULL;
168*b0d17251Schristos     int set_arg = 100;
169*b0d17251Schristos     ASYNC_callback_fn get_callback;
170*b0d17251Schristos     void *get_arg;
171*b0d17251Schristos     int set_status = 1;
172*b0d17251Schristos 
173*b0d17251Schristos     if (       !ASYNC_init_thread(1, 0)
174*b0d17251Schristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
175*b0d17251Schristos             || ASYNC_WAIT_CTX_set_callback(waitctx, test_callback, (void*)&set_arg)
176*b0d17251Schristos                != 1
177*b0d17251Schristos             || ASYNC_WAIT_CTX_get_callback(waitctx, &get_callback, &get_arg)
178*b0d17251Schristos                != 1
179*b0d17251Schristos             || test_callback != get_callback
180*b0d17251Schristos             || get_arg != (void*)&set_arg
181*b0d17251Schristos             || (*get_callback)(get_arg) != 1
182*b0d17251Schristos             || ASYNC_WAIT_CTX_set_status(waitctx, set_status) != 1
183*b0d17251Schristos             || set_status != ASYNC_WAIT_CTX_get_status(waitctx)) {
184*b0d17251Schristos         fprintf(stderr, "test_ASYNC_callback_status() failed\n");
185*b0d17251Schristos         ASYNC_WAIT_CTX_free(waitctx);
186*b0d17251Schristos         ASYNC_cleanup_thread();
187*b0d17251Schristos         return 0;
188*b0d17251Schristos     }
189*b0d17251Schristos 
190*b0d17251Schristos     ASYNC_WAIT_CTX_free(waitctx);
191*b0d17251Schristos     ASYNC_cleanup_thread();
192*b0d17251Schristos     return 1;
193*b0d17251Schristos 
194*b0d17251Schristos }
195*b0d17251Schristos 
test_ASYNC_start_job(void)19613d40330Schristos static int test_ASYNC_start_job(void)
197c7da899bSchristos {
198c7da899bSchristos     ASYNC_JOB *job = NULL;
199c7da899bSchristos     int funcret;
200c7da899bSchristos     ASYNC_WAIT_CTX *waitctx = NULL;
201c7da899bSchristos 
202c7da899bSchristos     ctr = 0;
203c7da899bSchristos 
204c7da899bSchristos     if (       !ASYNC_init_thread(1, 0)
205c7da899bSchristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
206c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, add_two, NULL, 0)
207c7da899bSchristos                != ASYNC_PAUSE
208c7da899bSchristos             || ctr != 1
209c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, add_two, NULL, 0)
210c7da899bSchristos                != ASYNC_FINISH
211c7da899bSchristos             || ctr != 2
212c7da899bSchristos             || funcret != 2) {
213c7da899bSchristos         fprintf(stderr, "test_ASYNC_start_job() failed\n");
214c7da899bSchristos         ASYNC_WAIT_CTX_free(waitctx);
215c7da899bSchristos         ASYNC_cleanup_thread();
216c7da899bSchristos         return 0;
217c7da899bSchristos     }
218c7da899bSchristos 
219c7da899bSchristos     ASYNC_WAIT_CTX_free(waitctx);
220c7da899bSchristos     ASYNC_cleanup_thread();
221c7da899bSchristos     return 1;
222c7da899bSchristos }
223c7da899bSchristos 
test_ASYNC_get_current_job(void)22413d40330Schristos static int test_ASYNC_get_current_job(void)
225c7da899bSchristos {
226c7da899bSchristos     ASYNC_JOB *job = NULL;
227c7da899bSchristos     int funcret;
228c7da899bSchristos     ASYNC_WAIT_CTX *waitctx = NULL;
229c7da899bSchristos 
230c7da899bSchristos     currjob = NULL;
231c7da899bSchristos 
232c7da899bSchristos     if (       !ASYNC_init_thread(1, 0)
233c7da899bSchristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
234c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, save_current, NULL, 0)
235c7da899bSchristos                 != ASYNC_PAUSE
236c7da899bSchristos             || currjob != job
237c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, save_current, NULL, 0)
238c7da899bSchristos                 != ASYNC_FINISH
239c7da899bSchristos             || funcret != 1) {
240c7da899bSchristos         fprintf(stderr, "test_ASYNC_get_current_job() failed\n");
241c7da899bSchristos         ASYNC_WAIT_CTX_free(waitctx);
242c7da899bSchristos         ASYNC_cleanup_thread();
243c7da899bSchristos         return 0;
244c7da899bSchristos     }
245c7da899bSchristos 
246c7da899bSchristos     ASYNC_WAIT_CTX_free(waitctx);
247c7da899bSchristos     ASYNC_cleanup_thread();
248c7da899bSchristos     return 1;
249c7da899bSchristos }
250c7da899bSchristos 
test_ASYNC_WAIT_CTX_get_all_fds(void)25113d40330Schristos static int test_ASYNC_WAIT_CTX_get_all_fds(void)
252c7da899bSchristos {
253c7da899bSchristos     ASYNC_JOB *job = NULL;
254c7da899bSchristos     int funcret;
255c7da899bSchristos     ASYNC_WAIT_CTX *waitctx = NULL;
256c7da899bSchristos     OSSL_ASYNC_FD fd = OSSL_BAD_ASYNC_FD, delfd = OSSL_BAD_ASYNC_FD;
257c7da899bSchristos     size_t numfds, numdelfds;
258c7da899bSchristos 
259c7da899bSchristos     if (       !ASYNC_init_thread(1, 0)
260c7da899bSchristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
261c7da899bSchristos                /* On first run we're not expecting any wait fds */
262c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
263c7da899bSchristos                 != ASYNC_PAUSE
264c7da899bSchristos             || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
265c7da899bSchristos             || numfds != 0
266c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
267c7da899bSchristos                                                &numdelfds)
268c7da899bSchristos             || numfds != 0
269c7da899bSchristos             || numdelfds != 0
270c7da899bSchristos                /* On second run we're expecting one added fd */
271c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
272c7da899bSchristos                 != ASYNC_PAUSE
273c7da899bSchristos             || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
274c7da899bSchristos             || numfds != 1
275c7da899bSchristos             || !ASYNC_WAIT_CTX_get_all_fds(waitctx, &fd, &numfds)
276c7da899bSchristos             || fd != MAGIC_WAIT_FD
277c7da899bSchristos             || (fd = OSSL_BAD_ASYNC_FD, 0) /* Assign to something else */
278c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
279c7da899bSchristos                                                &numdelfds)
280c7da899bSchristos             || numfds != 1
281c7da899bSchristos             || numdelfds != 0
282c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, &fd, &numfds, NULL,
283c7da899bSchristos                                                &numdelfds)
284c7da899bSchristos             || fd != MAGIC_WAIT_FD
285c7da899bSchristos                /* On third run we expect one deleted fd */
286c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
287c7da899bSchristos                 != ASYNC_PAUSE
288c7da899bSchristos             || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
289c7da899bSchristos             || numfds != 0
290c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
291c7da899bSchristos                                                &numdelfds)
292c7da899bSchristos             || numfds != 0
293c7da899bSchristos             || numdelfds != 1
294c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, &delfd,
295c7da899bSchristos                                                &numdelfds)
296c7da899bSchristos             || delfd != MAGIC_WAIT_FD
297c7da899bSchristos             /* On last run we are not expecting any wait fd */
298c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
299c7da899bSchristos                 != ASYNC_FINISH
300c7da899bSchristos             || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
301c7da899bSchristos             || numfds != 0
302c7da899bSchristos             || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
303c7da899bSchristos                                                &numdelfds)
304c7da899bSchristos             || numfds != 0
305c7da899bSchristos             || numdelfds != 0
306c7da899bSchristos             || funcret != 1) {
307c7da899bSchristos         fprintf(stderr, "test_ASYNC_get_wait_fd() failed\n");
308c7da899bSchristos         ASYNC_WAIT_CTX_free(waitctx);
309c7da899bSchristos         ASYNC_cleanup_thread();
310c7da899bSchristos         return 0;
311c7da899bSchristos     }
312c7da899bSchristos 
313c7da899bSchristos     ASYNC_WAIT_CTX_free(waitctx);
314c7da899bSchristos     ASYNC_cleanup_thread();
315c7da899bSchristos     return 1;
316c7da899bSchristos }
317c7da899bSchristos 
test_ASYNC_block_pause(void)31813d40330Schristos static int test_ASYNC_block_pause(void)
319c7da899bSchristos {
320c7da899bSchristos     ASYNC_JOB *job = NULL;
321c7da899bSchristos     int funcret;
322c7da899bSchristos     ASYNC_WAIT_CTX *waitctx = NULL;
323c7da899bSchristos 
324c7da899bSchristos     if (       !ASYNC_init_thread(1, 0)
325c7da899bSchristos             || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
326c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, blockpause, NULL, 0)
327c7da899bSchristos                 != ASYNC_PAUSE
328c7da899bSchristos             || ASYNC_start_job(&job, waitctx, &funcret, blockpause, NULL, 0)
329c7da899bSchristos                 != ASYNC_FINISH
330c7da899bSchristos             || funcret != 1) {
331c7da899bSchristos         fprintf(stderr, "test_ASYNC_block_pause() failed\n");
332c7da899bSchristos         ASYNC_WAIT_CTX_free(waitctx);
333c7da899bSchristos         ASYNC_cleanup_thread();
334c7da899bSchristos         return 0;
335c7da899bSchristos     }
336c7da899bSchristos 
337c7da899bSchristos     ASYNC_WAIT_CTX_free(waitctx);
338c7da899bSchristos     ASYNC_cleanup_thread();
339c7da899bSchristos     return 1;
340c7da899bSchristos }
341c7da899bSchristos 
test_ASYNC_start_job_ex(void)342*b0d17251Schristos static int test_ASYNC_start_job_ex(void)
343*b0d17251Schristos {
344*b0d17251Schristos     ASYNC_JOB *job = NULL;
345*b0d17251Schristos     int funcret;
346*b0d17251Schristos     ASYNC_WAIT_CTX *waitctx = NULL;
347*b0d17251Schristos     OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
348*b0d17251Schristos     OSSL_LIB_CTX *oldctx, *tmpctx, *globalctx;
349*b0d17251Schristos     int ret = 0;
350*b0d17251Schristos 
351*b0d17251Schristos     if (libctx == NULL) {
352*b0d17251Schristos         fprintf(stderr,
353*b0d17251Schristos                 "test_ASYNC_start_job_ex() failed to create libctx\n");
354*b0d17251Schristos         goto err;
355*b0d17251Schristos     }
356*b0d17251Schristos 
357*b0d17251Schristos     globalctx = oldctx = OSSL_LIB_CTX_set0_default(libctx);
358*b0d17251Schristos 
359*b0d17251Schristos     if ((waitctx = ASYNC_WAIT_CTX_new()) == NULL
360*b0d17251Schristos             || ASYNC_start_job(&job, waitctx, &funcret, change_deflt_libctx,
361*b0d17251Schristos                                NULL, 0)
362*b0d17251Schristos                != ASYNC_PAUSE) {
363*b0d17251Schristos         fprintf(stderr,
364*b0d17251Schristos                 "test_ASYNC_start_job_ex() failed to start job\n");
365*b0d17251Schristos         goto err;
366*b0d17251Schristos     }
367*b0d17251Schristos 
368*b0d17251Schristos     /* Reset the libctx temporarily to find out what it is*/
369*b0d17251Schristos     tmpctx = OSSL_LIB_CTX_set0_default(oldctx);
370*b0d17251Schristos     oldctx = OSSL_LIB_CTX_set0_default(tmpctx);
371*b0d17251Schristos     if (tmpctx != libctx) {
372*b0d17251Schristos         fprintf(stderr,
373*b0d17251Schristos                 "test_ASYNC_start_job_ex() failed - unexpected libctx\n");
374*b0d17251Schristos         goto err;
375*b0d17251Schristos     }
376*b0d17251Schristos 
377*b0d17251Schristos     if (ASYNC_start_job(&job, waitctx, &funcret, change_deflt_libctx, NULL, 0)
378*b0d17251Schristos                != ASYNC_PAUSE) {
379*b0d17251Schristos         fprintf(stderr,
380*b0d17251Schristos                 "test_ASYNC_start_job_ex() - restarting job failed\n");
381*b0d17251Schristos         goto err;
382*b0d17251Schristos     }
383*b0d17251Schristos 
384*b0d17251Schristos     /* Reset the libctx and continue with the global default libctx */
385*b0d17251Schristos     tmpctx = OSSL_LIB_CTX_set0_default(oldctx);
386*b0d17251Schristos     if (tmpctx != libctx) {
387*b0d17251Schristos         fprintf(stderr,
388*b0d17251Schristos                 "test_ASYNC_start_job_ex() failed - unexpected libctx\n");
389*b0d17251Schristos         goto err;
390*b0d17251Schristos     }
391*b0d17251Schristos 
392*b0d17251Schristos     if (ASYNC_start_job(&job, waitctx, &funcret, change_deflt_libctx, NULL, 0)
393*b0d17251Schristos                != ASYNC_FINISH
394*b0d17251Schristos                 || funcret != 1) {
395*b0d17251Schristos         fprintf(stderr,
396*b0d17251Schristos                 "test_ASYNC_start_job_ex() - finishing job failed\n");
397*b0d17251Schristos         goto err;
398*b0d17251Schristos     }
399*b0d17251Schristos 
400*b0d17251Schristos     /* Reset the libctx temporarily to find out what it is*/
401*b0d17251Schristos     tmpctx = OSSL_LIB_CTX_set0_default(libctx);
402*b0d17251Schristos     OSSL_LIB_CTX_set0_default(tmpctx);
403*b0d17251Schristos     if (tmpctx != globalctx) {
404*b0d17251Schristos         fprintf(stderr,
405*b0d17251Schristos                 "test_ASYNC_start_job_ex() failed - global libctx check failed\n");
406*b0d17251Schristos         goto err;
407*b0d17251Schristos     }
408*b0d17251Schristos 
409*b0d17251Schristos     ret = 1;
410*b0d17251Schristos  err:
411*b0d17251Schristos     ASYNC_WAIT_CTX_free(waitctx);
412*b0d17251Schristos     ASYNC_cleanup_thread();
413*b0d17251Schristos     OSSL_LIB_CTX_free(libctx);
414*b0d17251Schristos     return ret;
415*b0d17251Schristos }
416*b0d17251Schristos 
main(int argc,char ** argv)417c7da899bSchristos int main(int argc, char **argv)
418c7da899bSchristos {
419c7da899bSchristos     if (!ASYNC_is_capable()) {
420c7da899bSchristos         fprintf(stderr,
421c7da899bSchristos                 "OpenSSL build is not ASYNC capable - skipping async tests\n");
422c7da899bSchristos     } else {
423c7da899bSchristos         if (!test_ASYNC_init_thread()
424*b0d17251Schristos                 || !test_ASYNC_callback_status()
425c7da899bSchristos                 || !test_ASYNC_start_job()
426c7da899bSchristos                 || !test_ASYNC_get_current_job()
427c7da899bSchristos                 || !test_ASYNC_WAIT_CTX_get_all_fds()
428*b0d17251Schristos                 || !test_ASYNC_block_pause()
429*b0d17251Schristos                 || !test_ASYNC_start_job_ex()) {
430c7da899bSchristos             return 1;
431c7da899bSchristos         }
432c7da899bSchristos     }
433c7da899bSchristos     printf("PASS\n");
434c7da899bSchristos     return 0;
435c7da899bSchristos }
436