summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-01-07 11:38:22 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-01-16 13:20:37 +0100
commit84dfba15799a8426dcba28624a388e5a1962c2bf (patch)
treed6d9900951b277260efd0f58697d711370f3cf1d
parent68c74f59a40f4e4ad897e2ee7f5067ec2cac2012 (diff)
mgcp/test: Show the number of dummy packets sent
This patch extends the test_messages test to show the number of dummy packets that has been passed to sendto(). This way, dummy packets are even being counted when sendto() itself failes (e.g. due to the fd being -1). Sponsored-by: On-Waves ehf
-rw-r--r--openbsc/tests/mgcp/Makefile.am3
-rw-r--r--openbsc/tests/mgcp/mgcp_test.c32
2 files changed, 34 insertions, 1 deletions
diff --git a/openbsc/tests/mgcp/Makefile.am b/openbsc/tests/mgcp/Makefile.am
index 8c365b416..470cdd80e 100644
--- a/openbsc/tests/mgcp/Makefile.am
+++ b/openbsc/tests/mgcp/Makefile.am
@@ -11,4 +11,5 @@ mgcp_test_SOURCES = mgcp_test.c
mgcp_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libmgcp/libmgcp.a \
$(top_builddir)/src/libcommon/libcommon.a \
- $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS)
+ $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) \
+ $(LIBRARY_DL)
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 538dc9fa2..7eeef99af 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#undef _GNU_SOURCE
+#define _GNU_SOURCE
#include <openbsc/mgcp.h>
#include <openbsc/mgcp_internal.h>
@@ -24,6 +26,7 @@
#include <osmocom/core/talloc.h>
#include <string.h>
#include <limits.h>
+#include <dlfcn.h>
char *strline_r(char *str, char **saveptr);
@@ -293,6 +296,31 @@ static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint,
return MGCP_POLICY_CONT;
}
+#define MGCP_DUMMY_LOAD 0x23
+static int dummy_packets = 0;
+/* override and forward */
+ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
+ const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+ typedef ssize_t (*sendto_t)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t);
+ static sendto_t real_sendto = NULL;
+ uint32_t dest_host = htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr);
+ int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port);
+
+ if (!real_sendto)
+ real_sendto = dlsym(RTLD_NEXT, "sendto");
+
+ if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD ) {
+ fprintf(stderr, "Dummy packet to 0x%08x:%d, msg length %d\n%s\n\n",
+ dest_host, dest_port,
+ len, osmo_hexdump(buf, len));
+ dummy_packets += 1;
+ }
+
+ return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
+}
+
static void test_messages(void)
{
struct mgcp_config *cfg;
@@ -326,6 +354,7 @@ static void test_messages(void)
printf("Testing %s\n", t->name);
last_endpoint = -1;
+ dummy_packets = 0;
inp = create_msg(t->req);
msg = mgcp_handle_message(cfg, inp);
@@ -337,6 +366,9 @@ static void test_messages(void)
printf("%s failed '%s'\n", t->name, (char *) msg->data);
msgb_free(msg);
+ if (dummy_packets)
+ printf("Dummy packets: %d\n", dummy_packets);
+
if (last_endpoint != -1) {
endp = &cfg->trunk.endpoints[last_endpoint];