Skip to content

Commit e1eb8d9

Browse files
committed
Merge pull request swiftlang#26 from seabaylea/dispatch_io
Fix up dispatch_io tests
2 parents 008875a + aa8c21e commit e1eb8d9

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

Diff for: tests/dispatch_io.c

+33-9
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,19 @@ test_io_read_write(void)
240240
{
241241
const char *path_in = "/usr/share/dict/words";
242242
char path_out[] = "/tmp/dispatchtest_io.XXXXXX";
243-
const size_t siz_in = 1024 * 1024;
244243

245244
int in = open(path_in, O_RDONLY);
246245
if (in == -1) {
247246
test_errno("open", errno, 0);
248247
test_stop();
249248
}
249+
struct stat sb;
250+
if (fstat(in, &sb)) {
251+
test_errno("fstat", errno, 0);
252+
test_stop();
253+
}
254+
const size_t siz_in = MIN(1024 * 1024, sb.st_size);
255+
250256
int out = mkstemp(path_out);
251257
if (out == -1) {
252258
test_errno("mkstemp", errno, 0);
@@ -345,6 +351,11 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
345351
{
346352
int fd = open(path, O_RDONLY);
347353
if (fd == -1) {
354+
// Don't stop for access permission issues
355+
if (errno == EACCES) {
356+
process_data(size);
357+
return;
358+
}
348359
test_errno("Failed to open file", errno, 0);
349360
test_stop();
350361
}
@@ -382,16 +393,12 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
382393
break;
383394
case DISPATCH_IO_READ_ON_CONCURRENT_QUEUE:
384395
case DISPATCH_IO_READ_FROM_PATH_ON_CONCURRENT_QUEUE: {
385-
__block bool is_done = false;
386396
__block dispatch_data_t d = dispatch_data_empty;
387397
void (^cleanup_handler)(int error) = ^(int error) {
388398
if (error) {
389399
test_errno("dispatch_io_create error", error, 0);
390400
test_stop();
391401
}
392-
if (!is_done) {
393-
test_long("dispatch_io_read done", is_done, true);
394-
}
395402
close(fd);
396403
process_data(dispatch_data_get_size(d));
397404
dispatch_release(d);
@@ -432,7 +439,6 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
432439
test_stop();
433440
}
434441
}
435-
is_done = done;
436442
});
437443
dispatch_release(io);
438444
break;
@@ -569,12 +575,18 @@ test_io_from_io(void) // rdar://problem/8388909
569575
test_ptr_notnull("mkdtemp failed", path);
570576
test_stop();
571577
}
572-
#ifdef __APPLE__
578+
#ifdef UF_IMMUTABLE
573579
// Make the directory immutable
574580
if (chflags(path, UF_IMMUTABLE) == -1) {
575581
test_errno("chflags", errno, 0);
576582
test_stop();
577583
}
584+
#else
585+
// Make the directory non-read/writeable
586+
if (chmod(path, 0) == -1) {
587+
test_errno("chmod", errno, 0);
588+
test_stop();
589+
}
578590
#endif
579591
*tmp = '/';
580592
dispatch_io_t io = dispatch_io_create_with_path(DISPATCH_IO_RANDOM, path,
@@ -593,7 +605,11 @@ test_io_from_io(void) // rdar://problem/8388909
593605
dispatch_group_enter(g);
594606
dispatch_io_write(io, 0, tdata, q, ^(bool done, dispatch_data_t data_out,
595607
int err_out) {
608+
#ifdef UF_IMMUTABLE
596609
test_errno("error from write to immutable directory", err_out, EPERM);
610+
#else
611+
test_errno("error from write to write protected directory", err_out, EACCES);
612+
#endif
597613
test_long("unwritten data", dispatch_data_get_size(data_out), 256);
598614
if (!err_out && done) {
599615
test_stop();
@@ -605,13 +621,21 @@ test_io_from_io(void) // rdar://problem/8388909
605621
dispatch_release(tdata);
606622
dispatch_release(io);
607623
test_group_wait(g);
608-
// Change the directory to mutable
609624
*tmp = '\0';
625+
#ifdef UF_IMMUTABLE
626+
// Change the directory to mutable
610627
if (chflags(path, 0) == -1) {
611628
test_errno("chflags", errno, 0);
612629
test_stop();
613630
}
614-
const char *path_in = "/dev/random";
631+
#else
632+
// Change the directory to user read/write/execute
633+
if (chmod(path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) {
634+
test_errno("chmod", errno, 0);
635+
test_stop();
636+
}
637+
#endif
638+
const char *path_in = "/dev/urandom";
615639
int in = open(path_in, O_RDONLY);
616640
if (in == -1) {
617641
test_errno("open", errno, 0);

0 commit comments

Comments
 (0)