[PATCH] osmo-mgw[master]: mgcp_client: show failure by MGCP SDP section parsing test

2018-02-21 Thread Neels Hofmeyr

mgcp_client: show failure by MGCP SDP section parsing test

To show how the current code fails, add test_sdp_section_start() to
mgcp_client_test.c, and temporarily accept failing output. This will be fixed
in change I62a2453cd9e2e7d5408423161fa65ec9c9989f98.

Change-Id: I5c6d3566b8f6dbf04c0cd8b127423f5295c19f8d
---
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
3 files changed, 180 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/38/6638/2

diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index ef2fca8..588b313 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -271,6 +271,111 @@
fprintf(stderr, "%s() done\n", __func__);
 }
 
+struct sdp_section_start_test {
+   const char *body;
+   int expect_rc;
+   struct mgcp_response expect_params;
+};
+
+static struct sdp_section_start_test sdp_section_start_tests[] = {
+   {
+   .body = "",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "\n\n",
+   },
+   {
+   .body = "\r\n\r\n",
+   },
+   {
+   .body = "\n\r\n\r",
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n\r"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+};
+
+void test_sdp_section_start()
+{
+   int i;
+   int failures = 0;
+
+   for (i = 0; i < ARRAY_SIZE(sdp_section_start_tests); i++) {
+   int rc;
+   struct sdp_section_start_test *t = _section_start_tests[i];
+   struct mgcp_response *r = talloc_zero(ctx, struct 
mgcp_response);
+
+   r->body = talloc_strdup(r, t->body);
+
+   printf("\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "body: \"%s\"\n", osmo_escape_str(r->body, -1));
+
+   rc = mgcp_response_parse_params(r);
+
+   fprintf(stderr, "got rc=%d\n", rc);
+   if (rc != t->expect_rc) {
+   fprintf(stderr, "FAIL: Expected rc=%d\n", t->expect_rc);
+   failures++;
+   }
+   if (rc) {
+   talloc_free(r);
+   continue;
+   }
+
+   fprintf(stderr, "got audio_port=%u\n", 
t->expect_params.audio_port);
+   if (r->audio_port != t->expect_params.audio_port) {
+   fprintf(stderr, "FAIL: Expected audio_port=%u\n", 
t->expect_params.audio_port);
+   failures++;
+   }
+   talloc_free(r);
+   }
+
+   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
+   OSMO_ASSERT(!failures);
+   */
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -297,6 +402,7 @@
test_crcx();
test_mgcp_msg();
test_mgcp_client_cancel();
+   test_sdp_section_start();
 
printf("Done\n");
fprintf(stderr, "Done\n");
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 8e9f648..9079c27 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -12,4 +12,58 @@
 - canceling again does nothing
 DLMGCP Cannot cancel, no such transaction: 1
 test_mgcp_client_cancel() done
+
+test_sdp_section_start() test [0]:
+body: ""
+got rc=0
+FAIL: Expected rc=-22
+got audio_port=0
+
+test_sdp_section_start() test [1]:
+body: "\n\n"
+got rc=0
+got audio_port=0
+

[PATCH] osmo-mgw[master]: mgcp_client: show failure by MGCP SDP section parsing test

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6638

mgcp_client: show failure by MGCP SDP section parsing test

To show how the current code fails, add test_sdp_section_start() to
mgcp_client_test.c, and temporarily accept failing output. This will be fixed
in change Ib0d5a9fc3020ff630eb3460209c1317f09254a92.

Change-Id: I5c6d3566b8f6dbf04c0cd8b127423f5295c19f8d
---
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
3 files changed, 180 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/38/6638/1

diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index ef2fca8..588b313 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -271,6 +271,111 @@
fprintf(stderr, "%s() done\n", __func__);
 }
 
+struct sdp_section_start_test {
+   const char *body;
+   int expect_rc;
+   struct mgcp_response expect_params;
+};
+
+static struct sdp_section_start_test sdp_section_start_tests[] = {
+   {
+   .body = "",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "\n\n",
+   },
+   {
+   .body = "\r\n\r\n",
+   },
+   {
+   .body = "\n\r\n\r",
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n\r"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+};
+
+void test_sdp_section_start()
+{
+   int i;
+   int failures = 0;
+
+   for (i = 0; i < ARRAY_SIZE(sdp_section_start_tests); i++) {
+   int rc;
+   struct sdp_section_start_test *t = _section_start_tests[i];
+   struct mgcp_response *r = talloc_zero(ctx, struct 
mgcp_response);
+
+   r->body = talloc_strdup(r, t->body);
+
+   printf("\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "body: \"%s\"\n", osmo_escape_str(r->body, -1));
+
+   rc = mgcp_response_parse_params(r);
+
+   fprintf(stderr, "got rc=%d\n", rc);
+   if (rc != t->expect_rc) {
+   fprintf(stderr, "FAIL: Expected rc=%d\n", t->expect_rc);
+   failures++;
+   }
+   if (rc) {
+   talloc_free(r);
+   continue;
+   }
+
+   fprintf(stderr, "got audio_port=%u\n", 
t->expect_params.audio_port);
+   if (r->audio_port != t->expect_params.audio_port) {
+   fprintf(stderr, "FAIL: Expected audio_port=%u\n", 
t->expect_params.audio_port);
+   failures++;
+   }
+   talloc_free(r);
+   }
+
+   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
+   OSMO_ASSERT(!failures);
+   */
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -297,6 +402,7 @@
test_crcx();
test_mgcp_msg();
test_mgcp_client_cancel();
+   test_sdp_section_start();
 
printf("Done\n");
fprintf(stderr, "Done\n");
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 8e9f648..9079c27 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -12,4 +12,58 @@
 - canceling again does nothing
 DLMGCP Cannot cancel, no such transaction: 1
 test_mgcp_client_cancel() done
+
+test_sdp_section_start() test [0]:
+body: ""
+got rc=0
+FAIL: Expected rc=-22
+got audio_port=0
+
+test_sdp_section_start() test [1]:
+body: "\n\n"