]>
The Tcpdump Group git mirrors - libpcap/blob - testprogs/TESTmt.pm
2 use warnings FATAL
=> qw(uninitialized);
6 # TESTrun helper functions (multithreaded implementation).
21 print "INFO: This Perl supports threads, using $njobs tester thread(s).\n";
24 # Iterate over the list of tests, pick tests that belong to the current job,
25 # run one test at a time and send the result to the job's results queue.
26 sub tester_thread_func
{
28 $tmpid = sprintf 'job%03u', $jobid;
29 for (my $i = $jobid; $i < scalar @tests; $i += $njobs) {
30 my $result = $tests[$i]{func
} ($tests[$i]->%*);
31 $result->{label
} = $tests[$i]{label
};
32 $result_queues[$jobid]->enqueue ($result);
34 # Instead of detaching let the receiver join, this works around File::Temp
36 $result_queues[$jobid]->end;
41 for (0 .. $njobs - 1) {
42 $result_queues[$_] = Thread
::Queue
->new;
43 $tester_threads[$_] = threads
->create (\
&tester_thread_func
, $_);
48 # Here ordering of the results is the same as ordering of the tests because
49 # this function starts at job 0 and continues round-robin, which reverses the
50 # interleaving done in the thread function above; also because every attempt
51 # to dequeue blocks until it returns exactly one result or reaches the end of
54 for (0 .. $njobs - 1) {
55 my $result = $result_queues[$next_to_dequeue]->dequeue;
56 $next_to_dequeue = ($next_to_dequeue + 1) % $njobs;
57 return $result if defined $result;
59 # All queues have ended.
60 $_->join foreach @tester_threads;