2009-02-17 21:04:08 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Russell Bryant <russell@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief ast_sched performance test module
|
|
|
|
*
|
|
|
|
* \author Russell Bryant <russell@digium.com>
|
|
|
|
*/
|
|
|
|
|
2009-04-10 16:00:29 +00:00
|
|
|
/*** MODULEINFO
|
2010-01-25 21:32:38 +00:00
|
|
|
<depend>TEST_FRAMEWORK</depend>
|
2009-04-10 16:00:29 +00:00
|
|
|
***/
|
|
|
|
|
2009-02-17 21:04:08 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2009-02-17 22:02:42 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2009-02-17 21:04:08 +00:00
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/sched.h"
|
2010-01-22 04:50:38 +00:00
|
|
|
#include "asterisk/test.h"
|
2010-01-22 15:09:12 +00:00
|
|
|
#include "asterisk/cli.h"
|
2009-02-17 21:04:08 +00:00
|
|
|
|
|
|
|
static int sched_cb(const void *data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-22 04:50:38 +00:00
|
|
|
AST_TEST_DEFINE(sched_test_order)
|
2009-02-23 17:29:16 +00:00
|
|
|
{
|
|
|
|
struct sched_context *con;
|
2010-01-22 04:50:38 +00:00
|
|
|
enum ast_test_result_state res = AST_TEST_FAIL;
|
2009-02-23 17:29:16 +00:00
|
|
|
int id1, id2, id3, wait;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2010-01-22 04:50:38 +00:00
|
|
|
case TEST_INIT:
|
|
|
|
info->name = "sched_test_order";
|
2010-07-09 17:00:22 +00:00
|
|
|
info->category = "/main/sched/";
|
2010-01-22 04:50:38 +00:00
|
|
|
info->summary = "Test ordering of events in the scheduler API";
|
|
|
|
info->description =
|
|
|
|
"This test ensures that events are properly ordered by the "
|
|
|
|
"time they are scheduled to execute in the scheduler API.";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
2009-02-23 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(con = sched_context_create())) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"Test failed - could not create scheduler context\n");
|
|
|
|
return AST_TEST_FAIL;
|
2009-02-23 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add 3 scheduler entries, and then remove them, ensuring that the result
|
|
|
|
* of ast_sched_wait() looks appropriate at each step along the way. */
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) != -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned -1, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((id1 = ast_sched_add(con, 100000, sched_cb, NULL)) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to add scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) > 100000) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned <= 100000, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((id2 = ast_sched_add(con, 10000, sched_cb, NULL)) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to add scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) > 10000) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned <= 10000, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((id3 = ast_sched_add(con, 1000, sched_cb, NULL)) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to add scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) > 1000) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned <= 1000, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_sched_del(con, id3) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to remove scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) <= 1000) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned > 1000, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_sched_del(con, id2) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to remove scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) <= 10000) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned > 10000, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_sched_del(con, id1) == -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test, "Failed to remove scheduler entry\n");
|
2009-02-23 17:29:16 +00:00
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((wait = ast_sched_wait(con)) != -1) {
|
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
2010-02-09 23:32:14 +00:00
|
|
|
ast_test_status_update(test,
|
2010-01-22 04:50:38 +00:00
|
|
|
"ast_sched_wait() should have returned -1, returned '%d'\n",
|
2009-02-23 17:29:16 +00:00
|
|
|
wait);
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
2010-01-22 04:50:38 +00:00
|
|
|
res = AST_TEST_PASS;
|
2009-02-23 17:29:16 +00:00
|
|
|
|
|
|
|
return_cleanup:
|
|
|
|
sched_context_destroy(con);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *handle_cli_sched_bench(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2009-02-17 21:04:08 +00:00
|
|
|
{
|
|
|
|
struct sched_context *con;
|
|
|
|
struct timeval start;
|
|
|
|
unsigned int num, i;
|
|
|
|
int *sched_ids = NULL;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
2009-02-23 17:29:16 +00:00
|
|
|
e->command = "sched benchmark";
|
2009-02-17 21:04:08 +00:00
|
|
|
e->usage = ""
|
2009-05-04 12:52:44 +00:00
|
|
|
"Usage: sched benchmark <num>\n"
|
2009-02-17 21:04:08 +00:00
|
|
|
"";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != e->args + 1) {
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(a->argv[e->args], "%u", &num) != 1) {
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(con = sched_context_create())) {
|
|
|
|
ast_cli(a->fd, "Test failed - could not create scheduler context\n");
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(sched_ids = ast_malloc(sizeof(*sched_ids) * num))) {
|
|
|
|
ast_cli(a->fd, "Test failed - memory allocation failure\n");
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_cli(a->fd, "Testing ast_sched_add() performance - timing how long it takes "
|
|
|
|
"to add %u entries at random time intervals from 0 to 60 seconds\n", num);
|
|
|
|
|
|
|
|
start = ast_tvnow();
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
int when = abs(ast_random()) % 60000;
|
|
|
|
if ((sched_ids[i] = ast_sched_add(con, when, sched_cb, NULL)) == -1) {
|
|
|
|
ast_cli(a->fd, "Test failed - sched_add returned -1\n");
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-17 22:02:42 +00:00
|
|
|
ast_cli(a->fd, "Test complete - %" PRIi64 " us\n", ast_tvdiff_us(ast_tvnow(), start));
|
2009-02-17 21:04:08 +00:00
|
|
|
|
|
|
|
ast_cli(a->fd, "Testing ast_sched_del() performance - timing how long it takes "
|
|
|
|
"to delete %u entries with random time intervals from 0 to 60 seconds\n", num);
|
|
|
|
|
|
|
|
start = ast_tvnow();
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (ast_sched_del(con, sched_ids[i]) == -1) {
|
|
|
|
ast_cli(a->fd, "Test failed - sched_del returned -1\n");
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-17 22:02:42 +00:00
|
|
|
ast_cli(a->fd, "Test complete - %" PRIi64 " us\n", ast_tvdiff_us(ast_tvnow(), start));
|
2009-02-17 21:04:08 +00:00
|
|
|
|
|
|
|
return_cleanup:
|
|
|
|
sched_context_destroy(con);
|
|
|
|
if (sched_ids) {
|
|
|
|
ast_free(sched_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_cli_entry cli_sched[] = {
|
2009-02-23 17:29:16 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_sched_bench, "Benchmark ast_sched add/del performance"),
|
2009-02-17 21:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int unload_module(void)
|
|
|
|
{
|
2010-01-22 04:50:38 +00:00
|
|
|
AST_TEST_UNREGISTER(sched_test_order);
|
2009-02-17 21:04:08 +00:00
|
|
|
ast_cli_unregister_multiple(cli_sched, ARRAY_LEN(cli_sched));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_module(void)
|
|
|
|
{
|
2010-01-22 04:50:38 +00:00
|
|
|
AST_TEST_REGISTER(sched_test_order);
|
2009-02-17 21:04:08 +00:00
|
|
|
ast_cli_register_multiple(cli_sched, ARRAY_LEN(cli_sched));
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_sched performance test module");
|