summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2004-06-17 14:13:58 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2004-06-17 14:13:58 +0000
commit557894b0ab44fbaa2d68fbce4e5600c68cdfe7b6 (patch)
tree303beca675715c409cc6a5aca7607145341cc286 /test
parent605dae768a93b1af3b21f3e6ab9d00f8b035184e (diff)
downloadlibapr-557894b0ab44fbaa2d68fbce4e5600c68cdfe7b6.tar.gz
Reuse cleanup structures to prevent memory consumption from repeated
register/kill of a cleanup against a single pool: * memory/unix/apr_pools.c (struct apr_pool_t): Add freelist for cleanup structures. (apr_pool_cleanup_kill): Move used cleanup structures onto the freelist. (apr_pool_cleanup_register): Reuse cleanup structure if available. (apr_pool_clear, pool_clear_debug, apr_pool_create): Clear the freelist. * test/testpools.c (checker_cleanup, success_cleanup, test_cleanups): Add tests for cleanups. PR: 23567 (the easy half) git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65206 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/testpools.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/testpools.c b/test/testpools.c
index 18f2aa820..5ef6a7ef3 100644
--- a/test/testpools.c
+++ b/test/testpools.c
@@ -91,6 +91,53 @@ static void test_notancestor(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, 0, apr_pool_is_ancestor(pchild, pmain));
}
+static apr_status_t success_cleanup(void *data)
+{
+ return APR_SUCCESS;
+}
+
+static char *checker_data = "Hello, world.";
+
+static apr_status_t checker_cleanup(void *data)
+{
+ return data == checker_data ? APR_SUCCESS : APR_EGENERAL;
+}
+
+static void test_cleanups(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ int n;
+
+ /* do this several times to test the cleanup freelist handling. */
+ for (n = 0; n < 5; n++) {
+ apr_pool_cleanup_register(pchild, NULL, success_cleanup,
+ success_cleanup);
+ apr_pool_cleanup_register(pchild, checker_data, checker_cleanup,
+ success_cleanup);
+ apr_pool_cleanup_register(pchild, NULL, checker_cleanup,
+ success_cleanup);
+
+ rv = apr_pool_cleanup_run(p, NULL, success_cleanup);
+ ABTS_ASSERT(tc, "nullop cleanup run OK", rv == APR_SUCCESS);
+ rv = apr_pool_cleanup_run(p, checker_data, checker_cleanup);
+ ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_SUCCESS);
+ rv = apr_pool_cleanup_run(p, NULL, checker_cleanup);
+ ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_EGENERAL);
+
+ if (n == 2) {
+ /* clear the pool to check that works */
+ apr_pool_clear(pchild);
+ }
+
+ if (n % 2 == 0) {
+ /* throw another random cleanup into the mix */
+ apr_pool_cleanup_register(pchild, NULL,
+ apr_pool_cleanup_null,
+ apr_pool_cleanup_null);
+ }
+ }
+}
+
abts_suite *testpool(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -101,6 +148,7 @@ abts_suite *testpool(abts_suite *suite)
abts_run_test(suite, test_notancestor, NULL);
abts_run_test(suite, alloc_bytes, NULL);
abts_run_test(suite, calloc_bytes, NULL);
+ abts_run_test(suite, test_cleanups, NULL);
return suite;
}