forked from Open-CMSIS-Pack/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallerTests.cpp
148 lines (122 loc) · 4.86 KB
/
InstallerTests.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
/*
* Copyright (c) 2020-2022 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"
using namespace std;
class InstallerTests : public ::testing::Test {
void SetUp();
protected:
void RunInstallerScript(const string& arg);
void CheckInstallationDir(const string& path, bool expect);
void CheckExtractedDir(const string& path, bool expect);
};
void InstallerTests::SetUp() {
if (CBuildIntegTestEnv::ci_installer_path.empty()) {
GTEST_SKIP();
}
}
void InstallerTests::RunInstallerScript(const string& arg) {
int ret_val;
error_code ec;
ASSERT_EQ(true, fs::exists(scripts_folder + "/installer_run.sh", ec))
<< "error: installer_run.sh not found";
string cmd = "cd " + scripts_folder + " && " + SH + " \"./installer_run.sh " + arg + "\"";
ret_val = system(cmd.c_str());
ASSERT_EQ(ret_val, 0);
}
void InstallerTests::CheckInstallationDir(const string& path, bool expect) {
vector<pair<string, vector<string>>> dirVec = {
#ifdef _WIN32
{ "bin", vector<string>{ "cbuild.sh", "cbuildgen.exe", "cpackget.exe", "csolution.exe"} },
#else
{ "bin", vector<string>{ "cbuild.sh", "cbuildgen", "cpackget", "csolution"} },
#endif
{ "doc", vector<string>{ "index.html", "html"} },
{ "etc", vector<string>{ "AC6.6.18.0.cmake", "CPRJ.xsd",
"GCC.10.3.1.cmake", "IAR.9.32.1.cmake", "setup"} }
};
error_code ec;
EXPECT_EQ(expect, fs::exists(path, ec)) << "Path " << path << " does "
<< (expect ? "not " : "") << "exist!";
for (auto dirItr = dirVec.begin(); dirItr != dirVec.end(); ++dirItr) {
for (auto fileItr = dirItr->second.begin(); fileItr != dirItr->second.end(); ++fileItr) {
EXPECT_EQ(expect, fs::exists(path + "/" + dirItr->first + "/" + (*fileItr), ec))
<< "File " << (*fileItr) << " does " << (expect ? "not " : "") << "exist!";
}
}
EXPECT_EQ(expect, fs::exists(path + "/LICENSE.txt", ec))
<< "File LICENSE.txt does " << (expect ? "not " : "") << "exist!";
}
void InstallerTests::CheckExtractedDir(const string& path, bool expect) {
vector<pair<string, vector<string>>> dirVec = {
{ "bin", vector<string>{ "cbuild.sh",
"cbuild.lin-amd64", "cbuild.exe-amd64",
"cpackget.lin-amd64", "cpackget.exe-amd64",
"cbuildgen.lin-amd64", "cbuildgen.exe-amd64",
"csolution.lin-amd64", "csolution.exe-amd64",
"cbuild.lin-arm64",
"cpackget.lin-arm64",
"cbuildgen.lin-arm64",
"csolution.lin-arm64"} },
{ "doc", vector<string>{ "index.html", "html"} },
{ "etc", vector<string>{ "AC6.6.18.0.cmake", "CPRJ.xsd",
"GCC.10.3.1.cmake", "IAR.9.32.1.cmake", "setup"} }
};
error_code ec;
EXPECT_EQ(expect, fs::exists(path, ec)) << "Path "<< path << " does " << (expect ? "not " : "") << "exist!";
for (auto dirItr = dirVec.begin(); dirItr != dirVec.end(); ++dirItr) {
for (auto fileItr = dirItr->second.begin(); fileItr != dirItr->second.end(); ++fileItr) {
EXPECT_EQ(expect, fs::exists(path + "/" + dirItr->first + "/" + (*fileItr), ec))
<< "File " << (*fileItr) << " does " << (expect ? "not " : "") << "exist!";
}
}
EXPECT_EQ(expect, fs::exists(path + "/LICENSE.txt", ec))
<< "File LICENSE.txt does " << (expect ? "not " : "") << "exist!";
}
// Test installer with Invalid arguments
TEST_F(InstallerTests, InvalidArgTest) {
string installDir = testout_folder + "/Installation";
string arg = "--testoutput=" + testout_folder + " -Invalid";
RteFsUtils::RemoveDir(installDir);
RunInstallerScript (arg);
CheckInstallationDir (installDir, true);
}
// Run installer with help command
TEST_F(InstallerTests, InstallerHelpTest) {
string installDir = testout_folder + "/Installation";
string arg = "--testoutput=" + testout_folder + " -h";
RteFsUtils::RemoveDir(installDir);
RunInstallerScript (arg);
CheckInstallationDir (installDir, false);
}
// Run installer with version command
TEST_F(InstallerTests, InstallerVersionTest) {
string installDir = testout_folder + "/Installation";
string arg = "--testoutput=" + testout_folder + " -v";
RteFsUtils::RemoveDir(installDir);
RunInstallerScript (arg);
CheckInstallationDir (installDir, false);
}
// Validate installer extract option
TEST_F(InstallerTests, InstallerExtractTest) {
string arg = "--testoutput=" + testout_folder + " -x " +
testout_folder + "/Installation/ExtractOut";
string extractDir = testout_folder + "/Installation/ExtractOut";
RteFsUtils::RemoveDir(extractDir);
RunInstallerScript (arg);
CheckExtractedDir (extractDir, true);
}
// Validate installation and post installation content
TEST_F(InstallerTests, ValidInstallationTest) {
string installDir = testout_folder + "/Installation";
string arg = "--testoutput=" + testout_folder;
RteFsUtils::RemoveDir(installDir);
RunInstallerScript (arg);
CheckInstallationDir (installDir, true);
}