tests: Introduce afstest.pm
[openafs.git] / tests / rx / perf-t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
6
7 use afstest qw(obj_path);
8 use Test::More tests=>4;
9 use POSIX qw(:sys_wait_h :signal_h);
10
11 my $port = 4000;
12 my $rxperf = obj_path("src/tools/rxperf/rxperf");
13
14 # Start up an rxperf server
15
16 my $pid = fork();
17 if ($pid == -1) {
18     fail("Failed to fork rxperf server");
19     exit(1);
20 } elsif ($pid == 0) { 
21     exec({$rxperf}
22          "rxperf", "server", "-p", $port, "-u", "1024", "-H", "-N");
23     die("Kabooom ?");
24 }
25 pass("Started rxperf server");
26
27 # Start up an rxperf client, and run a test
28 is(0, 
29    system("$rxperf client -c rpc -p $port -S 1048576 -R 1048576 -T 30 -u 1024 -H -N"),
30    "single threaded client ran successfully");
31
32 is (0,
33     system("$rxperf client -c rpc -p $port -S 1048576 -R 1048576 -T 1 -t 30 -u 1024 -H -N"),
34     "multi threaded client ran succesfully");
35
36 # Kill the server, and check its exit code
37
38 kill("TERM", $pid);
39 waitpid($pid, 0);
40 my $ecode = ${^CHILD_ERROR_NATIVE};
41 if (WIFSIGNALED($ecode) && WTERMSIG($ecode) != SIGTERM) {
42     fail("Server died with signal ".WTERMSIG($ecode));
43 } elsif (WIFEXITED($ecode) && WEXITSTATUS($ecode) != 0) {
44     fail("Server exited with code". WEXITSTATUS($ecode));
45 } else {
46     pass("Server exited succesfully");
47 }
48
49