3 # Test interaction of threads and directory handles.
12 if (!$Config::Config{useithreads}) {
13 print "1..0 # Skip: no ithreads\n";
16 if ($ENV{PERL_CORE_MINITEST}) {
17 print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
29 use File::Spec::Functions qw 'updir catdir';
32 # Basic sanity check: make sure this does not crash
33 fresh_perl_is <<'# this is no comment', 'ok', {}, 'crash when duping dirh';
36 async{}->join for 1..2;
48 if(!$Config::Config{d_fchdir} && $^O ne "MSWin32") {
49 $::TODO = 'dir handle cloning currently requires fchdir on non-Windows platforms';
52 my @w :shared; # warnings accumulator
53 local $SIG{__WARN__} = sub { push @w, $_[0] };
55 $dir = catdir getcwd(), "thrext$$" . int rand() * 100000;
60 # Create a dir structure like this:
74 {open my $fh, ">thrit" or &$skip("Cannot create file thrit")}
75 {open my $fh, ">rile" or &$skip("Cannot create file rile")}
76 {open my $fh, ">zor" or &$skip("Cannot create file zor")}
79 # Then test that dir iterators are cloned correctly.
81 opendir my $toberead, 'toberead';
82 my $start_pos = telldir $toberead;
83 my @first_2 = (scalar readdir $toberead, scalar readdir $toberead);
84 my @from_thread = @{; async { [readdir $toberead ] } ->join };
85 my @from_main = readdir $toberead;
86 is join('-', sort @from_thread), join('-', sort @from_main),
87 'dir iterator is copied from one thread to another';
89 join('-', "", sort(@first_2, @from_thread), ""),
90 qr/(?<!-rile)-rile-thrit-zor-(?!zor-)/i,
91 'cloned iterator iterates exactly once over everything not already seen';
93 seekdir $toberead, $start_pos;
94 readdir $toberead for 1 .. @first_2+@from_thread;
96 local $::TODO; # This always passes when dir handles are not cloned.
98 async { readdir $toberead // 'undef' } ->join, 'undef',
99 'cloned dir iterator that points to the end of the directory'
103 # Make sure the cloning code can handle file names longer than 255 chars
107 ">floccipaucinihilopilification-"
108 . "pneumonoultramicroscopicsilicovolcanoconiosis-"
109 . "lopadotemachoselachogaleokranioleipsanodrimypotrimmatosilphiokarabo"
110 . "melitokatakechymenokichlepikossyphophattoperisteralektryonoptokephal"
111 . "liokinklopeleiolagoiosiraiobaphetraganopterygon"
114 skip("OS does not support long file names (and I mean *long*)", 1);
116 opendir my $dirh, "toberead";
118 = "dir iterators can be cloned when the next fn > 255 chars";
120 my $pos = telldir $dirh;
121 my $fn = readdir($dirh);
122 if(!defined $fn) { fail($test_name); last SKIP; }
123 if($fn =~ 'lagoio') {
128 is length async { scalar readdir $dirh } ->join, 258, $test_name;
131 is scalar @w, 0, 'no warnings during all that' or diag @w;