From 46aa4e29fb2081dcf55f6d9df4134c72b13cd6ee Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 25 Nov 2007 23:25:49 +0000 Subject: [PATCH] r276@brr: dpavlin | 2007-11-25 22:04:35 +0100 helper script to create tests from dumps git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@231 836a5e1a-633d-0410-964b-294494ad4392 --- bin/dump2test.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 bin/dump2test.pl diff --git a/bin/dump2test.pl b/bin/dump2test.pl new file mode 100755 index 0000000..40edb4d --- /dev/null +++ b/bin/dump2test.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w + +# dump2test.pl +# +# convert dump from one CPE to test files + +use strict; +use File::Find; +use File::Path qw/mkpath/; +use Data::Dump qw/dump/; +use File::Slurp; +use blib; +use CWMP::Request; + +my $path = shift @ARGV || die "usage: $0 dump/client_ip/\n"; + +my $requests; + +find({ + no_chdir => 1, + wanted => sub { + my $path = $File::Find::name; + + return unless -l $path; + + if ( $path =~ m!\d+-(.+)!) { + my $name = $1; + $requests->{$name} = $path; + } else { + warn "can't find request name in $path\n"; + } + + } +}, $path); + +warn "## requests = ",dump( $requests ); + +my $test_path = 't/dump/'; + +if ( my $i = $requests->{Inform} ) { + + my $xml = read_file($i); + $xml =~ s/^.*?parse( $xml ); + +# warn "## state = ",dump( $state ); + + $test_path .= + $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.HardwareVersion'} + . '/' . + $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.SoftwareVersion'} + ; + +} else { + die "need Inform found ", dump( $requests ); +} + +mkpath $test_path unless -e $test_path; + +warn "dumping new tests into $test_path\n"; + +foreach my $name ( keys %$requests ) { + my $from = $requests->{$name}; + my $to = "$test_path/$name"; + warn "## $from -> $to\n"; + next if -e $to; + write_file( $to, read_file( $from ) ); + warn "created $to\n"; +} -- 2.20.1