Status: | Needs review |
---|---|
Proposed branch: | lp:~charlesk/keeper/wtf |
Merge into: | lp:keeper/devel |
Diff against target: |
513 lines (+260/-117) 2 files modified
src/tar/tar-creator.cpp (+123/-64) tests/unit/tar/tar-creator-test.cpp (+137/-53) |
To merge this branch: | bzr merge lp:~charlesk/keeper/wtf |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
unity-api-1-bot | continuous-integration | Approve | |
Unity API Team | Pending | ||
Review via email: mp+305854@code.launchpad.net |
Commit message
Another testing branch for the CI bot, do not review/approve/land
Description of the change
Another testing branch for the CI bot, do not review/approve/land
unity-api-1-bot (unity-api-1-bot) wrote : | # |
- 111. By Charles Kerr
-
split tar-creator-test out from one big test to several more focused tests
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:111
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 112. By Charles Kerr
-
refactor tar-creator-test a bit more to remove redundant code
- 113. By Charles Kerr
-
in tar-creator, fix dtor issue by moving field step_buf_ ahead of step_archive_ in instantiation order
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:113
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 114. By Charles Kerr
-
in TarCreator:
:Impl:: Impl(), remove redundant variable initialization - 115. By Charles Kerr
-
in tar-creator, reintroduce wrapped_
archive_ write_new( ), which is a convenience function that wraps archive_write_new() in a shared_ptr
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:115
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 116. By Charles Kerr
-
in TarCreator:
:Impl:: step(), clear the step_archive_ smart_ptr after the last step is done
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:116
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 117. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_header( ), a helper that calls archive_ write_header( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:117
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 118. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_data( ), a helper that calls archive_ write_data( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:118
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 119. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_close( ), a helper that calls archive_ write_close( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:119
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 120. By Charles Kerr
-
in TarCreator:
:Impl:: step(), fix looping bug that caused too much data to be read in a single pass
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:120
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 121. By Charles Kerr
-
experimental commit: re-introduce TarCreatorFixtu
re::CreateCompr essed
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:121
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 122. By Charles Kerr
-
sync with trunk
- 123. By Charles Kerr
-
in tar-creator-test, add variations of making a tar from an empty file set
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:123
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Unmerged revisions
- 123. By Charles Kerr
-
in tar-creator-test, add variations of making a tar from an empty file set
- 122. By Charles Kerr
-
sync with trunk
- 121. By Charles Kerr
-
experimental commit: re-introduce TarCreatorFixtu
re::CreateCompr essed - 120. By Charles Kerr
-
in TarCreator:
:Impl:: step(), fix looping bug that caused too much data to be read in a single pass - 119. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_close( ), a helper that calls archive_ write_close( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN - 118. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_data( ), a helper that calls archive_ write_data( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN - 117. By Charles Kerr
-
in TarCreator::Impl add wrapped_
archive_ write_header( ), a helper that calls archive_ write_header( ) and handles return values like ARCHIVE_RETRY and ARCHIVE_WARN - 116. By Charles Kerr
-
in TarCreator:
:Impl:: step(), clear the step_archive_ smart_ptr after the last step is done - 115. By Charles Kerr
-
in tar-creator, reintroduce wrapped_
archive_ write_new( ), which is a convenience function that wraps archive_write_new() in a shared_ptr - 114. By Charles Kerr
-
in TarCreator:
:Impl:: Impl(), remove redundant variable initialization
Preview Diff
1 | === modified file 'src/tar/tar-creator.cpp' |
2 | --- src/tar/tar-creator.cpp 2016-09-05 18:38:36 +0000 |
3 | +++ src/tar/tar-creator.cpp 2016-09-17 00:21:32 +0000 |
4 | @@ -48,10 +48,6 @@ |
5 | Impl(const QStringList& filenames, bool compress) |
6 | : filenames_(filenames) |
7 | , compress_(compress) |
8 | - , step_archive_() |
9 | - , step_filenum_(-1) |
10 | - , step_file_() |
11 | - , step_buf_() |
12 | { |
13 | } |
14 | |
15 | @@ -63,15 +59,13 @@ |
16 | bool step(std::vector<char>& fillme) |
17 | { |
18 | step_buf_.resize(0); |
19 | - bool success = true; |
20 | + bool success {true}; |
21 | |
22 | // if this is the first step, create an archive |
23 | if (!step_archive_) |
24 | { |
25 | - step_archive_.reset(archive_write_new(), [](struct archive* a){archive_write_free(a);}); |
26 | - archive_write_set_format_pax(step_archive_.get()); |
27 | - if (compress_) |
28 | - archive_write_add_filter_xz(step_archive_.get()); |
29 | +qDebug() << "new archive"; |
30 | + step_archive_ = wrapped_archive_write_new(compress_); |
31 | archive_write_open(step_archive_.get(), &step_buf_, nullptr, append_bytes_write_cb, nullptr); |
32 | |
33 | step_file_.reset(); |
34 | @@ -86,13 +80,15 @@ |
35 | if (step_filenum_ >= filenames_.size()) // tried to read past the end |
36 | { |
37 | success = false; |
38 | + step_archive_.reset(); |
39 | break; |
40 | } |
41 | |
42 | // step to next file |
43 | if (++step_filenum_ == filenames_.size()) // we made it to the end! |
44 | { |
45 | - archive_write_close(step_archive_.get()); |
46 | +qDebug() << "finished last file, let's close the archive"; |
47 | + wrapped_archive_write_close(step_archive_.get()); |
48 | break; |
49 | } |
50 | |
51 | @@ -110,28 +106,16 @@ |
52 | const auto n = step_file_->read(inbuf, sizeof(inbuf)); |
53 | if (n > 0) // got data |
54 | { |
55 | - for(;;) { |
56 | - if (archive_write_data(step_archive_.get(), inbuf, size_t(n)) != -1) |
57 | - break; |
58 | - const auto err = archive_errno(step_archive_.get()); |
59 | - if (err == ARCHIVE_RETRY) |
60 | - continue; |
61 | - auto errstr = QString::fromUtf8("Error adding data for '%1': %2 (%3)") |
62 | - .arg(step_file_->fileName()) |
63 | - .arg(archive_error_string(step_archive_.get())) |
64 | - .arg(err); |
65 | - qWarning() << qPrintable(errstr); |
66 | - if (err != ARCHIVE_WARN) |
67 | - throw std::runtime_error(errstr.toStdString()); |
68 | - } |
69 | + wrapped_archive_write_data(step_archive_.get(), inbuf, size_t(n), step_file_->fileName()); |
70 | + break; |
71 | } |
72 | else if (n < 0) // read error |
73 | { |
74 | success = false; |
75 | - auto errstr = QStringLiteral("read()ing %1 returned %2 (%3)") |
76 | - .arg(step_file_->fileName()) |
77 | - .arg(n) |
78 | - .arg(step_file_->errorString()); |
79 | + auto const errstr = QStringLiteral("read()ing %1 returned %2 (%3)") |
80 | + .arg(step_file_->fileName()) |
81 | + .arg(n) |
82 | + .arg(step_file_->errorString()); |
83 | qWarning() << errstr; |
84 | throw std::runtime_error(errstr.toStdString()); |
85 | } |
86 | @@ -154,9 +138,9 @@ |
87 | const void * vsource, |
88 | size_t len) |
89 | { |
90 | - auto& target = *static_cast<std::vector<char>*>(vtarget); |
91 | - const auto& source = static_cast<const char*>(vsource); |
92 | - target.insert(target.end(), source, source+len); |
93 | + auto target = static_cast<std::vector<char>*>(vtarget); |
94 | + auto const source = static_cast<const char*>(vsource); |
95 | + target->insert(target->end(), source, source+len); |
96 | return ssize_t(len); |
97 | } |
98 | |
99 | @@ -165,12 +149,13 @@ |
100 | const void *, |
101 | size_t len) |
102 | { |
103 | - *static_cast<ssize_t*>(userdata) += len; |
104 | - return ssize_t(len); |
105 | + auto const sslen = ssize_t(len); |
106 | + *static_cast<ssize_t*>(userdata) += sslen; |
107 | + return sslen; |
108 | } |
109 | |
110 | - static void add_file_header_to_archive(struct archive* archive, |
111 | - const QString& filename) |
112 | + static void add_file_header_to_archive(struct archive * archive, |
113 | + QString const & filename) |
114 | { |
115 | struct stat st; |
116 | const auto filename_utf8 = filename.toUtf8(); |
117 | @@ -180,42 +165,119 @@ |
118 | archive_entry_copy_stat(entry, &st); |
119 | archive_entry_set_pathname(entry, filename_utf8.constData()); |
120 | |
121 | - int ret; |
122 | - do { |
123 | - ret = archive_write_header(archive, entry); |
124 | - if ((ret==ARCHIVE_WARN) || (ret==ARCHIVE_FAILED) || (ret==ARCHIVE_FATAL)) |
125 | - { |
126 | - auto errstr = QString::fromUtf8("Error adding header for '%1': %2 (%3)") |
127 | - .arg(filename) |
128 | - .arg(archive_error_string(archive)) |
129 | - .arg(ret); |
130 | - qWarning() << qPrintable(errstr); |
131 | - if ((ret==ARCHIVE_FATAL) || (ret==ARCHIVE_FAILED)) |
132 | - throw std::runtime_error(errstr.toStdString()); |
133 | - } |
134 | - } while (ret == ARCHIVE_RETRY); |
135 | + wrapped_archive_write_header(archive, entry, filename); |
136 | |
137 | archive_entry_free(entry); |
138 | } |
139 | |
140 | + static void wrapped_archive_write_header(struct archive * archive, |
141 | + struct archive_entry * entry, |
142 | + QString const & source) |
143 | + { |
144 | + for (;;) |
145 | + { |
146 | + auto const err = archive_write_header(archive, entry); |
147 | + if (err == ARCHIVE_OK) |
148 | + break; |
149 | + |
150 | + if (err == ARCHIVE_RETRY) |
151 | + continue; |
152 | + |
153 | + auto const errstr = QStringLiteral("Error adding header for '%1': %2 (%3)") |
154 | + .arg(source) |
155 | + .arg(archive_error_string(archive)) |
156 | + .arg(err); |
157 | + qWarning() << qPrintable(errstr); |
158 | + if (err == ARCHIVE_WARN) |
159 | + break; |
160 | + |
161 | + throw std::runtime_error(errstr.toStdString()); |
162 | + } |
163 | + } |
164 | + |
165 | + static void wrapped_archive_write_data(struct archive * archive, |
166 | + void const * buf_in, |
167 | + size_t bufsize_in, |
168 | + QString const source) |
169 | + { |
170 | + auto bufsize = bufsize_in; |
171 | + auto buf = static_cast<char const*>(buf_in); |
172 | + |
173 | + while (bufsize > 0) |
174 | + { |
175 | + auto const n_written = archive_write_data(archive, buf, bufsize); |
176 | + |
177 | + if (n_written != -1) |
178 | + { |
179 | + bufsize -= n_written; |
180 | + buf += n_written; |
181 | + continue; |
182 | + } |
183 | + |
184 | + auto const err = archive_errno(archive); |
185 | + if (err == ARCHIVE_RETRY) |
186 | + continue; |
187 | + |
188 | + auto const errstr = QStringLiteral("Error adding data for '%1': %2 (%3)") |
189 | + .arg(source) |
190 | + .arg(archive_error_string(archive)) |
191 | + .arg(err); |
192 | + qWarning() << qPrintable(errstr); |
193 | + if (err == ARCHIVE_WARN) |
194 | + continue; |
195 | + |
196 | + throw std::runtime_error(errstr.toStdString()); |
197 | + } |
198 | + } |
199 | + |
200 | + static std::shared_ptr<struct archive> wrapped_archive_write_new(bool compress) |
201 | + { |
202 | + auto archive = archive_write_new(); |
203 | + archive_write_set_format_pax(archive); |
204 | + archive_write_set_bytes_per_block(archive, 0); |
205 | + if (compress) |
206 | + archive_write_add_filter_xz(archive); |
207 | + return std::shared_ptr<struct archive>(archive, [](struct archive* a){archive_write_free(a);}); |
208 | + } |
209 | + |
210 | + static void wrapped_archive_write_close(struct archive* archive) |
211 | + { |
212 | + for (;;) |
213 | + { |
214 | + auto const err = archive_write_close(archive); |
215 | + if (err == ARCHIVE_OK) |
216 | + break; |
217 | + |
218 | + if (err == ARCHIVE_RETRY) |
219 | + continue; |
220 | + |
221 | + auto const errstr = QStringLiteral("Error calling archive_write_close(): %1 (%2)") |
222 | + .arg(archive_error_string(archive)) |
223 | + .arg(err); |
224 | + qWarning() << qPrintable(errstr); |
225 | + if (err == ARCHIVE_WARN) |
226 | + break; |
227 | + |
228 | + throw std::runtime_error(errstr.toStdString()); |
229 | + } |
230 | + } |
231 | + |
232 | ssize_t calculate_uncompressed_size() const |
233 | { |
234 | ssize_t archive_size {}; |
235 | |
236 | - auto a = archive_write_new(); |
237 | - archive_write_set_format_pax(a); |
238 | - archive_write_open(a, &archive_size, nullptr, count_bytes_write_cb, nullptr); |
239 | + auto a = wrapped_archive_write_new(false); |
240 | + archive_write_open(a.get(), &archive_size, nullptr, count_bytes_write_cb, nullptr); |
241 | |
242 | for (const auto& filename : filenames_) |
243 | { |
244 | - add_file_header_to_archive(a, filename); |
245 | + add_file_header_to_archive(a.get(), filename); |
246 | |
247 | // libarchive pads any missing data, |
248 | // so we don't need to call archive_write_data() |
249 | } |
250 | |
251 | - archive_write_close(a); |
252 | - archive_write_free(a); |
253 | + wrapped_archive_write_close(a.get()); |
254 | return archive_size; |
255 | } |
256 | |
257 | @@ -223,14 +285,12 @@ |
258 | { |
259 | ssize_t archive_size {}; |
260 | |
261 | - auto a = archive_write_new(); |
262 | - archive_write_set_format_pax(a); |
263 | - archive_write_add_filter_xz(a); |
264 | - archive_write_open(a, &archive_size, nullptr, count_bytes_write_cb, nullptr); |
265 | + auto a = wrapped_archive_write_new(true); |
266 | + archive_write_open(a.get(), &archive_size, nullptr, count_bytes_write_cb, nullptr); |
267 | |
268 | for (const auto& filename : filenames_) |
269 | { |
270 | - add_file_header_to_archive(a, filename); |
271 | + add_file_header_to_archive(a.get(), filename); |
272 | |
273 | // process the file |
274 | QFile file(filename); |
275 | @@ -242,7 +302,7 @@ |
276 | if (n_read == 0) |
277 | break; |
278 | if (n_read > 0) |
279 | - archive_write_data(a, buf, size_t(n_read)); |
280 | + wrapped_archive_write_data(a.get(), buf, size_t(n_read), filename); |
281 | if (n_read < 0) { |
282 | auto errstr = QStringLiteral("Reading '%1' returned %2 (%3)") |
283 | .arg(file.fileName()) |
284 | @@ -254,18 +314,17 @@ |
285 | } |
286 | } |
287 | |
288 | - archive_write_close(a); |
289 | - archive_write_free(a); |
290 | + wrapped_archive_write_close(a.get()); |
291 | return archive_size; |
292 | } |
293 | |
294 | const QStringList filenames_; |
295 | const bool compress_ {}; |
296 | |
297 | + std::vector<char> step_buf_; |
298 | std::shared_ptr<struct archive> step_archive_; |
299 | int step_filenum_ {-1}; |
300 | QSharedPointer<QFile> step_file_; |
301 | - std::vector<char> step_buf_; |
302 | }; |
303 | |
304 | /** |
305 | |
306 | === modified file 'tests/unit/tar/tar-creator-test.cpp' |
307 | --- tests/unit/tar/tar-creator-test.cpp 2016-09-12 15:28:06 +0000 |
308 | +++ tests/unit/tar/tar-creator-test.cpp 2016-09-17 00:21:32 +0000 |
309 | @@ -48,67 +48,151 @@ |
310 | { |
311 | } |
312 | |
313 | -}; |
314 | - |
315 | -/*** |
316 | -**** |
317 | -***/ |
318 | - |
319 | -TEST_F(TarCreatorFixture, Create) |
320 | -{ |
321 | - static constexpr int n_runs {5}; |
322 | - |
323 | - for (int i=0; i<n_runs; ++i) |
324 | + void test_tar_creation(int min_files, |
325 | + int max_files, |
326 | + int max_filesize, |
327 | + int max_dirs, |
328 | + bool compressed, |
329 | + int n_runs) |
330 | { |
331 | - for (const auto compression_enabled : std::array<bool,2>{false, true}) |
332 | + for (int i=0; i<n_runs; ++i) |
333 | { |
334 | - // build a directory full of random files |
335 | QTemporaryDir in; |
336 | QDir indir(in.path()); |
337 | - FileUtils::fillTemporaryDirectory(in.path()); |
338 | - |
339 | - // create the tar creator |
340 | - EXPECT_TRUE(QDir::setCurrent(in.path())); |
341 | - QStringList files; |
342 | - for (auto file : FileUtils::getFilesRecursively(in.path())) |
343 | - files += indir.relativeFilePath(file); |
344 | - TarCreator tar_creator(files, compression_enabled); |
345 | - |
346 | - // simple sanity check on its size estimate |
347 | - const auto estimated_size = tar_creator.calculate_size(); |
348 | - const auto filesize_sum = std::accumulate( |
349 | + FileUtils::fillTemporaryDirectory(in.path(), min_files, max_files, max_filesize, max_dirs); |
350 | + test_tar_creation(indir, compressed); |
351 | + } |
352 | + } |
353 | + |
354 | + void test_tar_creation(QDir const& in, |
355 | + bool compression_enabled) |
356 | + { |
357 | + qDebug() << Q_FUNC_INFO; |
358 | + |
359 | + // create the tar creator |
360 | + EXPECT_TRUE(QDir::setCurrent(in.path())); |
361 | + QStringList files; |
362 | + for (auto& file : FileUtils::getFilesRecursively(in.path())) { |
363 | + qDebug() << file; |
364 | + files += in.relativeFilePath(file); |
365 | + } |
366 | + TarCreator tar_creator(files, compression_enabled); |
367 | + |
368 | + // test that the size calculator returns a consistent value |
369 | + const auto calculated_size = tar_creator.calculate_size(); |
370 | + for (int i=0, n=5; i<n; ++i) |
371 | + EXPECT_EQ(calculated_size, tar_creator.calculate_size()); |
372 | + |
373 | + // if uncompressed, test that the tar is at least as large as the source files |
374 | + if (!compression_enabled) { |
375 | + auto const filesize_sum = std::accumulate( |
376 | files.begin(), |
377 | files.end(), |
378 | 0, |
379 | [](ssize_t sum, QString const& filename){return sum + QFileInfo(filename).size();} |
380 | ); |
381 | - if (!compression_enabled) |
382 | - ASSERT_GT(estimated_size, filesize_sum); |
383 | - |
384 | - // does it match the actual size? |
385 | - size_t actual_size {}; |
386 | - std::vector<char> contents, step; |
387 | - while (tar_creator.step(step)) { |
388 | - contents.insert(contents.end(), step.begin(), step.end()); |
389 | - actual_size += step.size(); |
390 | - } |
391 | - ASSERT_EQ(estimated_size, actual_size); |
392 | - |
393 | - // untar it |
394 | - QTemporaryDir out; |
395 | - QDir outdir(out.path()); |
396 | - QFile tarfile(outdir.filePath("tmp.tar")); |
397 | - tarfile.open(QIODevice::WriteOnly); |
398 | - tarfile.write(contents.data(), contents.size()); |
399 | - tarfile.close(); |
400 | - QProcess untar; |
401 | - untar.setWorkingDirectory(outdir.path()); |
402 | - untar.start("tar", QStringList() << "xf" << tarfile.fileName()); |
403 | - EXPECT_TRUE(untar.waitForFinished()) << qPrintable(untar.errorString()); |
404 | - |
405 | - // compare it to the original |
406 | - EXPECT_TRUE(tarfile.remove()); |
407 | - EXPECT_TRUE(FileUtils::compareDirectories(in.path(), out.path())); |
408 | - } |
409 | + EXPECT_GT(calculated_size, filesize_sum); |
410 | + } |
411 | + |
412 | + // create the tar |
413 | + size_t actual_size {}; |
414 | + std::vector<char> contents, step; |
415 | + while (tar_creator.step(step)) { |
416 | + contents.insert(contents.end(), step.begin(), step.end()); |
417 | + actual_size += step.size(); |
418 | + } |
419 | + EXPECT_EQ(calculated_size, actual_size); |
420 | + |
421 | + // untar it |
422 | + QTemporaryDir out; |
423 | + QDir const outdir(out.path()); |
424 | + QFile tarfile(outdir.filePath("tmp.tar")); |
425 | + tarfile.open(QIODevice::WriteOnly); |
426 | + tarfile.write(contents.data(), contents.size()); |
427 | + tarfile.close(); |
428 | + QProcess untar; |
429 | + untar.setWorkingDirectory(outdir.path()); |
430 | + untar.start("tar", QStringList() << "xf" << tarfile.fileName()); |
431 | + EXPECT_TRUE(untar.waitForFinished()) << qPrintable(untar.errorString()); |
432 | + |
433 | + // compare it to the original |
434 | + EXPECT_TRUE(tarfile.remove()); |
435 | + EXPECT_TRUE(FileUtils::compareDirectories(in.path(), out.path())); |
436 | } |
437 | +}; |
438 | + |
439 | +/*** |
440 | +**** |
441 | +***/ |
442 | + |
443 | +TEST_F(TarCreatorFixture, CreateUncompressedOfNothing) |
444 | +{ |
445 | + static constexpr int min_files {0}; |
446 | + static constexpr int max_files {min_files}; |
447 | + static constexpr int max_filesize {0}; |
448 | + static constexpr int max_dirs {0}; |
449 | + static constexpr bool compressed {false}; |
450 | + static constexpr int n_runs {5}; |
451 | + |
452 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
453 | +} |
454 | + |
455 | +TEST_F(TarCreatorFixture, CreateCompressedOfNothing) |
456 | +{ |
457 | + static constexpr int min_files {0}; |
458 | + static constexpr int max_files {min_files}; |
459 | + static constexpr int max_filesize {0}; |
460 | + static constexpr int max_dirs {0}; |
461 | + static constexpr bool compressed {true}; |
462 | + static constexpr int n_runs {5}; |
463 | + |
464 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
465 | +} |
466 | + |
467 | +TEST_F(TarCreatorFixture, CreateUncompressedOfSingleFile) |
468 | +{ |
469 | + static constexpr int min_files {1}; |
470 | + static constexpr int max_files {min_files}; |
471 | + static constexpr int max_filesize {1024}; |
472 | + static constexpr int max_dirs {0}; |
473 | + static constexpr bool compressed {false}; |
474 | + static constexpr int n_runs {5}; |
475 | + |
476 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
477 | +} |
478 | + |
479 | +TEST_F(TarCreatorFixture, CreateCompressedOfSingleFile) |
480 | +{ |
481 | + static constexpr int min_files {1}; |
482 | + static constexpr int max_files {min_files}; |
483 | + static constexpr int max_filesize {1024}; |
484 | + static constexpr int max_dirs {0}; |
485 | + static constexpr bool compressed {true}; |
486 | + static constexpr int n_runs {5}; |
487 | + |
488 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
489 | +} |
490 | + |
491 | +TEST_F(TarCreatorFixture, CreateUncompressedOfTree) |
492 | +{ |
493 | + static constexpr int min_files {100}; |
494 | + static constexpr int max_files {min_files}; |
495 | + static constexpr int max_filesize {1024}; |
496 | + static constexpr int max_dirs {10}; |
497 | + static constexpr bool compressed {false}; |
498 | + static constexpr int n_runs {5}; |
499 | + |
500 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
501 | +} |
502 | + |
503 | +TEST_F(TarCreatorFixture, CreateCompressedOfTree) |
504 | +{ |
505 | + static constexpr int min_files {100}; |
506 | + static constexpr int max_files {min_files}; |
507 | + static constexpr int max_filesize {1024}; |
508 | + static constexpr int max_dirs {10}; |
509 | + static constexpr bool compressed {true}; |
510 | + static constexpr int n_runs {5}; |
511 | + |
512 | + test_tar_creation(min_files, max_files, max_filesize, max_dirs, compressed, n_runs); |
513 | } |
FAILED: Continuous integration, rev:110 /jenkins. canonical. com/unity- api-1/job/ lp-keeper- ci/77/ /jenkins. canonical. com/unity- api-1/job/ build/663/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/669 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 484/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 484/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 484 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 484/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/unity- api-1/job/ lp-keeper- ci/77/rebuild
https:/