Asterisk - The Open Source Telephony Project
18.5.0
|
Unit Test Framework. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/test.h"
#include "asterisk/logger.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/ast_version.h"
#include "asterisk/paths.h"
#include "asterisk/time.h"
#include "asterisk/stasis.h"
#include "asterisk/json.h"
#include "asterisk/astobj2.h"
Go to the source code of this file.
Data Structures | |
struct | ast_test |
struct | ast_test_execute_results |
struct | ast_test_suite_message_payload |
A wrapper object that can be ao2 ref counted around an ast_json blob. More... | |
struct | tests |
Macros | |
#define | FORMAT "%-25.25s %-30.30s %-40.40s %-13.13s\n" |
#define | FORMAT_RES_ALL1 "%s%s %-30.30s %-25.25s %-10.10s\n" |
#define | FORMAT_RES_ALL2 "%s%s %-30.30s %-25.25s %s%ums\n" |
Enumerations | |
enum | test_mode { TEST_ALL = 0, TEST_CATEGORY = 1, TEST_NAME_CATEGORY = 2 } |
Functions | |
int | __ast_test_status_update (const char *file, const char *func, int line, struct ast_test *test, const char *fmt,...) |
void | __ast_test_suite_event_notify (const char *file, const char *func, int line, const char *state, const char *fmt,...) |
void | ast_test_debug (struct ast_test *test, const char *fmt,...) |
AST_TEST_DEFINE (test_registrations) | |
int | ast_test_init (void) |
int | ast_test_register (ast_test_cb_t *cb) |
int | ast_test_register_cleanup (const char *category, ast_test_cleanup_cb_t *cb) |
int | ast_test_register_init (const char *category, ast_test_init_cb_t *cb) |
void | ast_test_set_result (struct ast_test *test, enum ast_test_result_state state) |
struct ast_json * | ast_test_suite_get_blob (struct ast_test_suite_message_payload *payload) |
struct stasis_topic * | ast_test_suite_topic (void) |
int | ast_test_unregister (ast_test_cb_t *cb) |
static char * | complete_test_category (const char *word) |
static char * | complete_test_name (const char *word, const char *category) |
static int | is_reserved_word (const char *word) |
STASIS_MESSAGE_TYPE_DEFN (ast_test_suite_message_type,.to_ami=test_suite_event_to_ami) | |
The message type for test suite messages. More... | |
static struct ast_test * | test_alloc (ast_test_cb_t *cb) |
static int | test_cat_cmp (const char *cat1, const char *cat2) |
compares two test categories to determine if cat1 resides in cat2 More... | |
static void | test_cleanup (void) |
static char * | test_cli_execute_registered (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | test_cli_generate_results (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | test_cli_show_registered (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | test_cli_show_results (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | test_execute (struct ast_test *test) |
static int | test_execute_multiple (const char *name, const char *category, struct ast_cli_args *cli) |
static struct ast_test * | test_free (struct ast_test *test) |
static int | test_generate_results (const char *name, const char *category, const char *xml_path, const char *txt_path) |
static int | test_insert (struct ast_test *test) |
static struct ast_test * | test_remove (ast_test_cb_t *cb) |
static struct ast_manager_event_blob * | test_suite_event_to_ami (struct stasis_message *msg) |
static void | test_suite_message_payload_dtor (void *obj) |
static void | test_txt_entry (struct ast_test *test, FILE *f) |
static void | test_xml_entry (struct ast_test *test, FILE *f) |
Variables | |
static struct ast_test_execute_results | last_results |
static int | registration_errors = 0 |
static char * | reserved_words [] |
static struct ast_cli_entry | test_cli [] |
static const char *const | test_result2str [] |
struct stasis_topic * | test_suite_topic |
The topic for test suite messages. More... | |
static struct tests | tests = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
Unit Test Framework.
Definition in file test.c.
#define FORMAT "%-25.25s %-30.30s %-40.40s %-13.13s\n" |
Referenced by test_cli_show_registered().
#define FORMAT_RES_ALL1 "%s%s %-30.30s %-25.25s %-10.10s\n" |
Referenced by test_cli_show_results().
#define FORMAT_RES_ALL2 "%s%s %-30.30s %-25.25s %s%ums\n" |
Referenced by test_cli_show_results().
enum test_mode |
Enumerator | |
---|---|
TEST_ALL | |
TEST_CATEGORY | |
TEST_NAME_CATEGORY |
Definition at line 97 of file test.c.
int __ast_test_status_update | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
struct ast_test * | test, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 134 of file test.c.
References ast_cli(), ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set_va(), buf, ast_test::cli, ast_cli_args::fd, NULL, and ast_test::status_str.
void __ast_test_suite_event_notify | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
const char * | state, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 1145 of file test.c.
References ao2_alloc, ao2_cleanup, ast_free, ast_json_pack(), ast_str_buffer(), ast_str_create, ast_str_set_va(), ast_test_suite_topic(), buf, NULL, RAII_VAR, stasis_message_create(), stasis_publish(), and test_suite_message_payload_dtor().
void ast_test_debug | ( | struct ast_test * | test, |
const char * | fmt, | ||
... | |||
) |
Definition at line 113 of file test.c.
References ast_cli(), ast_free, ast_str_buffer(), ast_str_create, ast_str_set_va(), buf, ast_test::cli, ast_cli_args::fd, and NULL.
Referenced by astobj2_test_1_helper(), test_traversal_sorted(), and verify_mock_cdr_record().
AST_TEST_DEFINE | ( | test_registrations | ) |
Definition at line 1188 of file test.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_test_info::category, ast_test_info::description, ast_test::info, ast_test_info::name, registration_errors, ast_test_info::summary, TEST_EXECUTE, and TEST_INIT.
int ast_test_init | ( | void | ) |
Provided by test.c
Definition at line 1221 of file test.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), AST_TEST_REGISTER, STASIS_MESSAGE_TYPE_INIT, stasis_topic_create(), and test_cleanup().
Referenced by asterisk_daemon().
int ast_test_register | ( | ast_test_cb_t * | cb | ) |
Definition at line 194 of file test.c.
References ast_log, LOG_ERROR, registration_errors, test, test_alloc(), test_free(), and test_insert().
Referenced by load_module().
int ast_test_register_cleanup | ( | const char * | category, |
ast_test_cleanup_cb_t * | cb | ||
) |
Definition at line 177 of file test.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_test_info::category, ast_test::cb, ast_test::cleanup_cb, ast_test::info, test, and test_cat_cmp().
Referenced by load_module().
int ast_test_register_init | ( | const char * | category, |
ast_test_init_cb_t * | cb | ||
) |
Definition at line 160 of file test.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_test_info::category, ast_test::cb, ast_test::info, ast_test::init_cb, test, and test_cat_cmp().
Referenced by load_module().
void ast_test_set_result | ( | struct ast_test * | test, |
enum ast_test_result_state | state | ||
) |
Definition at line 262 of file test.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, and ast_test::state.
Referenced by AST_TEST_DEFINE(), handler_wait_for_message(), user_event_wait_for_events(), and verify_bad_headers().
struct ast_json* ast_test_suite_get_blob | ( | struct ast_test_suite_message_payload * | payload | ) |
Definition at line 1095 of file test.c.
References ast_test_suite_message_payload::blob.
Referenced by test_suite_event_to_ami().
struct stasis_topic* ast_test_suite_topic | ( | void | ) |
Definition at line 1069 of file test.c.
References test_suite_topic.
Referenced by __ast_test_suite_event_notify(), and __init_manager().
int ast_test_unregister | ( | ast_test_cb_t * | cb | ) |
Definition at line 218 of file test.c.
References test, test_free(), and test_remove().
Referenced by unload_module().
|
static |
Definition at line 755 of file test.c.
References ast_cli_completion_add(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_test_info::category, ast_test::info, NULL, and test.
Referenced by test_cli_execute_registered(), and test_cli_show_registered().
|
static |
Definition at line 773 of file test.c.
References ast_cli_completion_add(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_test_info::category, ast_test::info, ast_test_info::name, NULL, test, and test_cat_cmp().
Referenced by test_cli_execute_registered(), and test_cli_show_registered().
|
static |
Definition at line 287 of file test.c.
References ARRAY_LEN, and reserved_words.
Referenced by test_xml_entry().
STASIS_MESSAGE_TYPE_DEFN | ( | ast_test_suite_message_type | , |
. | to_ami = test_suite_event_to_ami |
||
) |
|
static |
Definition at line 681 of file test.c.
References ast_calloc, ast_log, ast_str_create, ast_strlen_zero, ast_test_info::category, ast_test::cb, ast_test_info::description, ast_test::info, LOG_ERROR, LOG_WARNING, ast_test_info::name, NULL, registration_errors, ast_test::status_str, ast_test_info::summary, test, test_free(), and TEST_INIT.
Referenced by ast_test_register().
|
static |
compares two test categories to determine if cat1 resides in cat2
Definition at line 642 of file test.c.
Referenced by ast_test_register_cleanup(), ast_test_register_init(), complete_test_name(), test_cli_show_registered(), test_execute_multiple(), and test_generate_results().
|
static |
Definition at line 1211 of file test.c.
References ao2_cleanup, ARRAY_LEN, ast_cli_unregister_multiple(), AST_TEST_UNREGISTER, NULL, and STASIS_MESSAGE_TYPE_CLEANUP.
Referenced by AST_TEST_DEFINE(), ast_test_init(), test_performance(), test_traversal_nonsorted(), and test_traversal_sorted().
|
static |
Definition at line 854 of file test.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), AST_LIST_LOCK, AST_LIST_UNLOCK, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_test_category(), complete_test_name(), ast_cli_args::fd, ast_test_execute_results::last_failed, ast_test_execute_results::last_passed, last_results, NULL, ast_cli_args::pos, test_execute_multiple(), ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 990 of file test.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), ast_config_AST_LOG_DIR, ast_free, ast_str_buffer(), ast_str_create, ast_str_set(), ast_tvnow(), buf, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, make_ari_stubs::file, NULL, ast_cli_args::pos, S_OR, test_generate_results(), type, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 792 of file test.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_test_info::category, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_test_category(), complete_test_name(), ast_cli_args::fd, FORMAT, ast_test::info, ast_test_info::name, NULL, ast_cli_args::pos, ast_test::state, ast_test_info::summary, test_cat_cmp(), test_result2str, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 919 of file test.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_info::category, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_GREEN, COLOR_RED, ast_cli_entry::command, ast_cli_args::fd, FORMAT_RES_ALL1, FORMAT_RES_ALL2, ast_test::info, ast_test_info::name, NULL, ast_cli_args::pos, result_buf, ast_test::state, term_color(), test_result2str, ast_test::time, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 238 of file test.c.
References ast_str_reset(), AST_TEST_FAIL, AST_TEST_NOT_RUN, ast_tvdiff_ms(), ast_tvnow(), ast_test::cb, ast_test::cleanup_cb, ast_test::info, ast_test::init_cb, result, ast_test::state, ast_test::status_str, TEST_EXECUTE, and ast_test::time.
Referenced by test_execute_multiple().
|
static |
Definition at line 382 of file test.c.
References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_info::category, ast_test::cli, COLOR_GREEN, COLOR_RED, execute(), ast_test_info::explicit_only, ast_cli_args::fd, ast_test::info, ast_test_execute_results::last_failed, ast_test_execute_results::last_passed, last_results, ast_test_execute_results::last_time, ast_test_info::name, NULL, result_buf, ast_test::state, term_color(), TEST_ALL, test_cat_cmp(), TEST_CATEGORY, test_execute(), TEST_NAME_CATEGORY, test_result2str, ast_test::time, ast_test_execute_results::total_failed, ast_test_execute_results::total_passed, ast_test_execute_results::total_tests, and ast_test_execute_results::total_time.
Referenced by test_cli_execute_registered().
Definition at line 665 of file test.c.
References ast_free, NULL, and ast_test::status_str.
Referenced by ast_test_register(), ast_test_unregister(), and test_alloc().
|
static |
Definition at line 492 of file test.c.
References ast_get_version(), ast_get_version_num(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_strlen_zero, ast_test_info::category, done, ast_test::info, last_results, LOG_WARNING, ast_test_info::name, NULL, TEST_ALL, test_cat_cmp(), TEST_CATEGORY, TEST_NAME_CATEGORY, test_txt_entry(), test_xml_entry(), ast_test_execute_results::total_failed, ast_test_execute_results::total_passed, ast_test_execute_results::total_tests, and ast_test_execute_results::total_time.
Referenced by test_cli_generate_results().
|
static |
Definition at line 598 of file test.c.
References AST_LIST_INSERT_SORTALPHA, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_test_info::category, and ast_test::info.
Referenced by ast_test_register().
|
static |
Definition at line 617 of file test.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_test::cb, and NULL.
Referenced by ast_test_unregister().
|
static |
Definition at line 1100 of file test.c.
References ast_free, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_manager_event_blob_create(), ast_str_append(), ast_str_buffer(), ast_str_create, ast_strlen_zero, ast_test_suite_get_blob(), EVENT_FLAG_REPORTING, NULL, RAII_VAR, stasis_message_data(), STASIS_MESSAGE_TYPE_DEFN(), to_ami(), and type.
|
static |
Definition at line 1086 of file test.c.
References ast_json_unref(), and ast_test_suite_message_payload::blob.
Referenced by __ast_test_suite_event_notify().
|
static |
Definition at line 348 of file test.c.
References ast_str_buffer(), AST_TEST_FAIL, AST_TEST_NOT_RUN, ast_test_info::category, ast_test_info::description, ast_test::info, ast_test_info::name, S_OR, ast_test::state, ast_test::status_str, ast_test_info::summary, test_result2str, and ast_test::time.
Referenced by test_generate_results().
|
static |
Definition at line 300 of file test.c.
References ast_alloca, ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_strdupa, ast_strsep(), AST_STRSEP_TRIM, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_info::category, ast_test::info, is_reserved_word(), ast_test_info::name, prefix, S_OR, ast_test::state, ast_test::status_str, and ast_test::time.
Referenced by test_generate_results().
|
static |
Referenced by test_cli_execute_registered(), test_execute_multiple(), and test_generate_results().
|
static |
Definition at line 111 of file test.c.
Referenced by AST_TEST_DEFINE(), ast_test_register(), and test_alloc().
|
static |
Definition at line 274 of file test.c.
Referenced by is_reserved_word().
|
static |
|
static |
This array corresponds to the values defined in the ast_test_state enum
Definition at line 58 of file test.c.
Referenced by test_cli_show_registered(), test_cli_show_results(), test_execute_multiple(), and test_txt_entry().
struct stasis_topic* test_suite_topic |
The topic for test suite messages.
Definition at line 55 of file test.c.
Referenced by ast_test_suite_topic().