Commit aec86032 authored by Pekka Pessi's avatar Pekka Pessi

s2check: added s2base.[hc], s2sip.[hc]

Ignore-this: 6a32b36a47a6f9dd2b5fec7c7375c564

Moved nua/test_s2 code here.

darcs-hash:20090303163730-db55f-12ba5d95bf31a9291c7273d182e507c6e3964df7.gz
parent 3d075e08
......@@ -19,6 +19,8 @@ noinst_LIBRARIES = libs2.a
# Rules for building the targets
libs2_a_SOURCES = s2check.h s2tcase.c \
s2base.h s2base.c \
s2sip.c s2sip.h \
s2_localinfo.h s2_localinfo.c \
s2dns.h s2dns.c \
s2util.h s2time.c
......
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2008 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@CFILE s2base.c
* @brief Common check-based tester for Sofia SIP modules
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Wed Apr 30 12:48:27 EEST 2008 ppessi
*/
#include "config.h"
#undef NDEBUG
#define TP_MAGIC_T struct tp_magic_s
#include "s2base.h"
#include <sofia-sip/sip_header.h>
#include <sofia-sip/sip_status.h>
#include <sofia-sip/msg_addr.h>
#include <sofia-sip/su_log.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/sresolv.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <time.h>
#if HAVE_SYS_TIME_H
#include <sys/time.h> /* Get struct timeval */
#endif
#if HAVE_CLOCK_GETTIME
static double
now(void)
{
struct timespec tv;
#if CLOCK_MONOTONIC
if (clock_gettime(CLOCK_MONOTONIC, &tv) != 0)
#endif
clock_gettime(CLOCK_REALTIME, &tv);
return tv.tv_sec * 1.0 + tv.tv_nsec * 1e-9;
}
#elif HAVE_GETTIMEOFDAY
static double
now(void)
{
struct timespec tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1.0 + tv.tv_usec * 1e-6;
}
#else
#error no gettimeofday for test timing
#endif
/* -- Module globals ---------------------------------------------------- */
struct s2base *s2base;
char const *s2_tester = "s2_tester";
int s2_start_stop;
char const *_s2_suite = "X";
char const *_s2_case = "0.0";
static struct {
double setup, start, done, toredown;
} stamps;
void s2_suite(char const *name)
{
_s2_suite = name;
}
/** Basic setup for test cases */
void s2_setup(char const *label)
{
assert(s2base == NULL);
stamps.setup = now();
if (s2_start_stop > 1) {
printf("%s - setup %s test case\n", s2_tester, label ? label : "next");
}
su_init();
s2base = su_home_new(sizeof *s2base);
assert(s2base != NULL);
s2base->root = su_root_create(s2base);
assert(s2base->root != NULL);
}
void s2_case(char const *number,
char const *title,
char const *description)
{
stamps.start = now();
_s2_case = number;
if (s2_start_stop)
printf("%s - starting %s/%s-%s\n", s2_tester, _s2_suite, _s2_case, title);
}
SOFIAPUBVAR su_log_t nua_log[];
SOFIAPUBVAR su_log_t soa_log[];
SOFIAPUBVAR su_log_t nea_log[];
SOFIAPUBVAR su_log_t nta_log[];
SOFIAPUBVAR su_log_t tport_log[];
SOFIAPUBVAR su_log_t su_log_default[];
void
s2_setup_logs(int level)
{
assert(s2base);
su_log_soft_set_level(nua_log, level);
su_log_soft_set_level(soa_log, level);
su_log_soft_set_level(su_log_default, level);
su_log_soft_set_level(nea_log, level);
su_log_soft_set_level(nta_log, level);
su_log_soft_set_level(tport_log, level);
}
void s2_step(void)
{
su_root_step(s2base->root, 10);
}
static char const *s2_teardown_label = NULL;
void
s2_teardown_started(char const *label)
{
stamps.done = now();
if (!s2_teardown_label) {
s2_teardown_label = label;
if (s2_start_stop > 1) {
double ms = (stamps.done - stamps.start) * 1000.0;
printf("%s - tearing down %s test case (%g ms)\n", s2_tester, label, ms);
}
}
}
void
s2_teardown(void)
{
struct s2base *_zap = s2base;
s2base = NULL;
su_root_destroy(_zap->root);
su_deinit();
stamps.toredown = now();
if (s2_start_stop > 1) {
double ms = (stamps.toredown - stamps.setup) * 1000.0;
printf("%s - %s test case tore down (total %g ms)\n", s2_tester,
s2_teardown_label ? s2_teardown_label : "previous", ms);
}
s2_teardown_label = NULL;
}
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2008 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef S2BASE_H
#define S2BASE_H
#include <sofia-sip/su_wait.h>
#include <sofia-sip/su_alloc.h>
#include "s2util.h"
extern struct s2base
{
su_home_t home[1];
su_root_t *root;
} *s2base;
extern char const *s2_tester, *_s2_suite, *_s2_case;
extern int s2_start_stop;
void s2_suite(char const *label);
void s2_setup(char const *label);
void s2_setup_logs(int level);
void s2_step(void);
void s2_case(char const *tag,
char const *title,
char const *description);
void s2_teardown_started(char const *label);
void s2_teardown(void);
#endif
This diff is collapsed.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2008 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef S2SIP_H
#define S2SIP_H
#include <sofia-sip/su_wait.h>
#include <sofia-sip/sip.h>
#include <sofia-sip/tport.h>
#include <sofia-sip/nua.h>
#include "s2util.h"
extern struct s2sip
{
su_home_t home[1];
su_root_t *root;
msg_mclass_t const *mclass;
int flags;
int server_uses_rport;
char const *hostname;
tport_t *master;
sip_to_t *aor;
sip_contact_t *contact;
struct {
sip_contact_t *contact;
tport_t *tport;
} udp, tcp, tls;
struct {
sip_to_t *aor;
sip_contact_t *contact;
tport_t *tport;
} sut;
struct message {
struct message *next, **prev;
msg_t *msg;
sip_t *sip;
tport_t *tport;
su_time_t when;
} *received;
unsigned long tid;
} *s2sip;
struct dialog
{
su_home_t home[1];
sip_from_t *local;
sip_to_t *remote;
sip_call_id_t *call_id;
uint32_t lseq, rseq;
sip_contact_t *target;
sip_route_t *route;
sip_contact_t *contact;
tport_t *tport;
msg_t *invite; /* latest invite sent */
};
extern tp_stack_class_t const s2_sip_stack[1];
char *s2_sip_generate_tag(su_home_t *home);
struct message *s2_sip_remove_message(struct message *m);
void s2_sip_free_message(struct message *m);
void s2_sip_flush_messages(void);
struct message *s2_sip_next_response(void);
struct message *s2_sip_wait_for_response(int status, sip_method_t , char const *);
int s2_sip_check_response(int status, sip_method_t method, char const *name);
struct message *s2_sip_next_request(sip_method_t method, char const *name);
struct message *s2_sip_wait_for_request(sip_method_t method, char const *name);
struct message *s2_sip_wait_for_request_timeout(sip_method_t, char const *,
unsigned timeout);
int s2_sip_check_request(sip_method_t method, char const *name);
int s2_sip_check_request_timeout(sip_method_t method, char const *, unsigned timeout);
void s2_sip_save_uas_dialog(struct dialog *d, sip_t *sip);
struct message *s2_sip_respond_to(struct message *m, struct dialog *d,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int s2_sip_request_to(struct dialog *d,
sip_method_t method, char const *name,
tport_t *tport,
tag_type_t tag, tag_value_t value, ...);
int s2_sip_update_dialog(struct dialog *d, struct message *response);
void s2_sip_setup(char const *hostname,
char const * const *protocols,
tag_type_t tag, tag_value_t value, ...);
void s2_sip_teardown(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment