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