Here is the Output with Data::Dumper
I have also given the script below
nandi@nandi-laptop:~/begperl$ perl try_expect.pl
Selecting sproc1 CPU
sproc1>
sproc1>loadprg a.out
Endianness of the ELF file:0
.text matched [text segment]
flag = 0x3
.ctors matched [data segment]
flag = 0x3
.dtors matched [data segment]
flag = 0x3
.data matched [data segment]
sproc1>run
Run mode selected
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 28
SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk Count = 1 Cycles
+: 332
$VAR1 = [
1,
undef,
'SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk Count =
+ 1 Cycles : 332',
'loadprg a.out
Endianness of the ELF file:0
.text matched [text segment]
flag = 0x3
.ctors matched [data segment]
flag = 0x3
.dtors matched [data segment]
flag = 0x3
.data matched [data segment]
sproc1>run
Run mode selected
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 32
Buffer Empty = 28
',
'
',
bless( \*Symbol::GEN0, 'Expect' )
];
$VAR1 shows that the pattern has matched in 1 poition ie 0 postion of my @match array
undef indicating no error
then comes the successfully_matching_string
then comes the before_match
finally after_match... But here the after match is empty.. So i gussed it must be "\n"
To verify that i did a print with Match_after in between "Hello World"
As it comes out my guess was right
So expect is sending "\n\n" before simulator finishes execution. So I put a sleep as advised.. :( Didnt work either
Here is the script..
#!/usr/bin/perl
use warnings;
use strict;
use Expect;
use Data::Dumper;
chdir '/home/nandi/simulator/' or die "Can't change directory : $!";
my $expect = Expect->new;
my $command = './simulator/pruthvi.out';
my @parameters = qw(-m 4);
my $timeout = 2;
my @pattern_list;
my @match = "SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk C
+ount = 1 Cycles : 332";
$expect->spawn($command,@parameters ) or die "Cannot spawn : $!\n";
$expect->expect($timeout,"Selecting sproc1 CPU");
$expect->send("\n\n");
$expect->expect($timeout,"sproc1>");
$expect->send("loadprg a.out\n");
$expect->expect($timeout,'sproc1>');
$expect->send("run\n");
@pattern_list = $expect->expect($timeout,@match);
print Dumper(\@pattern_list);
#$expect->expect($timeout,"SWBKPT hit for SLOT");
#my $match_after = $expect->after();
#print "Hello $match_after World";
sleep 3;
$expect->send("\n\n");
#$expect->expect("sproc1>");
#$expect->send("dump mem 74010 4 \n");
#$expect->expect("sproc1>");
#$expect->send("quit\n");
Now what I am supposed to do.. I entered "\n" at the end of string in @match but that too didnt work out.
I think CPAN Expect is not that friendly with Perl compared to Shell. I have no problem running expect in SHELL script. |