mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 04:39:28 +02:00
+ (OutputFileName variable): Add possibility to use output duplicated to a file by a modified dosbox
version, using an entry in [dos] section of dosbox.conf cinfig file. copy_con_to_file=/path/to/file/that/will/get/the/copy + (EchoOutput procedure) Write to ouput the content of this file so that it ends up into XXXX.elg file when checking test file XXXX. * Add use_temp_dir boolean variable, set to true by default, can be set to false by setting DOSBOX_NO_TEMPDIR env. variable. + Add hide_execution boolean variable (might only work on Windows), which sets SWOHide to Process.ShowWindow property if true. hide_execution defaults to true, but can be set to true by setting DOSBOX_NO_HIDE to set to false. + Add do_exit boolean variable (defaulting to true), which adds 'exit' as last line into autoexec section in dosbox.conf. Use DOSBOX_NO_EXIT to avoid automatic closing of DosBox at the end of test execution (can bbe useful for debugging purposes). git-svn-id: trunk@32623 -
This commit is contained in:
parent
9f79eeff0e
commit
1e38631cbe
@ -3,6 +3,13 @@
|
||||
uses
|
||||
SysUtils, StrUtils, Process;
|
||||
|
||||
const
|
||||
use_temp_dir : boolean = true;
|
||||
hide_execution : boolean = true;
|
||||
do_exit : boolean =true;
|
||||
var
|
||||
OutputFileName : String;
|
||||
|
||||
function GenerateTempDir: string;
|
||||
var
|
||||
FileName: string;
|
||||
@ -35,6 +42,8 @@ var
|
||||
begin
|
||||
SourceConfFileName := ExtractFilePath(ParamStr(0)) + 'dosbox.conf';
|
||||
TargetConfFileName := ADosBoxDir + 'dosbox.conf';
|
||||
OutputFileName := ADosBoxDir + 'dosbox.out';
|
||||
Writeln('Using target dosbox.conf ',TargetConfFileName);
|
||||
AssignFile(SourceFile, SourceConfFileName);
|
||||
AssignFile(TargetFile, TargetConfFileName);
|
||||
Reset(SourceFile);
|
||||
@ -45,6 +54,11 @@ begin
|
||||
begin
|
||||
Readln(SourceFile, S);
|
||||
S := AnsiReplaceStr(S, '$DosBoxDir', ADosBoxDir);
|
||||
S := AnsiReplaceStr(S, '$wrapper_output', OutputFileName);
|
||||
if do_exit then
|
||||
S := AnsiReplaceStr(S, '$exit', 'exit')
|
||||
else
|
||||
S := AnsiReplaceStr(S, '$exit', '');
|
||||
Writeln(TargetFile, S);
|
||||
end;
|
||||
finally
|
||||
@ -90,6 +104,40 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ On modified dosbox executable it is possible to get
|
||||
a copy of all output to CON into a file, simply write it
|
||||
back to output, so it ends up into testname.elg file }
|
||||
procedure EchoOutput;
|
||||
var
|
||||
StdText : TextFile;
|
||||
st : string;
|
||||
line : longint;
|
||||
begin
|
||||
if FileExists(OutputFileName) then
|
||||
begin
|
||||
Writeln('Trying to open ',OutputFileName);
|
||||
try
|
||||
AssignFile(StdText, OutputFileName);
|
||||
Reset(StdText);
|
||||
Writeln('Successfully opened ',OutputFileName,', copying content to output');
|
||||
try
|
||||
line:=0;
|
||||
while not eof(StdText) do
|
||||
begin
|
||||
Readln(StdText,st);
|
||||
inc(line);
|
||||
Writeln(line,': ',st);
|
||||
end;
|
||||
finally
|
||||
CloseFile(StdText);
|
||||
end;
|
||||
finally
|
||||
if use_temp_dir then
|
||||
DeleteFile(OutputFileName);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ReadExitCode(const ADosBoxDir: string): Integer;
|
||||
var
|
||||
F: TextFile;
|
||||
@ -98,9 +146,13 @@ begin
|
||||
Reset(F);
|
||||
try
|
||||
Readln(F, Result);
|
||||
finally
|
||||
CloseFile(F);
|
||||
if Result <> 0 then
|
||||
Writeln('ExitCode=',Result);
|
||||
except
|
||||
Writeln('Unable to read exitcode value');
|
||||
ReadExitCode:=127*256;
|
||||
end;
|
||||
CloseFile(F);
|
||||
end;
|
||||
|
||||
procedure ExecuteDosBox(const ADosBoxBinaryPath, ADosBoxDir: string);
|
||||
@ -115,13 +167,12 @@ begin
|
||||
Process.Executable := ADosBoxBinaryPath;
|
||||
Process.Parameters.Add('-conf');
|
||||
Process.Parameters.Add(ADosBoxDir + 'dosbox.conf');
|
||||
{$ifdef MSWINDOWS}
|
||||
Process.ShowWindow := swoHIDE;
|
||||
{$endif MSWINDOWS}
|
||||
if hide_execution then
|
||||
Process.ShowWindow := swoHIDE;
|
||||
Process.Execute;
|
||||
repeat
|
||||
Inc(Time);
|
||||
if Time > Timeout then
|
||||
if (Time > Timeout) and do_exit then
|
||||
break;
|
||||
Sleep(100);
|
||||
until not Process.Running;
|
||||
@ -129,6 +180,7 @@ begin
|
||||
Process.Terminate(254);
|
||||
finally
|
||||
Process.Free;
|
||||
EchoOutput;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -154,9 +206,28 @@ var
|
||||
DosBoxBinaryPath: string;
|
||||
begin
|
||||
Randomize;
|
||||
|
||||
if GetEnvironmentVariable('DOSBOX_NO_TEMPDIR')<>'' then
|
||||
begin
|
||||
use_temp_dir:=false;
|
||||
Writeln('use_temp_dir set to false');
|
||||
end;
|
||||
if GetEnvironmentVariable('DOSBOX_NO_HIDE')<>'' then
|
||||
begin
|
||||
hide_execution:=false;
|
||||
Writeln('hide_execution set to false');
|
||||
end;
|
||||
if GetEnvironmentVariable('DOSBOX_NO_EXIT')<>'' then
|
||||
begin
|
||||
do_exit:=false;
|
||||
Writeln('do_exit set to false');
|
||||
end;
|
||||
if ParamCount = 0 then
|
||||
begin
|
||||
Writeln('Usage: ' + ParamStr(0) + ' <executable>');
|
||||
Writeln('Set DOSBOX_NO_TEMPDIR env variable to 1 to avoid using a temporary directory');
|
||||
Writeln('Set DOSBOX_NO_HIDE to avoid running dosbox in an hidden window');
|
||||
Writeln('Set DOSBOX_NO_EXIT to avoid exiting dosbox after test has been run');
|
||||
halt(1);
|
||||
end;
|
||||
DosBoxBinaryPath := GetEnvironmentVariable('DOSBOX');
|
||||
@ -164,8 +235,23 @@ begin
|
||||
begin
|
||||
Writeln('Please set the DOSBOX environment variable to the dosbox executable');
|
||||
halt(1);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Writeln('Using DOSBOX executable: ',DosBoxBinaryPath);
|
||||
end;
|
||||
DosBoxDir := GenerateTempDir;
|
||||
|
||||
{ DosBoxDir is used inside dosbox.conf as a MOUNT parameter }
|
||||
if use_temp_dir then
|
||||
DosBoxDir := GenerateTempDir
|
||||
else
|
||||
begin
|
||||
Writeln('Using ',ParamStr(1));
|
||||
DosBoxDir:=ExtractFilePath(ParamStr(1));
|
||||
if DosBoxDir='' then
|
||||
DosBoxDir:=GetCurrentDir+DirectorySeparator;
|
||||
Writeln('Using DosBoxDir=',DosBoxDir);
|
||||
end;
|
||||
try
|
||||
GenerateDosBoxConf(DosBoxDir);
|
||||
CopyFile(ExtractFilePath(ParamStr(0)) + 'exitcode.exe', DosBoxDir + 'EXITCODE.EXE');
|
||||
@ -173,7 +259,8 @@ begin
|
||||
ExecuteDosBox(DosBoxBinaryPath, DosBoxDir);
|
||||
ExitCode := ReadExitCode(DosBoxDir);
|
||||
finally
|
||||
Cleanup(DosBoxDir);
|
||||
if use_temp_dir then
|
||||
Cleanup(DosBoxDir);
|
||||
end;
|
||||
halt(ExitCode);
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user