2000-09-11 11:03:10 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-09-13 11:07:17 +04:00
Copyright ( C ) Andrew Tridgell 2000
2010-07-19 23:00:31 +04:00
2000-09-11 11:03:10 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-09-11 11:03:10 +04:00
( at your option ) any later version .
2010-07-19 23:00:31 +04:00
2000-09-11 11:03:10 +04:00
This program 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 General Public License for more details .
2010-07-19 23:00:31 +04:00
2000-09-11 11:03:10 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-09-11 11:03:10 +04:00
*/
/*
2000-09-13 11:07:17 +04:00
test code for internal messaging
2000-09-11 11:03:10 +04:00
*/
# include "includes.h"
2010-05-05 03:39:16 +04:00
# include "librpc/gen_ndr/messaging.h"
2000-09-11 11:03:10 +04:00
2000-09-12 10:57:25 +04:00
static int pong_count ;
2006-05-20 06:09:35 +04:00
2000-09-12 10:57:25 +04:00
/****************************************************************************
a useful function for testing the message system
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-05-15 18:39:18 +04:00
static void pong_message ( struct messaging_context * msg_ctx ,
void * private_data ,
uint32_t msg_type ,
struct server_id pid ,
DATA_BLOB * data )
2000-09-12 10:57:25 +04:00
{
pong_count + + ;
}
2000-09-11 11:03:10 +04:00
int main ( int argc , char * argv [ ] )
{
2009-01-21 09:31:33 +03:00
struct tevent_context * evt_ctx ;
2007-05-15 18:39:18 +04:00
struct messaging_context * msg_ctx ;
2000-09-11 11:03:10 +04:00
pid_t pid ;
2000-09-12 10:57:25 +04:00
int i , n ;
2000-11-17 00:38:24 +03:00
char buf [ 12 ] ;
2009-01-21 09:31:33 +03:00
int ret ;
2000-09-11 11:03:10 +04:00
2006-05-20 06:04:19 +04:00
load_case_tables ( ) ;
2000-09-11 11:03:10 +04:00
setup_logging ( argv [ 0 ] , True ) ;
2010-07-19 23:00:31 +04:00
2007-12-10 22:30:37 +03:00
lp_load ( get_dyn_CONFIGFILE ( ) , False , False , False , True ) ;
2000-09-11 11:03:10 +04:00
2009-01-21 09:31:33 +03:00
if ( ! ( evt_ctx = tevent_context_init ( NULL ) ) | |
2010-02-23 17:04:10 +03:00
! ( msg_ctx = messaging_init ( NULL , procid_self ( ) , evt_ctx ) ) ) {
2007-05-15 18:39:18 +04:00
fprintf ( stderr , " could not init messaging context \n " ) ;
exit ( 1 ) ;
}
2010-07-19 23:00:31 +04:00
2000-11-17 00:38:24 +03:00
if ( argc ! = 3 ) {
2006-08-01 01:11:03 +04:00
fprintf ( stderr , " %s: Usage - %s pid count \n " , argv [ 0 ] ,
argv [ 0 ] ) ;
2000-11-17 00:38:24 +03:00
exit ( 1 ) ;
}
2000-09-11 11:03:10 +04:00
pid = atoi ( argv [ 1 ] ) ;
2000-09-12 10:57:25 +04:00
n = atoi ( argv [ 2 ] ) ;
2007-05-15 18:39:18 +04:00
messaging_register ( msg_ctx , NULL , MSG_PONG , pong_message ) ;
2000-09-12 10:57:25 +04:00
for ( i = 0 ; i < n ; i + + ) {
2007-05-15 18:39:18 +04:00
messaging_send ( msg_ctx , pid_to_procid ( pid ) , MSG_PING ,
& data_blob_null ) ;
2000-09-12 10:57:25 +04:00
}
2000-09-11 11:03:10 +04:00
2000-09-13 11:07:17 +04:00
while ( pong_count < i ) {
2009-01-21 09:31:33 +03:00
ret = tevent_loop_once ( evt_ctx ) ;
if ( ret ! = 0 ) {
break ;
}
2000-09-12 10:57:25 +04:00
}
2000-09-11 11:03:10 +04:00
2000-11-17 00:38:24 +03:00
/* Now test that the duplicate filtering code works. */
pong_count = 0 ;
safe_strcpy ( buf , " 1234567890 " , sizeof ( buf ) - 1 ) ;
for ( i = 0 ; i < n ; i + + ) {
2010-07-19 23:00:41 +04:00
messaging_send ( msg_ctx , messaging_server_id ( msg_ctx ) , MSG_PING ,
2007-05-15 18:39:18 +04:00
& data_blob_null ) ;
2010-07-19 23:00:41 +04:00
messaging_send_buf ( msg_ctx , messaging_server_id ( msg_ctx ) ,
MSG_PING , ( uint8 * ) buf , 11 ) ;
2000-11-17 00:38:24 +03:00
}
for ( i = 0 ; i < n ; i + + ) {
2009-01-21 09:31:33 +03:00
ret = tevent_loop_once ( evt_ctx ) ;
if ( ret ! = 0 ) {
break ;
}
2000-11-17 00:38:24 +03:00
}
if ( pong_count ! = 2 ) {
fprintf ( stderr , " Duplicate filter failed (%d). \n " , pong_count ) ;
2006-05-20 06:09:35 +04:00
}
/* Speed testing */
pong_count = 0 ;
{
struct timeval tv = timeval_current ( ) ;
size_t timelimit = n ;
size_t ping_count = 0 ;
2006-07-12 01:23:44 +04:00
printf ( " Sending pings for %d seconds \n " , ( int ) timelimit ) ;
2006-08-01 01:11:03 +04:00
while ( timeval_elapsed ( & tv ) < timelimit ) {
2007-05-15 18:39:18 +04:00
if ( NT_STATUS_IS_OK ( messaging_send_buf (
msg_ctx , pid_to_procid ( pid ) ,
MSG_PING ,
( uint8 * ) buf , 11 ) ) )
2007-02-02 01:06:59 +03:00
ping_count + + ;
2007-05-15 18:39:18 +04:00
if ( NT_STATUS_IS_OK ( messaging_send (
msg_ctx , pid_to_procid ( pid ) ,
MSG_PING , & data_blob_null ) ) )
2007-02-02 01:06:59 +03:00
ping_count + + ;
2006-05-20 06:09:35 +04:00
while ( ping_count > pong_count + 20 ) {
2009-01-21 09:31:33 +03:00
ret = tevent_loop_once ( evt_ctx ) ;
if ( ret ! = 0 ) {
break ;
}
2006-05-20 06:09:35 +04:00
}
}
2010-07-19 23:00:31 +04:00
2006-05-20 06:09:35 +04:00
printf ( " waiting for %d remaining replies (done %d) \n " ,
2006-07-12 01:23:44 +04:00
( int ) ( ping_count - pong_count ) , pong_count ) ;
2006-05-20 06:09:35 +04:00
while ( timeval_elapsed ( & tv ) < 30 & & pong_count < ping_count ) {
2009-01-21 09:31:33 +03:00
ret = tevent_loop_once ( evt_ctx ) ;
if ( ret ! = 0 ) {
break ;
}
2006-05-20 06:09:35 +04:00
}
2010-07-19 23:00:31 +04:00
2006-05-20 06:09:35 +04:00
if ( ping_count ! = pong_count ) {
2006-07-12 01:23:44 +04:00
fprintf ( stderr , " ping test failed! received %d, sent "
" %d \n " , pong_count , ( int ) ping_count ) ;
2006-05-20 06:09:35 +04:00
}
2010-07-19 23:00:31 +04:00
2006-05-20 06:09:35 +04:00
printf ( " ping rate of %.0f messages/sec \n " ,
2006-08-01 01:11:03 +04:00
( ping_count + pong_count ) / timeval_elapsed ( & tv ) ) ;
2000-11-17 00:38:24 +03:00
}
2000-09-11 11:03:10 +04:00
return ( 0 ) ;
}