mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-23 16:51:32 +02:00
* The Category of a testrun is now stored into the database. The default is CategoryID is 1 for compatibility with digests without category
* Fixed procession of db-errors * Added support for adding new fpcunit-tests and parse the testunits git-svn-id: trunk@9853 -
This commit is contained in:
parent
1d88e3eb11
commit
76636bad26
@ -68,6 +68,7 @@ TConfigOpt = (
|
|||||||
coLogFile,
|
coLogFile,
|
||||||
coOS,
|
coOS,
|
||||||
coCPU,
|
coCPU,
|
||||||
|
coCategory,
|
||||||
coVersion,
|
coVersion,
|
||||||
coDate,
|
coDate,
|
||||||
coSubmitter,
|
coSubmitter,
|
||||||
@ -87,6 +88,7 @@ ConfigStrings : Array [TConfigOpt] of string = (
|
|||||||
'logfile',
|
'logfile',
|
||||||
'os',
|
'os',
|
||||||
'cpu',
|
'cpu',
|
||||||
|
'category',
|
||||||
'version',
|
'version',
|
||||||
'date',
|
'date',
|
||||||
'submitter',
|
'submitter',
|
||||||
@ -97,12 +99,13 @@ ConfigStrings : Array [TConfigOpt] of string = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
ConfigOpts : Array[TConfigOpt] of char
|
ConfigOpts : Array[TConfigOpt] of char
|
||||||
= ('d','h','u','p','l','o','c','v','t','s','m','C','S','V');
|
= ('d','h','u','p','l','o','c','a','v','t','s','m','C','S','V');
|
||||||
|
|
||||||
Var
|
Var
|
||||||
TestOS,
|
TestOS,
|
||||||
TestCPU,
|
TestCPU,
|
||||||
TestVersion,
|
TestVersion,
|
||||||
|
TestCategory,
|
||||||
DatabaseName,
|
DatabaseName,
|
||||||
HostName,
|
HostName,
|
||||||
UserName,
|
UserName,
|
||||||
@ -125,6 +128,7 @@ begin
|
|||||||
coLogFile : LogFileName:=Value;
|
coLogFile : LogFileName:=Value;
|
||||||
coOS : TestOS:=Value;
|
coOS : TestOS:=Value;
|
||||||
coCPU : TestCPU:=Value;
|
coCPU : TestCPU:=Value;
|
||||||
|
coCategory : TestCategory:=Value;
|
||||||
coVersion : TestVersion:=Value;
|
coVersion : TestVersion:=Value;
|
||||||
coDate :
|
coDate :
|
||||||
begin
|
begin
|
||||||
@ -258,6 +262,7 @@ Var
|
|||||||
TestCPUID : Integer;
|
TestCPUID : Integer;
|
||||||
TestOSID : Integer;
|
TestOSID : Integer;
|
||||||
TestVersionID : Integer;
|
TestVersionID : Integer;
|
||||||
|
TestCategoryID : Integer;
|
||||||
TestRunID : Integer;
|
TestRunID : Integer;
|
||||||
|
|
||||||
Procedure GetIDs;
|
Procedure GetIDs;
|
||||||
@ -269,6 +274,12 @@ begin
|
|||||||
TestOSID := GetOSID(TestOS);
|
TestOSID := GetOSID(TestOS);
|
||||||
If TestOSID=-1 then
|
If TestOSID=-1 then
|
||||||
Verbose(V_Error,'NO ID for OS "'+TestOS+'" found.');
|
Verbose(V_Error,'NO ID for OS "'+TestOS+'" found.');
|
||||||
|
TestCategoryID := GetCategoryID(TestCategory);
|
||||||
|
If TestCategoryID=-1 then
|
||||||
|
begin
|
||||||
|
// Verbose(V_Error,'NO ID for Category "'+TestCategory+'" found.');
|
||||||
|
TestCategoryID:=1;
|
||||||
|
end;
|
||||||
TestVersionID := GetVersionID(TestVersion);
|
TestVersionID := GetVersionID(TestVersion);
|
||||||
If TestVersionID=-1 then
|
If TestVersionID=-1 then
|
||||||
Verbose(V_Error,'NO ID for version "'+TestVersion+'" found.');
|
Verbose(V_Error,'NO ID for version "'+TestVersion+'" found.');
|
||||||
@ -277,7 +288,7 @@ begin
|
|||||||
TestRunID:=GetRunID(TestOSID,TestCPUID,TestVersionID,TestDate);
|
TestRunID:=GetRunID(TestOSID,TestCPUID,TestVersionID,TestDate);
|
||||||
If (TestRunID=-1) then
|
If (TestRunID=-1) then
|
||||||
begin
|
begin
|
||||||
TestRunID:=AddRun(TestOSID,TestCPUID,TestVersionID,TestDate);
|
TestRunID:=AddRun(TestOSID,TestCPUID,TestVersionID,TestCategoryID,TestDate);
|
||||||
If TestRUnID=-1 then
|
If TestRUnID=-1 then
|
||||||
Verbose(V_Error,'Could not insert new testrun record!');
|
Verbose(V_Error,'Could not insert new testrun record!');
|
||||||
end
|
end
|
||||||
|
@ -20,9 +20,10 @@ Uses
|
|||||||
Function GetTestID(Name : string) : Integer;
|
Function GetTestID(Name : string) : Integer;
|
||||||
Function GetOSID(Name : String) : Integer;
|
Function GetOSID(Name : String) : Integer;
|
||||||
Function GetCPUID(Name : String) : Integer;
|
Function GetCPUID(Name : String) : Integer;
|
||||||
|
Function GetCategoryID(Name : String) : Integer;
|
||||||
Function GetVersionID(Name : String) : Integer;
|
Function GetVersionID(Name : String) : Integer;
|
||||||
Function GetRunID(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
Function GetRunID(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
||||||
Function AddRun(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
Function AddRun(OSID, CPUID, VERSIONID, CATEGORYID : Integer; Date : TDateTime) : Integer;
|
||||||
Function AddTest(Name : String; AddSource : Boolean) : Integer;
|
Function AddTest(Name : String; AddSource : Boolean) : Integer;
|
||||||
Function UpdateTest(ID : Integer; Info : TConfig; Source : String) : Boolean;
|
Function UpdateTest(ID : Integer; Info : TConfig; Source : String) : Boolean;
|
||||||
Function AddTestResult(TestID,RunID,TestRes : Integer;
|
Function AddTestResult(TestID,RunID,TestRes : Integer;
|
||||||
@ -105,7 +106,7 @@ Function RunQuery (Qry : String; Var res : TQueryResult) : Boolean ;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Verbose(V_DEBUG,'Running query:'+Qry);
|
Verbose(V_DEBUG,'Running query:'+Qry);
|
||||||
Result:=mysql_query(@Connection,PChar(qry))>=0;
|
Result:=mysql_query(@Connection,PChar(qry))=0;
|
||||||
If Not Result then
|
If Not Result then
|
||||||
Verbose(V_WARNING,'Query : '+Qry+'Failed : '+Strpas(mysql_error(@connection)))
|
Verbose(V_WARNING,'Query : '+Qry+'Failed : '+Strpas(mysql_error(@connection)))
|
||||||
else
|
else
|
||||||
@ -207,6 +208,14 @@ begin
|
|||||||
Result:=IDQuery(Format(SFromName,[Name]));
|
Result:=IDQuery(Format(SFromName,[Name]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function GetCategoryID(Name : String) : Integer;
|
||||||
|
|
||||||
|
Const
|
||||||
|
SFromName = 'SELECT TCAT_ID FROM TESTCATEGORY WHERE (TCAT_NAME="%s")';
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=IDQuery(Format(SFromName,[Name]));
|
||||||
|
end;
|
||||||
|
|
||||||
Function GetRunID(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
Function GetRunID(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
||||||
|
|
||||||
@ -222,24 +231,103 @@ begin
|
|||||||
Result:=IDQuery(Format(SFromIDS,[OSID,CPUID,VERSIONID,SQLDate(Date)]));
|
Result:=IDQuery(Format(SFromIDS,[OSID,CPUID,VERSIONID,SQLDate(Date)]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function AddRun(OSID, CPUID, VERSIONID : Integer; Date : TDateTime) : Integer;
|
Function AddRun(OSID, CPUID, VERSIONID, CATEGORYID : Integer; Date : TDateTime) : Integer;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
SInsertRun = 'INSERT INTO TESTRUN '+
|
SInsertRun = 'INSERT INTO TESTRUN '+
|
||||||
'(TU_OS_FK,TU_CPU_FK,TU_VERSION_FK,TU_DATE)'+
|
'(TU_OS_FK,TU_CPU_FK,TU_VERSION_FK,TU_CATEGORY_FK,TU_DATE)'+
|
||||||
' VALUES '+
|
' VALUES '+
|
||||||
'(%d,%d,%d,"%s")';
|
'(%d,%d,%d,%d,"%s")';
|
||||||
|
|
||||||
Var
|
Var
|
||||||
Res : TQueryResult;
|
Res : TQueryResult;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If RunQuery(Format(SInsertRun,[OSID,CPUID,VERSIONID,SQLDate(Date)]),Res) then
|
If RunQuery(Format(SInsertRun,[OSID,CPUID,VERSIONID,CATEGORYID,SQLDate(Date)]),Res) then
|
||||||
Result:=mysql_insert_id(@connection)
|
Result:=mysql_insert_id(@connection)
|
||||||
else
|
else
|
||||||
Result:=-1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function posr(c : Char; const s : AnsiString) : integer;
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
begin
|
||||||
|
i := length(s);
|
||||||
|
while (i>0) and (s[i] <> c) do dec(i);
|
||||||
|
Result := i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetUnitTestConfig(const fn : string; var r : TConfig) : Boolean;
|
||||||
|
var
|
||||||
|
Path : string;
|
||||||
|
ClassName : string;
|
||||||
|
MethodName : string;
|
||||||
|
slashpos : integer;
|
||||||
|
FileName : string;
|
||||||
|
s : string;
|
||||||
|
t : text;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
FillChar(r,sizeof(r),0);
|
||||||
|
if pos('.',fn) > 0 then exit; // This is normally not a unit-test
|
||||||
|
slashpos := posr('/',fn);
|
||||||
|
if slashpos < 1 then exit;
|
||||||
|
MethodName := copy(fn,slashpos+1,length(fn));
|
||||||
|
Path := copy(fn,1,slashpos-1);
|
||||||
|
slashpos := posr('/',Path);
|
||||||
|
if slashpos > 0 then
|
||||||
|
begin
|
||||||
|
ClassName := copy(Path,slashpos+1,length(Path));
|
||||||
|
Path := copy(Path,1,slashpos-1);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
ClassName := Path;
|
||||||
|
path := '.';
|
||||||
|
end;
|
||||||
|
if upper(ClassName[1])<>'T' then exit;
|
||||||
|
FileName := lowercase(TestSrcDir+Path+DirectorySeparator+copy(ClassName,2,length(classname)));
|
||||||
|
if FileExists(FileName+'.pas') then
|
||||||
|
FileName := FileName + '.pas'
|
||||||
|
else if FileExists(FileName+'.pp') then
|
||||||
|
FileName := FileName + '.pp'
|
||||||
|
else exit;
|
||||||
|
|
||||||
|
Verbose(V_Debug,'Reading '+FileName);
|
||||||
|
assign(t,FileName);
|
||||||
|
{$I-}
|
||||||
|
reset(t);
|
||||||
|
{$I+}
|
||||||
|
if ioresult<>0 then
|
||||||
|
begin
|
||||||
|
Verbose(V_Error,'Can''t open '+FileName);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
while not eof(t) do
|
||||||
|
begin
|
||||||
|
readln(t,s);
|
||||||
|
|
||||||
|
if s<>'' then
|
||||||
|
begin
|
||||||
|
TrimB(s);
|
||||||
|
if SameText(copy(s,1,9),'PROCEDURE') then
|
||||||
|
begin
|
||||||
|
if pos(';',s)>11 then
|
||||||
|
begin
|
||||||
|
s := copy(s,11,pos(';',s)-11);
|
||||||
|
TrimB(s);
|
||||||
|
if SameText(s,ClassName+'.'+MethodName) then
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
r.Note:= 'unittest';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
close(t);
|
||||||
|
end;
|
||||||
|
|
||||||
Function AddTest(Name : String; AddSource : Boolean) : Integer;
|
Function AddTest(Name : String; AddSource : Boolean) : Integer;
|
||||||
|
|
||||||
@ -253,8 +341,9 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=-1;
|
Result:=-1;
|
||||||
If FileExists(TestSrcDir+Name) and
|
If (FileExists(TestSrcDir+Name) and
|
||||||
GetConfig(TestSrcDir+Name,Info) then
|
GetConfig(TestSrcDir+Name,Info)) or
|
||||||
|
GetUnitTestConfig(Name,Info) then
|
||||||
begin
|
begin
|
||||||
If RunQuery(Format(SInsertTest,[Name]),Res) then
|
If RunQuery(Format(SInsertTest,[Name]),Res) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user