2009-12-22 16:09:11 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
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
|
|
|
* Copyright (C) 2009-2010, Digium, Inc.
|
2009-12-22 16:09:11 +00:00
|
|
|
*
|
|
|
|
* David Vossel <dvossel@digium.com>
|
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
|
|
|
* Russell Bryant <russell@digium.com>
|
2009-12-22 16:09:11 +00:00
|
|
|
*
|
|
|
|
* 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 Test Framework API
|
|
|
|
*
|
|
|
|
* For an overview on how to use the test API, see \ref AstUnitTestAPI
|
|
|
|
*
|
|
|
|
* \author David Vossel <dvossel@digium.com>
|
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
|
|
|
* \author Russell Bryant <russell@digium.com>
|
2009-12-22 16:09:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _AST_TEST_H_
|
|
|
|
#define _AST_TEST_H_
|
|
|
|
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/strings.h"
|
|
|
|
#endif
|
|
|
|
|
2013-01-09 21:14:39 +00:00
|
|
|
/*!
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
\page AstUnitTestAPI Asterisk Unit Test API
|
|
|
|
|
|
|
|
\section UnitTestAPIUsage How to Use the Unit Test API
|
|
|
|
|
|
|
|
\subsection DefineTest Define a Test
|
|
|
|
|
|
|
|
Create a callback function for the test using the AST_TEST_DEFINE macro.
|
|
|
|
|
|
|
|
Each defined test has three arguments avaliable to it's test code.
|
|
|
|
\param struct ast_test_info *info
|
|
|
|
\param enum ast_test_command cmd
|
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
|
|
|
\param struct ast_test *test
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
While these arguments are not visible they are passed to every test function
|
|
|
|
defined using the AST_TEST_DEFINE macro.
|
|
|
|
|
|
|
|
Below is an example of how to define and write a test function.
|
|
|
|
|
|
|
|
\code
|
|
|
|
AST_TEST_DEFINE(sample_test_cb) \\The name of the callback function
|
2013-01-09 21:14:39 +00:00
|
|
|
{ \\The the function's body
|
2009-12-22 16:09:11 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = "sample_test";
|
|
|
|
info->category = "main/test/";
|
|
|
|
info->summary = "sample test for example purpose";
|
|
|
|
info->description = "This demonstrates how to initialize a test function";
|
|
|
|
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
\test code
|
|
|
|
.
|
|
|
|
.
|
|
|
|
.
|
|
|
|
if (fail) { \\ the following is just some example logic
|
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, "an error occured because...");
|
2009-12-22 16:09:11 +00:00
|
|
|
res = AST_RESULT_FAIL;
|
|
|
|
} else {
|
|
|
|
res = AST_RESULT_PASS
|
|
|
|
}
|
|
|
|
return res; \\ result must be of type enum ast_test_result_state
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
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
|
|
|
Details of the test execution, especially failure details, should be provided
|
|
|
|
by using the ast_test_status_update() function.
|
2009-12-22 16:09:11 +00:00
|
|
|
|
2013-01-09 21:14:39 +00:00
|
|
|
\subsection RegisterTest Register a Test
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
Register the test using the AST_TEST_REGISTER macro.
|
|
|
|
|
|
|
|
AST_TEST_REGISTER uses the callback function to retrieve all the information
|
|
|
|
pertaining to a test, so the callback function is the only argument required
|
|
|
|
for registering a test.
|
|
|
|
|
|
|
|
AST_TEST_REGISTER(sample_test_cb); \\ Test callback function defined by AST_TEST_DEFINE
|
|
|
|
|
|
|
|
Tests are unregestered by using the AST_TEST_UNREGISTER macro.
|
|
|
|
|
|
|
|
AST_TEST_UNREGISTER(sample_test_cb); \\ Remove a registered test by callback function
|
|
|
|
|
|
|
|
\subsection ExecuteTest Execute a Test
|
|
|
|
|
|
|
|
Execute and generate test results via CLI commands
|
|
|
|
|
|
|
|
CLI Examples:
|
|
|
|
\code
|
|
|
|
'test show registered all' will show every registered test.
|
|
|
|
'test execute all' will execute every registered test.
|
|
|
|
'test show results all' will show detailed results for ever executed test
|
|
|
|
'test generate results xml' will generate a test report in xml format
|
|
|
|
'test generate results txt' will generate a test report in txt format
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! Macros used for defining and registering a test */
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
|
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
|
|
|
#define AST_TEST_DEFINE(hdr) static enum ast_test_result_state hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test *test)
|
2009-12-22 16:09:11 +00:00
|
|
|
#define AST_TEST_REGISTER(cb) ast_test_register(cb)
|
|
|
|
#define AST_TEST_UNREGISTER(cb) ast_test_unregister(cb)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
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
|
|
|
#define AST_TEST_DEFINE(hdr) static enum ast_test_result_state attribute_unused hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test *test)
|
2009-12-22 16:09:11 +00:00
|
|
|
#define AST_TEST_REGISTER(cb)
|
|
|
|
#define AST_TEST_UNREGISTER(cb)
|
2010-01-06 16:36:02 +00:00
|
|
|
#define ast_test_status_update(a,b,c...)
|
2012-11-21 18:33:16 +00:00
|
|
|
#define ast_test_debug(test, fmt, ...) ast_cli /* Dummy function that should not be called. */
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-08-22 19:19:44 +00:00
|
|
|
/*! Macros used for the Asterisk Test Suite AMI events */
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Notifies the test suite of a change in application state
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Raises a TestEvent manager event with a subtype of StateChange. Additional parameters
|
|
|
|
* The fmt parameter allows additional parameters to be added to the manager event using
|
|
|
|
* printf style statement formatting.
|
|
|
|
*
|
|
|
|
* \param state The state the application has changed to
|
|
|
|
* \param fmt The message with format parameters to add to the manager event
|
|
|
|
*
|
2013-01-09 22:15:41 +00:00
|
|
|
* \return Nothing
|
2011-08-22 19:19:44 +00:00
|
|
|
*/
|
2013-01-09 22:15:41 +00:00
|
|
|
void __ast_test_suite_event_notify(const char *file, const char *func, int line, const char *state, const char *fmt, ...)
|
2013-01-09 21:14:39 +00:00
|
|
|
__attribute__((format(printf, 5, 6)));
|
2011-08-22 19:19:44 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Notifies the test suite of a failed assert on an expression
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* If the expression provided evaluates to true, no action is taken. If the expression
|
|
|
|
* evaluates to a false, a TestEvent manager event is raised with a subtype of Assert, notifying
|
|
|
|
* the test suite that the expression failed to evaluate to true.
|
|
|
|
*
|
|
|
|
* \param exp The expression to evaluate
|
|
|
|
*
|
2013-01-09 22:15:41 +00:00
|
|
|
* \return Nothing
|
2011-08-22 19:19:44 +00:00
|
|
|
*/
|
2013-01-09 22:15:41 +00:00
|
|
|
void __ast_test_suite_assert_notify(const char *file, const char *func, int line, const char *exp);
|
2011-08-22 19:19:44 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \ref __ast_test_suite_event_notify()
|
|
|
|
*/
|
|
|
|
#define ast_test_suite_event_notify(s, f, ...) \
|
|
|
|
__ast_test_suite_event_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, (s), (f), ## __VA_ARGS__)
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \ref __ast_test_suite_assert_notify()
|
|
|
|
*/
|
2013-01-09 22:15:41 +00:00
|
|
|
#define ast_test_suite_assert(exp) \
|
|
|
|
do { \
|
|
|
|
if (__builtin_expect(!(exp), 1)) { \
|
|
|
|
__ast_test_suite_assert_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, #exp); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2011-08-22 19:19:44 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2013-01-09 22:15:41 +00:00
|
|
|
#define ast_test_suite_event_notify(s, f, ...)
|
|
|
|
#define ast_test_suite_assert(exp)
|
2011-08-22 19:19:44 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-12-22 16:09:11 +00:00
|
|
|
enum ast_test_result_state {
|
|
|
|
AST_TEST_NOT_RUN,
|
|
|
|
AST_TEST_PASS,
|
|
|
|
AST_TEST_FAIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ast_test_command {
|
|
|
|
TEST_INIT,
|
|
|
|
TEST_EXECUTE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
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
|
|
|
* \brief An Asterisk unit test.
|
|
|
|
*
|
|
|
|
* This is an opaque type.
|
2009-12-22 16:09:11 +00:00
|
|
|
*/
|
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
|
|
|
struct ast_test;
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
/*!
|
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
|
|
|
* \brief Contains all the initialization information required to store a new test definition
|
2009-12-22 16:09:11 +00:00
|
|
|
*/
|
|
|
|
struct ast_test_info {
|
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
|
|
|
/*! \brief name of test, unique to category */
|
2009-12-22 16:09:11 +00:00
|
|
|
const char *name;
|
2010-07-09 15:35:53 +00:00
|
|
|
/*!
|
|
|
|
* \brief test category
|
|
|
|
*
|
|
|
|
* Tests are categorized in a directory tree style hierarchy. It is expected that
|
|
|
|
* this string have both a leading and trailing forward slash ('/').
|
|
|
|
*/
|
2009-12-22 16:09:11 +00:00
|
|
|
const char *category;
|
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
|
|
|
/*! \brief optional short summary of test */
|
2009-12-22 16:09:11 +00:00
|
|
|
const char *summary;
|
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
|
|
|
/*! \brief optional brief detailed description of test */
|
2009-12-22 16:09:11 +00:00
|
|
|
const char *description;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
/*!
|
|
|
|
* \brief Generic test callback function
|
|
|
|
*
|
|
|
|
* \param error buffer string for failure results
|
|
|
|
*
|
|
|
|
* \retval AST_TEST_PASS for pass
|
|
|
|
* \retval AST_TEST_FAIL for failure
|
|
|
|
*/
|
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
|
|
|
typedef enum ast_test_result_state (ast_test_cb_t)(struct ast_test_info *info,
|
2013-01-09 21:14:39 +00:00
|
|
|
enum ast_test_command cmd, struct ast_test *test);
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief unregisters a test with the test framework
|
|
|
|
*
|
|
|
|
* \param test callback function (required)
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
|
|
|
int ast_test_unregister(ast_test_cb_t *cb);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief registers a test with the test framework
|
|
|
|
*
|
|
|
|
* \param test callback function (required)
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
|
|
|
int ast_test_register(ast_test_cb_t *cb);
|
|
|
|
|
2012-11-21 18:33:16 +00:00
|
|
|
/*!
|
|
|
|
* \brief Unit test debug output.
|
|
|
|
* \since 12.0.0
|
|
|
|
*
|
|
|
|
* \param test Unit test control structure.
|
|
|
|
* \param fmt printf type format string.
|
|
|
|
*
|
|
|
|
* \return Nothing
|
|
|
|
*/
|
|
|
|
void ast_test_debug(struct ast_test *test, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
|
2009-12-22 16:09:11 +00:00
|
|
|
/*!
|
|
|
|
* \brief update test's status during testing.
|
|
|
|
*
|
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
|
|
|
* \param test currently executing test
|
2009-12-22 16:09:11 +00:00
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2013-01-09 21:14:39 +00:00
|
|
|
int __ast_test_status_update(const char *file, const char *func, int line, struct ast_test *test, const char *fmt, ...)
|
|
|
|
__attribute__((format(printf, 5, 6)));
|
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
|
|
|
|
|
|
|
/*!
|
|
|
|
* \ref __ast_test_status_update()
|
|
|
|
*/
|
|
|
|
#define ast_test_status_update(t, f, ...) __ast_test_status_update(__FILE__, __PRETTY_FUNCTION__, __LINE__, (t), (f), ## __VA_ARGS__)
|
2009-12-22 16:09:11 +00:00
|
|
|
|
|
|
|
#endif /* TEST_FRAMEWORK */
|
|
|
|
#endif /* _AST_TEST_H */
|