forked from Open-CMSIS-Pack/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebPkgTests.cpp
161 lines (136 loc) · 5.67 KB
/
DebPkgTests.cpp
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
/*
* Copyright (c) 2020-2024 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* IMPORTANT:
* These tests are designed to run only in CI environment.
*/
#include "CBuildIntegTestEnv.h"
#include "CbuildUtils.h"
#include <algorithm>
using namespace std;
class DebPkgTests : public ::testing::Test {
public:
void SetUp();
void ValidateExtract(const string& path);
protected:
string FindPackage (const string& path);
void ExtractPackage (const string& pkg, const string& extPath);
};
void DebPkgTests::SetUp() {
if (CBuildIntegTestEnv::ci_installer_path.empty()) {
GTEST_SKIP();
}
}
string DebPkgTests::FindPackage(const string& path) {
string cmd = "find " + path + " -name *.deb";
string pkgfile = CrossPlatformUtils::ExecCommand(cmd.c_str()).first;
pkgfile.erase(pkgfile.find_last_not_of(" \f\n\r\t\v") + 1);
return pkgfile;
}
void DebPkgTests::ExtractPackage(const string& pkg, const string& extPath) {
string cmd = "dpkg-deb -xv " + pkg + " " + extPath;
auto res = CrossPlatformUtils::ExecCommand(cmd.c_str());
ASSERT_FALSE(res.first.empty());
ASSERT_EQ(res.second, 0);
}
void DebPkgTests::ValidateExtract(const string& extPath) {
vector<string> pathVec = {
"./etc/cmsis-build/AC6.6.16.2.cmake",
"./etc/cmsis-build/CPRJ.xsd", "./etc/cmsis-build/GCC.10.3.1.cmake",
"./etc/cmsis-build/setup",
"./etc/cmsis-build/cdefault.schema.json", "./etc/cmsis-build/clayer.schema.json",
"./etc/cmsis-build/common.schema.json", "./etc/cmsis-build/cproject.schema.json",
"./etc/cmsis-build/csolution.schema.json",
"./etc/cmsis-build/cbuild-gen.schema.json", "./etc/cmsis-build/cbuild-gen-idx.schema.json",
"./etc/cmsis-build/cbuild-pack.schema.json", "./etc/cmsis-build/cbuild-set.schema.json",
"./etc/cmsis-build/generator.schema.json", "./etc/cmsis-build/cgen.schema.json",
"./etc/cmsis-build/global.generator.yml",
"./etc/profile.d/cmsis-build.sh", "./usr/bin/cbuild.sh",
"./usr/bin/cpackget",
"./usr/bin/cbuildgen",
"./usr/bin/csolution",
"./usr/doc/doc-base/cmsis-build",
"./usr/lib/cmsis-build/bin/cbuild.sh",
"./usr/lib/cmsis-build/bin/cbuildgen",
"./usr/lib/cmsis-build/bin/cpackget",
"./usr/lib/cmsis-build/bin/csolution",
"./usr/lib/cmsis-build/etc/AC6.6.16.2.cmake",
"./usr/lib/cmsis-build/etc/CPRJ.xsd", "./usr/lib/cmsis-build/etc/GCC.10.3.1.cmake",
"./usr/lib/cmsis-build/etc/setup",
"./usr/lib/cmsis-build/cdefault.schema.json", "./usr/lib/cmsis-build/clayer.schema.json",
"./usr/lib/cmsis-build/common.schema.json", "./usr/lib/cmsis-build/cproject.schema.json",
"./usr/lib/cmsis-build/csolution.schema.json",
"./usr/lib/cmsis-build/cbuild-gen.schema.json", "./usr/lib/cmsis-build/cbuild-gen-idx.schema.json",
"./usr/lib/cmsis-build/cbuild-pack.schema.json", "./usr/lib/cmsis-build/cbuild-set.schema.json",
"./usr/lib/cmsis-build/generator.schema.json", "./usr/lib/cmsis-build/cgen.schema.json",
"./usr/lib/cmsis-build/global.generator.yml",
"./usr/share/doc/cmsis-build/copyright",
"./usr/share/doc/cmsis-build/doc/index.html"
};
error_code ec;
fs::current_path(extPath, ec);
for_each(pathVec.begin(), pathVec.end(),
[&](const string& str) { ASSERT_TRUE(fs::exists(str, ec) || fs::is_symlink(str, ec)) << str << " not found !!!"; });
}
TEST_F(DebPkgTests, CheckMetadata) {
string debpkgpath = CrossPlatformUtils::GetEnv("CI_CBUILD_DEB_PKG");
string cmd, del = ", ", substr;
set<string> deplist;
set<string> expectDep = {
"cmake", "ninja-build",
"curl", "libxml2-utils",
"dos2unix", "unzip" };
cmd = "find " + debpkgpath + " -name *.deb";
auto result = CrossPlatformUtils::ExecCommand(cmd.c_str());
ASSERT_FALSE(result.first.empty());
ASSERT_EQ(result.second, 0);
string pkgfile = result.first;
cmd = "dpkg-deb --info " + pkgfile;
auto res = CrossPlatformUtils::ExecCommand(cmd.c_str());
ASSERT_FALSE(res.first.empty());
ASSERT_EQ(res.second, 0);
istringstream f(res.first);
string package, arch, depends, section, priority, homepage;
string line;
while (getline(f, line)) {
if (line.compare(0, 10, " Package: ") == 0) package = line.substr(10, line.length());
else if (line.compare(0, 15, " Architecture: ") == 0) arch = line.substr(15, line.length());
else if (line.compare(0, 10, " Depends: ") == 0) depends = line.substr(10, line.length());
else if (line.compare(0, 10, " Section: ") == 0) section = line.substr(10, line.length());
else if (line.compare(0, 11, " Priority: ") == 0) priority = line.substr(11, line.length());
else if (line.compare(0, 11, " Homepage: ") == 0) homepage = line.substr(11, line.length());
else {
continue;
}
}
ASSERT_EQ(package, "cmsis-build");
ASSERT_EQ(arch, "amd64");
ASSERT_EQ(section, "devel");
ASSERT_EQ(priority, "optional");
ASSERT_EQ(homepage, "https://arm-software.github.io/CMSIS_5/Build/html/index.html");
size_t start, end = 0;
while ((start = depends.find_first_not_of(", ", end)) != std::string::npos) {
end = depends.find(", ", start);
deplist.insert(depends.substr(start, end - start));
}
for_each(expectDep.begin(), expectDep.end(), [&](const string& dep) {
if (deplist.find(dep) == deplist.end()) {
ASSERT_TRUE(false) << "error: dependency [" << dep << "] not found";
}
});
}
TEST_F(DebPkgTests, Extract_Completion) {
error_code ec;
string pkgPath, package, extPath;
pkgPath = CrossPlatformUtils::GetEnv("CI_CBUILD_DEB_PKG");
package = FindPackage(pkgPath);
extPath = testout_folder + "/debextract";
if (fs::exists(extPath, ec)) {
RteFsUtils::RemoveDir(extPath);
}
ExtractPackage(package, extPath);
ValidateExtract(extPath);
}