[asterisk-commits] mjordan: branch mjordan/trunk_jitter_tests r358763 - /team/mjordan/trunk_jitt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 12 08:49:37 CDT 2012


Author: mjordan
Date: Mon Mar 12 08:49:33 2012
New Revision: 358763

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=358763
Log:
Merge tests added over weekend into branch

Yay more unit tests.

Modified:
    team/mjordan/trunk_jitter_tests/tests/test_jitterbuffer.c

Modified: team/mjordan/trunk_jitter_tests/tests/test_jitterbuffer.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk_jitter_tests/tests/test_jitterbuffer.c?view=diff&rev=358763&r1=358762&r2=358763
==============================================================================
--- team/mjordan/trunk_jitter_tests/tests/test_jitterbuffer.c (original)
+++ team/mjordan/trunk_jitter_tests/tests/test_jitterbuffer.c Mon Mar 12 08:49:33 2012
@@ -46,6 +46,23 @@
 #define DEFAULT_TARGET_EXTRA -1
 #define DEFAULT_CODEC_INTERP_LEN 20
 
+#define JB_INFO_NUMERIC_TEST(attribute, expected) do { \
+	if (attribute != expected) { \
+		ast_test_status_update(test, #attribute ": expected [%ld]; actual [%ld]\n", (long int)expected, attribute); \
+		goto cleanup; \
+	} \
+} while (0)
+
+#define JB_INFO_PRINT_FRAME_DEBUG(jbinfo) do { \
+	ast_debug(1, "JitterBuffer Frame Info:\n" \
+		"\tFrames In: %ld\n\tFrames Out: %ld\n" \
+		"\tDropped Frames: %ld\n\tLate Frames: %ld\n" \
+		"\tLost Frames: %ld\n\tOut of Order Frames: %ld\n" \
+		"\tCurrent Frame: %ld\n", jbinfo.frames_in, jbinfo.frames_out, \
+		jbinfo.frames_dropped, jbinfo.frames_late, jbinfo.frames_lost, \
+		jbinfo.frames_ooo, jbinfo.frames_cur); \
+} while (0)
+
 static const char *jitter_buffer_return_codes[] = {
 	"JB_OK",            /* 0 */
 	"JB_EMPTY",         /* 1 */
@@ -312,7 +329,6 @@
 	enum ast_test_result_state result = AST_TEST_FAIL;
 	struct jitterbuf *jb = NULL;
 	struct jb_frame frame;
-	struct jb_info jbinfo;
 	struct jb_conf jbconf;
 	int i;
 
@@ -345,7 +361,7 @@
 		if (i % 5 == 0) {
 			i++;
 		}
-		if (jb_put(jb, NULL, JB_TYPE_CONTROL, 20, i * 20, i * 20 + 5) == JB_DROP) {
+		if (jb_put(jb, NULL, JB_TYPE_VOICE, 20, i * 20, i * 20 + 5) == JB_DROP) {
 			ast_test_status_update(test, "Jitter buffer dropped packet %d\n", i);
 			goto cleanup;
 		}
@@ -355,7 +371,7 @@
 		enum jb_return_code ret;
 		if ((ret = jb_get(jb, &frame, i * 20 + 5, DEFAULT_CODEC_INTERP_LEN)) != JB_OK) {
 			/* If we didn't get an OK, make sure that it was an expected lost frame */
-			if (!(ret == JB_NOFRAME && i % 5 == 0)) {
+			if (!((ret == JB_INTERP && i % 5 == 0) || (ret == JB_NOFRAME && i == 0))) {
 				ast_test_status_update(test,
 					"Unexpected jitter buffer return code [%s] when retrieving frame %d\n",
 					jitter_buffer_return_codes[ret], i);
@@ -467,9 +483,8 @@
 		ast_test_status_update(test, "Failed to get jitterbuffer information\n");
 		goto cleanup;
 	}
-	if (jbinfo.frames_ooo != 10) {
-		ast_test_status_update(test, "Out of order frames: expected [%d]; actual [%ld]\n", 10, jbinfo.frames_ooo);
-	}
+	JB_INFO_PRINT_FRAME_DEBUG(jbinfo);
+	JB_INFO_NUMERIC_TEST(jbinfo.frames_ooo, 10);
 
 	result = AST_TEST_PASS;
 
@@ -483,13 +498,136 @@
 	return result;
 }
 
+AST_TEST_DEFINE(jitterbuffer_overflow)
+{
+	enum ast_test_result_state result = AST_TEST_FAIL;
+	struct jitterbuf *jb = NULL;
+	struct jb_frame frame;
+	struct jb_info jbinfo;
+	struct jb_conf jbconf;
+	int i;
+	int queued_frames = 0;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "jitterbuffer_overflow";
+		info->category = "/main/jitterbuffer/";
+		info->summary = "Tests sending frames to a jitterbuffer that are late";
+		info->description = "Blahblah";
+		/* TODO: */
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(jb = jb_new())) {
+		ast_test_status_update(test, "Failed to allocate memory for jitterbuffer\n");
+		goto cleanup;
+	}
+
+	test_jb_populate_config(&jbconf);
+	if (jb_setconf(jb, &jbconf) != JB_OK) {
+		ast_test_status_update(test, "Failed to set jitterbuffer configuration\n");
+		goto cleanup;
+	}
+
+	for (i = 0; i < 100; i++) {
+		jb_put(jb, NULL, JB_TYPE_VOICE, 20, i * 20, i * 20 + 5);
+	}
+
+	while (jb_get(jb, &frame, i * 20 + 5, DEFAULT_CODEC_INTERP_LEN) == JB_OK) {
+		++queued_frames;
+	}
+
+
+	if (jb_getinfo(jb, &jbinfo) != JB_OK) {
+		ast_test_status_update(test, "Failed to get jitterbuffer information\n");
+		goto cleanup;
+	}
+
+	JB_INFO_PRINT_FRAME_DEBUG(jbinfo);
+	JB_INFO_NUMERIC_TEST(jbinfo.frames_dropped, 49);
+	JB_INFO_NUMERIC_TEST(jbinfo.frames_out, 51);
+
+	result = AST_TEST_PASS;
+
+cleanup:
+	if (jb) {
+		/* No need to do anything - this will put all frames on the 'free' list,
+		 * so jb_destroy will dispose of them */
+		while (jb_getall(jb, &frame) == JB_OK) { }
+		jb_destroy(jb);
+	}
+	return result;
+}
+
+AST_TEST_DEFINE(jitterbuffer_resynch)
+{
+	enum ast_test_result_state result = AST_TEST_FAIL;
+	struct jitterbuf *jb = NULL;
+	struct jb_frame frame;
+	struct jb_info jbinfo;
+	struct jb_conf jbconf;
+	int i;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "jitterbuffer_resynch";
+		info->category = "/main/jitterbuffer/";
+		info->summary = "Tests sending frames to a jitterbuffer that are late";
+		info->description = "Blahblah";
+		/* TODO: */
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(jb = jb_new())) {
+		ast_test_status_update(test, "Failed to allocate memory for jitterbuffer\n");
+		goto cleanup;
+	}
+
+	test_jb_populate_config(&jbconf);
+	if (jb_setconf(jb, &jbconf) != JB_OK) {
+		ast_test_status_update(test, "Failed to set jitterbuffer configuration\n");
+		goto cleanup;
+	}
+
+	for (i = 0; i < 20; i++) {
+		jb_put(jb, NULL, JB_TYPE_VOICE, 20, i * 20, i * 20 + 5);
+	}
+
+	for (i = 0; i < 20; i++) {
+		jb_put(jb, NULL, JB_TYPE_VOICE, 20, i * 20 + 2000, i * 20 + 2005);
+	}
+
+	if (jb_getinfo(jb, &jbinfo) != JB_OK) {
+		ast_test_status_update(test, "Failed to get jitterbuffer information\n");
+		goto cleanup;
+	}
+
+	result = AST_TEST_PASS;
+
+cleanup:
+	if (jb) {
+		/* No need to do anything - this will put all frames on the 'free' list,
+		 * so jb_destroy will dispose of them */
+		while (jb_getall(jb, &frame) == JB_OK) { }
+		jb_destroy(jb);
+	}
+	return result;
+}
+
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(jitterbuffer_nominal_audio_frames);
 	AST_TEST_UNREGISTER(jitterbuffer_nominal_control_frames);
 	AST_TEST_UNREGISTER(jitterbuffer_out_of_order);
 	AST_TEST_UNREGISTER(jitterbuffer_lost);
-	AST_TEST_REGISTER(jitterbuffer_late);
+	AST_TEST_UNREGISTER(jitterbuffer_late);
+	AST_TEST_UNREGISTER(jitterbuffer_overflow);
+	AST_TEST_UNREGISTER(jitterbuffer_resynch);
 	return 0;
 }
 
@@ -500,6 +638,8 @@
 	AST_TEST_REGISTER(jitterbuffer_out_of_order);
 	AST_TEST_REGISTER(jitterbuffer_lost);
 	AST_TEST_REGISTER(jitterbuffer_late);
+	AST_TEST_REGISTER(jitterbuffer_overflow);
+	AST_TEST_REGISTER(jitterbuffer_resynch);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list