Asterisk - The Open Source Telephony Project
18.5.0
|
#include "asterisk.h"
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "asterisk/dns_core.h"
#include "asterisk/dns_resolver.h"
#include "asterisk/dns_internal.h"
Go to the source code of this file.
Data Structures | |
struct | async_resolution_data |
Data used by async result callback. More... | |
struct | resolver_data |
File-scoped data used during resolver tests. More... | |
Macros | |
#define | DNS_ANSWER "Grumble Grumble" |
#define | DNS_ANSWER_SIZE strlen(DNS_ANSWER) |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
AST_TEST_DEFINE (resolver_register_unregister) | |
AST_TEST_DEFINE (resolver_register_off_nominal) | |
AST_TEST_DEFINE (resolver_unregister_off_nominal) | |
AST_TEST_DEFINE (resolver_data) | |
AST_TEST_DEFINE (resolver_set_result) | |
AST_TEST_DEFINE (resolver_set_result_off_nominal) | |
AST_TEST_DEFINE (resolver_add_record) | |
AST_TEST_DEFINE (resolver_add_record_off_nominal) | |
AST_TEST_DEFINE (resolver_resolve_sync) | |
AST_TEST_DEFINE (resolver_resolve_sync_off_nominal) | |
AST_TEST_DEFINE (resolver_resolve_async) | |
AST_TEST_DEFINE (resolver_resolve_async_off_nominal) | |
AST_TEST_DEFINE (resolver_resolve_async_cancel) | |
static void | async_callback (const struct ast_dns_query *query) |
Async DNS callback. More... | |
static struct async_resolution_data * | async_data_alloc (void) |
Allocation/initialization for async_resolution_data. More... | |
static void | async_data_destructor (void *obj) |
Destructor for async_resolution_data. More... | |
static int | fail_resolve (struct ast_dns_query *query) |
A resolve() method that simply fails. More... | |
static int | load_module (void) |
static void * | resolution_thread (void *dns_query) |
Thread spawned by the mock resolver. More... | |
static void | resolver_data_cleanup (void) |
Cleanup global mock resolver data. More... | |
static void | resolver_data_init (void) |
Initialize global mock resolver data. More... | |
static void | stub_callback (const struct ast_dns_query *query) |
static int | stub_cancel (struct ast_dns_query *query) |
static int | stub_resolve (struct ast_dns_query *query) |
static int | test_cancel (struct ast_dns_query *query) |
Mock resolver's cancel method. More... | |
static int | test_record (struct ast_test *test, const struct ast_dns_record *record, int rr_type, int rr_class, int ttl, const char *data, const size_t size) |
static int | test_resolve (struct ast_dns_query *query) |
Mock resolver's resolve method. More... | |
static int | test_results (struct ast_test *test, const struct ast_dns_query *query, unsigned int expected_secure, unsigned int expected_bogus, unsigned int expected_rcode, const char *expected_canonical, const char *expected_answer, size_t answer_size) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "DNS API Tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_dns_resolver | test_resolver |
The mock resolver. More... | |
static struct resolver_data | test_resolver_data |
#define DNS_ANSWER "Grumble Grumble" |
Definition at line 294 of file test_dns.c.
Referenced by AST_TEST_DEFINE(), and resolution_thread().
#define DNS_ANSWER_SIZE strlen(DNS_ANSWER) |
Definition at line 295 of file test_dns.c.
Referenced by AST_TEST_DEFINE(), and resolution_thread().
|
static |
Definition at line 1337 of file test_dns.c.
|
static |
Definition at line 1337 of file test_dns.c.
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1337 of file test_dns.c.
AST_TEST_DEFINE | ( | resolver_register_unregister | ) |
Definition at line 47 of file test_dns.c.
References ast_dns_resolver_register(), ast_dns_resolver_unregister(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_dns_resolver::name, stub_cancel(), stub_resolve(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_register_off_nominal | ) |
Definition at line 81 of file test_dns.c.
References ast_dns_resolver_register(), ast_dns_resolver_unregister(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_dns_resolver::name, NULL, stub_cancel(), stub_resolve(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_unregister_off_nominal | ) |
Definition at line 158 of file test_dns.c.
References ast_dns_resolver_unregister(), AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), ast_dns_resolver::name, NULL, stub_cancel(), stub_resolve(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_data | ) |
Definition at line 189 of file test_dns.c.
References ao2_alloc, ao2_cleanup, ao2_ref, ast_dns_resolver_get_data(), ast_dns_resolver_set_data(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_set_result | ) |
Definition at line 297 of file test_dns.c.
References ARRAY_LEN, ast_dns_query_get_result(), ast_dns_resolver_set_result(), ast_dns_result_free(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, DNS_ANSWER, DNS_ANSWER_SIZE, sip_to_pjsip::info(), result, TEST_EXECUTE, TEST_INIT, and test_results().
AST_TEST_DEFINE | ( | resolver_set_result_off_nominal | ) |
Definition at line 355 of file test_dns.c.
References ast_dns_query_get_result(), ast_dns_resolver_set_result(), ast_dns_result_free(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, DNS_ANSWER, DNS_ANSWER_SIZE, sip_to_pjsip::info(), NULL, result, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_add_record | ) |
Definition at line 421 of file test_dns.c.
References ARRAY_LEN, ast_dns_query_get_result(), ast_dns_record_get_next(), ast_dns_record_get_rr_type(), ast_dns_resolver_add_record(), ast_dns_resolver_set_result(), ast_dns_result_free(), ast_dns_result_get_records(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, DNS_ANSWER, DNS_ANSWER_SIZE, sip_to_pjsip::info(), NULL, RAII_VAR, records, result, TEST_EXECUTE, TEST_INIT, test_record(), and type.
AST_TEST_DEFINE | ( | resolver_add_record_off_nominal | ) |
Definition at line 550 of file test_dns.c.
References ast_dns_query_get_result(), ast_dns_resolver_add_record(), ast_dns_resolver_set_result(), ast_dns_result_free(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, DNS_ANSWER, DNS_ANSWER_SIZE, sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_resolve_sync | ) |
Definition at line 781 of file test_dns.c.
References ast_dns_resolve(), ast_dns_resolver_register(), ast_dns_resolver_unregister(), ast_dns_result_free(), ast_dns_result_get_records(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, resolver_data::canceled, cleanup(), sip_to_pjsip::info(), NULL, RAII_VAR, resolver_data::resolution_complete, resolver_data::resolve_called, resolver_data_cleanup(), resolver_data_init(), result, TEST_EXECUTE, TEST_INIT, and test_resolver_data.
AST_TEST_DEFINE | ( | resolver_resolve_sync_off_nominal | ) |
Definition at line 862 of file test_dns.c.
References ARRAY_LEN, ast_dns_resolve(), ast_dns_resolver_register(), ast_dns_resolver_unregister(), ast_dns_result_free(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, fail_resolve(), sip_to_pjsip::info(), ast_dns_resolver::name, name, NULL, result, stub_cancel(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_resolve_async | ) |
Definition at line 1018 of file test_dns.c.
References ao2_cleanup, ast_cond_timedwait, ast_dns_query_get_result(), ast_dns_resolve_async(), ast_dns_resolver_register(), ast_dns_resolver_unregister(), ast_dns_result_get_records(), ast_mutex_lock, ast_mutex_unlock, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_tsnow(), async_callback(), async_data_alloc(), resolver_data::canceled, cleanup(), async_data::complete, async_data::cond, sip_to_pjsip::info(), async_data::lock, NULL, RAII_VAR, resolver_data::resolution_complete, resolver_data::resolve_called, resolver_data_cleanup(), resolver_data_init(), result, TEST_EXECUTE, TEST_INIT, and test_resolver_data.
AST_TEST_DEFINE | ( | resolver_resolve_async_off_nominal | ) |
Definition at line 1121 of file test_dns.c.
References ao2_ref, ARRAY_LEN, ast_dns_resolve_async(), ast_dns_resolver_register(), ast_dns_resolver_unregister(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, fail_resolve(), sip_to_pjsip::info(), ast_dns_resolver::name, name, NULL, stub_callback(), stub_cancel(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolver_resolve_async_cancel | ) |
Definition at line 1200 of file test_dns.c.
References ao2_cleanup, ast_cond_timedwait, ast_dns_query_get_result(), ast_dns_resolve_async(), ast_dns_resolve_cancel(), ast_dns_resolver_register(), ast_dns_resolver_unregister(), ast_mutex_lock, ast_mutex_unlock, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_tsnow(), async_callback(), async_data_alloc(), resolver_data::canceled, cleanup(), async_data::complete, async_data::cond, sip_to_pjsip::info(), async_data::lock, NULL, RAII_VAR, resolver_data::resolution_complete, resolver_data::resolve_called, resolver_data_cleanup(), resolver_data_init(), result, TEST_EXECUTE, TEST_INIT, and test_resolver_data.
|
static |
Async DNS callback.
This is called when an async query completes, either because it resolved or because it was canceled. In our case, this callback is used to signal to the test that it can continue
query | The DNS query that has completed |
Definition at line 1008 of file test_dns.c.
References ast_cond_signal, ast_dns_query_get_data(), ast_mutex_lock, ast_mutex_unlock, async_resolution_data::complete, async_resolution_data::cond, and async_resolution_data::lock.
Referenced by AST_TEST_DEFINE().
|
static |
Allocation/initialization for async_resolution_data.
The DNS core mandates that a query's user data has to be ao2 allocated, so this is a helper method for doing that.
NULL | Failed allocation |
non-NULL | Newly allocated async_resolution_data |
Definition at line 983 of file test_dns.c.
References ao2_alloc, ast_cond_init, ast_mutex_init, async_data_destructor(), async_resolution_data::complete, async_resolution_data::cond, async_resolution_data::lock, and NULL.
Referenced by AST_TEST_DEFINE().
|
static |
Destructor for async_resolution_data.
Definition at line 966 of file test_dns.c.
References ast_cond_destroy, ast_mutex_destroy, async_resolution_data::cond, and async_resolution_data::lock.
Referenced by async_data_alloc().
|
static |
A resolve() method that simply fails.
query | The DNS query to resolve. This is ignored. |
Definition at line 857 of file test_dns.c.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1318 of file test_dns.c.
References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.
|
static |
Thread spawned by the mock resolver.
All DNS resolvers are required to be asynchronous. The mock resolver spawns this thread for every DNS query that is executed.
This thread waits for 5 seconds and then returns the same A record every time. The 5 second wait is to allow for the query to be canceled if desired
dns_query | The ast_dns_query that is being resolved |
Definition at line 670 of file test_dns.c.
References ao2_ref, ast_cond_timedwait, ast_dns_resolver_add_record(), ast_dns_resolver_completed(), ast_dns_resolver_set_result(), ast_mutex_lock, ast_mutex_unlock, ast_tsnow(), resolver_data::cancel_cond, resolver_data::canceled, DNS_ANSWER, DNS_ANSWER_SIZE, resolver_data::lock, NULL, resolver_data::resolution_complete, and test_resolver_data.
Referenced by test_resolve().
|
static |
Cleanup global mock resolver data.
This must be called at the end of tests that use the mock resolver
Definition at line 761 of file test_dns.c.
References ast_cond_destroy, ast_mutex_destroy, resolver_data::cancel_cond, resolver_data::lock, and test_resolver_data.
Referenced by AST_TEST_DEFINE().
|
static |
Initialize global mock resolver data.
This must be called at the beginning of tests that use the mock resolver
Definition at line 746 of file test_dns.c.
References ast_cond_init, ast_mutex_init, resolver_data::cancel_cond, resolver_data::canceled, resolver_data::lock, NULL, resolver_data::resolution_complete, resolver_data::resolve_called, and test_resolver_data.
Referenced by AST_TEST_DEFINE().
|
static |
Stub async resolution callback
Definition at line 1116 of file test_dns.c.
Referenced by AST_TEST_DEFINE().
|
static |
|
static |
|
static |
Mock resolver's cancel method.
This signals the resolution thread not to return any DNS results.
query | DNS query to cancel |
Definition at line 731 of file test_dns.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, resolver_data::cancel_cond, resolver_data::canceled, resolver_data::lock, and test_resolver_data.
|
static |
Definition at line 395 of file test_dns.c.
References ast_dns_record_get_data(), ast_dns_record_get_rr_class(), ast_dns_record_get_rr_type(), ast_dns_record_get_ttl(), and ast_test_status_update.
Referenced by AST_TEST_DEFINE().
|
static |
Mock resolver's resolve method.
query | The query to resolve |
0 | Successfully spawned resolution thread |
non-zero | Failed to spawn the resolution thread |
Definition at line 715 of file test_dns.c.
References ao2_bump, ast_pthread_create_detached, NULL, resolution_thread(), resolver_data::resolve_called, and test_resolver_data.
|
static |
Definition at line 265 of file test_dns.c.
References ast_dns_query_get_result(), ast_dns_result_get_answer(), ast_dns_result_get_bogus(), ast_dns_result_get_canonical(), ast_dns_result_get_rcode(), ast_dns_result_get_secure(), ast_test_status_update, and result.
Referenced by AST_TEST_DEFINE().
|
static |
|
static |
Definition at line 1337 of file test_dns.c.
|
static |
Definition at line 1337 of file test_dns.c.
|
static |
The mock resolver.
The mock resolver does not care about the DNS query that is actually being made on it. It simply regurgitates the same DNS record no matter what.
Definition at line 774 of file test_dns.c.
|
static |
Referenced by AST_TEST_DEFINE(), resolution_thread(), resolver_data_cleanup(), resolver_data_init(), test_cancel(), and test_resolve().