File: test.pl

package info (click to toggle)
spread 3.17.4-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,800 kB
  • ctags: 2,322
  • sloc: ansic: 15,666; sh: 2,611; java: 2,291; perl: 556; yacc: 523; makefile: 255; lex: 204; xml: 77
file content (164 lines) | stat: -rwxr-xr-x 4,019 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl

# Filename: test.pl
# Author:   Theo Schlossnagle <jesus@cnds.jhu.edu>
# Created:  12th October 1999
# Version:  1.0312
#
# Copyright (c) 1999,2001 Theo Schlossnagle. All rights reserved.
#   This program is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#

use ExtUtils::testlib;
use Spread qw(:SP :MESS :ERROR);

$version = Spread::version();

$| = 1;

$connect = $join = $multicast = $poll = $receive = $leave = $disconnect = 0;
$timeout = undef;
$spreaddaemon = "4803";

$tests = $fails = 0;

while($_ = shift @ARGV) {
  $multicast=1 if(/-m/);
  $receive=1 if(/-r/);
  $join = 1 if(/-j/);
  $poll = 1 if(/-p/);
  $leave = 1 if(/-l/);
  $disconnect = 1 if(/-d/);
  if(/-rt/) {
    $select = shift @ARGV;
    if($select =~ /^-/) {
      unshift(@ARGV,$select);
    } else {
      $timeout = $select;
    }
    $select = 1;
  }
  if(/-c/) {
    $connect = shift @ARGV;
    if($connect =~ /^-/) {
      unshift(@ARGV,$connect);
    } else {
      $spreaddaemon = $connect;
    }
    $connect = 1;
  }
}

print "Spread client library version $version\n";

$args{'spread_name'} = $spreaddaemon;
$args{'private_name'} = "perltest";
$args{'priority'} = 0;
$args{'group_membership'} = 1;

# CONNECT
if($connect) {
print "Trying to connect to spread...\n";
($mbox, $privategroup) = Spread::connect(
	\%args
	);
$tests++;
$fails++ unless defined($mbox);
print "Mailbox is: ".(defined($mbox)?$mbox:"undef")." and ";
print "private_group is ".(defined($privategroup)?$privategroup:"undef")."\n";
print "$sperrno\n" unless defined($mbox);
}

#JOIN
if($join) {
@groups = ('flooder');
print "Attempting to join: ".join(',', @groups).".\n";
@joined = grep (Spread::join($mbox, $_), @groups);
print "Successfully joined: ".scalar(@joined)." of ".scalar(@groups).
  " group(s) [".join(',', @joined)."].\n";
$tests+=scalar(@groups);
$fails+=(scalar(@groups)-scalar(@joined));
}

#MULTICAST
if($multicast) {
$message = "This is a test.";
print "Attempting to multicast ".length($message)." bytes to [@joined[0]].\n";
$tests++;
if(($ret = Spread::multicast($mbox, 
			     SAFE_MESS, @joined[0], 0, $message))>0) {
  print "Successfully multicasted $ret bytes to [@joined[0]]\n";
} else {
  print "Failed multicast to [@joined[0]]: $sperrno\n";
  $fails++;
}
$message =~ s/a/another/;
print "Attempting to multicast ".length($message)." bytes to [".join(',', @joined)."].\n";
$tests++;
if(($ret = Spread::multicast($mbox, 
			     SAFE_MESS, \@joined, 0, $message))>0) {
  print "Successfully multicasted $ret bytes to [".join(',', @joined)."].\n";
} else {
  print "Failed multicast to [".join(',', @joined)."]: $sperrno\n";
  $fails++;
}
}

#POLL
if($poll) {
print "Polling mailbox for messages.\n";
$tests++;
$ans = Spread::poll($mbox);
if(defined($ans)) {
  print "Mailbox contains $ans bytes.\n";
} else {
  print "Poll failed: $sperrno\n";
  $fails++;
}
}

#RECEIVE
if($receive) {
print "Entering receive loop. ".
  (defined($timeout)?"(Timeout = ".$timeout."s)\n":"\n");
$tests++;
$ato=0;
$received=0;
while(($st, $s, $g, $mt, $e, $mess) = (defined($timeout))?Spread::receive($mbox, $timeout):Spread::receive($mbox)) {
 $received++;
 if(!defined($st)) {
   print "Receive error: $Spread::sperrorno\n";
   last;
 }
}
print "Received $received messages.\n";
}

#LEAVE
if($leave) {
print "Attempting to leave: [".join(',', @joined)."].\n";
$tests+=scalar(@joined);
@left = grep (Spread::leave($mbox, $_) ||
	(($lerror{$_} = $sperrno) && 0), @joined);
$fails+=scalar(@joined)-scalar(@left);
print "Successfully left: [".join(',', @left)."].\n" if(scalar(@left));
while(($k, $v) = each %lerror) {
  print "Failed leave for '$k' beacuse of $v\n";
}
}

#DISCONNECT
if($disconnect) {
$tests++;
if(Spread::disconnect($mbox)) {
  print "Successful disconnect\n";
} else {
  print "Unsuccessful disconnect: $sperrno\n";
  $fails++;
}
}
$tests = 1 unless $tests>0;
printf "\n\nTests $tests, passed ".($tests-$fails)."/$tests = %0.2f%%\n\n",
  100.0*($tests-$fails)/$tests;