summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>2022-02-24 13:13:25 -0500
committerMatt Caswell <matt@openssl.org>2022-03-10 13:54:07 +0000
commitf6f56f4776727e18d4dd5490e3b507bae068013a (patch)
treecf3781579d62905f2e4198f2595204ba4b22892c /test
parent83c48d96ff24728d94e0890f320b0d1220d9cba3 (diff)
async_posix: Allow custom stack allocation functions to be specified for POSIX contexts
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17762)
Diffstat (limited to 'test')
-rw-r--r--test/asynctest.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/test/asynctest.c b/test/asynctest.c
index 6502ee9845..0e2e012403 100644
--- a/test/asynctest.c
+++ b/test/asynctest.c
@@ -18,6 +18,8 @@
static int ctr = 0;
static ASYNC_JOB *currjob = NULL;
+static int custom_alloc_used = 0;
+static int custom_free_used = 0;
static int only_pause(void *args)
{
@@ -413,6 +415,51 @@ static int test_ASYNC_start_job_ex(void)
return ret;
}
+static void *test_alloc_stack(size_t *num)
+{
+ custom_alloc_used = 1;
+ return OPENSSL_malloc(*num);
+}
+
+static void test_free_stack(void *addr)
+{
+ custom_free_used = 1;
+ OPENSSL_free(addr);
+}
+
+static int test_ASYNC_set_mem_functions(void)
+{
+ ASYNC_stack_alloc_fn alloc_fn;
+ ASYNC_stack_free_fn free_fn;
+
+ /* Not all platforms support this */
+ if (ASYNC_set_mem_functions(test_alloc_stack, test_free_stack) == 0) return 1;
+
+ ASYNC_get_mem_functions(&alloc_fn, &free_fn);
+
+ if ((alloc_fn != test_alloc_stack) || (free_fn != test_free_stack)) {
+ fprintf(stderr,
+ "test_ASYNC_set_mem_functions() - setting and retrieving custom allocators failed\n");
+ return 0;
+ }
+
+ if (!ASYNC_init_thread(1, 1)) {
+ fprintf(stderr,
+ "test_ASYNC_set_mem_functions() - failed initialising ctx pool\n");
+ return 0;
+ }
+ ASYNC_cleanup_thread();
+
+ if (!custom_alloc_used || !custom_free_used) {
+ fprintf(stderr,
+ "test_ASYNC_set_mem_functions() - custom allocation functions not used\n");
+
+ return 0;
+ }
+
+ return 1;
+}
+
int main(int argc, char **argv)
{
if (!ASYNC_is_capable()) {
@@ -425,7 +472,8 @@ int main(int argc, char **argv)
|| !test_ASYNC_get_current_job()
|| !test_ASYNC_WAIT_CTX_get_all_fds()
|| !test_ASYNC_block_pause()
- || !test_ASYNC_start_job_ex()) {
+ || !test_ASYNC_start_job_ex()
+ || !test_ASYNC_set_mem_functions()) {
return 1;
}
}