1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
unit TestBase;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LazFileUtils, LazLogger, DbgIntfDebuggerBase,
TestDbgConfig, TTestDbgExecuteables, TestDbgTestSuites, TestDbgControl,
FpDebugDebugger, Dialogs, Forms,
FpDbgDwarfFreePascal;
type
{ THookedFpDebugDebugger }
THookedFpDebugDebugger = class(TFpDebugDebugger)
protected
procedure LockRelease; override;
public
LockRelCount: Integer;
end;
implementation
type
{ TTestFpDebugDebugger }
TTestFpDebugDebugger = class(TTestDbgDebugger)
protected
procedure DoBetweenWaitForFinish; override;
public
function StartDebugger(AppDir, TestExeName: String): Boolean;
override;
procedure CleanAfterTestDone; override;
end;
procedure BuildTestSuites;
var
FpcList, GdbList: TBaseList;
DbgInfo: TExternalExeInfo;
begin
FpcList := TBaseList(LoadConfig(ConfDir + 'fpclist.txt'));
DbgInfo.Name := 'FpDebug';
DbgInfo.CpuBitTypes := [cpu32,cpu64];
{$IFDEF WIN64}
DbgInfo.CpuBitTypes := [cpu32,cpu64];
{$ENDIF}
{$IFDEF WIN32} // Windows can not cross debug
DbgInfo.CpuBitTypes := [cpu32];
{$ENDIF}
DbgInfo.SymbolTypes := [stDwarf, stDwarfSet, stDwarf3, stDwarf4];
GdbList := TBaseList.Create;
GdbList.Add(DbgInfo);
CreateCompilerList(FpcList, TTestDbgCompiler);
CreateDebuggerList(GdbList, TTestFpDebugDebugger);
CreateTestSuites(TestDbgCompilerList, TestDbgDebuggerList, TDBGTestsuite);
TestControlRegisterCompilers(FpcList);
TestControlRegisterDebuggers(GdbList);
FpcList.Free;
GdbList.Free;
end;
function CheckAppDir(AppDir: string): Boolean;
begin
Result := DirectoryExistsUTF8(AppDir + 'TestApps') and
DirectoryExistsUTF8(AppDir + 'TestApps' + DirectorySeparator + 'lib');
end;
function AppDirStripAppBundle(AppDir: string): String;
var
p: LongInt;
begin
Result := AppDir;
p := pos('.app' + DirectorySeparator, AppDir);
while (p > 1) and (AppDir[p-1] <> DirectorySeparator) do
dec(p);
if p > 1 then
Result := Copy(AppDir, 1, p - 1);
end;
{ THookedFpDebugDebugger }
procedure THookedFpDebugDebugger.LockRelease;
begin
inc(LockRelCount);
inherited LockRelease;
end;
{ TTestFpDebugDebugger }
procedure TTestFpDebugDebugger.DoBetweenWaitForFinish;
begin
CheckSynchronize(25);
Application.ProcessMessages;
inherited DoBetweenWaitForFinish;
end;
function TTestFpDebugDebugger.StartDebugger(AppDir, TestExeName: String
): Boolean;
begin
Result := False;
FLazDebugger := THookedFpDebugDebugger.Create('');
//FLazDebugger.OnDbgOutput := @InternalDbgOutPut;
//FLazDebugger.OnFeedback := @InternalFeedBack;
//FLazDebugger.OnDbgEvent:=@InternalDbgEvent;
InitDebuggerMonitors(FLazDebugger);
FLazDebugger.Init;
if FLazDebugger.State = dsError then begin
FreeAndNil(FLazDebugger);
Exit;
end;
FLazDebugger.WorkingDir := AppDir;
FLazDebugger.FileName := TestExeName;
FLazDebugger.Arguments := '';
//FLazDebugger.ShowConsole := True;
Result := True;
end;
procedure TTestFpDebugDebugger.CleanAfterTestDone;
begin
if FLazDebugger = nil then exit;
try
FLazDebugger.Release;
FLazDebugger := nil;
ClearDebuggerMonitors;
except
end;
end;
initialization
DebugLogger.FindOrRegisterLogGroup('DBG_CMD_ECHO' , True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBG_VERBOSE' , True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS', True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBG_DISASSEMBLER', True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_ERRORS', True);
DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_SEARCH', True)^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_WARNINGS', True)^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_VERBOSE', True);
DebugLogger.FindOrRegisterLogGroup('FPDBG_DWARF_DATA_WARNINGS', True);
AppDir := AppendPathDelim(ExtractFilePath(ParamStr(0)));
if not(CheckAppDir(AppDir))
then begin
AppDir := AppDirStripAppBundle(AppDir);
if not(CheckAppDir(AppDir))
then
with TSelectDirectoryDialog.Create(nil) do begin
if Execute then AppDir := AppendPathDelim(FileName);
Free;
end;
end;
ConfDir := AppDir;
AppDir := AppendPathDelim(AppDir + 'testapps');
if DirectoryExistsUTF8(ConfDir+'logs') then
TestControlSetLogPath(ConfDir+'logs'+DirectorySeparator)
else if DirectoryExistsUTF8(ConfDir+'log') then
TestControlSetLogPath(ConfDir+'log'+DirectorySeparator)
else
TestControlSetLogPath(ConfDir);
BuildTestSuites;
finalization
end.
|