2024-06-24 10:09:24 +02:00
/*
2005-01-31 09:54:39 +00:00
Unix SMB / CIFS implementation .
NBT name query testing
Copyright ( C ) Andrew Tridgell 2005
2024-06-24 10:09:24 +02:00
2005-01-31 09:54:39 +00: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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-31 09:54:39 +00:00
( at your option ) any later version .
2024-06-24 10:09:24 +02:00
2005-01-31 09:54:39 +00: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 .
2024-06-24 10:09:24 +02:00
2005-01-31 09:54:39 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-31 09:54:39 +00:00
*/
# include "includes.h"
2005-02-03 11:56:03 +00:00
# include "lib/events/events.h"
2006-03-07 11:07:23 +00:00
# include "libcli/resolve/resolve.h"
2006-03-25 16:01:28 +00:00
# include "torture/torture.h"
2006-10-16 13:06:41 +00:00
# include "torture/nbt/proto.h"
2007-12-06 16:26:56 +01:00
# include "param/param.h"
2005-01-31 09:54:39 +00:00
struct result_struct {
int num_pass ;
int num_fail ;
} ;
static void increment_handler ( struct nbt_name_request * req )
{
2008-09-23 09:02:16 +02:00
struct result_struct * v = talloc_get_type ( req - > async . private_data , struct result_struct ) ;
2005-01-31 09:54:39 +00:00
if ( req - > state ! = NBT_REQUEST_DONE ) {
v - > num_fail + + ;
} else {
v - > num_pass + + ;
}
talloc_free ( req ) ;
}
/*
benchmark simple name queries
*/
2006-10-16 13:06:41 +00:00
static bool bench_namequery ( struct torture_context * tctx )
2005-01-31 09:54:39 +00:00
{
2008-06-05 22:02:41 +02:00
struct nbt_name_socket * nbtsock = torture_init_nbt_socket ( tctx ) ;
2005-01-31 09:54:39 +00:00
int num_sent = 0 ;
struct result_struct * result ;
2024-06-24 10:09:43 +02:00
struct nbt_name_query io = {
. in = {
. retries = 0 ,
}
} ;
2005-01-31 09:54:39 +00:00
struct timeval tv = timeval_current ( ) ;
2007-04-17 22:35:01 +00:00
int timelimit = torture_setting_int ( tctx , " timelimit " , 5 ) ;
2005-01-31 09:54:39 +00:00
2006-10-16 13:06:41 +00:00
const char * address ;
struct nbt_name name ;
if ( ! torture_nbt_get_name ( tctx , & name , & address ) )
return false ;
io . in . name = name ;
2005-01-31 09:54:39 +00:00
io . in . dest_addr = address ;
2010-07-16 14:32:42 +10:00
io . in . dest_port = lpcfg_nbt_port ( tctx - > lp_ctx ) ;
2007-10-06 22:28:14 +00:00
io . in . broadcast = false ;
io . in . wins_lookup = false ;
2005-01-31 09:54:39 +00:00
io . in . timeout = 1 ;
2006-10-16 13:06:41 +00:00
result = talloc_zero ( tctx , struct result_struct ) ;
2005-01-31 09:54:39 +00:00
2006-10-16 13:06:41 +00:00
torture_comment ( tctx , " Running for %d seconds \n " , timelimit ) ;
2005-01-31 09:54:39 +00:00
while ( timeval_elapsed ( & tv ) < timelimit ) {
while ( num_sent - ( result - > num_pass + result - > num_fail ) < 10 ) {
struct nbt_name_request * req ;
req = nbt_name_query_send ( nbtsock , & io ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , req ! = NULL , " Failed to setup request! " ) ;
2005-01-31 09:54:39 +00:00
req - > async . fn = increment_handler ;
2008-09-23 09:02:16 +02:00
req - > async . private_data = result ;
2005-01-31 09:54:39 +00:00
num_sent + + ;
2005-02-03 11:25:52 +00:00
if ( num_sent % 1000 = = 0 ) {
2007-04-29 21:37:29 +00:00
if ( torture_setting_bool ( tctx , " progress " , true ) ) {
2024-06-24 10:09:24 +02:00
torture_comment ( tctx , " %.1f queries per second (%d failures) \r " ,
2007-04-29 21:37:29 +00:00
result - > num_pass / timeval_elapsed ( & tv ) ,
result - > num_fail ) ;
fflush ( stdout ) ;
}
2005-01-31 09:54:39 +00:00
}
}
2010-05-25 15:23:55 -04:00
tevent_loop_once ( nbtsock - > event_ctx ) ;
2005-01-31 09:54:39 +00:00
}
while ( num_sent ! = ( result - > num_pass + result - > num_fail ) ) {
2010-05-25 15:23:55 -04:00
tevent_loop_once ( nbtsock - > event_ctx ) ;
2005-01-31 09:54:39 +00:00
}
2024-06-24 10:09:24 +02:00
torture_comment ( tctx , " %.1f queries per second (%d failures) \n " ,
2005-01-31 09:54:39 +00:00
result - > num_pass / timeval_elapsed ( & tv ) ,
result - > num_fail ) ;
2006-10-16 13:06:41 +00:00
return true ;
2005-01-31 09:54:39 +00:00
}
/*
benchmark how fast a server can respond to name queries
*/
2007-09-07 16:27:57 +00:00
struct torture_suite * torture_bench_nbt ( TALLOC_CTX * mem_ctx )
2005-01-31 09:54:39 +00:00
{
2010-12-11 03:26:31 +01:00
struct torture_suite * suite = torture_suite_create ( mem_ctx , " bench " ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " namequery " , bench_namequery ) ;
2005-01-31 09:54:39 +00:00
2006-10-16 13:06:41 +00:00
return suite ;
2005-01-31 09:54:39 +00:00
}