File: Child.pm

package info (click to toggle)
proftpd-dfsg 1.3.8.c%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 56,576 kB
  • sloc: perl: 286,353; ansic: 241,458; sh: 16,680; php: 11,586; makefile: 1,092; xml: 93
file content (84 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (8)
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
package ProFTPD::TestSuite::Child;

use base qw(Test::Unit::TestCase);
use strict;

use Carp;
use File::Path qw(mkpath rmtree);
use POSIX qw(:sys_wait_h);

use ProFTPD::TestSuite::Utils qw(:testsuite);

my $processes = {};

sub sig_chld {
  my $child;

  while (($child = waitpid(-1, 0)) > 0) {
    $processes->{$child} = ($? >> 8);
  }

  $SIG{CHLD} = \&sig_chld;
}

sub handle_sigchld {
  my $self = shift;
  $SIG{CHLD} = \&sig_chld;
}

sub assert_child_ok {
  my $self = shift;
  my $pid = shift;

  my ($pkg, $file, $lineno, $func, @rest) = caller(1);

  $self->assert($processes->{$pid} == 0,
    "Child test process $pid failed in $func (line $lineno) [see above for possible errors]");
}

sub assert_transfer_ok {
  my $self = shift;
  my $resp_code = shift;
  my $resp_msg = shift;
  my $aborted = shift;
  $aborted = 0 unless $aborted;

  if ($resp_code == 226) {
    my $expected = "Transfer complete";
    if ($aborted) {
      $expected = "Abort successful";
    }

    if ($expected ne $resp_msg) {
      croak("Expected response message '$expected', got '$resp_msg'");
    }

  } elsif ($resp_code == 150) {
    my $expected = "Opening .*? mode data connection";
    if ($resp_msg !~ /$expected/) {
      croak("Expected response message '$expected', got '$resp_msg'");
    }

  } else {
    croak("Expected response code 150 or 226, got $resp_code");
  }
}

sub set_up {
  my $self = shift;

  # Create temporary scratch dir
  $self->{tmpdir} = testsuite_get_tmp_dir();
}

sub tear_down {
  my $self = shift;

  # Remove temporary scratch dir
  if ($self->{tmpdir} &&
      !$ENV{KEEP_TMPFILES}) {
    eval { rmtree($self->{tmpdir}) };
  }
}

1;