summaryrefslogtreecommitdiffstats
path: root/test/asynctest.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-11-12 10:42:08 +0000
committerMatt Caswell <matt@openssl.org>2015-11-20 23:37:17 +0000
commite8dfb5bf8e525c9799820d01b2df5fde098a9c4c (patch)
tree3f8dc36c25a36b3bf07d55cea8cccdd2a993b716 /test/asynctest.c
parentf4511d4897f56a18a2a681e2ade8063658ff2cbb (diff)
Add ASYNC_block_pause and ASYNC_unblock_pause
There are potential deadlock situations that can occur if code executing within the context of a job aquires a lock, and then pauses the job. This adds an ability to temporarily block pauses from occuring whilst performing work and holding a lock. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'test/asynctest.c')
-rw-r--r--test/asynctest.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/test/asynctest.c b/test/asynctest.c
index 9ce23fbec2..d89e8ad789 100644
--- a/test/asynctest.c
+++ b/test/asynctest.c
@@ -114,6 +114,16 @@ static int wake(void *args)
return 1;
}
+static int blockpause(void *args)
+{
+ ASYNC_block_pause();
+ ASYNC_pause_job();
+ ASYNC_unblock_pause();
+ ASYNC_pause_job();
+
+ return 1;
+}
+
static int test_ASYNC_init_pool()
{
ASYNC_JOB *job1 = NULL, *job2 = NULL, *job3 = NULL;
@@ -210,8 +220,6 @@ static int test_ASYNC_get_wait_fd()
ASYNC_JOB *job = NULL;
int funcret, fd;
- currjob = NULL;
-
if ( !ASYNC_init_pool(1, 0)
|| ASYNC_start_job(&job, &funcret, wake, NULL, 0)
!= ASYNC_PAUSE
@@ -235,6 +243,27 @@ static int test_ASYNC_get_wait_fd()
ASYNC_free_pool();
return 1;
}
+
+static int test_ASYNC_block_pause()
+{
+ ASYNC_JOB *job = NULL;
+ int funcret;
+
+ if ( !ASYNC_init_pool(1, 0)
+ || ASYNC_start_job(&job, &funcret, blockpause, NULL, 0)
+ != ASYNC_PAUSE
+ || ASYNC_start_job(&job, &funcret, blockpause, NULL, 0)
+ != ASYNC_FINISH
+ || funcret != 1) {
+ fprintf(stderr, "test_ASYNC_block_pause() failed\n");
+ ASYNC_free_pool();
+ return 0;
+ }
+
+ ASYNC_free_pool();
+ return 1;
+}
+
#endif
int main(int argc, char **argv)
@@ -250,7 +279,8 @@ int main(int argc, char **argv)
if ( !test_ASYNC_init_pool()
|| !test_ASYNC_start_job()
|| !test_ASYNC_get_current_job()
- || !test_ASYNC_get_wait_fd()) {
+ || !test_ASYNC_get_wait_fd()
+ || !test_ASYNC_block_pause()) {
return 1;
}
#endif