/[cwmp]/google/trunk/bin/dump2test.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /google/trunk/bin/dump2test.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 232 - (show annotations)
Sun Nov 25 23:25:49 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 1344 byte(s)
 r276@brr:  dpavlin | 2007-11-25 22:04:35 +0100
 helper script to create tests from dumps

1 #!/usr/bin/perl -w
2
3 # dump2test.pl
4 #
5 # convert dump from one CPE to test files
6
7 use strict;
8 use File::Find;
9 use File::Path qw/mkpath/;
10 use Data::Dump qw/dump/;
11 use File::Slurp;
12 use blib;
13 use CWMP::Request;
14
15 my $path = shift @ARGV || die "usage: $0 dump/client_ip/\n";
16
17 my $requests;
18
19 find({
20 no_chdir => 1,
21 wanted => sub {
22 my $path = $File::Find::name;
23
24 return unless -l $path;
25
26 if ( $path =~ m!\d+-(.+)!) {
27 my $name = $1;
28 $requests->{$name} = $path;
29 } else {
30 warn "can't find request name in $path\n";
31 }
32
33 }
34 }, $path);
35
36 warn "## requests = ",dump( $requests );
37
38 my $test_path = 't/dump/';
39
40 if ( my $i = $requests->{Inform} ) {
41
42 my $xml = read_file($i);
43 $xml =~ s/^.*?</</s;
44
45 # warn "## xml: $xml\n";
46
47 my $state = CWMP::Request->parse( $xml );
48
49 # warn "## state = ",dump( $state );
50
51 $test_path .=
52 $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.HardwareVersion'}
53 . '/' .
54 $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.SoftwareVersion'}
55 ;
56
57 } else {
58 die "need Inform found ", dump( $requests );
59 }
60
61 mkpath $test_path unless -e $test_path;
62
63 warn "dumping new tests into $test_path\n";
64
65 foreach my $name ( keys %$requests ) {
66 my $from = $requests->{$name};
67 my $to = "$test_path/$name";
68 warn "## $from -> $to\n";
69 next if -e $to;
70 write_file( $to, read_file( $from ) );
71 warn "created $to\n";
72 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26