我的测试套件有以下布局:

TestSuite1.cmd:

  1. 运行我的程序
  2. 检查其返回结果
  3. 如果返回结果不为0,则将错误转换为文本输出并中止脚本。如果成功,请写出成功。
  4. 在我的单个.cmd文件中,我使用不同的输入调用我的程序大约10次。

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

    我有没有办法并行化我的程序的所有这10个运行,同时仍然以某种方式检查返回结果并提供正确的输出文件,同时仍然使用单个 .cmd文件并且单个输出文件?

有帮助吗?

解决方案

假设他们不会通过写入相同的文件等来互相干扰:

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文件和(最终)一个输出文件。

其他提示

批处理文件中并行运行可以通过'start'可执行文件/命令完成。

视窗:

您创建一个基本上调用的批处理文件:

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

依此类推,这基本上是在分配新的命令行,

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

您将需要在不同的计算机上使用不同的参数启动脚本,因为任何使程序花费这么长时间来完成任务(IO,CPU时间)的时间将会更短,当多个实例时你的程序一次运行。

唯一的例外:运行时间是程序将自己置于睡眠状态的原因。

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

我使用它生成运行测试的批处理文件,然后使用>>附加到output.txt;就这样:

testthingie.cmd >> output.txt
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top