#include <stdlib.h> #include <time.h> #include "clientapi.h" #include "enviro.h" #include "strtable.h" #include "strops.h" StrBuf grempath; StrBufDict dirs1, dirs2, dirs3, dirs4, dirs5; StrBufDict descwords, dirwords, filewords; StrBufDict files; StrBufDict changes; StrBufDict names; bool debug; void init_words(); void task_super( ClientApi* ); void task_report( ClientApi* ); void task_meta( ClientApi* ); void task_open( ClientApi* ); void task_pending( ClientApi* ); void run_report_dirs( ClientApi* ); void run_meta_client( ClientApi* ); void run_report_have( ClientApi* ); int main( int argc, char** argv ) { ClientApi client; // Ensure that port is not a production depot! StrBuf port, p, s, r; p = client.GetPort(); s = "1666"; r = "XXXX"; StrOps::Replace( port, p, s, r ); client.SetPort( &port ); //Seed random number generator with time srand( time( NULL ) ); //Generate dictionaries init_words(); // Set username to arg1, if provided if ( argc > 1 ) { client.SetUser( argv[1] ); } else //If not, generate a random one { StrBuf newname; for ( int i = -2 ; i < rand() % 5 ; i++ ) newname.Append ( names.GetVar( StrNum( rand() % names.GetCount() ) ) ); client.SetUser( &newname ); } printf( "Gremlin %s reporting for work!\n", client.GetUser().Text() ); // Find root directory Enviro env; char* gpath; if( !( gpath = env.Get( "P4GREMLIN" ) ) ) { printf( "Specify root path in $P4GREMLIN.\n" ); return 1; } grempath = gpath; // Test connection Error e; client.Init( &e ); if ( e.IsFatal() ) { printf( "Gremlin died on arrival.\n" ); StrBuf msg; e.Fmt( msg, EF_INDENT ); printf( msg.Text() ); return 1; } client.Final( &e ); printf( "Found a server to trash at %s!\n", client.GetPort().Text() ); //Set clientname StrBuf user, host, clispec; user = client.GetUser(); host = client.GetHost(); clispec.Set( user ); clispec.Append( "-" ); clispec.Append( &host ); StrOps::Lower( clispec ); //lowercase client.SetClient( &clispec ); //Set CWD for client creation grempath.Append( "/" ); grempath.Append( &user ); client.SetCwd( &grempath ); //Get initial dir list run_report_dirs( &client ); //Make client spec. run_meta_client( &client ); run_report_have( &client ); //Enter random task loop. while ( 1 ) { int rnd = rand() % 100; if ( rnd == 0 ) task_super( &client ); else if ( rnd < 51 ) task_report( &client ); else if ( rnd < 66 ) task_meta( &client ); else if ( rnd < 91 ) task_open( &client ); else task_pending( &client ); /* time_t start_time, cur_time; time( &start_time ); do { time( &cur_time ); } while( ( cur_time - start_time ) < rnd % 3 ); */ } return 0; } //Initialize word lists. void init_words() { descwords.VSetVar( StrNum( 0 ), StrRef( "moonshot" ) ); descwords.VSetVar( StrNum( 1 ), StrRef( "cow" ) ); descwords.VSetVar( StrNum( 2 ), StrRef( "xerxes" ) ); descwords.VSetVar( StrNum( 3 ), StrRef( "silly" ) ); descwords.VSetVar( StrNum( 4 ), StrRef( "wrestler" ) ); descwords.VSetVar( StrNum( 5 ), StrRef( "bonk" ) ); descwords.VSetVar( StrNum( 6 ), StrRef( "monkey" ) ); descwords.VSetVar( StrNum( 7 ), StrRef( "donkey" ) ); descwords.VSetVar( StrNum( 8 ), StrRef( "kitty" ) ); descwords.VSetVar( StrNum( 9 ), StrRef( "ooblek" ) ); descwords.VSetVar( StrNum( 10 ), StrRef( "puppy" ) ); descwords.VSetVar( StrNum( 11 ), StrRef( "Beelzebub" ) ); descwords.VSetVar( StrNum( 12 ), StrRef( "Cthulhu" ) ); descwords.VSetVar( StrNum( 13 ), StrRef( "celphone" ) ); descwords.VSetVar( StrNum( 14 ), StrRef( "orangutan" ) ); descwords.VSetVar( StrNum( 15 ), StrRef( "yo-yo" ) ); descwords.VSetVar( StrNum( 16 ), StrRef( "jerry curl" ) ); descwords.VSetVar( StrNum( 17 ), StrRef( "tiki" ) ); descwords.VSetVar( StrNum( 18 ), StrRef( "bowling" ) ); descwords.VSetVar( StrNum( 19 ), StrRef( "ball" ) ); descwords.VSetVar( StrNum( 20 ), StrRef( "sea" ) ); descwords.VSetVar( StrNum( 21 ), StrRef( "invasion" ) ); descwords.VSetVar( StrNum( 22 ), StrRef( "defenestration" ) ); descwords.VSetVar( StrNum( 23 ), StrRef( "electric" ) ); descwords.VSetVar( StrNum( 24 ), StrRef( "hog" ) ); descwords.VSetVar( StrNum( 25 ), StrRef( "chipmunk" ) ); descwords.VSetVar( StrNum( 26 ), StrRef( "soda" ) ); descwords.VSetVar( StrNum( 27 ), StrRef( "can" ) ); descwords.VSetVar( StrNum( 28 ), StrRef( "lava" ) ); descwords.VSetVar( StrNum( 29 ), StrRef( "lamp" ) ); descwords.VSetVar( StrNum( 30 ), StrRef( "fan" ) ); descwords.VSetVar( StrNum( 31 ), StrRef( "fool" ) ); descwords.VSetVar( StrNum( 32 ), StrRef( "ape" ) ); descwords.VSetVar( StrNum( 33 ), StrRef( "baboon" ) ); descwords.VSetVar( StrNum( 34 ), StrRef( "lemur" ) ); descwords.VSetVar( StrNum( 35 ), StrRef( "orange" ) ); descwords.VSetVar( StrNum( 36 ), StrRef( "apple" ) ); descwords.VSetVar( StrNum( 37 ), StrRef( "banana" ) ); descwords.VSetVar( StrNum( 38 ), StrRef( "kiwi" ) ); descwords.VSetVar( StrNum( 39 ), StrRef( "rubber" ) ); descwords.VSetVar( StrNum( 40 ), StrRef( "right" ) ); descwords.VSetVar( StrNum( 41 ), StrRef( "left" ) ); descwords.VSetVar( StrNum( 42 ), StrRef( "wrong" ) ); descwords.VSetVar( StrNum( 43 ), StrRef( "yeti" ) ); descwords.VSetVar( StrNum( 44 ), StrRef( "grue" ) ); dirwords.VSetVar( StrNum( 0 ), StrRef( "main" ) ); dirwords.VSetVar( StrNum( 1 ), StrRef( "devv" ) ); dirwords.VSetVar( StrNum( 2 ), StrRef( "rel1" ) ); dirwords.VSetVar( StrNum( 3 ), StrRef( "rel2" ) ); dirwords.VSetVar( StrNum( 4 ), StrRef( "quux" ) ); filewords.VSetVar( StrNum( 0 ), StrRef( "foo" ) ); filewords.VSetVar( StrNum( 1 ), StrRef( "bar" ) ); filewords.VSetVar( StrNum( 2 ), StrRef( "baz" ) ); filewords.VSetVar( StrNum( 3 ), StrRef( "qux" ) ); names.VSetVar( StrNum( 0 ), StrRef( "hob" ) ); names.VSetVar( StrNum( 1 ), StrRef( "nob" ) ); names.VSetVar( StrNum( 2 ), StrRef( "gob" ) ); names.VSetVar( StrNum( 3 ), StrRef( "lin" ) ); names.VSetVar( StrNum( 4 ), StrRef( "wik" ) ); names.VSetVar( StrNum( 5 ), StrRef( "kip" ) ); names.VSetVar( StrNum( 6 ), StrRef( "nod" ) ); names.VSetVar( StrNum( 7 ), StrRef( "tak" ) ); names.VSetVar( StrNum( 8 ), StrRef( "yap" ) ); names.VSetVar( StrNum( 9 ), StrRef( "muc" ) ); names.VSetVar( StrNum( 10 ), StrRef( "oth" ) ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 2041 | Sam Stafford |
P4GREMLIN, a stress testing utility. Requires the P4 Client API to build. |