#include <stdlib.h> #include "clientapi.h" #include "strtable.h" #include "globals.h" #include "clientgremlin.h" #include "clientgremlindir.h" #include "clientgremlinhave.h" void run_report_dirs( ClientApi* client ); void run_report_fstat( ClientApi* client ); void run_report_changes( ClientApi* client ); void run_report_have( ClientApi* client ); void run_report_filelog( ClientApi* client ); void run_report_jobs( ClientApi* client ); void run_report_fixes( ClientApi* client ); void run_report_diffs( ClientApi* client ); void task_report( ClientApi* client ) { int rnd = rand() % 100; if ( rnd < 21 ) run_report_dirs( client ); else if ( rnd < 31 ) run_report_fstat( client ); else if ( rnd < 51 ) run_report_changes( client ); else if ( rnd < 66 ) run_report_have( client ); else if ( rnd < 81 ) run_report_filelog( client ); else if ( rnd < 91 ) run_report_jobs( client ); else if ( rnd < 96 ) run_report_fixes( client ); else run_report_diffs( client ); } void run_report_dirs( ClientApi* client ) { ClientGremlinDir grem = ClientGremlinDir( client ); StrBuf arg; arg.Set( "//depot" ); for ( int a = 1 ; a < 6 ; a++ ) { grem.active = false; grem.dirlevel = a; arg.Append( "/*" ); grem.arg1 = arg; grem.Run(); if ( !grem.active ) break; } } void run_report_fstat( ClientApi* client ) { ClientGremlin grem = ClientGremlin( client, "fstat" ); grem.arg1.Set( "-l" ); StrBuf arg; arg.Set( "//depot" ); for ( int a = 1 ; a < 6 ; a++ ) { arg.Append( "/*" ); grem.arg2 = arg; grem.Run(); } } void run_report_changes( ClientApi* client ) { ClientGremlin grem = ClientGremlin( client, "changes" ); if ( rand() % 4 ) grem.arg1.Set( "-l" ); else grem.arg1.Set( "-i" ); grem.arg2.Set( "//depot/" ); grem.arg2.Append( dirwords.GetVar( StrNum( rand() % dirwords.GetCount() ) ) ); grem.arg2.Append( "/*" ); grem.Run(); } void run_report_have( ClientApi* client ) { if ( debug ) printf( "<have>\n" ); ClientGremlinHave grem = ClientGremlinHave( client, "have" ); files.Clear(); grem.Run(); if ( debug ) printf( "</have>\n" ); } void run_report_filelog( ClientApi* client ) { StrBuf fspec; fspec.Set( "//depot/" ); for ( int a = 0 ; a < 5 ; a++ ) { if ( rand() % 15 < 5 ) break; fspec.Append ( dirwords.GetVar( StrNum( rand() % dirwords.GetCount() ) ) ); fspec.Append( "/" ); } if ( rand() % 15 < 3 ) { fspec.Append( "..." ); } else { fspec.Append ( filewords.GetVar( StrNum( rand() % filewords.GetCount() ) ) ); } ClientGremlin grem = ClientGremlin( client, "filelog" ); if ( rand() % 4 ) grem.arg1.Set( "-l" ); else grem.arg1.Set( "-i" ); grem.arg2.Set( fspec ); grem.Run(); } void run_report_jobs( ClientApi* client ) { StrBuf query; query.Set( descwords.GetVar( StrNum( rand() % descwords.GetCount() ) ) ); for ( int a = 0 ; a < rand() % 20 ; a++ ) { if ( rand() % 3 < 2 ) query.Append( " " ); else query.Append( "|" ); query.Append( descwords.GetVar( StrNum( rand() % descwords.GetCount() ) ) ); } ClientGremlin grem = ClientGremlin( client, "jobs" ); grem.arg1.Set( "-e" ); grem.arg2.Set( query ); grem.Run(); } void run_report_fixes( ClientApi* client ) { ClientGremlin grem = ClientGremlin( client, "fixes" ); grem.arg1.Set( "-i" ); grem.arg2.Set( "//depot/...#have" ); grem.Run(); } void run_report_diffs( ClientApi* client ) { StrBuf fspec1, fspec2; fspec1.Set( "//depot/" ); fspec2.Set( "//depot/" ); for ( int a = 0 ; a < 5 ; a++ ) { if ( rand() % 15 < 5 ) break; fspec1.Append ( dirwords.GetVar( StrNum( rand() % dirwords.GetCount() ) ) ); fspec1.Append( "/" ); fspec2.Append ( dirwords.GetVar( StrNum( rand() % dirwords.GetCount() ) ) ); fspec2.Append( "/" ); } if ( rand() % 15 < 3 ) { fspec1.Append( "..." ); fspec2.Append( "..." ); } else { fspec1.Append ( filewords.GetVar( StrNum( rand() % filewords.GetCount() ) ) ); fspec2.Append ( filewords.GetVar( StrNum( rand() % filewords.GetCount() ) ) ); } ClientGremlin grem = ClientGremlin( client, "diff2" ); grem.arg1.Set( fspec1 ); grem.arg2.Set( fspec2 ); grem.Run(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 2041 | Sam Stafford |
P4GREMLIN, a stress testing utility. Requires the P4 Client API to build. |