From 077c4187d9789eaf585568f8178f5e3a470ab781 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Fri, 6 Jun 2014 14:12:57 +0000 Subject: Split astobj2.c into more maintainable components. Split astobj2.c into the following files to improve maintainability. astobj2.c - object primitives, object primitive misc and initialization code. astobj2_private.h - internal object declarations needed by the containers. astobj2_container.c - generic conainer and container misc code. astobj2_container_hash.c - hash container specific code. astobj2_container_rbtree.c - rbtree container specific code. astobj2_container_private.h - generic container definitions and rtti prototypes. https://reviewboard.asterisk.org/r/3576/ ........ Merged revisions 415317 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@415319 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- tests/test_astobj2.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'tests/test_astobj2.c') diff --git a/tests/test_astobj2.c b/tests/test_astobj2.c index 11c79946e..67e8e45bd 100644 --- a/tests/test_astobj2.c +++ b/tests/test_astobj2.c @@ -1924,12 +1924,123 @@ AST_TEST_DEFINE(astobj2_test_4) return res; } +static enum ast_test_result_state test_performance(struct ast_test *test, + enum test_container_type type, unsigned int copt) +{ +#define OBJS 256 + int res = AST_TEST_PASS; + struct ao2_container *c1 = NULL; + struct test_obj *tobj[OBJS]; + struct test_obj *tobj2; + int i; + + switch (type) { + case TEST_CONTAINER_HASH: + c1 = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, copt, 17, + test_hash_cb, test_sort_cb, test_cmp_cb); + break; + case TEST_CONTAINER_LIST: + c1 = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, copt, + test_sort_cb, test_cmp_cb); + break; + case TEST_CONTAINER_RBTREE: + c1 = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX, copt, + test_sort_cb, test_cmp_cb); + break; + } + + for (i = 0; i < OBJS; i++) { + tobj[i] = NULL; + } + + if (!c1) { + ast_test_status_update(test, "Container c1 creation failed.\n"); + res = AST_TEST_FAIL; + goto test_cleanup; + } + + for (i = 0; i < OBJS; i++) { + tobj[i] = ao2_alloc(sizeof(struct test_obj), test_obj_destructor); + if (!tobj[i]) { + ast_test_status_update(test, "test object creation failed.\n"); + res = AST_TEST_FAIL; + goto test_cleanup; + } + tobj[i]->i = i; + ao2_link(c1, tobj[i]); + } + + for (i = 0; i < OBJS; i++) { + if ((!(tobj2 = ao2_find(c1, &i, OBJ_KEY)))) { + ast_test_status_update(test, "Should have found object %d in container.\n", i); + res = AST_TEST_FAIL; + goto test_cleanup; + } + ao2_ref(tobj2, -1); + tobj2 = NULL; + } + +test_cleanup: + for (i = 0; i < OBJS ; i++) { + ao2_cleanup(tobj[i]); + } + ao2_cleanup(c1); + return res; +} + +static enum ast_test_result_state testloop(struct ast_test *test, + enum test_container_type type, int copt) +{ +#define ITERATIONS 2500 + int res = AST_TEST_PASS; + int i; + struct timeval start; + + start = ast_tvnow(); + for (i = 1 ; i <= ITERATIONS && res == AST_TEST_PASS ; i++) { + res = test_performance(test, type, copt); + } + ast_test_status_update(test, "%dK traversals, %9s : %5lu ms\n", + ITERATIONS / 1000, test_container2str(type), (unsigned long)ast_tvdiff_ms(ast_tvnow(), start)); + return res; +} + +AST_TEST_DEFINE(astobj2_test_perf) +{ + int res = AST_TEST_PASS; + + switch (cmd) { + case TEST_INIT: + info->name = "astobj2_test_perf"; + info->category = "/main/astobj2/"; + info->summary = "Test container performance"; + info->description = + "Runs 100000 container traversal tests."; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + res = testloop(test, TEST_CONTAINER_LIST, 0); + if (!res) { + return res; + } + res = testloop(test, TEST_CONTAINER_HASH, 0); + if (!res) { + return res; + } + res = testloop(test, TEST_CONTAINER_RBTREE, 0); + + return res; +} + static int unload_module(void) { AST_TEST_UNREGISTER(astobj2_test_1); AST_TEST_UNREGISTER(astobj2_test_2); AST_TEST_UNREGISTER(astobj2_test_3); AST_TEST_UNREGISTER(astobj2_test_4); + AST_TEST_UNREGISTER(astobj2_test_perf); return 0; } @@ -1939,6 +2050,7 @@ static int load_module(void) AST_TEST_REGISTER(astobj2_test_2); AST_TEST_REGISTER(astobj2_test_3); AST_TEST_REGISTER(astobj2_test_4); + AST_TEST_REGISTER(astobj2_test_perf); return AST_MODULE_LOAD_SUCCESS; } -- cgit v1.2.3