resolv-tests.c revision 4139a7a731f2831963a42b26aac111422be28792
/*
SSSD
Async resolver tests
Authors:
Martin Nagy <mnagy@redhat.com>
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) Red Hat, Inc 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <check.h>
#include <string.h>
#include <talloc.h>
#include <tevent.h>
#include <popt.h>
#include "tests/common_check.h"
/* Interface under test */
#include "resolv/async_resolv.h"
#define RESOLV_DEFAULT_TIMEOUT 5
static int use_net_test;
static char *txt_host;
static char *srv_host;
struct resolv_test_ctx {
struct tevent_context *ev;
struct resolv_ctx *resolv;
enum {
int error;
bool done;
};
{
struct resolv_test_ctx *test_ctx;
int ret;
fail("Could not allocate memory for test context");
return ENOMEM;
}
fail("Could not init tevent context");
return EFAULT;
}
fail("Could not init resolv context");
return ret;
}
return EOK;
}
{
}
{
void *ctx;
struct resolv_hostent *rhe;
char name[] = "foo.example.com";
char alias_1[] = "bar.example.com";
char alias_2[] = "baz.example.com";
int ttl_1 = 12;
int ttl_2 = 34;
};
}
{
int recv_status;
int status;
struct resolv_hostent *rhostent;
int i;
struct resolv_test_ctx);
if (recv_status != EOK) {
return;
}
char addr_buf[256];
}
}
}
{
struct resolv_test_ctx *test_ctx;
struct tevent_req *req;
const char *hostname = "127.0.0.1";
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
struct resolv_hostent *rhostent;
int i;
struct resolv_test_ctx);
if (recv_status != EOK) {
return;
}
char addr_buf[256];
/* test that localhost resolves to 127.0.0.1 or ::1 */
}
}
}
{
struct resolv_test_ctx *test_ctx;
struct tevent_req *req;
const char *hostname = "localhost.localdomain";
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
struct resolv_hostent *hostent;
struct resolv_test_ctx *test_ctx;
if (recv_status == EOK) {
return;
}
}
{
struct tevent_req *req;
const char *hostname = "sssd.foo";
struct resolv_test_ctx *test_ctx;
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
struct resolv_test_ctx *test_ctx;
void *tmp_ctx;
int i;
switch (test_ctx->tested_function) {
case TESTING_HOSTNAME:
char addr_buf[256];
}
}
break;
case TESTING_TXT:
&txt_replies);
}
break;
case TESTING_SRV:
&srv_replies);
}
break;
default:
break;
}
} else if (txt_replies != NULL) {
} else if (srv_replies != NULL) {
}
}
{
struct tevent_req *req;
struct resolv_test_ctx *test_ctx;
fail("Could not set up test");
return;
}
}
}
}
{
int ret;
struct tevent_req *req;
struct resolv_test_ctx *test_ctx;
}
{
int ret;
struct tevent_req *req;
struct resolv_test_ctx *test_ctx;
}
struct tevent_timer *te,
{
}
struct tevent_timer *te,
{
}
{
struct tevent_req *req;
struct resolv_test_ctx *test_ctx;
fail("Could not set up test");
return;
}
fail("Error calling resolv_gethostbyname_send");
goto done;
}
terminate_tv.tv_usec = 0;
free_timer = tevent_add_timer(test_ctx->ev, test_ctx, free_tv, resolv_free_context, test_ctx->resolv);
if (free_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
terminate_timer = tevent_add_timer(test_ctx->ev, test_ctx, terminate_tv, resolv_free_done, test_ctx);
if (terminate_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
done:
}
struct tevent_timer *te,
{
}
{
int ret;
struct resolv_test_ctx *test_ctx;
int num_replies = 3;
int i;
fail("Could not set up test");
return;
}
/* prepare linked list with reversed values */
for (i = 0; i<num_replies; i++) {
r->priority = num_replies-i;
r->weight = i;
if (!replies) {
replies = r;
prev = r;
} else {
}
}
/* do the sort */
/* check if the list is sorted */
prev = r;
fail_unless(r->priority == i);
}
/* check if the list is complete */
/* test if the weighting algorithm runs..not much do
* deterministically test here since it is based on
* random weight-selection */
for (i = 0; i<num_replies; i++) {
r->weight = i;
if (!replies) {
replies = r;
prev = r;
} else {
}
}
/* do the sort */
/* clean up */
prev = r;
}
/* check for leaks */
}
{
struct tevent_req *req;
struct resolv_test_ctx *test_ctx;
fail("Could not set up test");
return;
}
fail("Error calling resolv_gethostbyname_send");
goto done;
}
terminate_tv.tv_usec = 0;
if (free_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
terminate_timer = tevent_add_timer(test_ctx->ev, test_ctx, terminate_tv, resolv_free_done, test_ctx);
if (terminate_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
done:
}
{
int recv_status;
int status;
struct resolv_test_ctx *test_ctx;
}
{
struct resolv_test_ctx *test_ctx;
struct tevent_req *req;
fail("Could not set up test");
return;
}
}
}
}
Suite *create_resolv_suite(void)
{
/* Do some testing */
if (use_net_test) {
}
}
}
/* Add all test cases to the test suite */
suite_add_tcase(s, tc_resolv);
return s;
}
{
int opt;
int failure_count;
int debug = 0;
struct poptOption long_options[] = {
{ "use-net-test", 'n', POPT_ARG_NONE, 0, 'n', "Run tests that need an active internet connection", NULL },
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
case 'n':
use_net_test = 1;
break;
case 't':
break;
case 's':
break;
default:
return 1;
}
}
if (!use_net_test) {
printf("Network tests disabled. Rerun with the \"-n\" "
"option to run the full suite of tests\n");
}
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
}