diff options
author | Russell Bryant <russell@russellbryant.com> | 2010-02-09 23:32:14 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2010-02-09 23:32:14 +0000 |
commit | bbed34f76455df0250862ba4c4c324452ad6c0bb (patch) | |
tree | d10f5c6801b7a0d86ccd2dd6b5b3986e93b82fb5 /tests/test_heap.c | |
parent | dd48c7eb407db16ac60d013319b893f021253af9 (diff) |
Various updates to the unit test API.
1) It occurred to me that the difference in usage between the error ast_str and
the ast_test_update_status() usage has turned out to be a bit ambiguous in
practice. In a lot of cases, the same message was being sent to both.
In other cases, it was only sent to one or the other. My opinion now is that
in every case, I think it makes sense to do both; we should output it to the
CLI as well as save it off for logging purposes.
This change results in most of the changes in this diff, since it required
changes to all existing unit tests. It also allowed for some simplifications
of unit test API implementation code.
2) Update ast_test_status_update() to include the file, function, and line
number for the code providing the update.
3) There are some formatting tweaks here and there. Hopefully they aren't too
distracting for code review purposes. Reviewboard's diff viewer seems to do a
pretty good job of pointing out when something is a whitespace change.
4) I moved the md5_test and sha1_test into the test_utils module. It seemed
like a better approach since these tests are so tiny.
5) I changed the number of nodes used in heap_test_2 from 1 million to
100 thousand. The only reason for this was to reduce the time it took
for this test to run.
6) Remove an unused function prototype that was at the bottom of utils.h.
7) Simplify test_insert() using the LIST_INSERT_SORTALPHA() macro. The one
minor difference in behavior is that it no longer checks for a test registered
with the same name.
8) Expand the code in test_alloc() to provide specific error messages for each
failure case, to clearly inform developers if they forget to set the name,
summary, description, etc.
9) Tweak the output of the "test show registered" CLI command. I swapped the
name and category to have the category first. It seemed more natural since
that is the sort key.
10) Don't output the status ast_str in the "test show results" CLI command.
This is going to tend to be pretty verbose, so just leave that for the
detailed test logs (test generate results).
Review: https://reviewboard.asterisk.org/r/493/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@245864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_heap.c')
-rw-r--r-- | tests/test_heap.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tests/test_heap.c b/tests/test_heap.c index 420bd4f7b..a8dd13e0a 100644 --- a/tests/test_heap.c +++ b/tests/test_heap.c @@ -80,8 +80,6 @@ AST_TEST_DEFINE(heap_test_1) return AST_TEST_FAIL; } - ast_test_status_update(&args->status_update, "pushing nodes\n"); - ast_heap_push(h, &nodes[0]); ast_heap_push(h, &nodes[1]); @@ -90,22 +88,25 @@ AST_TEST_DEFINE(heap_test_1) obj = ast_heap_pop(h); if (obj->val != 3) { + ast_test_status_update(test, "expected 3, got %ld\n", obj->val); return AST_TEST_FAIL; } - ast_test_status_update(&args->status_update, "popping nodes\n"); obj = ast_heap_pop(h); if (obj->val != 2) { + ast_test_status_update(test, "expected 2, got %ld\n", obj->val); return AST_TEST_FAIL; } obj = ast_heap_pop(h); if (obj->val != 1) { + ast_test_status_update(test, "expected 1, got %ld\n", obj->val); return AST_TEST_FAIL; } obj = ast_heap_pop(h); if (obj) { + ast_test_status_update(test, "got unexpected object\n"); return AST_TEST_FAIL; } @@ -117,10 +118,10 @@ AST_TEST_DEFINE(heap_test_1) AST_TEST_DEFINE(heap_test_2) { struct ast_heap *h = NULL; - static const unsigned int one_million = 1000000; + static const unsigned int total = 100000; struct node *nodes = NULL; struct node *node; - unsigned int i = one_million; + unsigned int i = total; long last = LONG_MAX; long cur; enum ast_test_result_state res = AST_TEST_PASS; @@ -130,13 +131,18 @@ AST_TEST_DEFINE(heap_test_2) info->name = "heap_test_2"; info->category = "main/heap/"; info->summary = "load test"; - info->description = "Push a million random elements on to a heap,verify that the heap has been properly constructed, and then ensure that the elements are come back off in the proper order"; + info->description = + "Push one hundred thousand random elements on to a heap, " + "verify that the heap has been properly constructed, " + "and then ensure that the elements are come back off " + "in the proper order." + "\n"; return AST_TEST_NOT_RUN; case TEST_EXECUTE: break; } - if (!(nodes = ast_malloc(one_million * sizeof(*node)))) { + if (!(nodes = ast_malloc(total * sizeof(*node)))) { res = AST_TEST_FAIL; goto return_cleanup; } @@ -160,7 +166,7 @@ AST_TEST_DEFINE(heap_test_2) while ((node = ast_heap_pop(h))) { cur = node->val; if (cur > last) { - ast_str_set(&args->ast_test_error_str, 0, "i: %u, cur: %ld, last: %ld\n", i, cur, last); + ast_test_status_update(test, "i: %u, cur: %ld, last: %ld\n", i, cur, last); res = AST_TEST_FAIL; goto return_cleanup; } @@ -168,8 +174,8 @@ AST_TEST_DEFINE(heap_test_2) i++; } - if (i != one_million) { - ast_str_set(&args->ast_test_error_str, 0, "Stopped popping off after only getting %u nodes\n", i); + if (i != total) { + ast_test_status_update(test, "Stopped popping off after only getting %u nodes\n", i); res = AST_TEST_FAIL; goto return_cleanup; } |