@@ -16,15 +16,59 @@ class PackChkIntegTests : public ::testing::Test {
1616public:
1717 void SetUp () override ;
1818 void TearDown () override ;
19+
20+ string GetPackXsd ();
21+ void CheckCopyPackXsd ();
22+ void DeletePackXsd ();
1923};
2024
2125void PackChkIntegTests::SetUp () {
26+ CheckCopyPackXsd ();
2227}
2328
2429void PackChkIntegTests::TearDown () {
2530 ErrLog::Get ()->ClearLogMessages ();
2631}
2732
33+ string PackChkIntegTests::GetPackXsd () {
34+ const string schemaDestDir = string (PROJMGRUNITTESTS_BIN_PATH) + " /../etc" ;
35+ const string schemaFileName = schemaDestDir + " /PACK.xsd" ;
36+
37+ return schemaFileName;
38+ }
39+
40+ void PackChkIntegTests::CheckCopyPackXsd () {
41+ error_code ec;
42+
43+ const string schemaDestDir = string (PROJMGRUNITTESTS_BIN_PATH) + " /../etc" ;
44+ const string schemaFileName = GetPackXsd ();
45+
46+ if (RteFsUtils::Exists (schemaFileName)) {
47+ return ;
48+ }
49+
50+ // Copy Pack.xsd
51+ const string packXsd = string (PACKXSD_FOLDER) + " /PACK.xsd" ;
52+ if (RteFsUtils::Exists (schemaDestDir)) {
53+ RteFsUtils::RemoveDir (schemaDestDir);
54+ }
55+ RteFsUtils::CreateDirectories (schemaDestDir);
56+ fs::copy (fs::path (packXsd), fs::path (schemaFileName), ec);
57+ }
58+
59+ void PackChkIntegTests::DeletePackXsd () {
60+ const string schemaFileName = GetPackXsd ();
61+
62+ if (!RteFsUtils::Exists (schemaFileName)) {
63+ return ;
64+ }
65+
66+ // Delete Pack.xsd
67+ RteFsUtils::RemoveFile (schemaFileName);
68+ ASSERT_FALSE (RteFsUtils::Exists (schemaFileName));
69+ }
70+
71+
2872 // Validate packchk when no .pdsc file found
2973TEST_F (PackChkIntegTests, FileNotAVailable) {
3074 const char * argv[2 ];
@@ -674,3 +718,106 @@ TEST_F(PackChkIntegTests, CheckDuplicateFlashAlgo) {
674718 FAIL () << " error: missing message M348 or M369" ;
675719 }
676720}
721+
722+ // Test schema validation
723+ TEST_F (PackChkIntegTests, CheckSchemaValidation) {
724+ const char * argv[3 ];
725+
726+ const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
727+ " /SchemaValidation/TestVendor.SchemaValidation.pdsc" ;
728+ ASSERT_TRUE (RteFsUtils::Exists (pdscFile));
729+
730+ argv[0 ] = (char *)" " ;
731+ argv[1 ] = (char *)pdscFile.c_str ();
732+
733+ PackChk packChk;
734+ EXPECT_EQ (1 , packChk.Check (2 , argv, nullptr ));
735+
736+ auto errMsgs = ErrLog::Get ()->GetLogMessages ();
737+ int M510_foundCnt = 0 ;
738+ int M511_foundCnt = 0 ;
739+ int M306_foundCnt = 0 ;
740+
741+ for (const string& msg : errMsgs) {
742+ size_t s;
743+ if ((s = msg.find (" M306" )) != string::npos) {
744+ M306_foundCnt++; // follows one M511: <descripton>
745+ }
746+ else if ((s = msg.find (" M510" )) != string::npos) {
747+ M510_foundCnt++;
748+ }
749+ else if ((s = msg.find (" M511" )) != string::npos) {
750+ M511_foundCnt++;
751+ }
752+ }
753+
754+ if (M510_foundCnt != 0 || M511_foundCnt != 6 || M306_foundCnt != 1 ) {
755+ FAIL () << " error: missing message M510, M511 or M306" ;
756+ }
757+ }
758+
759+ TEST_F (PackChkIntegTests, CheckPackXsdNotFound) {
760+ const char * argv[2 ];
761+
762+ const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
763+ " /SchemaValidation/TestVendor.SchemaValidation.pdsc" ;
764+ ASSERT_TRUE (RteFsUtils::Exists (pdscFile));
765+
766+ DeletePackXsd ();
767+
768+ argv[0 ] = (char *)" " ;
769+ argv[1 ] = (char *)pdscFile.c_str ();
770+
771+ PackChk packChk;
772+ EXPECT_EQ (1 , packChk.Check (2 , argv, nullptr ));
773+
774+ auto errMsgs = ErrLog::Get ()->GetLogMessages ();
775+ int M218_foundCnt = 0 ;
776+
777+ for (const string& msg : errMsgs) {
778+ size_t s;
779+ if ((s = msg.find (" M218" )) != string::npos) {
780+ M218_foundCnt++; // follows one M511: <descripton>
781+ }
782+ }
783+
784+ if (M218_foundCnt != 1 ) {
785+ FAIL () << " error: missing message M218" ;
786+ }
787+ }
788+
789+ TEST_F (PackChkIntegTests, CheckPackNamedXsdNotFound) {
790+ const char * argv[4 ];
791+
792+ const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
793+ " /SchemaValidation/TestVendor.SchemaValidation.pdsc" ;
794+ ASSERT_TRUE (RteFsUtils::Exists (pdscFile));
795+
796+ DeletePackXsd ();
797+
798+ const string schemaFileName = GetPackXsd ();
799+
800+ argv[0 ] = (char *)" " ;
801+ argv[1 ] = (char *)pdscFile.c_str ();
802+ argv[2 ] = (char *)" --xsd" ;
803+ argv[3 ] = (char *)schemaFileName.c_str ();
804+
805+ PackChk packChk;
806+ EXPECT_EQ (1 , packChk.Check (4 , argv, nullptr ));
807+
808+ auto errMsgs = ErrLog::Get ()->GetLogMessages ();
809+ int M218_foundCnt = 0 ;
810+
811+ for (const string& msg : errMsgs) {
812+ size_t s;
813+ if ((s = msg.find (" M218" )) != string::npos) {
814+ M218_foundCnt++; // follows one M511: <descripton>
815+ }
816+ }
817+
818+ if (M218_foundCnt != 1 ) {
819+ FAIL () << " error: missing message M218" ;
820+ }
821+ }
822+
823+
0 commit comments