forked from Open-CMSIS-Pack/devtools
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathValidateSemantic.cpp
More file actions
1021 lines (865 loc) · 37.1 KB
/
Copy pathValidateSemantic.cpp
File metadata and controls
1021 lines (865 loc) · 37.1 KB
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
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "Validate.h"
#include "ValidateSemantic.h"
#include "GatherCompilers.h"
#include "RteModel.h"
#include "RteProject.h"
#include "RteFsUtils.h"
#include "ErrLog.h"
using namespace std;
/**
* @brief class constructor
* @param rteModel RTE Model to run on
* @param packOptions options configured for program
*/
ValidateSemantic::ValidateSemantic(RteGlobalModel& rteModel, CPackOptions& packOptions) :
Validate(rteModel, packOptions)
{
}
/**
* @brief class destructor
*/
ValidateSemantic::~ValidateSemantic()
{
}
/**
* @brief base function to run through all tests
* @return passed / failed
*/
bool ValidateSemantic::Check()
{
for(auto packItem : GetModel().GetChildren()) {
RtePackage* pKg = dynamic_cast<RtePackage*>(packItem);
if(!pKg) {
continue;
}
string fileName = pKg->GetPackageFileName();
if(GetOptions().IsSkipOnPdscTest(fileName)) {
continue;
}
BeginTest(fileName);
GatherCompilers(pKg);
TestMcuDependencies(pKg);
EndTest();
}
TestComponentDependencies();
return true;
}
/**
* @brief setup a test run
* @param packName name of tested package
* @return passed / failed
*/
bool ValidateSemantic::BeginTest(const std::string& packName)
{
ErrLog::Get()->SetFileName(packName);
return true;
}
/**
* @brief clean up after test run ended
* @return passed / failed
*/
bool ValidateSemantic::EndTest()
{
ErrLog::Get()->SetFileName("");
return true;
}
/**
* @brief search for compilers referenced in pack
* @param pKg package under test
* @return passed / failed
*/
bool ValidateSemantic::GatherCompilers(RtePackage* pKg)
{
if(!pKg) {
return false;
}
GatherCompilersVisitor compilersVisitor;
pKg->AcceptVisitor(&compilersVisitor);
string comps;
m_compilers = compilersVisitor.GetCompilerList();
for(auto& [key, compiler] : m_compilers) {
if(!comps.empty()) {
comps += ", ";
}
string compilerName = compilersVisitor.GetCompilerName(compiler);
comps += compilerName;
}
if(comps.empty()) {
comps = "<no compiler dependency found>";
}
LogMsg("M079", VAL("COMPILER", comps));
if(m_compilers.empty()) {
compiler_s compiler;
m_compilers[""] = compiler; // add "empty" compiler as default
}
return true;
}
/**
* @brief RTE Model messages
*/
const map<RteItem::ConditionResult, string> conditionResultTxt = {
{ RteItem::UNDEFINED , "not evaluated yet" },
{ RteItem::R_ERROR , "error evaluating condition ( recursion detected, condition is missing)" },
{ RteItem::FAILED , "HW or compiler not match" },
{ RteItem::MISSING , "no component is installed" },
{ RteItem::MISSING_API , "no required API is installed" },
{ RteItem::MISSING_API_VERSION , "no API with the required or compatible version is installed" },
{ RteItem::UNAVAILABLE , "component is installed, but filtered out" },
{ RteItem::UNAVAILABLE_PACK , "component is installed, pack is not selected" },
{ RteItem::INCOMPATIBLE , "incompatible component is selected" },
{ RteItem::INCOMPATIBLE_VERSION , "incompatible version of component is selected" },
{ RteItem::INCOMPATIBLE_VARIANT , "incompatible variant of component is selected" },
{ RteItem::CONFLICT , "several exclusive or incompatible components selected" },
{ RteItem::INSTALLED , "matching components are installed, but not selectable because not in active bundle" },
{ RteItem::SELECTABLE , "matching components are installed, but not selected" },
{ RteItem::FULFILLED , "required component selected or no dependency exist" },
{ RteItem::IGNORED , "condition/expression is irrelevant for the current context" },
};
/**
* @brief output dependency result for error reporting
* @param dependencyResult result
* @param inRecursion flag if in recursion
* @return passed / failed
*/
bool ValidateSemantic::OutputDepResults(const RteDependencyResult& dependencyResult, bool inRecursion /*= 0*/)
{
static int recursionCnt = 0;
if(!inRecursion) {
recursionCnt = 0;
}
string spaces;
for(int i = 0; i < recursionCnt; i++) {
spaces += " ";
}
const string& errNum = dependencyResult.GetErrorNum();
const string& msgText = dependencyResult.GetMessageText();
const string& dispName = dependencyResult.GetDisplayName();
const string& outMsgText = dependencyResult.GetOutputMessage();
if(!outMsgText.empty()) {
if(!errNum.empty()) {
LogMsg("M502", VAL("NUM", errNum), NAME(dispName), MSG(msgText));
recursionCnt = 0;
}
else {
if(outMsgText.find("missing") != string::npos) {
LogMsg("M504", SPACE(spaces), NAME(dispName));
}
recursionCnt++;
}
}
for(auto &[key, value] : dependencyResult.GetResults()) {
OutputDepResults(value, true);
}
return true;
}
/**
* @brief check defined memories
* @param device RteDeviceItem to run on
* @return passed / failed
*/
bool ValidateSemantic::CheckMemories(RteDeviceItem* device)
{
string devName = device->GetName();
list<RteDeviceProperty*> processors;
device->GetEffectiveProcessors(processors);
for(auto processor : processors) {
const string& pName = processor->GetName();
if(!pName.empty()) {
devName += ":";
devName += pName;
}
LogMsg("M071", NAME(devName), processor->GetLineNumber());
const list<RteDeviceProperty*>& memories = device->GetEffectiveProperties("memory", pName);
if(memories.empty()) {
LogMsg("M312", TAG("memory"), NAME(device->GetName()), device->GetLineNumber());
return false;
}
map<const string, RteDeviceProperty*> memoryNameCheck;
list<RteDeviceProperty*> rxRegionWithStartup;
for(auto memory : memories) {
int lineNo = memory->GetLineNumber();
const string& id = memory->GetEffectiveAttribute("id");
const string& name = memory->GetEffectiveAttribute("name");
const string& access = memory->GetEffectiveAttribute("access");
const string& start = memory->GetEffectiveAttribute("start");
const string& size = memory->GetEffectiveAttribute("size");
const string& pname = memory->GetEffectiveAttribute("pname");
const string& startup = memory->GetEffectiveAttribute("startup");
string memoryName = name.empty() ? id : name;
if(!pname.empty()) {
memoryName += ":" + pname;
}
LogMsg("M070", NAME(memoryName), NAME2(devName), lineNo); // Checking Memory '%NAME%' for device '%NAME2%'
if(id.empty()) { // new description, where 'name' is just a string and 'access' describes the permissions
if(name.empty() && access.empty()) {
LogMsg("M307", TAG("id"), TAG2("name"), TAG3("access"), lineNo); // Attribute '%TAG%' or '%TAG2%' + '%TAG3%' must be specified for 'memory'
}
}
else { // "classic" way of RAM/ROM description, where RAM/ROM already has access permissions R, RW
if(!name.empty() && !access.empty()) {
LogMsg("M399", TAG("id"), TAG2("name"), TAG3("access"), lineNo); // Attribute '%TAG% = %NAME%' is ignored, because '%TAG2% = %NAME2%' + '%TAG3% = %NAME3%' is specified
}
}
if(name.empty()) {
if(!access.empty()) {
LogMsg("M309", TAG("name"), TAG2("memory"), TAG3("access"), lineNo); // Attribute '%TAG%' missing when specifying '%TAG2%' for 'memory'
}
}
else {
if(access.empty()) {
LogMsg("M309", TAG("access"), TAG2("memory"), TAG3("name"), lineNo); // Attribute '%TAG%' missing when specifying '%TAG2%' for 'memory'
}
}
if(start.empty()) {
LogMsg("M308", TAG("start"), TAG2("memory"), lineNo); // Attribute '%TAG%' missing
}
if(size.empty()) {
LogMsg("M308", TAG("size"), TAG2("memory"), lineNo); // Attribute '%TAG%' missing
}
if(!memoryName.empty()) {
auto propNameCheckIt = memoryNameCheck.find(memoryName);
if(propNameCheckIt != memoryNameCheck.end()) {
RteDeviceProperty* propFound = propNameCheckIt->second;
if(propFound) {
LogMsg("M311", TAG("memory"), NAME(memoryName), LINE(propFound->GetLineNumber()), lineNo);
}
}
else {
memoryNameCheck[memoryName] = memory;
}
}
// Check startup attribute
if(startup == "1") {
rxRegionWithStartup.push_back(memory);
if(id.find("IROM") != 0 && id.find("IRAM") != 0) { // no deprecated IRAM / IROM which have eXecute implicitly set
if(access.find_first_of("x") == string::npos) {
LogMsg("M608", NAME(memoryName), ATTR("startup"), VALUE("1"), ATTR2("access"), VALUE2("x"), lineNo);
}
}
}
}
const int numOfMemories = rxRegionWithStartup.size();
if(!numOfMemories || numOfMemories > 1) {
LogMsg("M609", NAME(devName), NUM(numOfMemories), processor->GetLineNumber());
}
}
return true;
}
/**
* @brief check for unsupported characters in 'name'
* @param name string input name
* @param tag tag for error reporting
* @param lineNo line number for error reporting
* @return passed / failed
*/
bool ValidateSemantic::CheckForUnsupportedChars(const string& name, const string& tag, int lineNo)
{
if(name.empty()) {
return false;
}
const string supportedChars = "[\\-_A-Za-z0-9/]+";
LogMsg("M065", TAG(tag), NAME(name), CHR(supportedChars), lineNo);
if(!RteUtils::CheckCMSISName(name)) {
LogMsg("M383", TAG(tag), NAME(name), CHR(supportedChars), lineNo);
return false;
}
LogMsg("M010");
return true;
}
/**
* @brief checks for device description
* @param device RteDEviceItem to run on
* @param processorProperty properties set for device
* @return passed / failed
*/
bool ValidateSemantic::CheckDeviceDescription(RteDeviceItem* device, RteDeviceProperty* processorProperty)
{
const string& mcuName = device->GetName();
const string& mcuVendor = device->GetEffectiveAttribute("Dvendor");
const string& Pname = processorProperty->GetEffectiveAttribute("Pname");
int lineNo = device->GetLineNumber();
RteDeviceProperty* descrProp = device->GetSingleEffectiveProperty("description", Pname);
if(descrProp) {
const string& descr = descrProp->GetDescription();
if(descr.empty()) {
LogMsg("M380", VENDOR(mcuVendor), MCU(mcuName), lineNo);
return false;
}
}
return true;
}
/**
* @brief compares name against name and extension
* @param name string name to check
* @param searchName string name to search for
* @param searchExt string extension (e.g. ".h") to search for
* @return true / false
*/
bool ValidateSemantic::FindName(const string& name, const string& searchName, const string& searchExt)
{
if(name.find(searchName, 0) != 0) {
return false;
}
if(name.find(searchExt, 0) != name.length() - searchExt.length()) {
return false;
}
return true;
}
/**
* @brief update RTE model after new options have been set
* @param target RteTarget selected target
* @param rteProject RteProject selected project
* @param component RteComponent selected component
* @return passed / failed
*/
bool ValidateSemantic::UpdateRte(RteTarget* target, RteProject* rteProject, RteComponent* component)
{
target->ClearCollections();
target->ClearSelectedComponents();
RteComponentAggregate* cmsisComp = target->GetComponentAggregate("ARM::CMSIS.CORE");
target->SelectComponent(cmsisComp, 1, true);
target->SelectComponent(component, 1, true, true);
rteProject->Apply();
target->CollectFilteredFiles();
target->EvaluateComponentDependencies();
return true;
}
/**
* @brief check RTE Model output for dependency result
* @param target RteTarget selected target
* @param component RteComponent selected component
* @param mcuVendor string mcuVendor for error reporting
* @param mcuDispName string mcuDispName for error reporting
* @param compiler compiler_s compiler for error reporting
* @return passed / failed
*/
bool ValidateSemantic::CheckDependencyResult(RteTarget* target, RteComponent* component, string mcuVendor, string mcuDispName, compiler_s compiler)
{
string compId = component->GetComponentID(true);
RteDependencyResult dependencyResult;
RteItem::ConditionResult res = target->GetDepsResult(dependencyResult.Results(), target);
switch(res) {
case RteItem::SELECTABLE: // all dependencies resolved, component can be selected
case RteItem::FULFILLED: // all dependencies resolved, component is selected
case RteItem::IGNORED: // condition/expression is irrelevant for the current context
break;
default: { // error
string msg;
auto resultText = conditionResultTxt.find(res);
if(resultText != conditionResultTxt.end()) {
msg = "\nDependency Result: " + resultText->second;
}
int lineNo = component->GetLineNumber();
LogMsg("M351", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), MSG(msg), lineNo);
OutputDepResults(dependencyResult);
} break;
}
return true;
}
/**
* @brief skip directories
* @param systemHeader string name to test
* @param rteFolder the "RTE" folder path used for placing files
* @return true / false
*/
bool ValidateSemantic::ExcludeSysHeaderDirectories(const string& systemHeader, const string& rteFolder)
{
if(systemHeader.empty()) {
return true;
}
if(systemHeader == rteFolder) {
return true;
}
if(systemHeader == "./" + rteFolder) {
return true;
}
if(systemHeader == "./" + rteFolder + "/_Test") {
return true;
}
return false;
}
/**
* @brief searches for given file
* @param systemHeader string name to search for
* @param targFiles list of target files to view
* @return true / false
*/
bool ValidateSemantic::FindFileFromList(const string& systemHeader, const set<RteFile*>& targFiles)
{
for(auto findSysH : targFiles) {
string fNameSysH = RteUtils::BackSlashesToSlashes(RteUtils::ExtractFileName(findSysH->GetName()));
if(fNameSysH == systemHeader) {
return true;
}
}
return false;
}
bool ValidateSemantic::FileIsHeader(const std::string& name)
{
return RteFsUtils::FileCategoryFromExtension(name) == "header";
}
/**
* @brief Check device attributes. Tests if all attributes like Dtz, Ddsp, ... are set
* @param device RteDeviceItem to run on
* @return passed / failed
*/
const map<string, list<string>> processorFeaturesMap = {
//{ "ARMV81MML" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M0" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M0+" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M1" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M3" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M4" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M7" , { "Dfpu", "Dmpu", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M23" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M33" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M35P" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M52" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M55" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-M85" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
{ "Star-MC1" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
{ "SC000" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "SC300" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "ARMV8MBL" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "ARMV8MML" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dendian", "Dclock","DcoreVersion" } },
{ "ARMV81MML" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dendian", "Dclock","DcoreVersion" } },
/* Currently unchecked
{ "Cortex-R4" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-R5" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-R7" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-R8" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A5" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A7" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A8" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A9" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A15" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A17" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A32" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A35" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A53" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A57" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A72" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
{ "Cortex-A73" , { "Dfpu", "Dmpu", "Dtz", "Ddsp", "Dmve", "Dcdecp", "Dpacbti", "Dendian", "Dclock","DcoreVersion" } },
*/
};
const list<string> processorMulticoreFeaturesList = {
"Pname",
};
bool ValidateSemantic::CheckDeviceAttributes(RteDeviceItem *device)
{
if(!device) {
return true;
}
bool bOk = false;
int lineNo = device->GetLineNumber();
const auto processors = device->GetProcessors();
for(const auto& [core, processor] : processors) {
const auto& Dcore = processor->GetAttribute("Dcore");
const auto& processorFeatures = processorFeaturesMap.find(Dcore);
if(processorFeatures == processorFeaturesMap.end()) {
LogMsg("M604", NAME(Dcore), lineNo); // Dcore not found in list for feature check
return true;
}
const auto& features = processorFeatures->second;
for(const auto& feature : features) {
if(processor->GetEffectiveAttribute(feature) == "") {
LogMsg("M605", NAME(Dcore), NAME2(feature), lineNo); // Required processor feature '%NAME%' not found.
bOk = false;
}
}
// Test dependant features (if one is found, all the others must be present as well)
if(processors.size() > 1) {
for(const auto& requiredMulticoreFeature : processorMulticoreFeaturesList) {
if(processor->GetEffectiveAttribute(requiredMulticoreFeature) == "") {
LogMsg("M605", NAME(Dcore), NAME2(requiredMulticoreFeature), lineNo); // Required processor feature '%NAME%' not found.
bOk = false;
}
}
}
}
return bOk;
}
/**
* @brief Check device dependencies. Tests if all dependencies are solved and a minimum
* on support files and configuration has been defined
* @param device RteDeviceItem to run on
* @param rteProject RteProject to run on
* @return passed / failed
*/
bool ValidateSemantic::CheckDeviceDependencies(RteDeviceItem *device, RteProject* rteProject)
{
if(!device) {
return false;
}
const string& mcuName = device->GetName();
const string& mcuVendor = device->GetEffectiveAttribute("Dvendor");
int lineNo = device->GetLineNumber();
CheckForUnsupportedChars(mcuName, "Dname", lineNo);
XmlItem deviceStartup;
deviceStartup.SetAttribute("Cclass", "Device");
deviceStartup.SetAttribute("Cgroup", "Startup");
bool bOk = true;
for(auto &[processorName, processor] : device->GetProcessors()) {
const string& Pname = processor->GetEffectiveAttribute("Pname");
lineNo = processor->GetLineNumber();
CheckDeviceDescription(device, processor);
string mcuDispName = mcuName;
if(!processorName.empty()) {
mcuDispName += ":";
mcuDispName += Pname;
}
list<string> trustZoneList;
auto trustZone = processor->GetAttribute("Dtz");
if(trustZone.empty()) {
trustZoneList.push_back("");
}
else {
trustZoneList.push_back("TZ-disabled");
trustZoneList.push_back("Secure");
trustZoneList.push_back("Non-secure");
}
for(auto trustZoneMode : trustZoneList) {
RteItem filter;
device->GetEffectiveFilterAttributes(processorName, filter);
filter.AddAttribute("Dname", mcuName);
for(auto &[compilerKey, compiler] : m_compilers) {
filter.AddAttribute("Tcompiler", compiler.tcompiler);
filter.AddAttribute("Toptions", compiler.toptions);
if(!trustZoneMode.empty()) {
filter.AddAttribute("Dsecure", trustZoneMode);
}
rteProject->Clear();
rteProject->SetAttribute("update-rte-files", "0");
rteProject->AddTarget("Test", filter.GetAttributes(), true, true);
rteProject->SetActiveTarget("Test");
RteTarget* target = rteProject->GetActiveTarget();
rteProject->FilterComponents();
set<RteComponentAggregate*> startupComponents;
target->GetComponentAggregates(deviceStartup, startupComponents);
if(startupComponents.empty()) {
LogMsg("M350", COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue; // error: no startup component found
}
for(auto aggregate : startupComponents) {
ErrLog::Get()->SetFileName(aggregate->GetPackage()->GetPackageFileName());
string targetPath = RteUtils::ExtractFilePath(aggregate->GetPackage()->GetPackageFileName(), false);
for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
int foundSystemC = 0, foundStartup = 0;
bool bFoundSystemH = false;
int lineSystem = 0, lineStartup = 0;
for(auto& [key, component] : componentMap) {
string compId = component->GetComponentID(true);
LogMsg("M091", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
UpdateRte(target, rteProject, component);
int lineNo = component->GetLineNumber();
CheckDependencyResult(target, component, mcuVendor, mcuDispName, compiler);
const set<RteFile*>& targFiles = target->GetFilteredFiles(component);
if(targFiles.empty()) {
LogMsg("M352", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue;
}
const string& deviceHeaderfile = target->GetDeviceHeader();
if(deviceHeaderfile.empty()) {
LogMsg("M353", VAL("FILECAT", "Device Header-file"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}
const set<string>& incPaths = target->GetIncludePaths();
if(incPaths.empty()) {
LogMsg("M355", VAL("FILECAT", "Include"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}
for(auto file : targFiles) {
const string& category = file->GetAttribute("category");
if(category == "source" || category == "sourceAsm" || category == "sourceC") {
string fileName = RteUtils::BackSlashesToSlashes(RteUtils::ExtractFileName(file->GetName()));
if(fileName.empty()) {
continue;
}
const string& attribute = file->GetAttribute("attr");
if(attribute == "config" && FileIsHeader(fileName)) {
const string& fullFileName = targetPath + "/" + file->GetName();
const string hPath = RteUtils::ExtractFilePath(fullFileName, false);
const auto incPathFound = incPaths.find(hPath);
if(incPathFound != incPaths.end()) {
LogMsg("M357", NAME(file->GetName()), file->GetLineNumber());
}
}
if(FindName(fileName, "system_", ".c")) {
foundSystemC++;
lineSystem = file->GetLineNumber();
if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
}
string systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
bFoundSystemH = FindFileFromList(systemHeader, targFiles);
if(!bFoundSystemH) {
string incPathsMsg;
int incPathsCnt = 0;
for(auto& incPath : incPaths) {
systemHeader = RteUtils::BackSlashesToSlashes(incPath);
if(ExcludeSysHeaderDirectories(systemHeader, rteProject->GetRteFolder())) {
continue;
}
incPathsMsg += "\n ";
incPathsMsg += to_string((unsigned long long) ++incPathsCnt);
incPathsMsg += ": ";
incPathsMsg += systemHeader;
systemHeader += "/";
systemHeader += RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
string sysHeader = RteUtils::ExtractFileName(systemHeader);
for (auto f : targFiles) {
if(RteUtils::ExtractFileName(f->GetName()) == sysHeader) {
systemHeader = f->GetOriginalAbsolutePath();
break;
}
}
if(RteFsUtils::Exists(systemHeader)) {
bFoundSystemH = true;
}
}
if(!bFoundSystemH) {
systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
if(incPathsMsg.empty()) {
incPathsMsg = "\n ";
incPathsMsg += to_string((unsigned long long) ++incPathsCnt);
incPathsMsg += ": ";
incPathsMsg += "<not found any include path>";
}
LogMsg("M358", VAL("HFILE", RteUtils::ExtractFileName(systemHeader)), VAL("CFILE", fileName), COMP("Startup"), VAL("COMPID", compId),
VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), PATH(incPathsMsg), lineNo);
bOk = false;
}
}
}
if(fileName.find("startup_", 0) != string::npos) {
foundStartup++;
lineStartup = file->GetLineNumber();
if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
}
}
}
if(category == "header") {
string fileName = RteUtils::BackSlashesToSlashes(RteUtils::ExtractFileName(file->GetName()));
if(fileName.empty()) {
continue;
}
const string& attribute = file->GetAttribute("attr");
if(attribute == "config") {
const string& fullFileName = targetPath + "/" + file->GetName();
const string hPath = RteUtils::ExtractFilePath(fullFileName, false);
const auto incPathFound = incPaths.find(hPath);
if(incPathFound != incPaths.end()) {
LogMsg("M357", NAME(file->GetName()), file->GetLineNumber());
}
}
}
}
}
if(foundSystemC != 1 || foundStartup != 1) { // ignore if generator="..."
if(HasExternalGenerator(aggregate)) {
continue;
}
}
if(foundSystemC != 1) {
LogMsg(foundSystemC ? "M354" : "M353",
VAL("FILECAT", "system_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundSystemC ? lineSystem : lineNo);
bOk = false;
}
if(foundStartup != 1) {
LogMsg(foundStartup ? "M354" : "M353",
VAL("FILECAT", "startup_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundStartup ? lineStartup : lineNo);
bOk = false;
}
}
}
}
filter.RemoveAttribute("Tcompiler");
if(bOk) {
LogMsg("M010");
}
}
}
return bOk;
}
/**
* @brief check for MCU dependencies
* @param pKg package under test
* @return passed / failed
*/
bool ValidateSemantic::HasExternalGenerator(RteComponentAggregate* aggregate)
{
auto bundleName = aggregate->GetCbundleName();
if(!bundleName.empty()) {
for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
for(auto& [key, component] : componentMap) {
auto parentBundle = component->GetParentBundle();
if(parentBundle) {
for(auto bundleComponent : parentBundle->GetChildren()) {
auto generatorAttrName = bundleComponent->GetAttribute("generator");
if(!generatorAttrName.empty()) {
return true;
}
}
}
}
}
}
return false;
}
/**
* @brief check for MCU dependencies
* @param pKg package under test
* @return passed / failed
*/
bool ValidateSemantic::TestMcuDependencies(RtePackage* pKg)
{
RteGlobalModel& model = GetModel();
RteProject* rteProject = model.AddProject(1);
if(!rteProject || !pKg) {
return false;
}
rteProject->SetAttribute("update-rte-files", "0");
model.GetLatestPackage("ARM.CMSIS");
list<RteDeviceItem*> devices;
pKg->GetEffectiveDeviceItems(devices);
for(auto device : devices) {
CheckDeviceDependencies(device, rteProject);
CheckMemories(device);
CheckDeviceAttributes(device);
}
model.DeleteProject(1);
return true;
}
/**
* @brief check component dependencies
* @return passed / failed
*/
bool ValidateSemantic::TestComponentDependencies()
{
list<RteDevice*> devices;
string dname, dvendor;
string pKgFileName;
RteGlobalModel& model = GetModel();
RteProject* rteProject = model.AddProject(1);
if(!rteProject) {
return true;
}
rteProject->SetAttribute("update-rte-files", "0");
bool bOk = true;
for(auto &[compKey, component] : model.GetComponentList()) {
RtePackage* pKg = component->GetPackage();
if(!pKg) {
continue;
}
const string& packName = pKg->GetPackageFileName();
if(GetOptions().IsSkipOnPdscTest(packName)) {
continue;
}
ErrLog::Get()->SetFileName(packName);
const string& compClass = component->GetAttribute("Cclass");
const string& compGroup = component->GetAttribute("Cgroup");
const string& compVer = component->GetAttribute("Cversion");
const string& compSub = component->GetAttribute("Csub");
const string& apiVer = component->GetAttribute("Capiversion");
int lineNo = component->GetLineNumber();
LogMsg("M069", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer));
XmlItem filter;
rteProject->Clear();
rteProject->SetAttribute("update-rte-files", "0");
rteProject->AddTarget("Test", filter.GetAttributes(), true, true);
rteProject->SetActiveTarget("Test");
RteTarget* target = rteProject->GetActiveTarget();
rteProject->FilterComponents();
CheckSelfResolvedCondition(component, target);
target->SelectComponent(component, 1, true);
const string& apiVersion = component->GetAttribute("Capiversion");
RteApi* api = component->GetApi(target, false);
if(!apiVersion.empty()) {
if(!api) {
LogMsg("M363", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer), APIVER(apiVer), lineNo);
continue; // skip Model based test, if API is missing, test will fail
}
}
else if(api) {
RtePackage* apiPkg = api->GetPackage();
if(apiPkg) {
const string& packN = apiPkg->GetPackageFileName();
LogMsg("M378", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer), NAME(packN), lineNo);
}
}
RteDependencyResult dependencyResult;
RteItem::ConditionResult result = target->GetDepsResult(dependencyResult.Results(), target);
switch(result) {
case RteItem::SELECTABLE: // all dependencies resolved, component can be selected
case RteItem::INSTALLED:
case RteItem::IGNORED: // condition/expression is irrelevant for the current context (same as FULFILLED)
case RteItem::FULFILLED: // all dependencies resolved, component is selected
break;
default: // error
bOk = false;
break;
}
if(!bOk) {
string msg;
auto resultText = conditionResultTxt.find(result);
if(resultText != conditionResultTxt.end()) {
msg = "\nDependency Result: " + resultText->second;
}
LogMsg("M362", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer), APIVER(apiVer), MSG(msg), lineNo);
OutputDepResults(dependencyResult);
}
else {
LogMsg("M010");
}
}
model.DeleteProject(1);
ErrLog::Get()->SetFileName("");
return bOk;
}
bool ValidateSemantic::TestDepsResult(const map<const RteItem*, RteDependencyResult>& results, RteComponent* component)
{
bool success = true;
const string& compName = component->GetID();
for(auto& [item, dRes] : results) {
RteItem::ConditionResult r = dRes.GetResult();
if(r < RteItem::INSTALLED) {
continue;
}
if(!TestDepsResult(dRes.GetResults(), component)) {
success = false;
}
const string& itemName = item->GetID();
auto aggrs = dRes.GetComponentAggregates();
for(auto aggr : aggrs) {
if(aggr->HasComponent(component)) {
const string errExprStr = item->GetParent()->GetID();
const int compLineNo = item->GetLineNumber();
// "The component '%NAME%' has dependency '%NAME2%' : '%EXPR%' that is be resolved by the component itself."
LogMsg("M389", NAME(compName), LINE(compLineNo), NAME2(itemName), VAL("EXPR", errExprStr), item->GetLineNumber());
success = false;