changeset 1230:992437a90bda

Enable mix of short and long messages in test_app
author Sebastien Decugis <sdecugis@freediameter.net>
date Thu, 20 Jun 2013 11:01:19 +0800
parents cf9bad611f90
children 8608085d7b0d
files doc/test_app.conf.sample extensions/test_app/ta_bench.c extensions/test_app/ta_cli.c extensions/test_app/ta_conf.l extensions/test_app/ta_conf.y extensions/test_app/ta_serv.c extensions/test_app/test_app.c extensions/test_app/test_app.h
diffstat 8 files changed, 63 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/doc/test_app.conf.sample	Thu Jun 20 10:20:29 2013 +0800
+++ b/doc/test_app.conf.sample	Thu Jun 20 11:01:19 2013 +0800
@@ -53,6 +53,11 @@
 #   concurrency is the number of messages that can be on the wire before waiting for an answer (default 100).
 # benchmark [duration concurrency];
 
+# The keywork "MixedSizes" can also be specified. When present, the client will send 
+# short or long records randomly with 25% probability that it is a long record sent next.
+# This works both in normal and benchmark modes.
+# mixedsizes;
+
 
 #######################
 # Client-specific configuration
--- a/extensions/test_app/ta_bench.c	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/ta_bench.c	Thu Jun 20 11:01:19 2013 +0800
@@ -121,6 +121,7 @@
 	struct avp * avp;
 	union avp_value val;
 	struct ta_mess_info * mi = NULL;
+	static uint8_t * long_payload = NULL;
 	
 	TRACE_DEBUG(FULL, "Creating a new message for sending.");
 	
@@ -180,6 +181,19 @@
 		CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out  );
 	}
 	
+	/* Set the Test-Payload-AVP AVP if requested */
+	if ((ta_conf->long_avp_id) &&
+		(!(ta_conf->mode & MODE_MIXSIZE) || (!(mi->randval & 0x3)))) {
+		CHECK_FCT_DO( fd_msg_avp_new ( ta_avp_long, 0, &avp ), goto out  );
+		if (!long_payload) {
+			CHECK_MALLOC_DO( long_payload = calloc(1, ta_conf->long_avp_len), goto out);
+		}
+		val.os.data = long_payload;
+		val.os.len = ta_conf->long_avp_len;
+		CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out  );
+		CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out  );
+	}
+	
 	CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out );
 	
 	/* Send the request */
--- a/extensions/test_app/ta_cli.c	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/ta_cli.c	Thu Jun 20 11:01:19 2013 +0800
@@ -238,8 +238,9 @@
 		CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out  );
 	}
 	
-	/* Set the Test-Payload-AVP AVP */
-	if (ta_conf->long_avp_id) {
+	/* Set the Test-Payload-AVP AVP if requested */
+	if ((ta_conf->long_avp_id) &&
+		(!(ta_conf->mode & MODE_MIXSIZE) || (!(mi->randval & 0x3)))) {
 		int l;
 		CHECK_FCT_DO( fd_msg_avp_new ( ta_avp_long, 0, &avp ), goto out  );
 		CHECK_MALLOC_DO( val.os.data = malloc(ta_conf->long_avp_len), goto out);
--- a/extensions/test_app/ta_conf.l	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/ta_conf.l	Thu Jun 20 11:01:19 2013 +0800
@@ -164,6 +164,10 @@
 				return BENCH;
 			}
 
+(?i:"mixedsizes")	{
+				return MIXEDSIZES;
+			}
+
 			
 	/* Valid single characters for yyparse */
 [=;]			{ return yytext[0]; }
--- a/extensions/test_app/ta_conf.y	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/ta_conf.y	Thu Jun 20 11:01:19 2013 +0800
@@ -128,6 +128,7 @@
 %token 		USER_NAME
 %token 		SIGNAL
 %token		BENCH
+%token		MIXEDSIZES
 
 /* Tokens and types for routing table definition */
 /* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
@@ -155,6 +156,7 @@
 			| conffile usrname
 			| conffile signal
 			| conffile bench
+			| conffile mix
 			;
 
 vendor:			VENDOR_ID '=' INTEGER ';'
@@ -211,6 +213,12 @@
 			}
 			;
 
+mix:			MIXEDSIZES ';'
+			{
+				ta_conf->mode |= MODE_MIXSIZE;
+			}
+			;
+			
 dstrealm:		DEST_REALM '=' QSTRING ';'
 			{
 				free(ta_conf->dest_realm);
--- a/extensions/test_app/ta_serv.c	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/ta_serv.c	Thu Jun 20 11:01:19 2013 +0800
@@ -100,11 +100,13 @@
 		struct avp_hdr * hdr = NULL;
 		
 		CHECK_FCT( fd_msg_search_avp ( qry, ta_avp_long, &src) );
-		CHECK_FCT( fd_msg_avp_hdr( src, &hdr )  );
-		
-		CHECK_FCT( fd_msg_avp_new ( ta_avp_long, 0, &avp ) );
-		CHECK_FCT( fd_msg_avp_setvalue( avp, hdr->avp_value ) );
-		CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
+		if (src) {
+			CHECK_FCT( fd_msg_avp_hdr( src, &hdr )  );
+
+			CHECK_FCT( fd_msg_avp_new ( ta_avp_long, 0, &avp ) );
+			CHECK_FCT( fd_msg_avp_setvalue( avp, hdr->avp_value ) );
+			CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
+		}
 	}
 	
 	
--- a/extensions/test_app/test_app.c	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/test_app.c	Thu Jun 20 11:01:19 2013 +0800
@@ -70,20 +70,23 @@
 
 static void ta_conf_dump(void)
 {
-	if (!TRACE_BOOL(INFO))
-		return;
-	fd_log_debug( "------- app_test configuration dump: ---------");
-	fd_log_debug( " Vendor Id .......... : %u", ta_conf->vendor_id);
-	fd_log_debug( " Application Id ..... : %u", ta_conf->appli_id);
-	fd_log_debug( " Command Id ......... : %u", ta_conf->cmd_id);
-	fd_log_debug( " AVP Id ............. : %u", ta_conf->avp_id);
-	fd_log_debug( " Long AVP Id ........ : %u", ta_conf->long_avp_id);
-	fd_log_debug( " Long AVP len ....... : %zu", ta_conf->long_avp_len);
-	fd_log_debug( " Mode ............... : %s%s%s", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "",  ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "");
-	fd_log_debug( " Destination Realm .. : %s", ta_conf->dest_realm ?: "- none -");
-	fd_log_debug( " Destination Host ... : %s", ta_conf->dest_host ?: "- none -");
-	fd_log_debug( " Signal ............. : %i", ta_conf->signal);
-	fd_log_debug( "------- /app_test configuration dump ---------");
+	LOG_D( "------- app_test configuration dump: ---------");
+	LOG_D( " Vendor Id .......... : %u", ta_conf->vendor_id);
+	LOG_D( " Application Id ..... : %u", ta_conf->appli_id);
+	LOG_D( " Command Id ......... : %u", ta_conf->cmd_id);
+	LOG_D( " AVP Id ............. : %u", ta_conf->avp_id);
+	LOG_D( " Long AVP Id ........ : %u", ta_conf->long_avp_id);
+	LOG_D( " Long AVP len ....... : %zu", ta_conf->long_avp_len);
+	LOG_D( " Mode ............... : %s%s%s%s", 
+						ta_conf->mode & MODE_SERV ? "Serv" : "", 
+						ta_conf->mode & MODE_CLI ? "Cli" : "",  
+						ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "",
+						ta_conf->mode & MODE_MIXSIZE ? " (Mix)" : ""
+						);
+	LOG_D( " Destination Realm .. : %s", ta_conf->dest_realm ?: "- none -");
+	LOG_D( " Destination Host ... : %s", ta_conf->dest_host ?: "- none -");
+	LOG_D( " Signal ............. : %i", ta_conf->signal);
+	LOG_D( "------- /app_test configuration dump ---------");
 }
 
 /* Function to display statistics periodically */
@@ -167,7 +170,10 @@
 		CHECK_FCT( ta_conf_handle(conffile) );
 	}
 	
-	TRACE_DEBUG(INFO, "Extension Test_App initialized with configuration: '%s'", conffile);
+	if ((ta_conf->mode & MODE_MIXSIZE) && (!ta_conf->long_avp_id))
+		ta_conf->long_avp_id = 0xfffffe;
+	
+	LOG_N("Extension test_app initialized with configuration: '%s'", conffile);
 	ta_conf_dump();
 	
 	/* Install objects definitions for this test application */
--- a/extensions/test_app/test_app.h	Thu Jun 20 10:20:29 2013 +0800
+++ b/extensions/test_app/test_app.h	Thu Jun 20 11:01:19 2013 +0800
@@ -52,6 +52,7 @@
 #define MODE_SERV	0x1
 #define	MODE_CLI	0x2
 #define	MODE_BENCH	0x4
+#define	MODE_MIXSIZE	0x8
 
 /* The module configuration */
 struct ta_conf {
"Welcome to our mercurial repository"