@@ -47,7 +47,6 @@ public void SetupTest(PlatformID platform)
4747 this . mockFixture . Parameters = new Dictionary < string , IConvertible > ( )
4848 {
4949 { nameof ( StressAppTestExecutor . PackageName ) , "stressapptest" } ,
50- { nameof ( StressAppTestExecutor . CommandLine ) , "" } ,
5150 { nameof ( StressAppTestExecutor . Scenario ) , "ApplyStress" } ,
5251 { nameof ( StressAppTestExecutor . Duration ) , "00:01:00" } ,
5352 { nameof ( StressAppTestExecutor . UseCpuStressfulMemoryCopy ) , false }
@@ -161,14 +160,52 @@ public void StressAppTestExecutorThrowsOnInvalidProfileDefinition(PlatformID pla
161160 }
162161
163162 this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . Scenario ) ] = "ApplyStress" ;
164- this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . CommandLine ) ] = "-l logfile.txt " ;
163+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . Duration ) ] = "00:00:00 " ;
165164 using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
166165 {
167166 Assert . Throws < WorkloadException > ( ( ) => executor . Validate ( ) ) ;
168167 }
168+ }
169169
170- this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . CommandLine ) ] = "" ;
171- this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . Duration ) ] = "00:00:00" ;
170+ [ Test ]
171+ [ TestCase ( PlatformID . Unix ) ]
172+ public void StressAppTestExecutorThrowsWhenMemoryInMBIsInvalid ( PlatformID platform )
173+ {
174+ this . SetupTest ( platform ) ;
175+
176+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . MemoryInMB ) ] = 0 ;
177+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
178+ {
179+ Assert . Throws < WorkloadException > ( ( ) => executor . Validate ( ) ) ;
180+ }
181+
182+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . MemoryInMB ) ] = - 1 ;
183+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
184+ {
185+ Assert . Throws < WorkloadException > ( ( ) => executor . Validate ( ) ) ;
186+ }
187+ }
188+
189+ [ Test ]
190+ [ TestCase ( PlatformID . Unix ) ]
191+ public void StressAppTestExecutorThrowsWhenThreadCountIsInvalid ( PlatformID platform )
192+ {
193+ this . SetupTest ( platform ) ;
194+
195+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . ThreadCount ) ] = 0 ;
196+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
197+ {
198+ Assert . Throws < WorkloadException > ( ( ) => executor . Validate ( ) ) ;
199+ }
200+ }
201+
202+ [ Test ]
203+ [ TestCase ( PlatformID . Unix ) ]
204+ public void StressAppTestExecutorThrowsWhenCpuStressThreadCountIsInvalid ( PlatformID platform )
205+ {
206+ this . SetupTest ( platform ) ;
207+
208+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . CpuStressThreadCount ) ] = - 1 ;
172209 using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
173210 {
174211 Assert . Throws < WorkloadException > ( ( ) => executor . Validate ( ) ) ;
@@ -241,6 +278,145 @@ public void StressAppTestExecutorSupportsIntegerAndTimeSpanDurationFormats(Platf
241278 Assert . AreEqual ( integerBasedDuration , timespanBasedDuration ) ;
242279 }
243280
281+ [ Test ]
282+ [ TestCase ( PlatformID . Unix , @"/linux-x64/stressapptest" ) ]
283+ public async Task StressAppTestExecutorIncludesMemoryParameterInCommandLine ( PlatformID platform , string command )
284+ {
285+ this . SetupTest ( platform ) ;
286+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . MemoryInMB ) ] = 1024 ;
287+
288+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
289+ {
290+ bool commandExecuted = false ;
291+ this . mockFixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
292+ {
293+ if ( arguments . Contains ( "-M 1024" ) )
294+ {
295+ commandExecuted = true ;
296+ }
297+
298+ return new InMemoryProcess
299+ {
300+ StartInfo = new ProcessStartInfo
301+ {
302+ FileName = exe ,
303+ Arguments = arguments
304+ } ,
305+ ExitCode = 0 ,
306+ OnStart = ( ) => true ,
307+ OnHasExited = ( ) => true
308+ } ;
309+ } ;
310+
311+ await executor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
312+ Assert . IsTrue ( commandExecuted ) ;
313+ }
314+ }
315+
316+ [ Test ]
317+ [ TestCase ( PlatformID . Unix , @"/linux-x64/stressapptest" ) ]
318+ public async Task StressAppTestExecutorIncludesThreadCountParameterInCommandLine ( PlatformID platform , string command )
319+ {
320+ this . SetupTest ( platform ) ;
321+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . ThreadCount ) ] = 8 ;
322+
323+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
324+ {
325+ bool commandExecuted = false ;
326+ this . mockFixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
327+ {
328+ if ( arguments . Contains ( "-m 8" ) )
329+ {
330+ commandExecuted = true ;
331+ }
332+
333+ return new InMemoryProcess
334+ {
335+ StartInfo = new ProcessStartInfo
336+ {
337+ FileName = exe ,
338+ Arguments = arguments
339+ } ,
340+ ExitCode = 0 ,
341+ OnStart = ( ) => true ,
342+ OnHasExited = ( ) => true
343+ } ;
344+ } ;
345+
346+ await executor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
347+ Assert . IsTrue ( commandExecuted ) ;
348+ }
349+ }
350+
351+ [ Test ]
352+ [ TestCase ( PlatformID . Unix , @"/linux-x64/stressapptest" ) ]
353+ public async Task StressAppTestExecutorIncludesCpuStressThreadCountParameterInCommandLine ( PlatformID platform , string command )
354+ {
355+ this . SetupTest ( platform ) ;
356+ this . mockFixture . Parameters [ nameof ( StressAppTestExecutor . CpuStressThreadCount ) ] = 4 ;
357+
358+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
359+ {
360+ bool commandExecuted = false ;
361+ this . mockFixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
362+ {
363+ if ( arguments . Contains ( "-C 4" ) )
364+ {
365+ commandExecuted = true ;
366+ }
367+
368+ return new InMemoryProcess
369+ {
370+ StartInfo = new ProcessStartInfo
371+ {
372+ FileName = exe ,
373+ Arguments = arguments
374+ } ,
375+ ExitCode = 0 ,
376+ OnStart = ( ) => true ,
377+ OnHasExited = ( ) => true
378+ } ;
379+ } ;
380+
381+ await executor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
382+ Assert . IsTrue ( commandExecuted ) ;
383+ }
384+ }
385+
386+ [ Test ]
387+ [ TestCase ( PlatformID . Unix , @"/linux-x64/stressapptest" ) ]
388+ public async Task StressAppTestExecutorOmitsOptionalParametersWhenNotSpecified ( PlatformID platform , string command )
389+ {
390+ this . SetupTest ( platform ) ;
391+
392+ using ( TestStressAppTestExecutor executor = new TestStressAppTestExecutor ( this . mockFixture ) )
393+ {
394+ bool commandCorrect = false ;
395+ this . mockFixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
396+ {
397+ if ( ! arguments . Contains ( "-M" ) && ! arguments . Contains ( "-m " ) && ! arguments . Contains ( "-C" ) )
398+ {
399+ commandCorrect = true ;
400+ }
401+
402+ return new InMemoryProcess
403+ {
404+ StartInfo = new ProcessStartInfo
405+ {
406+ FileName = exe ,
407+ Arguments = arguments
408+ } ,
409+ ExitCode = 0 ,
410+ OnStart = ( ) => true ,
411+ OnHasExited = ( ) => true
412+ } ;
413+ } ;
414+
415+ await executor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
416+ Assert . IsTrue ( commandCorrect ) ;
417+ }
418+ }
419+
244420 private class TestStressAppTestExecutor : StressAppTestExecutor
245421 {
246422 public TestStressAppTestExecutor ( MockFixture fixture )
0 commit comments