+ ASYNC_JOB *job = NULL;
+ int funcret;
+ ASYNC_WAIT_CTX *waitctx = NULL;
+ OSSL_ASYNC_FD fd = OSSL_BAD_ASYNC_FD, delfd = OSSL_BAD_ASYNC_FD;
+ size_t numfds, numdelfds;
+
+ if ( !ASYNC_init_thread(1, 0)
+ || (waitctx = ASYNC_WAIT_CTX_new()) == NULL
+ /* On first run we're not expecting any wait fds */
+ || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
+ != ASYNC_PAUSE
+ || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
+ || numfds != 0
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
+ &numdelfds)
+ || numfds != 0
+ || numdelfds != 0
+ /* On second run we're expecting one added fd */
+ || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
+ != ASYNC_PAUSE
+ || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
+ || numfds != 1
+ || !ASYNC_WAIT_CTX_get_all_fds(waitctx, &fd, &numfds)
+ || fd != MAGIC_WAIT_FD
+ || (fd = OSSL_BAD_ASYNC_FD, 0) /* Assign to something else */
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
+ &numdelfds)
+ || numfds != 1
+ || numdelfds != 0
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, &fd, &numfds, NULL,
+ &numdelfds)
+ || fd != MAGIC_WAIT_FD
+ /* On third run we expect one deleted fd */
+ || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
+ != ASYNC_PAUSE
+ || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
+ || numfds != 0
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
+ &numdelfds)
+ || numfds != 0
+ || numdelfds != 1
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, &delfd,
+ &numdelfds)
+ || delfd != MAGIC_WAIT_FD
+ /* On last run we are not expecting any wait fd */
+ || ASYNC_start_job(&job, waitctx, &funcret, waitfd, NULL, 0)
+ != ASYNC_FINISH
+ || !ASYNC_WAIT_CTX_get_all_fds(waitctx, NULL, &numfds)
+ || numfds != 0
+ || !ASYNC_WAIT_CTX_get_changed_fds(waitctx, NULL, &numfds, NULL,
+ &numdelfds)
+ || numfds != 0
+ || numdelfds != 0
+ || funcret != 1) {
+ fprintf(stderr, "test_ASYNC_get_wait_fd() failed\n");
+ ASYNC_WAIT_CTX_free(waitctx);
+ ASYNC_cleanup_thread();
+ return 0;
+ }
+
+ ASYNC_WAIT_CTX_free(waitctx);
+ ASYNC_cleanup_thread();
+ return 1;