Skip to content

Commit 89ec24b

Browse files
committed
more tests
1 parent 40c5591 commit 89ec24b

File tree

7 files changed

+142
-20
lines changed

7 files changed

+142
-20
lines changed

src/external.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ size_t external_read_file(struct input *in,
231231
path, strerror(err), err);
232232
free(line);
233233
line = NULL;
234+
len = 0;
234235
continue;
235236
}
236237

src/parallel_cpr.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ static int cpr_file(QPTPool_t *ctx, const size_t id, void *data, void *args) {
182182
static int cpr_link(struct work *work, struct entry_data *ed, struct input *in) {
183183
int rc = 0;
184184

185-
struct stat st;
186-
if (lstat(work->name, &st) != 0) {
187-
const int err = errno;
188-
fprintf(stderr, "Error: Could not lstat link \"%s\": %s (%d)\n",
189-
work->name, strerror(err), err);
190-
rc = 1;
191-
goto cleanup;
192-
}
193-
194185
/* need to give users ability to force overwriting of links */
195186

196187
str_t dst = create_dst_name(in, work);

test/regression/parallel_cpr.expected

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,29 @@ prefix/1KB
110110

111111
$ rm -rf "copy"
112112

113-
$ parallel_cpr "prefix" "prefix"
113+
$ parallel_cpr "prefix" "prefix"
114114
Not copying into itself: "prefix" -> "prefix"
115115

116-
$ parallel_cpr "prefix" "prefix/directory"
116+
$ parallel_cpr "prefix" "prefix/directory"
117117
Not copying into itself: "prefix" -> "prefix/directory"
118118

119-
$ parallel_cpr /dev/null "copy"
119+
$ parallel_cpr "badtrace" "copy"
120+
Error: Cannot lstat "badtrace": No such file or directory (2)
121+
122+
$ parallel_cpr /dev/null "copy"
120123
Not copying "/dev/null"
121124

125+
$ chmod 000 "copy"
126+
127+
$ parallel_cpr "prefix" "copy"
128+
Error: Could not create directory "copy/prefix": Permission denied (13)
129+
130+
$ rm -rf "copy"
131+
132+
$ chmod 000 "baddir"
133+
134+
$ parallel_cpr "baddir" "copy"
135+
Error: Could not open directory "baddir": Permission denied (13)
136+
137+
$ rm -rf "baddir"
138+

test/regression/parallel_cpr.sh.in

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,34 @@ run_no_sort "readlink \"${CPR_ROOT}/file_symlink\""
130130
run_no_sort "rm -rf \"${CPR_ROOT}\""
131131

132132
set +e
133-
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${SRCDIR}\""
134-
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${SRCDIR}/directory\""
135-
run_no_sort "${PARALLEL_CPR} /dev/null \"${CPR_ROOT}\""
133+
# copy into self
134+
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${SRCDIR}\""
135+
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${SRCDIR}/directory\""
136+
137+
# non-existant source
138+
run_no_sort "${PARALLEL_CPR} \"${BADTRACE}\" \"${CPR_ROOT}\""
139+
140+
# non-directory/link/file source
141+
run_no_sort "${PARALLEL_CPR} /dev/null \"${CPR_ROOT}\""
142+
143+
# destination exists, but can't be written to
144+
(
145+
run_no_sort "chmod 000 \"${CPR_ROOT}\""
146+
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${CPR_ROOT}\""
147+
run_no_sort "rm -rf \"${CPR_ROOT}\""
148+
)
149+
150+
# source can't be read
151+
baddir="$(mktemp -d XXXXXX)"
152+
(
153+
run_no_sort "chmod 000 \"${baddir}\""
154+
run_no_sort "${PARALLEL_CPR} \"${baddir}\" \"${CPR_ROOT}\""
155+
156+
run_no_sort "rm -rf \"${baddir}\""
157+
) | sed "s/${baddir}/baddir/g"
158+
136159
set -e
160+
137161
) | tee "${OUTPUT}"
138162

139163
@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/parallel_cpr.expected "${OUTPUT}"

test/regression/parallel_rmr.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ $ ls -1 prefix
2121
db.db
2222
unusual#? directory ,
2323

24+
$ chmod ugo-x "prefix"
25+
26+
$ parallel_rmr -n 2 "prefix"
27+
Error: Could not stat "prefix/db.db": Permission denied
28+
Error: Could not stat "prefix/unusual#? directory ,": Permission denied
29+
Warning: Failed to remove "prefix": Directory not empty
30+
31+
$ chmod ugo+x "prefix"
32+

test/regression/parallel_rmr.sh.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ run_no_sort "${PARALLEL_RMR} -h"
7171
run_sort "ls -1 ${INDEXROOT}"
7272
run_no_sort "${PARALLEL_RMR} -n ${THREADS} \"${INDEXROOT}/directory\" \"${INDEXROOT}/empty_directory\" \"${INDEXROOT}/leaf_directory\""
7373
run_sort "ls -1 ${INDEXROOT}"
74+
75+
run_no_sort "chmod ugo-x \"${INDEXROOT}\""
76+
run_no_sort "${PARALLEL_RMR} -n ${THREADS} \"${INDEXROOT}\""
77+
run_no_sort "chmod ugo+x \"${INDEXROOT}\""
78+
7479
) | tee "${OUTPUT}"
7580

7681
@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/parallel_rmr.expected "${OUTPUT}"

test/unit/googletest/external.cpp.in

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ OF SUCH DAMAGE.
6363

6464

6565
#include <cstddef>
66+
#include <cstdlib>
6667

6768
#include <gtest/gtest.h>
6869

@@ -75,6 +76,49 @@ static size_t bad_filename(char **dst, const size_t dst_size,
7576
return SNPRINTF(*dst, dst_size, "@CMAKE_BINARY_DIR@");
7677
}
7778

79+
TEST(external, read_file) {
80+
const char DEVNULL[] = "/dev/null";
81+
const std::size_t DEVNULL_LEN = strlen(DEVNULL);
82+
83+
struct input in;
84+
in.check_extdb_valid = true;
85+
86+
struct work work;
87+
88+
char filename[] = "XXXXXX";
89+
const int fd = mkstemp(filename);
90+
ASSERT_GE(fd, 0);
91+
EXPECT_EQ(strncpy(work.name, filename, 6), work.name);
92+
EXPECT_EQ(write(fd, DEVNULL, DEVNULL_LEN), (ssize_t) DEVNULL_LEN);
93+
EXPECT_EQ(write(fd, "\n", (std::size_t) 1), (ssize_t) 1);
94+
95+
char extdb_filename[] = "XXXXXX";
96+
const int extdb_fd = mkstemp(extdb_filename);
97+
ASSERT_GE(extdb_fd, 0);
98+
EXPECT_EQ(close(extdb_fd), 0);
99+
EXPECT_EQ(remove(extdb_filename), 0);
100+
EXPECT_EQ(write(fd, extdb_filename, (std::size_t) 6), (ssize_t) 6);
101+
EXPECT_EQ(write(fd, "\n", (std::size_t) 1), (ssize_t) 1);
102+
103+
EXPECT_EQ(close(fd), 0);
104+
105+
EXPECT_EQ(external_read_file(&in, &work,
106+
[](struct input *, void *,
107+
const long long int,
108+
const char *) -> int { return 0; },
109+
nullptr),
110+
(std::size_t) 1);
111+
112+
EXPECT_EQ(remove(filename), 0);
113+
114+
EXPECT_EQ(external_read_file(&in, &work,
115+
[](struct input *, void *,
116+
const long long int,
117+
const char *) -> int { return 0; },
118+
nullptr),
119+
(std::size_t) 0);
120+
}
121+
78122
TEST(external, concatenate) {
79123
// type is used when querying the external database table,
80124
// not for attching the individual external databases
@@ -144,8 +188,8 @@ TEST(external, concatenate) {
144188

145189
external_concatenate_cleanup(db, drop_view,
146190
&type,
147-
NULL,
148-
NULL, NULL
191+
nullptr,
192+
nullptr, nullptr
149193
#if defined(DEBUG) && defined(CUMULATIVE_TIMES)
150194
, &query_count
151195
#endif
@@ -176,8 +220,8 @@ TEST(external, concatenate) {
176220

177221
external_concatenate_cleanup(db, drop_view,
178222
&type,
179-
NULL,
180-
NULL, NULL
223+
nullptr,
224+
nullptr, nullptr
181225
#if defined(DEBUG) && defined(CUMULATIVE_TIMES)
182226
, &query_count
183227
#endif
@@ -200,6 +244,28 @@ TEST(external, concatenate) {
200244
EXPECT_EQ(rc, 0);
201245

202246
external_concatenate_cleanup(db, drop_view,
247+
&type,
248+
nullptr,
249+
nullptr, nullptr
250+
#if defined(DEBUG) && defined(CUMULATIVE_TIMES)
251+
, &query_count
252+
#endif
253+
);
254+
255+
sqlite3_close(db);
256+
257+
// drop view but bad db
258+
external_concatenate_cleanup(nullptr, drop_view,
259+
&type,
260+
nullptr,
261+
nullptr, nullptr
262+
#if defined(DEBUG) && defined(CUMULATIVE_TIMES)
263+
, &query_count
264+
#endif
265+
);
266+
267+
// no drop view, drop type but bad db
268+
external_concatenate_cleanup(nullptr, drop_view,
203269
&type,
204270
NULL,
205271
NULL, NULL
@@ -208,5 +274,14 @@ TEST(external, concatenate) {
208274
#endif
209275
);
210276

211-
sqlite3_close(db);
277+
278+
// no drop view, no type
279+
external_concatenate_cleanup(db, nullptr,
280+
nullptr,
281+
nullptr,
282+
nullptr, nullptr
283+
#if defined(DEBUG) && defined(CUMULATIVE_TIMES)
284+
, &query_count
285+
#endif
286+
);
212287
}

0 commit comments

Comments
 (0)