我的测试套件有以下布局:
测试套件1.cmd:
- 运行我的程序
- 检查其返回结果
- 如果返回结果不为 0,则将错误转换为文本输出并中止脚本。如果成功,写出成功。
在我的单个 .cmd 文件中,我用不同的输入调用我的程序大约 10 次。
问题是我运行 10 次的程序每次都需要几个小时才能运行。
有没有办法让我并行化我的程序的所有这 10 次运行,同时仍然以某种方式检查返回结果并提供正确的输出文件,同时仍然使用单个.cmd 文件和单个输出文件?
我的测试套件有以下布局:
测试套件1.cmd:
在我的单个 .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 TestSuite1.cmd [TestParams1]
start TestSuite1.cmd [TestParams2]
等等,本质上是分叉新的命令行,
如果应用程序可以处理并发用户(即使它是同一个用户),并且您的 TestSuite1.cmd 能够处理参数,这将起作用。
尝试命令start,它会产生一个新的命令提示符,您可以发送任何您希望它运行的命令。
我将使用它来生成运行测试的批处理文件,然后使用 >> 附加到 output.txt 中:
testthingie.cmd >> output.txt
You will need to start the script with different parameters on different machines because whatever makes the program take so long for a task (IO, CPU time) will be in even shorter supply when multiple instances of your program run at once.
Only exception: the run time is cause by the program putting itself to sleep.