]>
The Tcpdump Group git mirrors - libpcap/blob - testprogs/TESTmt.pm
b7152e0e399f77e1910ec9482acbbfd39fefee65
1 require 5.10.1; # Debian 6
3 use warnings FATAL
=> qw(uninitialized);
7 # TESTrun helper functions (multithreaded implementation).
22 print "INFO: This Perl supports threads, using $njobs tester thread(s).\n";
25 # Iterate over the list of tests, pick tests that belong to the current job,
26 # run one test at a time and send the result to the job's results queue.
27 sub tester_thread_func
{
29 $tmpid = sprintf 'job%03u', $jobid;
30 for (my $i = $jobid; $i < scalar @tests; $i += $njobs) {
31 my $test = $tests[$i];
32 my $result = $test->{func
} ($test);
33 $result->{label
} = $test->{label
};
34 $result_queues[$jobid]->enqueue ($result);
36 # Instead of detaching let the receiver join, this works around File::Temp
38 # No Thread::Queue->end() in Perl 5.10.1, so use an undef to mark the end.
39 $result_queues[$jobid]->enqueue (undef);
44 for (0 .. $njobs - 1) {
45 $result_queues[$_] = Thread
::Queue
->new;
46 $tester_threads[$_] = threads
->create (\
&tester_thread_func
, $_);
51 # Here ordering of the results is the same as ordering of the tests because
52 # this function starts at job 0 and continues round-robin, which reverses the
53 # interleaving done in the thread function above; also because every attempt
54 # to dequeue blocks until it returns exactly one result.
56 for (0 .. $njobs - 1) {
57 my $jobid = $next_to_dequeue;
58 $next_to_dequeue = ($next_to_dequeue + 1) % $njobs;
59 # Skip queues that have already ended.
60 next unless defined $result_queues[$jobid];
61 my $result = $result_queues[$jobid]->dequeue;
63 return $result if defined $result;
64 # No, an end-of-queue marker.
65 $result_queues[$jobid] = undef;
66 $tester_threads[$jobid]->join;
68 # No results after one complete round, therefore done.