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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
|
unit TestBase;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, fpcunit, testutils, testregistry,
LCLProc, LazLogger, DbgIntfDebuggerBase, CompileHelpers, Dialogs, TestGDBMIControl,
GDBMIDebugger; // , FpGdbmiDebugger;
// EnvironmentOpts, ExtToolDialog, TransferMacros,
(*
fpclist.txt contains lines of format:
[Name]
exe=/path/fpc.exe
symbols=none,gs,gw,gwset,gw3
gdblist.txt contains lines of format:
[Name]
exe=/path/fpc.exe
version=070201
symbols=none,gs,gw,gwset,gw3
*)
type
TSymbolType = (stNone, stStabs, stDwarf, stDwarfSet, stDwarf3);
TSymbolTypes = set of TSymbolType;
const
SymbolTypeNames: Array [TSymbolType] of String = ('No_Dbg', 'Stabs', 'Dwarf', 'Dwarf+Sets', 'Dwarf3');
SymbolTypeSwitches: Array [TSymbolType] of String = ('', '-gs', '-gw', '-gw -godwarfsets', '-gw3');
stDwarf2All = [stDwarf, stDwarfSet];
stDwarfAll = [stDwarf, stDwarfSet, stDwarf3];
stSymAll = [stStabs, stDwarf, stDwarfSet, stDwarf3];
TWatchDisplayFormatNames: array [TWatchDisplayFormat] of string =
('wdfDefault',
'wdfStructure',
'wdfChar', 'wdfString',
'wdfDecimal', 'wdfUnsigned', 'wdfFloat', 'wdfHex',
'wdfPointer',
'wdfMemDump'
);
type
TGDBMIDebuggerClass = class of TGDBMIDebugger;
TCompilerInfo = record
Name: string;
ExeName: string;
SymbolTypes: TSymbolTypes;
ExtraOpts: string;
Version: Integer;
end;
TDebuggerInfo = record
Name: string;
ExeName: string;
SymbolTypes: TSymbolTypes;
Version: Integer;
end;
TUsesDir = record
DirName, ExeId: String; // dirname = filename
SymbolType: TSymbolType;
ExtraOpts, NamePostFix: string;
end;
{ TTestCallStackList }
TTestCallStackList = class(TCallStackList)
protected
function NewEntryForThread(const AThreadId: Integer): TCallStackBase; override;
end;
{ TTestCallStackMonitor }
TTestCallStackMonitor = class(TCallStackMonitor)
protected
function CreateCallStackList: TCallStackList; override;
end;
TTestThreadsMonitor = class;
{ TTestThreads }
TTestThreads = class(TThreads)
private
FMonitor: TTestThreadsMonitor;
FDataValidity: TDebuggerDataState;
public
constructor Create;
function Count: Integer; override;
procedure Clear; override;
procedure SetValidity(AValidity: TDebuggerDataState); override;
end;
{ TTestThreadsMonitor }
TTestThreadsMonitor = class(TThreadsMonitor)
protected
procedure DoStateEnterPause; override;
function CreateThreads: TThreads; override;
procedure RequestData;
end;
{ TTestWatchValue }
TTestWatchValue = class(TWatchValue)
protected
procedure RequestData;
function GetTypeInfo: TDBGType; override;
function GetValue: String; override;
public
constructor Create(AOwnerWatch: TWatch;
const AThreadId: Integer;
const AStackFrame: Integer
);
constructor Create(AOwnerWatch: TWatch);
end;
{ TTestWatchValueList }
TTestWatchValueList = class(TWatchValueList)
protected
function CopyEntry(AnEntry: TWatchValue): TWatchValue; override;
function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TWatchValue; override;
end;
{ TTestWatch }
TTestWatch = class(TWatch)
function CreateValueList: TWatchValueList; override;
procedure RequestData(AWatchValue: TTestWatchValue);
public
end;
TTestWatchesMonitor = class;
{ TTestWatches }
TTestWatches = class(TWatches)
protected
FMonitor: TTestWatchesMonitor;
function WatchClass: TWatchClass; override;
procedure RequestData(AWatchValue: TWatchValue);
end;
{ TTestWatchesMonitor }
TTestWatchesMonitor = class(TWatchesMonitor)
protected
procedure DoStateChangeEx(const AOldState, ANewState: TDBGState); override;
procedure RequestData(AWatchValue: TWatchValue);
function CreateWatches: TWatches; override;
end;
TTestRegistersMonitor = class;
{ TTestRegisters }
TTestRegisters = class(TRegisters)
private
FMonitor: TTestRegistersMonitor;
protected
procedure DoDataValidityChanged(AnOldValidity: TDebuggerDataState); override;
public
function Count: Integer; reintroduce; override;
end;
{ TTEstRegistersList }
TTestRegistersList = class(TRegistersList)
private
FMonitor: TTestRegistersMonitor;
protected
function CreateEntry(AThreadId, AStackFrame: Integer): TRegisters; override;
end;
{ TTestRegistersMonitor }
TTestRegistersMonitor = class(TRegistersMonitor)
protected
function CreateRegistersList: TRegistersList; override;
procedure RequestData(ARegisters: TRegisters);
procedure DoStateEnterPause; override;
procedure DoStateLeavePause; override;
end;
{ TBaseList }
TBaseList = class
protected
function AddName(const AName: string): Integer; virtual; abstract;
procedure SetAttribute(AIndex: Integer; const AAttr, AValue: string); virtual; abstract;
public
procedure LoadFromFile(const AFileName: string);
end;
{ TCompilerList }
TCompilerList = class(TBaseList)
private
FList: array of TCompilerInfo;
function GetCompilerInfo(Index: Integer): TCompilerInfo;
function GetExeName(Index: Integer): string;
function GetName(Index: Integer): string;
function GetSymbolTypes(Index: Integer): TSymbolTypes;
protected
function AddName(const AName: string): Integer; override;
procedure SetAttribute(AIndex: Integer; const AAttr, AValue: string); override;
public
procedure Add(Name, Exe: string; Opts: String = '');
function Count: Integer;
property CompilerInfo[Index: Integer]: TCompilerInfo read GetCompilerInfo;
property Name[Index: Integer]: string read GetName;
property ExeName[Index: Integer]: string read GetExeName;
property SymbolTypes[Index: Integer]: TSymbolTypes read GetSymbolTypes;
end;
{ TDebuggerList }
TDebuggerList = class(TBaseList)
private
FList: array of TDebuggerInfo;
function GetDebuggerInfo(Index: Integer): TDebuggerInfo;
function GetExeName(Index: Integer): string;
function GetName(Index: Integer): string;
function GetSymbolTypes(Index: Integer): TSymbolTypes;
protected
function AddName(const AName: string): Integer; override;
procedure SetAttribute(AIndex: Integer; const AAttr, AValue: string); override;
public
procedure Add(Name, Exe: string);
function Count: Integer;
property DebuggerInfo[Index: Integer]: TDebuggerInfo read GetDebuggerInfo;
property Name[Index: Integer]: string read GetName;
property ExeName[Index: Integer]: string read GetExeName;
property SymbolTypes[Index: Integer]: TSymbolTypes read GetSymbolTypes;
end;
{ TCompilerSuite }
TCompilerSuite = class(TTestSuite)
private
FCompileCommandLine: String;
FCompilerInfo: TCompilerInfo;
FSymbolSwitch: String;
FSymbolType: TSymbolType;
FFileNameExt: String;
FCompiledList, FCompiledListCmdLines, FCompiledUsesList, FCompiledUsesListID: TStringList;
FInRun: Boolean;
protected
procedure Clear;
public
constructor Create(ACompilerInfo: TCompilerInfo; ASymbolType: TSymbolType; ADebuggerList: TDebuggerList);
destructor Destroy; override;
procedure Run(AResult: TTestResult); override;
procedure RunTest(ATest: TTest; AResult: TTestResult); override;
procedure RegisterDbgTest(ATestClass: TTestCaseClass);
procedure TestCompileUses(UsesDir: TUsesDir; out UsesLibDir: String; out ExeID:string);
Procedure TestCompile(const PrgName: string;
out ExeName: string;
NamePostFix: String=''; ExtraArgs: String=''
); overload;
Procedure TestCompile(const PrgName: string;
out ExeName: string;
UsesDirs: array of TUsesDir;
NamePostFix: String=''; ExtraArgs: String=''
); overload;
property CompileCommandLine: String read FCompileCommandLine;
public
property SymbolType: TSymbolType read FSymbolType;
property SymbolSwitch: String read FSymbolSwitch;
property CompilerInfo: TCompilerInfo read FCompilerInfo;
end;
{ TDebuggerSuite }
TDebuggerSuite = class(TTestSuite)
private
FDebuggerInfo: TDebuggerInfo;
FParent: TCompilerSuite;
function GetCompileCommandLine: String;
function GetCompilerInfo: TCompilerInfo;
function GetSymbolType: TSymbolType;
public
constructor Create(AParent: TCompilerSuite; ADebuggerInfo: TDebuggerInfo);
procedure RegisterDbgTest(ATestClass: TTestCaseClass);
Procedure TestCompile(const PrgName: string; out ExeName: string; UsesDirs: array of TUsesDir; NamePostFix: String=''; ExtraArgs: String='');
property CompileCommandLine: String read GetCompileCommandLine;
public
property Parent: TCompilerSuite read FParent;
property DebuggerInfo: TDebuggerInfo read FDebuggerInfo;
property SymbolType: TSymbolType read GetSymbolType;
property CompilerInfo: TCompilerInfo read GetCompilerInfo;
end;
{ TGDBTestsuite }
TGDBTestsuite = class(TTestSuite)
private
FParent: TDebuggerSuite;
function GetCompileCommandLine: String;
function GetCompilerInfo: TCompilerInfo;
function GetDebuggerInfo: TDebuggerInfo;
function GetSymbolType: TSymbolType;
public
constructor Create(AParent: TDebuggerSuite; AClass: TClass);
procedure AddTest(ATest: TTest); overload; override;
Procedure TestCompile(const PrgName: string; out ExeName: string; UsesDirs: array of TUsesDir; NamePostFix: String=''; ExtraArgs: String='');
property CompileCommandLine: String read GetCompileCommandLine;
public
property Parent: TDebuggerSuite read FParent;
property DebuggerInfo: TDebuggerInfo read GetDebuggerInfo;
property SymbolType: TSymbolType read GetSymbolType;
property CompilerInfo: TCompilerInfo read GetCompilerInfo;
end;
{ TGDBTestCase }
TGDBTestResult = class(TTestResult)
end;
TGDBTestCase = class(TTestCase)
private
// stuff for the debugger
FCallStack: TTestCallStackMonitor;
FDisassembler: TBaseDisassembler;
FExceptions: TBaseExceptions;
//FSignals: TBaseSignals;
//FBreakPoints: TIDEBreakPoints;
//FBreakPointGroups: TIDEBreakPointGroups;
FLocals: TLocalsMonitor;
FLineInfo: TBaseLineInfo;
FWatches: TTestWatchesMonitor;
FThreads: TTestThreadsMonitor;
FRegisters: TTestRegistersMonitor;
private
FParent: TGDBTestsuite;
FTestBaseName: String;
FTestResult: TGDBTestResult;
FTestErrors, FIgnoredErrors, FUnexpectedSuccess: String;
FTestCnt, FTestErrorCnt, FIgnoredErrorCnt, FUnexpectedSuccessCnt, FSucessCnt: Integer;
FTotalErrorCnt, FTotalIgnoredErrorCnt, FTotalUnexpectedSuccessCnt: Integer;
FCurrentPrgName, FCurrentExename: String;
FLogFile: TextFile;
FLogFileCreated: Boolean;
FLogFileName, FFinalLogFileName, FLogBufferText: String;
FLogDebuglnCount: Integer;
function GetCompilerInfo: TCompilerInfo;
function GetDebuggerInfo: TDebuggerInfo;
function GetSymbolType: TSymbolType;
procedure DoDbgOut(Sender: TObject; S: string; var Handled: Boolean);
procedure DoDebugln(Sender: TObject; S: string; var Handled: Boolean);
protected
function CreateResult: TTestResult; override;
function GetLogActive: Boolean;
procedure CreateLog;
procedure SetUp; override;
procedure TearDown; override;
procedure DoDbgOutPut(Sender: TObject; const AText: String); virtual;
procedure InternalDbgOutPut(Sender: TObject; const AText: String);
function InternalFeedBack(Sender: TObject; const AText, AInfo: String;
AType: TDBGFeedbackType; AButtons: TDBGFeedbackResults): TDBGFeedbackResult;
function GdbClass: TGDBMIDebuggerClass; virtual;
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
Procedure TestCompile(const PrgName: string; out ExeName: string; NamePostFix: String=''; ExtraArgs: String=''); overload;
Procedure TestCompile(const PrgName: string; out ExeName: string; UsesDirs: array of TUsesDir;
NamePostFix: String=''; ExtraArgs: String=''); overload;
function SkipTest: Boolean;
procedure LogToFile(const s: string);
public
property Parent: TGDBTestsuite read FParent write FParent;
property DebuggerInfo: TDebuggerInfo read GetDebuggerInfo;
property SymbolType: TSymbolType read GetSymbolType;
property CompilerInfo: TCompilerInfo read GetCompilerInfo;
property TestBaseName: String read FTestBaseName write FTestBaseName;
public
//property BreakPoints: TIDEBreakPoints read FBreakpoints; // A list of breakpoints for the current project
//property BreakPointGroups: TIDEBreakPointGroups read FBreakPointGroups;
property Exceptions: TBaseExceptions read FExceptions; // A list of exceptions we should ignore
property CallStack: TTestCallStackMonitor read FCallStack;
property Disassembler: TBaseDisassembler read FDisassembler;
property Locals: TLocalsMonitor read FLocals;
property LineInfo: TBaseLineInfo read FLineInfo;
property Registers: TTestRegistersMonitor read FRegisters;
//property Signals: TBaseSignals read FSignals; // A list of actions for signals we know of
property Watches: TTestWatchesMonitor read FWatches;
property Threads: TTestThreadsMonitor read FThreads;
end;
function GetCompilers: TCompilerList;
function GetDebuggers: TDebuggerList;
procedure RegisterDbgTest(ATestClass: TTestCaseClass);
var
AppDir: String;
ConfDir: String;
Logdir: String;
WriteLog, WriteLogOnErr: Boolean;
TestGdbClass: TGDBMIDebuggerClass = TGDBMIDebugger;
// TestGdbClass: TGDBMIDebuggerClass = TFPGDBMIDebugger;
implementation
var
Compilers: TCompilerList = nil;
Debuggers: TDebuggerList = nil;
function StrToSymbolTypes(s: string): TSymbolTypes;
var
s2: string;
begin
Result := [];
while (s <> '') do begin
while (s <> '') and (s[1] in [' ', ',', #9, #10, #13]) do delete(s,1, 1);
s2 := '';
while (s <> '') and not (s[1] in [' ', ',', #9, #10, #13]) do begin
s2 := s2 + s[1];
delete(s,1, 1);
end;
if s2 = 'none' then Result := Result + [stNone];
if s2 = 'gs' then Result := Result + [stStabs];
if s2 = 'gw' then Result := Result + [stDwarf];
if s2 = 'gwset' then Result := Result + [stDwarfSet];
if s2 = 'gw3' then Result := Result + [stDwarf3];
end;
end;
function NameToFileName(AName: String): String;
var
i: Integer;
begin
Result := '';
for i := 1 to length(AName) do begin
if AName[i] in ['a'..'z', 'A'..'Z', '0'..'9', '.', '-'] then
Result := Result + AName[i]
else if AName[i] = ' ' then
Result := Result + '__'
else
Result := Result + '_' + IntToHex(ord(AName[i]), 2);
end;
end;
function GetCompilers: TCompilerList;
begin
if Compilers <> nil then exit(Compilers);
Result := TCompilerList.Create;
if FileExists(ConfDir + 'fpclist.txt') then
Result.LoadFromFile(ConfDir + 'fpclist.txt');
//if (Result.Count = 0) and (EnvironmentOptions.GetParsedCompilerFilename <> '') then begin
// Result.Add('fpc from conf', EnvironmentOptions.GetParsedCompilerFilename);
// Result.Add('fpc from conf -Xe', EnvironmentOptions.GetParsedCompilerFilename, '-Xe');
//end;
Compilers := Result;
end;
function GetDebuggers: TDebuggerList;
begin
if Debuggers <> nil then exit(Debuggers);
Result := TDebuggerList.Create;
if FileExists(ConfDir + 'gdblist.txt') then
Result.LoadFromFile(ConfDir + 'gdblist.txt');
//if (Result.Count = 0) and (EnvironmentOptions.GetParsedDebuggerFilename <> '') then
// Result.Add('gdb from conf', EnvironmentOptions.GetParsedDebuggerFilename);
Debuggers := Result;
end;
{ TTestThreads }
constructor TTestThreads.Create;
begin
inherited Create;
FDataValidity := ddsUnknown;
end;
function TTestThreads.Count: Integer;
begin
if (FDataValidity = ddsUnknown) then begin
FDataValidity := ddsRequested;
FMonitor.RequestData;
end;
Result := inherited Count;
end;
procedure TTestThreads.Clear;
begin
FDataValidity := ddsUnknown;
inherited Clear;
end;
procedure TTestThreads.SetValidity(AValidity: TDebuggerDataState);
begin
if FDataValidity = AValidity then exit;
FDataValidity := AValidity;
if FDataValidity = ddsUnknown then Clear;
end;
{ TTestThreadsMonitor }
procedure TTestThreadsMonitor.DoStateEnterPause;
begin
inherited DoStateEnterPause;
TTestThreads(Threads).SetValidity(ddsUnknown);
end;
function TTestThreadsMonitor.CreateThreads: TThreads;
begin
Result := TTestThreads.Create;
TTestThreads(Result).FMonitor := Self;
end;
procedure TTestThreadsMonitor.RequestData;
begin
if Supplier <> nil
then Supplier.RequestMasterData;
end;
{ TTestRegistersMonitor }
function TTestRegistersMonitor.CreateRegistersList: TRegistersList;
begin
Result := TTestRegistersList.Create;
TTestRegistersList(Result).FMonitor := Self;
end;
procedure TTestRegistersMonitor.RequestData(ARegisters: TRegisters);
begin
if Supplier <> nil
then Supplier.RequestData(ARegisters)
else ARegisters.DataValidity := ddsInvalid;
end;
procedure TTestRegistersMonitor.DoStateEnterPause;
begin
inherited DoStateEnterPause;
RegistersList.Clear;
end;
procedure TTestRegistersMonitor.DoStateLeavePause;
begin
inherited DoStateLeavePause;
RegistersList.Clear;
end;
{ TTEstRegistersList }
function TTestRegistersList.CreateEntry(AThreadId, AStackFrame: Integer): TRegisters;
begin
Result := TTestRegisters.Create(AThreadId, AStackFrame);
TTestRegisters(Result).FMonitor := FMonitor;
end;
{ TTestRegisters }
procedure TTestRegisters.DoDataValidityChanged(AnOldValidity: TDebuggerDataState);
begin
inherited DoDataValidityChanged(AnOldValidity);
end;
function TTestRegisters.Count: Integer;
begin
case DataValidity of
ddsUnknown: begin
AddReference;
try
Result := 0;
DataValidity := ddsRequested;
FMonitor.RequestData(Self); // Locals can be cleared, if debugger is "run" again
if DataValidity = ddsValid then Result := inherited Count();
finally
ReleaseReference;
end;
end;
ddsRequested, ddsEvaluating: Result := 0;
ddsValid: Result := inherited Count;
ddsInvalid, ddsError: Result := 0;
end;
end;
{ TTestWatches }
function TTestWatches.WatchClass: TWatchClass;
begin
Result := TTestWatch;
end;
procedure TTestWatches.RequestData(AWatchValue: TWatchValue);
begin
TTestWatchesMonitor(FMonitor).RequestData(AWatchValue);
end;
{ TTestWatchesMonitor }
procedure TTestWatchesMonitor.DoStateChangeEx(const AOldState, ANewState: TDBGState);
begin
inherited DoStateChangeEx(AOldState, ANewState);
Watches.ClearValues;
end;
procedure TTestWatchesMonitor.RequestData(AWatchValue: TWatchValue);
begin
if Supplier <> nil
then Supplier.RequestData(AWatchValue)
else AWatchValue.Validity := ddsInvalid;
end;
function TTestWatchesMonitor.CreateWatches: TWatches;
begin
Result := TTestWatches.Create;
TTestWatches(Result).FMonitor := Self;
end;
{ TTestWatchValue }
procedure TTestWatchValue.RequestData;
begin
TTestWatch(Watch).RequestData(self);
end;
function TTestWatchValue.GetTypeInfo: TDBGType;
var
i: Integer;
begin
Result := nil;
if not Watch.Enabled then
exit;
i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue
if Validity = ddsUnknown then begin
Validity := ddsRequested;
RequestData;
if i <> DbgStateChangeCounter then exit;
end;
case Validity of
ddsRequested,
ddsEvaluating: Result := nil;
ddsValid: Result := inherited GetTypeInfo;
ddsInvalid,
ddsError: Result := nil;
end;
end;
function TTestWatchValue.GetValue: String;
var
i: Integer;
begin
if not Watch.Enabled then begin
Result := '<disabled>';
exit;
end;
i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue
if Validity = ddsUnknown then begin
Result := '<evaluating>';
Validity := ddsRequested;
RequestData;
if i <> DbgStateChangeCounter then exit; // in case the debugger did run.
// TODO: The watch can also be deleted by the user
end;
case Validity of
ddsRequested, ddsEvaluating: Result := '<evaluating>';
ddsValid: Result := inherited GetValue;
ddsInvalid: Result := '<invalid>';
ddsError: Result := '<Error: '+ (inherited GetValue) +'>';
end;
end;
constructor TTestWatchValue.Create(AOwnerWatch: TWatch; const AThreadId: Integer;
const AStackFrame: Integer);
begin
inherited Create(AOwnerWatch);
Validity := ddsUnknown;
FDisplayFormat := Watch.DisplayFormat;
FEvaluateFlags := Watch.EvaluateFlags;
FRepeatCount := Watch.RepeatCount;
FThreadId := AThreadId;
FStackFrame := AStackFrame;
end;
constructor TTestWatchValue.Create(AOwnerWatch: TWatch);
begin
inherited Create(AOwnerWatch);
Validity := ddsUnknown;
FDisplayFormat := Watch.DisplayFormat;
FEvaluateFlags := Watch.EvaluateFlags;
FRepeatCount := Watch.RepeatCount;
end;
{ TTestWatchValueList }
function TTestWatchValueList.CopyEntry(AnEntry: TWatchValue): TWatchValue;
begin
Result := TTestWatchValue.Create(Watch);
Result.Assign(AnEntry);
end;
function TTestWatchValueList.CreateEntry(const AThreadId: Integer;
const AStackFrame: Integer): TWatchValue;
begin
Result := TTestWatchValue.Create(Watch, AThreadId, AStackFrame);
Add(Result);
end;
{ TTestWatch }
function TTestWatch.CreateValueList: TWatchValueList;
begin
Result := TTestWatchValueList.Create(Self);
end;
procedure TTestWatch.RequestData(AWatchValue: TTestWatchValue);
begin
if Collection <> nil
then TTestWatches(Collection).RequestData(AWatchValue)
else AWatchValue.Validity := ddsInvalid;
end;
{ TTestCallStackMonitor }
function TTestCallStackMonitor.CreateCallStackList: TCallStackList;
begin
Result := TTestCallStackList.Create;
end;
{ TTestCallStackList }
function TTestCallStackList.NewEntryForThread(const AThreadId: Integer): TCallStackBase;
begin
Result := TCallStackBase.Create;
Result.ThreadId := AThreadId;
add(Result);
end;
{ TGDBTestCase }
procedure TGDBTestCase.DoDbgOutPut(Sender: TObject; const AText: String);
begin
//
end;
procedure TGDBTestCase.InternalDbgOutPut(Sender: TObject; const AText: String);
begin
//LogToFile(AText);
DoDbgOutPut(Sender, AText);
end;
function TGDBTestCase.GdbClass: TGDBMIDebuggerClass;
begin
Result := TestGdbClass;
end;
procedure TGDBTestCase.DoDbgOut(Sender: TObject; S: string; var Handled: Boolean);
begin
DoDebugln(Sender, '| '+S, Handled);
end;
procedure TGDBTestCase.DoDebugln(Sender: TObject; S: string; var Handled: Boolean);
begin
if GetLogActive then begin
CreateLog;
writeln(FLogFile, s);
end
else begin
if length(FLogBufferText) + length(s) < 50000000 then
FLogBufferText := FLogBufferText + s + LineEnding;
end;
Handled := True;
if pos('(gdb)', s) > 0 then begin
inc(FLogDebuglnCount);
if FLogDebuglnCount mod 10 = 0 then begin
DebugLogger.OnDebugLn := nil;
DebugLn([FLogDebuglnCount]);
DebugLogger.OnDebugLn := @DoDebugln;
end;
end;
end;
function TGDBTestCase.InternalFeedBack(Sender: TObject; const AText, AInfo: String;
AType: TDBGFeedbackType; AButtons: TDBGFeedbackResults): TDBGFeedbackResult;
begin
Result := frOk;
end;
function TGDBTestCase.GetCompilerInfo: TCompilerInfo;
begin
Result := Parent.CompilerInfo;
end;
function TGDBTestCase.GetDebuggerInfo: TDebuggerInfo;
begin
Result := Parent.DebuggerInfo;
end;
function TGDBTestCase.GetSymbolType: TSymbolType;
begin
Result := Parent.SymbolType;
end;
function TGDBTestCase.CreateResult: TTestResult;
begin
FTestResult := TGDBTestResult.Create;
Result := FTestResult;
end;
function TGDBTestCase.GetLogActive: Boolean;
begin
Result := WriteLog or FLogFileCreated;
end;
procedure TGDBTestCase.CreateLog;
var
name: String;
i: Integer;
dir: String;
begin
if FLogFileCreated then exit;
//if GetLogActive then begin
name := TestName
+ '_' + NameToFileName(GetCompilerInfo.Name)
+ '_' + SymbolTypeNames[GetSymbolType]
+ '_' + NameToFileName(GetDebuggerInfo.Name)
;
dir := ConfDir;
if DirectoryExistsUTF8(Logdir) then
dir := Logdir;
for i := 1 to length(name) do
if name[i] in ['/', '\', '*', '?', ':'] then
name[i] := '_';
FFinalLogFileName := dir + name;
FLogFileName := dir + name + '.log.running';
AssignFile(FLogFile, FLogFileName);
Rewrite(FLogFile);
FLogFileCreated := True;
writeln(FLogFile, FLogBufferText);
FLogBufferText := '';
//end;
end;
procedure TGDBTestCase.SetUp;
begin
FLogDebuglnCount := 0;
FLogFileCreated := False;
FLogBufferText := '';
ClearTestErrors;
FTotalErrorCnt := 0;
FTotalIgnoredErrorCnt := 0;
FTotalUnexpectedSuccessCnt := 0;
DebugLogger.OnDbgOut := @DoDbgOut;
DebugLogger.OnDebugLn := @DoDebugln;
inherited SetUp;
end;
procedure TGDBTestCase.TearDown;
begin
inherited TearDown;
DebugLogger.OnDbgOut := nil;
DebugLogger.OnDebugLn := nil;
if FLogFileCreated then begin
CloseFile(FLogFile);
FTotalErrorCnt := FTotalErrorCnt + FTestErrorCnt;
FTotalIgnoredErrorCnt := FTotalIgnoredErrorCnt + FIgnoredErrorCnt;
FTotalUnexpectedSuccessCnt := FTotalUnexpectedSuccessCnt + FUnexpectedSuccessCnt;
if (FTotalIgnoredErrorCnt > 0)
then FFinalLogFileName := FFinalLogFileName + '.ignored_'+IntToStr(FTotalIgnoredErrorCnt);
if (FTotalUnexpectedSuccessCnt > 0)
then FFinalLogFileName := FFinalLogFileName + '.unexpected_'+IntToStr(FTotalUnexpectedSuccessCnt);
if (FTotalErrorCnt > 0)
then FFinalLogFileName := FFinalLogFileName + '.failed_'+IntToStr(FTotalErrorCnt);
FFinalLogFileName := FFinalLogFileName + '.log';
RenameFileUTF8(FLogFileName, FFinalLogFileName);
end;
DebugLogger.OnDbgOut := nil;
DebugLogger.OnDebugLn := nil;
FLogBufferText := '';
end;
function TGDBTestCase.StartGDB(AppDir, TestExeName: String): TGDBMIDebugger;
begin
//FBreakPoints := TManagedBreakPoints.Create(Self);
//FBreakPointGroups := TIDEBreakPointGroups.Create;
FWatches := TTestWatchesMonitor.Create;
FThreads := TTestThreadsMonitor.Create;
FExceptions := TBaseExceptions.Create(TBaseException);
//FSignals := TBaseSignals.Create(TBaseSignal);
FLocals := TLocalsMonitor.Create;
FLineInfo := TBaseLineInfo.Create;
FCallStack := TTestCallStackMonitor.Create;
FDisassembler := TBaseDisassembler.Create;
FRegisters := TTestRegistersMonitor.Create;
Result := GdbClass.Create(DebuggerInfo.ExeName);
Result.OnDbgOutput := @InternalDbgOutPut;
Result.OnFeedback := @InternalFeedBack;
//TManagedBreakpoints(FBreakpoints).Master := FDebugger.BreakPoints;
FWatches.Supplier := Result.Watches;
FThreads.Supplier := Result.Threads;
FLocals.Supplier := Result.Locals;
//FLineInfo.Master := Result.LineInfo;
FCallStack.Supplier := Result.CallStack;
//FDisassembler.Master := Result.Disassembler;
Result.Exceptions := FExceptions;
//FSignals.Master := Result.Signals;
FRegisters.Supplier := Result.Registers;
Result.Init;
if Result.State = dsError then
Fail(' Failed Init');
Result.WorkingDir := AppDir;
Result.FileName := TestExeName;
Result.Arguments := '';
Result.ShowConsole := True;
end;
procedure TGDBTestCase.CleanGdb;
begin
//TManagedBreakpoints(FBreakpoints).Master := nil;
FWatches.Supplier := nil;
FThreads.Supplier := nil;
FLocals.Supplier := nil;
//FLineInfo.Master := nil;
FCallStack.Supplier := nil;
//FDisassembler.Master := nil;
//FExceptions.Master := nil;
//FSignals.Master := nil;
// FRegisters.Master := nil;
FreeAndNil(FWatches);
FreeAndNil(FThreads);
//FreeAndNil(FBreakPoints);
//FreeAndNil(FBreakPointGroups);
FreeAndNil(FCallStack);
FreeAndNil(FDisassembler);
FreeAndNil(FExceptions);
//FreeAndNil(FSignals);
FreeAndNil(FLocals);
FreeAndNil(FLineInfo);
FreeAndNil(FRegisters);
end;
procedure TGDBTestCase.ClearTestErrors;
begin
FTotalErrorCnt := FTotalErrorCnt + FTestErrorCnt;
FTotalIgnoredErrorCnt := FTotalIgnoredErrorCnt + FIgnoredErrorCnt;
FTotalUnexpectedSuccessCnt := FTotalUnexpectedSuccessCnt + FUnexpectedSuccessCnt;
FTestErrors := '';
FIgnoredErrors := '';
FUnexpectedSuccess := '';
FTestErrorCnt := 0;
FIgnoredErrorCnt := 0;
FUnexpectedSuccessCnt := 0;
FSucessCnt := 0;
FTestCnt := 0;
FTestBaseName := '';
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;
begin
inc(FTestCnt);
IgnoreReason := '';
s := FTestBaseName + s;
if MinGdbVers > 0 then begin
i := GetDebuggerInfo.Version;
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);
end else begin
FTestErrors := FTestErrors + IntToStr(FTestCnt) + ': ' + s + LineEnding;
inc(FTestErrorCnt);
end;
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) then begin
i := GetDebuggerInfo.Version;
if (i > 0) and (i < MinGdbVers) then
AIgnoreReason := AIgnoreReason
+ 'GDB ('+IntToStr(i)+') to old, required:'+IntToStr(MinGdbVers);
end;
if (MinFpcVers > 0) then begin
i := GetCompilerInfo.Version;
if (i > 0) and (i < MinFpcVers) then
AIgnoreReason := AIgnoreReason
+ 'FPC ('+IntToStr(i)+') to old, required:'+IntToStr(MinFpcVers);
end;
if AIgnoreReason <> '' then begin
FUnexpectedSuccess:= FUnexpectedSuccess + IntToStr(FTestCnt) + ': ' + '### '+AIgnoreReason +' >>> '+s+LineEnding;
inc(FUnexpectedSuccessCnt);
end
else
inc(FSucessCnt);
end;
function TGDBTestCase.TestEquals(Expected, Got: string): Boolean;
begin
Result := TestEquals('', Expected, Got);
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: string; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
begin
Result := 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, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "'+Expected+'", Got "'+Got+'"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
function TGDBTestCase.TestEquals(Expected, Got: integer): Boolean;
begin
Result := TestEquals('', Expected, Got);
end;
function TGDBTestCase.TestEquals(Name: string; Expected, Got: integer; MinGdbVers: Integer = 0; AIgnoreReason: String = ''): Boolean;
begin
Result := 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, 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
Result := 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, 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
Result := 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, MinFpcVers, AIgnoreReason)
else AddTestError(Name + ': Expected "False", Got "True"', MinGdbVers, MinFpcVers, AIgnoreReason);
end;
procedure TGDBTestCase.AssertTestErrors;
var
s, s1: String;
begin
s := FTestErrors;
s1 := Format('Failed: %d of %d - Ignored: %d Unexpected: %d - Success: %d',
[FTestErrorCnt, FTestCnt, FIgnoredErrorCnt, FUnexpectedSuccessCnt, FSucessCnt ]);
FTestErrors := '';
if GetLogActive or (WriteLogOnErr and (FTestErrorCnt > 0)) then begin
CreateLog;
writeln(FLogFile, '***' + s1 + '***' +LineEnding);
writeln(FLogFile, '================= Failed:'+LineEnding);
writeln(FLogFile, s);
writeln(FLogFile, '================= Ignored'+LineEnding);
writeln(FLogFile, FIgnoredErrors);
writeln(FLogFile, '================= Unexpected Success'+LineEnding);
writeln(FLogFile, FUnexpectedSuccess);
writeln(FLogFile, '================='+LineEnding);
end;
if s <> '' then begin
Fail(s1+ LineEnding + s);
end;
end;
procedure TGDBTestCase.TestCompile(const PrgName: string; out ExeName: string;
NamePostFix: String=''; ExtraArgs: String='');
begin
TestCompile(PrgName, ExeName, [], NamePostFix, ExtraArgs);
end;
procedure TGDBTestCase.TestCompile(const PrgName: string; out ExeName: string;
UsesDirs: array of TUsesDir; NamePostFix: String; ExtraArgs: String);
begin
LogToFile(LineEnding+LineEnding + '******************* compile '+PrgName + ' ' + ExtraArgs +LineEnding );
Parent.TestCompile(PrgName, ExeName, UsesDirs, NamePostFix, ExtraArgs);
LogToFile(Parent.CompileCommandLine+LineEnding + '*******************' +LineEnding+LineEnding );
FCurrentPrgName := PrgName;
FCurrentExename := ExeName;
end;
function TGDBTestCase.SkipTest: Boolean;
begin
Result := not TestControlForm.chkGDB.Checked[TestControlForm.chkGDB.Items.IndexOf(DebuggerInfo.Name)];
Result := Result or
not TestControlForm.chkFPC.Checked[TestControlForm.chkFPC.Items.IndexOf(CompilerInfo.Name)];
end;
procedure TGDBTestCase.LogToFile(const s: string);
begin
DebugLn('## '+s);
end;
{ TBaseList }
procedure TBaseList.LoadFromFile(const AFileName: string);
var
txt: TStringList;
s: string;
i, j, k: Integer;
begin
txt := TStringList.Create;
txt.LoadFromFile(AFileName);
j := -1;
for i := 0 to txt.Count - 1 do begin
s := txt[i];
if Trim(s) = '' then continue;
if copy(s, 1, 1) = '[' then begin
j := AddName(GetPart(['['], [']'], s));
continue;
end;
if j < 0 then continue;
k := pos('=', s);
SetAttribute(j, copy(s, 1, k-1), copy(s, k + 1, length(s)));
end;
txt.Free;
end;
{ TCompilerList }
function TCompilerList.GetExeName(Index: Integer): string;
begin
Result := FList[Index].ExeName;
end;
function TCompilerList.GetCompilerInfo(Index: Integer): TCompilerInfo;
begin
Result := FList[Index];
end;
function TCompilerList.GetName(Index: Integer): string;
begin
Result := FList[Index].Name;
end;
function TCompilerList.GetSymbolTypes(Index: Integer): TSymbolTypes;
begin
Result := FList[Index].SymbolTypes;
end;
function TCompilerList.AddName(const AName: string): Integer;
begin
Result := length(FList);
SetLength(FList, Result + 1);
FList[Result].Name := AName;
FList[Result].SymbolTypes := [];
FList[Result].ExtraOpts := '';
end;
procedure TCompilerList.SetAttribute(AIndex: Integer; const AAttr, AValue: string);
begin
case StringCase(AAttr, ['exe', 'symbols', 'opts', 'vers', 'version'], True, False) of
0: begin // exe
FList[AIndex].ExeName := AValue;
end;
1: begin // symbols
FList[AIndex].SymbolTypes := StrToSymbolTypes(AValue);
end;
2: begin //opts
FList[AIndex].ExtraOpts := AValue;
end;
3,4: begin
FList[AIndex].Version := StrToIntDef(AValue,-1);
end;
end;
end;
procedure TCompilerList.Add(Name, Exe: string; Opts: String = '');
var
i: LongInt;
begin
i := AddName(Name);
FList[i].ExeName := Exe;
FList[i].SymbolTypes := [stStabs, stDwarf, stDwarfSet];
FList[i].ExtraOpts := Opts;
end;
function TCompilerList.Count: Integer;
begin
Result := length(FList);
end;
{ TDebuggerList }
function TDebuggerList.GetExeName(Index: Integer): string;
begin
Result := FList[Index].ExeName;
end;
function TDebuggerList.GetDebuggerInfo(Index: Integer): TDebuggerInfo;
begin
Result := FList[Index];
end;
function TDebuggerList.GetName(Index: Integer): string;
begin
Result := FList[Index].Name;
end;
function TDebuggerList.GetSymbolTypes(Index: Integer): TSymbolTypes;
begin
Result := FList[Index].SymbolTypes;
end;
function TDebuggerList.AddName(const AName: string): Integer;
begin
Result := length(FList);
SetLength(FList, Result + 1);
FList[Result].Name := AName;
FList[Result].SymbolTypes := [];
end;
procedure TDebuggerList.SetAttribute(AIndex: Integer; const AAttr, AValue: string);
begin
case StringCase(AAttr, ['exe', 'symbols', 'vers', 'version'], True, False) of
0: begin // exe
FList[AIndex].ExeName := AValue;
end;
1: begin // symbols
FList[AIndex].SymbolTypes := StrToSymbolTypes(AValue);
end;
2,3: begin
FList[AIndex].Version := StrToIntDef(AValue,-1);
end;
end;
end;
procedure TDebuggerList.Add(Name, Exe: string);
var
i: LongInt;
begin
i := AddName(Name);
FList[i].ExeName := Exe;
FList[i].SymbolTypes := [stStabs, stDwarf, stDwarfSet];
end;
function TDebuggerList.Count: Integer;
begin
Result := length(FList);
end;
{ TCompilerSuite }
procedure TCompilerSuite.Clear;
var
i: Integer;
begin
for i := 0 to FCompiledList.Count - 1 do
DeleteFile(FCompiledList[i]);
for i := 0 to FCompiledUsesList.Count - 1 do
DeleteDirectory(FCompiledUsesList[i], False);
FCompiledList.Clear;
FCompiledListCmdLines.Clear;
FCompiledUsesList.Clear;
FCompiledUsesListID.Clear;
end;
constructor TCompilerSuite.Create(ACompilerInfo: TCompilerInfo; ASymbolType: TSymbolType;
ADebuggerList: TDebuggerList);
var
i: Integer;
SubSuite: TDebuggerSuite;
begin
inherited Create(ACompilerInfo.Name + ' / ' + SymbolTypeNames[ASymbolType]);
FCompilerInfo := ACompilerInfo;
FSymbolType := ASymbolType;
FCompiledList := TStringList.Create;
FCompiledListCmdLines := TStringList.Create;
FCompiledUsesList := TStringList.Create;
FCompiledUsesListID := TStringList.Create;
FSymbolSwitch := SymbolTypeSwitches[FSymbolType];
FInRun := False;
FFileNameExt := SymbolTypeNames[FSymbolType] + '_' + NameToFileName(CompilerInfo.Name);
for i := 0 to ADebuggerList.Count - 1 do begin
if not (FSymbolType in ADebuggerList.SymbolTypes[i]) then
continue;
SubSuite := TDebuggerSuite.Create(Self, ADebuggerList.DebuggerInfo[i]);
Self.AddTest(SubSuite);
end;
end;
destructor TCompilerSuite.Destroy;
begin
inherited Destroy;
Clear;
FreeAndNil(FCompiledList);
FreeAndNil(FCompiledListCmdLines);
FreeAndNil(FCompiledUsesList);
FreeAndNil(FCompiledUsesListID);
end;
procedure TCompilerSuite.Run(AResult: TTestResult);
begin
FInRun := True;
try
inherited Run(AResult);
finally
FInRun := False;
Clear;
end;
end;
procedure TCompilerSuite.RunTest(ATest: TTest; AResult: TTestResult);
begin
try
inherited RunTest(ATest, AResult);
finally
if not FInRun then Clear;
end;
end;
procedure TCompilerSuite.RegisterDbgTest(ATestClass: TTestCaseClass);
var
i: Integer;
begin
for i := 0 to Tests.Count - 1 do
if Test[i] is TDebuggerSuite then
TDebuggerSuite(Test[i]).RegisterDbgTest(ATestClass);
end;
procedure TCompilerSuite.TestCompileUses(UsesDir: TUsesDir; out UsesLibDir: String; out ExeID:string);
var
Opts: String;
i: Integer;
DirPostFix: String;
begin
DirPostFix := SymbolTypeNames[UsesDir.SymbolType] + '_' + NameToFileName(CompilerInfo.Name);
UsesLibDir := AppendPathDelim(ExtractFilePath(UsesDir.DirName)) + 'lib__'
+ DirPostFix;
if UsesDir.NamePostFix <> '' then
UsesLibDir := UsesLibDir + '__' + UsesDir.NamePostFix;
i := FCompiledUsesList.IndexOf(UsesLibDir);
if i < 0 then begin
if DirectoryExists(AppendPathDelim(UsesLibDir)) then
raise EAssertionFailedError.Create('Found existing dir before compiling: ' + UsesLibDir);
i := FCompiledUsesList.Add(UsesLibDir);
ExeID := '_U'+IntToStr(i)+UsesDir.ExeId+'_'+DirPostFix+'__';
FCompiledUsesListID.Add(ExeID);
CreateDirUTF8(UsesLibDir);
Opts := SymbolTypeSwitches[UsesDir.SymbolType] + ' ' + UsesDir.ExtraOpts;
if not CompileHelper.TestCompileUnits(CompilerInfo.ExeName, Opts, UsesDir.DirName, UsesLibDir)
then
raise EAssertionFailedError.Create('Compilation Failed: ' + UsesDir.DirName + LineEnding + CompileHelper.LastError);
end
else begin
ExeID := FCompiledUsesListID[i];
end;
end;
procedure TCompilerSuite.TestCompile(const PrgName: string; out ExeName: string;
NamePostFix: String=''; ExtraArgs: String='');
begin
TestCompile(PrgName, ExeName, [], NamePostFix, ExtraArgs);
end;
procedure TCompilerSuite.TestCompile(const PrgName: string; out ExeName: string;
UsesDirs: array of TUsesDir; NamePostFix: String; ExtraArgs: String);
var
ExePath, ErrMsg, ExtraFUPath: String;
i: Integer;
NewLibDir, NewExeID: string;
begin
FCompileCommandLine := '';
ExePath := ExtractFileNameWithoutExt(PrgName);
ExeName := ExtractFileNameOnly(ExePath);
ExePath := AppendPathDelim(copy(ExePath, 1, length(ExePath) - length(ExeName)));
if DirectoryExistsUTF8(ExePath + 'lib') then
ExePath := AppendPathDelim(ExePath + 'lib');
ExtraFUPath := '';
for i := low(UsesDirs) to high(UsesDirs) do begin
TestCompileUses(UsesDirs[i], NewLibDir, NewExeID);
ExtraFUPath := ExtraFUPath + ' -Fu'+NewLibDir;
NamePostFix := NamePostFix + NewExeID;
end;
ExeName := ExePath + ExeName + FFileNameExt + NamePostFix + GetExeExt;
if ExtraArgs <> '' then
ExtraArgs := ' '+ExtraArgs;
i := FCompiledList.IndexOf(ExeName);
if i < 0 then begin
if FileExists(ExeName) then
raise EAssertionFailedError.Create('Found existing file before compiling: ' + ExeName);
i := FCompiledList.Add(ExeName);
ErrMsg := CompileHelper.TestCompile(PrgName,
FSymbolSwitch + ' ' + ExtraFUPath + ' ' + FCompilerInfo.ExtraOpts + ExtraArgs,
ExeName,
CompilerInfo.ExeName);
FCompileCommandLine := CompileHelper.CommandLine;
FCompiledListCmdLines.Add(FCompileCommandLine);
if ErrMsg <> '' then begin
debugln(ErrMsg);
raise EAssertionFailedError.Create('Compilation Failed: ' + ExeName + LineEnding + ErrMsg);
end;
end
else
FCompileCommandLine := FCompiledListCmdLines[i];
if not FileExists(ExeName) then
raise EAssertionFailedError.Create('Missing compiled exe ' + ExeName);
end;
{ TDebuggerSuite }
function TDebuggerSuite.GetCompilerInfo: TCompilerInfo;
begin
Result := Parent.CompilerInfo;
end;
function TDebuggerSuite.GetCompileCommandLine: String;
begin
Result := Parent.CompileCommandLine;
end;
function TDebuggerSuite.GetSymbolType: TSymbolType;
begin
Result := Parent.SymbolType;
end;
constructor TDebuggerSuite.Create(AParent: TCompilerSuite;
ADebuggerInfo: TDebuggerInfo);
begin
inherited Create(ADebuggerInfo.Name + ' ('+AParent.TestName+')');
FParent := AParent;
FDebuggerInfo := ADebuggerInfo;
end;
procedure TDebuggerSuite.RegisterDbgTest(ATestClass: TTestCaseClass);
var
NewTest: TGDBTestsuite;
begin
NewTest := TGDBTestsuite.Create(Self, ATestClass);
AddTest(NewTest);
end;
procedure TDebuggerSuite.TestCompile(const PrgName: string; out ExeName: string;
UsesDirs: array of TUsesDir; NamePostFix: String=''; ExtraArgs: String='');
begin
Parent.TestCompile(PrgName, ExeName, UsesDirs, NamePostFix, ExtraArgs);
end;
{ TGDBTestsuite }
function TGDBTestsuite.GetCompilerInfo: TCompilerInfo;
begin
Result := Parent.CompilerInfo;
end;
function TGDBTestsuite.GetCompileCommandLine: String;
begin
Result := Parent.CompileCommandLine;
end;
function TGDBTestsuite.GetDebuggerInfo: TDebuggerInfo;
begin
Result := Parent.DebuggerInfo;
end;
function TGDBTestsuite.GetSymbolType: TSymbolType;
begin
Result := Parent.SymbolType;
end;
constructor TGDBTestsuite.Create(AParent: TDebuggerSuite; AClass: TClass);
begin
inherited Create(AClass);
FParent := AParent;
end;
procedure TGDBTestsuite.AddTest(ATest: TTest);
begin
inherited AddTest(ATest);
if ATest is TGDBTestCase then
TGDBTestCase(ATest).Parent := Self;
end;
procedure TGDBTestsuite.TestCompile(const PrgName: string; out ExeName: string;
UsesDirs: array of TUsesDir; NamePostFix: String=''; ExtraArgs: String='');
begin
Parent.TestCompile(PrgName, ExeName, UsesDirs, NamePostFix, ExtraArgs);
end;
{ --- }
procedure RegisterDbgTest(ATestClass: TTestCaseClass);
var
Suite: TTestSuite;
i: Integer;
begin
Suite := GetTestRegistry;
for i := 0 to Suite.Tests.Count - 1 do
if Suite.Test[i] is TCompilerSuite then
TCompilerSuite(Suite.Test[i]).RegisterDbgTest(ATestClass);
end;
procedure BuildTestSuites;
var
FpcList: TCompilerList;
GdbList: TDebuggerList;
CompilerSuite: TCompilerSuite;
i: Integer;
st: TSymbolType;
begin
FpcList := GetCompilers;
GdbList := GetDebuggers;
for i := 0 to FpcList.Count - 1 do begin
for st := low(TSymbolType) to high(TSymbolType) do begin
if not (st in FpcList.CompilerInfo[i].SymbolTypes) then
continue;
CompilerSuite := TCompilerSuite.Create(FpcList.CompilerInfo[i], st, GdbList);
if CompilerSuite.Tests.Count >0 then
GetTestRegistry.AddTest(CompilerSuite)
else
CompilerSuite.Free;
end;
end;
end;
function CheckAppDir(var AppDir: string): Boolean;
begin
Result := DirectoryExistsUTF8(AppDir + 'TestApps');
end;
function CheckAppDirLib(var AppDir: string): Boolean;
var
s: string;
begin
Result := False;
if RightStr(AppDir, length('lib' + DirectorySeparator)) = 'lib' + DirectorySeparator
then begin
s := copy(AppDir, 1, length(AppDir) - length('lib' + DirectorySeparator));
Result := DirectoryExistsUTF8(s + 'TestApps');
if Result then
AppDir := s;
end;
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;
initialization
// GDBMIDebugger is un uses
DebugLogger.FindOrRegisterLogGroup('DBG_CMD_ECHO' , True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBGMI_QUEUE_DEBUG' , True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBGMI_STRUCT_PARSER' , 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('DBGMI_TYPE_INFO', True )^.Enabled := True;
DebugLogger.FindOrRegisterLogGroup('DBGMI_TIMEOUT_DEBUG', 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))
and not(CheckAppDirLib(AppDir))
then begin
AppDir := AppDirStripAppBundle(AppDir);
if not(CheckAppDir(AppDir))
and not(CheckAppDirLib(AppDir))
then
with TSelectDirectoryDialog.Create(nil) do begin
if Execute then AppDir := AppendPathDelim(FileName);
Free;
end;
end;
ConfDir := AppDir;
AppDir := AppendPathDelim(AppDir + 'TestApps');
//EnvironmentOptions := TEnvironmentOptions.Create;
//with EnvironmentOptions do
//begin
// CreateConfig;
// Load(false);
//end;
//GlobalMacroList:=TTransferMacroList.Create;
BuildTestSuites;
finalization
FreeAndNil(Compilers);
FreeAndNil(Debuggers);
//FreeAndNil(EnvironmentOptions);
end.
|