#include <stdlib.h> #include "clientapi.h" #include "globals.h" #include "clientgremlin.h" #include "clientgremlinhave.h" void run_open_add( ClientApi* client ); void run_open_sync( ClientApi* client ); void run_open_integ( ClientApi* client ); void run_open_edit( ClientApi* client ); void run_open_del( ClientApi* client); void task_open( ClientApi* client ) { int rnd = rand() % 90; if ( rnd < 35 ) run_open_sync( client ); else if ( rnd < 55 ) run_open_edit( client ); else if ( rnd < 70 ) run_open_add( client ); else if ( rnd < 75 ) run_open_del( client ); else run_open_integ( client ); } void run_open_sync( ClientApi* client ) { ClientGremlinHave grem = ClientGremlinHave( client, "sync" ); if ( ! ( rand() % 20 ) ) { grem.arg1.Set( "-f" ); grem.Run(); return; } if ( !dirs1.GetCount() ) return; grem.arg1.Set( dirs1.GetVar( StrNum( rand() % dirs1.GetCount() ) ) ); grem.arg1.Append( "/..." ); grem.Run(); if ( !dirs2.GetCount() ) return; grem.arg1.Set( dirs2.GetVar( StrNum( rand() % dirs2.GetCount() ) ) ); grem.arg1.Append( "/..." ); grem.Run(); if ( !dirs3.GetCount() ) return; grem.arg1.Set( dirs3.GetVar( StrNum( rand() % dirs3.GetCount() ) ) ); grem.arg1.Append( "/..." ); grem.Run(); if ( !dirs4.GetCount() ) return; grem.arg1.Set( dirs4.GetVar( StrNum( rand() % dirs4.GetCount() ) ) ); grem.arg1.Append( "/..." ); grem.Run(); if ( !dirs5.GetCount() ) return; grem.arg1.Set( dirs5.GetVar( StrNum( rand() % dirs5.GetCount() ) ) ); grem.arg1.Append( "/..." ); grem.Run(); } void run_open_edit( ClientApi* client ) { if ( !files.GetCount() ) return; for ( int a = 0 ; a <= rand() % 10 ; a++ ) { StrBuf lpath; lpath.Set( files.GetVar( StrNum( rand() % files.GetCount() ) ) ); FileSys* lfile = FileSys::Create( FST_TEXT ); lfile->Set( lpath ); Error e; ClientGremlin grem = ClientGremlin( client, "edit" ); grem.arg1.Set( lpath ); grem.Run(); lfile->Open( FOM_WRITE, &e ); StrBuf content; lfile->ReadWhole( &content, &e ); if ( !( rand() % 50 ) ) content.Clear(); for ( int c = 1 ; c < rand() % 900 + 1 ; c++ ) { content.Append ( descwords.GetVar( StrNum( rand() % descwords.GetCount() ) ) ); content.Append( " " ); if ( ! ( c % 7 ) ) content.Append( "\n" ); } lfile->Write( &content, &e ); lfile->Close( &e ); delete lfile; } } void run_open_del( ClientApi* client ) { if ( !files.GetCount() ) return; for ( int a = 0 ; a <= rand() % 3 ; a++ ) { StrBuf lpath; lpath.Set( files.GetVar( StrNum( rand() % files.GetCount() ) ) ); ClientGremlin grem = ClientGremlin( client, "delete" ); grem.arg1.Set( lpath ); grem.Run(); } } void run_open_integ( 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() % 20 ) ) { switch ( rand() % 10 ) { case 0: if ( !dirs1.GetCount() ) break; fspec1.Set( dirs1.GetVar( StrNum( rand() % dirs1.GetCount() ) ) ); break; case 1: if ( !dirs2.GetCount() ) break; fspec1.Set( dirs2.GetVar( StrNum( rand() % dirs2.GetCount() ) ) ); break; case 2: if ( !dirs3.GetCount() ) break; fspec1.Set( dirs3.GetVar( StrNum( rand() % dirs3.GetCount() ) ) ); break; case 3: if ( !dirs4.GetCount() ) break; fspec1.Set( dirs4.GetVar( StrNum( rand() % dirs4.GetCount() ) ) ); break; case 4: if ( !dirs5.GetCount() ) break; fspec1.Set( dirs5.GetVar( StrNum( rand() % dirs5.GetCount() ) ) ); break; case 5: if ( !dirs1.GetCount() ) break; fspec2.Set( dirs1.GetVar( StrNum( rand() % dirs1.GetCount() ) ) ); break; case 6: if ( !dirs2.GetCount() ) break; fspec2.Set( dirs2.GetVar( StrNum( rand() % dirs2.GetCount() ) ) ); break; case 7: if ( !dirs3.GetCount() ) break; fspec2.Set( dirs3.GetVar( StrNum( rand() % dirs3.GetCount() ) ) ); break; case 8: if ( !dirs4.GetCount() ) break; fspec2.Set( dirs4.GetVar( StrNum( rand() % dirs4.GetCount() ) ) ); break; case 9: if ( !dirs5.GetCount() ) break; fspec2.Set( dirs5.GetVar( StrNum( rand() % dirs5.GetCount() ) ) ); break; } fspec1.Append( "/" ); 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, "integ" ); grem.arg1.Set( "-id" ); grem.arg2.Set( fspec1 ); grem.arg3.Set( fspec2 ); grem.Run(); } void run_open_add( ClientApi* client ) { for ( int a = 0 ; a <= rand() % 5 ; a++ ) { StrBuf lpath; lpath.Set( grempath ); lpath.Append( "/" ); for ( int b = 0 ; b < 5 ; b++ ) { if ( rand() % 20 <= b*3 ) break; lpath.Append ( dirwords.GetVar( StrNum( rand() % dirwords.GetCount() ) ) ); lpath.Append( "/" ); } lpath.Append ( filewords.GetVar( StrNum( rand() % filewords.GetCount() ) ) ); ClientGremlin grem = ClientGremlin( client, "add" ); grem.arg1.Set( lpath ); grem.Run(); FileSys* lfile = FileSys::Create( FST_TEXT ); lfile->Set( lpath ); Error e; lfile->MkDir( &e ); lfile->Open( FOM_WRITE, &e ); grem.HandleError( &e ); if ( e.IsFatal() ) return; StrBuf content; for ( int c = 1 ; c < rand() % 900 + 1 ; c++ ) { content.Append ( descwords.GetVar( StrNum( rand() % descwords.GetCount() ) ) ); content.Append( " " ); if ( ! ( c % 7 ) ) content.Append( "\n" ); } lfile->Write( &content, &e ); grem.HandleError( &e ); if ( e.IsFatal() ) return; lfile->Close( &e ); grem.HandleError( &e ); delete lfile; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 2056 | Sam Stafford | Tweaked the edit routine - let's see if this does the right thing. | ||
#1 | 2041 | Sam Stafford |
P4GREMLIN, a stress testing utility. Requires the P4 Client API to build. |