DBG: tests

git-svn-id: trunk@32922 -
This commit is contained in:
martin 2011-10-16 13:36:13 +00:00
parent 36cdc25ab4
commit f2951a1fd4
2 changed files with 166 additions and 33 deletions

View File

@ -41,6 +41,7 @@ type
ExeName: string;
SymbolTypes: TSymbolTypes;
ExtraOpts: string;
Version: Integer;
end;
TDebuggerInfo = record
@ -231,14 +232,25 @@ type
function StartGDB(AppDir, TestExeName: String): TGDBMIDebugger;
procedure CleanGdb;
procedure ClearTestErrors;
procedure AddTestError(s: string; MinGdbVers: Integer = 0; AIgnoreReason: String = '');
procedure AddTestError(s: string; MinGdbVers: Integer; MinFpcVers: Integer;AIgnoreReason: String = '');
procedure AddTestSuccess(s: string; MinGdbVers: Integer = 0; AIgnoreReason: String = '');
procedure AddTestSuccess(s: string; MinGdbVers: Integer; MinFpcVers: Integer;AIgnoreReason: String = '');
function TestEquals(Expected, Got: string): Boolean;
function TestEquals(Name: string; Expected, Got: string; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
function TestEquals(Name: string; Expected, Got: string; MinGdbVers: Integer; MinFpcVers: Integer; AIgnoreReason: String = ''): Boolean;
function TestEquals(Expected, Got: integer): Boolean;
function TestEquals(Name: string; Expected, Got: integer; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
function TestEquals(Name: string; Expected, Got: integer; MinGdbVers: Integer; MinFpcVers: Integer; AIgnoreReason: String = ''): Boolean;
function TestTrue(Name: string; Got: Boolean; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
function TestTrue(Name: string; Got: Boolean; MinGdbVers: Integer; MinFpcVers: Integer; AIgnoreReason: String = ''): Boolean;
function TestFalse(Name: string; Got: Boolean; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
function TestFalse(Name: string; Got: Boolean; MinGdbVers: Integer; MinFpcVers: Integer; AIgnoreReason: String = ''): Boolean;
procedure AssertTestErrors;
property TestErrors: string read FTestErrors;
public
@ -518,6 +530,12 @@ begin
end;
procedure TGDBTestCase.AddTestError(s: string; MinGdbVers: Integer = 0; AIgnoreReason: String = '');
begin
AddTestError(s, MinGdbVers, 0, AIgnoreReason);
end;
procedure TGDBTestCase.AddTestError(s: string; MinGdbVers: Integer; MinFpcVers: Integer;
AIgnoreReason: String);
var
IgnoreReason: String;
i: Integer;
@ -530,7 +548,13 @@ begin
if (i > 0) and (i < MinGdbVers) then
IgnoreReason := 'GDB ('+IntToStr(i)+') to old, required:'+IntToStr(MinGdbVers);
end;
if MinFpcVers > 0 then begin
i := GetCompilerInfo.Version;
if (i > 0) and (i < MinFpcVers) then
IgnoreReason := 'FPC ('+IntToStr(i)+') to old, required:'+IntToStr(MinFpcVers);
end;
IgnoreReason := IgnoreReason + AIgnoreReason;
if IgnoreReason <> '' then begin
FIgnoredErrors := FIgnoredErrors + IntToStr(FTestCnt) + ': ' + '### '+IgnoreReason +' >>> '+s+LineEnding;
inc(FIgnoredErrorCnt);
@ -541,21 +565,35 @@ begin
end;
procedure TGDBTestCase.AddTestSuccess(s: string; MinGdbVers: Integer; AIgnoreReason: String = '');
begin
AddTestSuccess(s, MinGdbVers, 0, AIgnoreReason);
end;
procedure TGDBTestCase.AddTestSuccess(s: string; MinGdbVers: Integer; MinFpcVers: Integer;
AIgnoreReason: String);
var
i: Integer;
begin
s := FTestBaseName + s;
inc(FTestCnt);
if (MinGdbVers > 0) or (AIgnoreReason <> '') then begin
if (MinGdbVers > 0) then begin
i := GetDebuggerInfo.Version;
if (i > 0) and (i < MinGdbVers) then
AIgnoreReason := AIgnoreReason + IntToStr(FTestCnt) + ': ' + s
+ 'GDB ('+IntToStr(i)+') to old, required:'+IntToStr(MinGdbVers)
+ LineEnding;
if AIgnoreReason <> '' then begin;
FUnexpectedSuccess := FUnexpectedSuccess + AIgnoreReason;
inc(FUnexpectedSuccessCnt);
end;
end;
if (MinFpcVers > 0) then begin
i := GetCompilerInfo.Version;
if (i > 0) and (i < MinFpcVers) then
AIgnoreReason := AIgnoreReason + IntToStr(FTestCnt) + ': ' + s
+ 'FPC ('+IntToStr(i)+') to old, required:'+IntToStr(MinFpcVers)
+ LineEnding;
end;
if AIgnoreReason <> '' then begin
FUnexpectedSuccess := FUnexpectedSuccess + AIgnoreReason;
inc(FUnexpectedSuccessCnt);
end
else
inc(FSucessCnt);
@ -567,11 +605,17 @@ begin
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: string; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
begin
TestEquals(Name, Expected, Got, MinGdbVers, 0, AIgnoreReason);
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: string; MinGdbVers: Integer;
MinFpcVers: Integer; AIgnoreReason: String): Boolean;
begin
Result := Got = Expected;
if Result
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "'+Got+'"', MinGdbVers, AIgnoreReason)
else AddTestError(Name + ': Expected "'+Expected+'", Got "'+Got+'"', MinGdbVers, AIgnoreReason);
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "'+Got+'"', MinGdbVers, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "'+Expected+'", Got "'+Got+'"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
function TGDBTestCase.TestEquals(Expected, Got: integer): Boolean;
@ -580,27 +624,45 @@ begin
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: integer; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
begin
TestEquals(Name, Expected, Got, MinGdbVers, 0, AIgnoreReason);
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: integer; MinGdbVers: Integer;
MinFpcVers: Integer; AIgnoreReason: String): Boolean;
begin
Result := Got = Expected;
if Result
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "'+IntToStr(Got)+'"', MinGdbVers, AIgnoreReason)
else AddTestError(Name + ': Expected "'+IntToStr(Expected)+'", Got "'+IntToStr(Got)+'"', MinGdbVers, AIgnoreReason);
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "'+IntToStr(Got)+'"', MinGdbVers, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "'+IntToStr(Expected)+'", Got "'+IntToStr(Got)+'"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
function TGDBTestCase.TestTrue(Name: string; Got: Boolean; MinGdbVers: Integer; AIgnoreReason: String = ''): Boolean;
begin
TestTrue(Name, Got, MinGdbVers, 0, AIgnoreReason);
end;
function TGDBTestCase.TestTrue(Name: string; Got: Boolean; MinGdbVers: Integer;
MinFpcVers: Integer; AIgnoreReason: String): Boolean;
begin
Result := Got;
if Result
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "True"', MinGdbVers, AIgnoreReason)
else AddTestError(Name + ': Expected "True", Got "False"', MinGdbVers, AIgnoreReason);
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "True"', MinGdbVers, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "True", Got "False"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
function TGDBTestCase.TestFalse(Name: string; Got: Boolean; MinGdbVers: Integer; AIgnoreReason: String = ''): Boolean;
begin
TestFalse(Name, Got, MinGdbVers, 0, AIgnoreReason);
end;
function TGDBTestCase.TestFalse(Name: string; Got: Boolean; MinGdbVers: Integer;
MinFpcVers: Integer; AIgnoreReason: String): Boolean;
begin
Result := not Got;
if Result
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "False"', MinGdbVers, AIgnoreReason)
else AddTestError(Name + ': Expected "False", Got "True"', MinGdbVers, AIgnoreReason);
then AddTestSuccess(Name + ': Expected to fail with, but succeded, Got "False"', MinGdbVers, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "False", Got "True"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
procedure TGDBTestCase.AssertTestErrors;
@ -722,7 +784,7 @@ end;
procedure TCompilerList.SetAttribute(AIndex: Integer; const AAttr, AValue: string);
begin
case StringCase(AAttr, ['exe', 'symbols', 'opts'], True, False) of
case StringCase(AAttr, ['exe', 'symbols', 'opts', 'vers', 'version'], True, False) of
0: begin // exe
FList[AIndex].ExeName := AValue;
end;
@ -732,6 +794,9 @@ begin
2: begin //opts
FList[AIndex].ExtraOpts := AValue;
end;
3,4: begin
FList[AIndex].Version := StrToIntDef(AValue,-1);
end;
end;
end;

View File

@ -45,6 +45,7 @@ type
ExpKind: TDBGSymbolKind;
ExpTypeName: string;
Flgs: TWatchExpectationFlags;
MinGdb, MinFpc: Integer;
end;
TWatchExpectation = record
@ -78,14 +79,20 @@ type
AnExpr: string; AFmt: TWatchDisplayFormat;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string;
AFlgs: TWatchExpectationFlags = [];
AStackFrame: Integer = 0
AStackFrame: Integer = 0;
AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;
function AddTo(var ExpArray: TWatchExpectationArray; ATestName: String;
AnExpr: string; AFmt: TWatchDisplayFormat;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string;
AFlgs: TWatchExpectationFlags = [];
AStackFrame: Integer = 0
AStackFrame: Integer = 0;
AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;
procedure UpdRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags;
AMinGdb: Integer; AMinFpc: Integer
);
procedure UpdRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags = []
);
@ -98,6 +105,8 @@ type
procedure UpdRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
ATpNm: string; AFlgs: TWatchExpectationFlags
);
procedure UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType; AMinGdb: Integer);
procedure UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType; AMinFpc: Integer);
procedure AddExpectBreakFooGdb;
procedure AddExpectBreakFooAll;
@ -175,7 +184,8 @@ end;
function TTestWatches.AddTo(var ExpArray: TWatchExpectationArray; AnExpr: string;
AFmt: TWatchDisplayFormat; AMtch: string; AKind: TDBGSymbolKind; ATpNm: string;
AFlgs: TWatchExpectationFlags; AStackFrame: Integer = 0): PWatchExpectation;
AFlgs: TWatchExpectationFlags; AStackFrame: Integer = 0; AMinGdb: Integer = 0;
AMinFpc: Integer = 0): PWatchExpectation;
var
i: TSymbolType;
begin
@ -195,6 +205,8 @@ begin
( (fnoDwrf3 in AFlgs) and (i in [stDwarf3]) ) or
( (fnoStabs in AFlgs) and (i in [stStabs]) )
then Result[i].Flgs := Result[i].Flgs + [fTstSkip];
Result[i].MinGdb := AMinGdb;
Result[i].MinFpc := AMinFpc;
end;
StackFrame := AStackFrame;
end;
@ -203,7 +215,8 @@ end;
function TTestWatches.AddTo(var ExpArray: TWatchExpectationArray; ATestName: String;
AnExpr: string; AFmt: TWatchDisplayFormat; AMtch: string; AKind: TDBGSymbolKind;
ATpNm: string; AFlgs: TWatchExpectationFlags; AStackFrame: Integer): PWatchExpectation;
ATpNm: string; AFlgs: TWatchExpectationFlags; AStackFrame: Integer; AMinGdb: Integer = 0;
AMinFpc: Integer = 0): PWatchExpectation;
var
i: TSymbolType;
begin
@ -220,12 +233,28 @@ begin
if ( (fnoDwrf in AFlgs) and (i in [stDwarf, stDwarfSet, stDwarf3]) ) or
( (fnoDwrfNoSet in AFlgs) and (i in [stDwarf]) )
then Result[i].Flgs := Result[i].Flgs + [fTstSkip];
Result[i].MinGdb := AMinGdb;
Result[i].MinFpc := AMinFpc;
end;
StackFrame := AStackFrame;
end;
Result := @ExpArray[Length(ExpArray)-1];
end;
procedure TTestWatches.UpdRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags;
AMinGdb: Integer; AMinFpc: Integer);
begin
with AWatchExp^ do begin
Result[ASymbolType].ExpMatch := AMtch;
Result[ASymbolType].ExpKind := AKind;
Result[ASymbolType].ExpTypeName := ATpNm;
Result[ASymbolType].Flgs := AFlgs;
Result[ASymbolType].MinGdb := AMinGdb;
Result[ASymbolType].MinFpc := AMinFpc;
end;
end;
procedure TTestWatches.UpdRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags);
begin
@ -263,6 +292,22 @@ begin
end;
end;
procedure TTestWatches.UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMinGdb: Integer);
begin
with AWatchExp^ do begin
Result[ASymbolType].MinGdb := AMinGdb;
end;
end;
procedure TTestWatches.UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
AMinFpc: Integer);
begin
with AWatchExp^ do begin
Result[ASymbolType].MinFpc := AMinFpc;
end;
end;
procedure TTestWatches.AddExpectBreakFooGdb;
function Add(AnExpr: string; AFmt: TWatchDisplayFormat;
AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
@ -560,8 +605,13 @@ begin
// string in array
r:=AddStringFmtDef('ArgTMyAnsiStringDArray[0]', '''DArray1 Str0''$', 'AnsiString', []);
r:=AddStringFmtDef('ArgTMyAnsiStringDArray[1]', '''DArray1 Str1''$', 'AnsiString', []);
r:=AddStringFmtDef('VArgTMyAnsiStringDArray[0]', '''DArray2 Str0''$', 'AnsiString', [fnoDwrf2, fnoStabs]);
r:=AddStringFmtDef('VArgTMyAnsiStringDArray[1]', '''DArray2 Str1''$', 'AnsiString', [fnoDwrf2, fnoStabs]);
r:=AddStringFmtDef('VArgTMyAnsiStringDArray[0]', '''DArray2 Str0''$', 'AnsiString', []);
UpdResMinFpc(r, stDwarf, 020600);
UpdResMinFpc(r, stDwarfSet, 020600);
r:=AddStringFmtDef('VArgTMyAnsiStringDArray[1]', '''DArray2 Str1''$', 'AnsiString', []);
UpdResMinFpc(r, stDwarf, 020600);
UpdResMinFpc(r, stDwarfSet, 020600);
r:=AddFmtDef('ArgTMyAnsiStringDArray[0][1]', '.$', skSimple, 'char', [fnoDwrf2, fnoStabs]);
UpdRes(r, stDwarf3, '''D''$', skSimple);
@ -1044,8 +1094,8 @@ var
if flag then begin;
WV := AWatch.Values[1, Stack];// trigger read
s := WV.Value;
flag := flag and TestTrue (Name+ ' (HasValue)', WV.Validity = ddsValid);
//flag := flag and TestFalse (Name+ ' (One Value)', AWatch.HasMultiValue);
flag := flag and TestTrue (Name+ ' (HasValue)', WV.Validity = ddsValid, DataRes.MinGdb, DataRes.MinFpc);
//flag := flag and TestFalse (Name+ ' (One Value)', AWatch.HasMultiValue, DataRes.MinGdb, DataRes.MinFpc);
end
else
s := WatchValue;
@ -1057,12 +1107,12 @@ var
rx.ModifierI := true;
rx.Expression := DataRes.ExpMatch;
if DataRes.ExpMatch <> ''
then TestTrue(Name + ' Matches "'+DataRes.ExpMatch + '", but was "' + s + '"', rx.Exec(s));
then TestTrue(Name + ' Matches "'+DataRes.ExpMatch + '", but was "' + s + '"', rx.Exec(s), DataRes.MinGdb, DataRes.MinFpc);
//end;
flag := (AWatch <> nil) and (DataRes.ExpTypeName <> '');
if flag then flag := TestTrue(Name + ' has typeinfo', WV.TypeInfo <> nil);
if flag then flag := TestEquals(Name + ' kind', KindName[DataRes.ExpKind], KindName[WV.TypeInfo.Kind]);
if flag then flag := TestTrue(Name + ' has typeinfo', WV.TypeInfo <> nil, DataRes.MinGdb, DataRes.MinFpc);
if flag then flag := TestEquals(Name + ' kind', KindName[DataRes.ExpKind], KindName[WV.TypeInfo.Kind], DataRes.MinGdb, DataRes.MinFpc);
if flag then begin
if fTpMtch in DataRes.Flgs
then begin
@ -1071,16 +1121,16 @@ var
rx := TRegExpr.Create;
rx.ModifierI := true;
rx.Expression := DataRes.ExpTypeName;
TestTrue(Name + ' TypeName matches '+DataRes.ExpTypeName+' but was '+WV.TypeInfo.TypeName, rx.Exec(s))
TestTrue(Name + ' TypeName matches '+DataRes.ExpTypeName+' but was '+WV.TypeInfo.TypeName, rx.Exec(s), DataRes.MinGdb, DataRes.MinFpc)
end
else TestEquals(Name + ' TypeName', LowerCase(DataRes.ExpTypeName), LowerCase(WV.TypeInfo.TypeName));
else TestEquals(Name + ' TypeName', LowerCase(DataRes.ExpTypeName), LowerCase(WV.TypeInfo.TypeName), DataRes.MinGdb, DataRes.MinFpc);
end;
FreeAndNil(rx);
end;
var
i, Only: Integer;
OnlyName: String;
OnlyName, OnlyNamePart: String;
WList, WListSub: Array of TCurrentWatch;
begin
@ -1088,7 +1138,13 @@ begin
if not HasTestArraysData then exit;
Only := StrToIntDef(TestControlForm.EdOnlyWatch.Text, -1);
if Only < 0
then OnlyName := TestControlForm.EdOnlyWatch.Text;
then begin
OnlyName := TestControlForm.EdOnlyWatch.Text;
if (OnlyName <> '') and (OnlyName[1]='*') then begin
OnlyNamePart := copy(OnlyName, 2, length(OnlyName));
OnlyName := '';
end;
end;
try
@ -1119,7 +1175,10 @@ begin
(* Create all watches *)
SetLength(WList, length(ExpectBreakFoo));
for i := low(ExpectBreakFoo) to high(ExpectBreakFoo) do begin
if ((Only >=0) and (Only <> i)) or ((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) then continue;
if ((Only >=0) and (Only <> i)) or
((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) or
((OnlyNamePart<>'') and (pos(OnlyNamePart, ExpectBreakFoo[i].TestName)<1))
then continue;
if not SkipTest(ExpectBreakFoo[i]) then begin
WList[i] := TCurrentWatch.Create(FWatches);
WList[i].Expression := ExpectBreakFoo[i].Expression;
@ -1129,7 +1188,10 @@ begin
end;
SetLength(WListSub, length(ExpectBreakSubFoo));
for i := low(ExpectBreakSubFoo) to high(ExpectBreakSubFoo) do begin
if ((Only >=0) and (Only <> i)) or ((OnlyName<>'') and (OnlyName<>ExpectBreakSubFoo[i].TestName)) then continue;
if ((Only >=0) and (Only <> i)) or
((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) or
((OnlyNamePart<>'') and (pos(OnlyNamePart, ExpectBreakFoo[i].TestName)<1))
then continue;
if not SkipTest(ExpectBreakSubFoo[i]) then begin
WListSub[i] := TCurrentWatch.Create(FWatches);
WListSub[i].Expression := ExpectBreakSubFoo[i].Expression;
@ -1145,7 +1207,10 @@ begin
then begin
(* Hit first breakpoint: NESTED SubFoo -- (1st loop) Called with none nil data *)
for i := low(ExpectBreakSubFoo) to high(ExpectBreakSubFoo) do begin
if ((Only >=0) and (Only <> i)) or ((OnlyName<>'') and (OnlyName<>ExpectBreakSubFoo[i].TestName)) then continue;
if ((Only >=0) and (Only <> i)) or
((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) or
((OnlyNamePart<>'') and (pos(OnlyNamePart, ExpectBreakFoo[i].TestName)<1))
then continue;
if not SkipTest(ExpectBreakSubFoo[i]) then
TestWatch('Brk1 '+IntToStr(i)+' ', WListSub[i], ExpectBreakSubFoo[i]);
end;
@ -1169,7 +1234,10 @@ begin
FDbgOutPutEnable := False;
for i := low(ExpectBreakFoo) to high(ExpectBreakFoo) do begin
if ((Only >=0) and (Only <> i)) or ((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) then continue;
if ((Only >=0) and (Only <> i)) or
((OnlyName<>'') and (OnlyName<>ExpectBreakFoo[i].TestName)) or
((OnlyNamePart<>'') and (pos(OnlyNamePart, ExpectBreakFoo[i].TestName)<1))
then continue;
if not SkipTest(ExpectBreakFoo[i]) then
TestWatch('Brk1 '+IntToStr(i)+' ', WList[i], ExpectBreakFoo[i]);
end;