2008-09-25 68 views
2

我有我的测试套件以下布局:自动化测试使用批处理文件:

TestSuite1.cmd:

  1. 运行我的程序
  2. 检查它的返回结果
  3. 如果返回结果不是0,将错误转换为文本输出并中止脚本。如果成功,写出成功。

在我的单个.cmd文件中,我用不同的输入调用我的程序约10次。

问题是我运行10次的程序每次运行需要几个小时。

有没有办法对我来说,所有的并行我的程序的这10只奔跑的同时仍然以某种方式检查返回结果,并提供适当的输出文件,同时还使用 .cmd文件和一个输出文件?

回答

4

假设他们将不会被写入同一文件的相互干扰等:

test1.cmd

:: intercept sub-calls. 
    if "%1"=="test2" then goto :test2 

:: start sub-calls. 
    start test1.cmd test2 1 
    start test1.cmd test2 2 
    start test1.cmd test2 3 

:: wait for sub-calls to complete. 
:loop1 
    if not exist test2_1.flg goto :loop1 
:loop2 
    if not exist test2_2.flg goto :loop2 
:loop3 
    if not exist test2_3.flg goto :loop3 

:: output results sequentially 
    type test2_1.out >test1.out 
    del /s test2_1.out 
    del /s test2_1.flg 
    type test2_2.out >test1.out 
    del /s test2_2.out 
    del /s test2_2.flg 
    type test2_3.out >test1.out 
    del /s test2_3.out 
    del /s test2_3.flg 

    goto :eof 
:test2 

:: Generate one output file 
    echo %1 >test2_%1.out 
    ping -n 31 127.0.0.1 >nul: 2>nul: 

:: generate flag file to indicate finished 
    echo x >test2_%1.flg 

这将启动三个并行处理每个呼应它的序列号,然后等待30秒。

所有都带有一个cmd文件和(最终)一个输出文件。

+0

如果test1有时需要比test2更长的时间会怎么样? – 2008-09-25 12:16:09

+0

这一个将开始所有三个,但主程序将负责收集各个输出 - 标志文件用于向主程序表明子程序已完成。 – paxdiablo 2008-09-25 12:22:35

+0

在这个版本中,时序并不重要 - 它会等到所有并行子程序在主程序整理输出文件之前完成。整个过程只需要最长的子程序(对于整理还有一点额外的)。 – paxdiablo 2008-09-25 12:23:47

0

尝试命令start,它会产生一个新的命令提示符,并且您可以发送任何您希望它运行的命令。

我会用这产卵运行测试批处理文件,然后追加到使用>>作为这样一个output.txt的:

testthingie.cmd >> output.txt 
+0

但这并没有解决我的问题,我仍然想检查和写输出到单个输出文件。 – 2008-09-25 12:04:37

1

在批处理文件运行并行的东西可以通过“做启动'可执行文件/命令。

1

的Windows:

您创建一个批处理文件,基本上要求:

start TestSuite1.cmd [TestParams1] 
start TestSuite1.cmd [TestParams2] 

等,基本上是分叉新的命令行,

这将工作,如果应用程序可以处理并发用户(即使它是同一个用户),你的TestSuite1.cmd能够处理参数。

0

您将需要与不同的机器不同的参数启动脚本,因为不管是什么让该计划花了这么长时间任务(IO,CPU时间)将在供应更短,当你的程序运行多个实例一旦。

只有例外:运行时间是由程序自己进入睡眠状态引起的。