summaryrefslogtreecommitdiff
path: root/ACE/bin/PerlACE/TestTarget_WinCE.pm
blob: b4144b9c3444587888df9a8e52ef28efa7e7c042 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env perl
package PerlACE::TestTarget_WinCE;

# ******************************************************************
# Description : Creates a PerlACE::WinCE
# Author      : Johnny Willemsen
# Create Date : 29/20/2008
# ******************************************************************

# ******************************************************************
# Pragma Section
# ******************************************************************

use strict;

use PerlACE::TestTarget;
use PerlACE::ProcessVX;
use File::Copy;
use Cwd;
use English;

our @ISA = qw(PerlACE::TestTarget);

sub new
{
    my $proto = shift;
    my $config_name = shift;
    my $class = ref ($proto) || $proto;
    my $self = {};
    bless ($self, $class);
    $self->GetConfigSettings($config_name);
    my $targethost;
    my $env_name = $config_name.'_IPNAME';
    if (exists $ENV{$env_name}) {
        $targethost = $ENV{$env_name};
    }
    else {
        print STDERR "You must define target hostname/IP with $env_name\n";
        undef $self;
        return undef;
    }

    $env_name = $config_name.'_FS_ROOT';
    my $fsroot = '\network\temp\ACE\wince6';
    if (exists $ENV{$env_name}) {
        $fsroot = $ENV{$env_name};
    }
    else {
        print STDERR "Warning: no $env_name variable; falling back ",
                     "to $fsroot\n";
    }
    $self->{FSROOT} = $fsroot;

    $self->{REBOOT_CMD} = $ENV{'ACE_REBOOT_LVRT_CMD'};
    if (!defined $self->{REBOOT_CMD}) {
        $self->{REBOOT_CMD} = 'I_Need_A_Reboot_Command';
    }
    $self->{REBOOT_TIME} = $ENV{'ACE_LVRT_REBOOT_TIME'};
    if (!defined $self->{REBOOT_TIME}) {
        $self->{REBOOT_TIME} = 200;
    }

    $self->{REBOOT_TIME} = $ENV{'ACE_RUN_LVRT_REBOOT_TIME'};
    if (!defined $self->{REBOOT_TIME}) {
        $self->{REBOOT_TIME} = 200;
    }
    $self->{REBOOT_NEEDED} = undef;

    my $telnet_port = $ENV{'ACE_RUN_VX_TGT_TELNET_PORT'};
    my $telnet_host = $ENV{'ACE_RUN_VX_TGT_TELNET_HOST'};
    if (!defined $telnet_host)  {
      $telnet_host = $ENV{'ACE_RUN_VX_TGTHOST'};
    }
    if (!defined $telnet_port)  {
      $telnet_port = 23;
    }
    if (!defined $self->{HOST_ROOT})  {
      $self->{HOST_ROOT} = $self->{FSROOT};
    }

    $PerlACE::ProcessVX::ExeExt = '.exe';

    return $self;
}

# ******************************************************************
# Subroutine Section
# ******************************************************************

sub LocalFile {
    my $self = shift;
    my $file = shift;
    my $cwdrel = $file;
    my $prjroot = defined $ENV{'ACE_RUN_VX_PRJ_ROOT'} ? $ENV{'ACE_RUN_VX_PRJ_ROOT'}  : $ENV{'ACE_ROOT'};
    if (length ($cwdrel) > 0) {
        $cwdrel = File::Spec->abs2rel( cwd(), $prjroot );
    }
    else {
        $cwdrel = File::Spec->abs2rel( $cwdrel, $prjroot );
    }
    my $newfile = $self->{FSROOT} . "/" . $cwdrel . "/" . $file;
    if (defined $ENV{'ACE_TEST_VERBOSE'}) {
      print STDERR "WinCE LocalFile for $file is $newfile\n";
    }
    return $newfile;
}

sub AddLibPath ($)
{
    my $self = shift;
    my $dir = shift;
    if (defined $ENV{'ACE_TEST_VERBOSE'}) {
        print STDERR "Adding libpath $dir\n";
    }
    PerlACE::add_lib_path ($dir);
}

sub CreateProcess
{
    my $self = shift;
    if ($OSNAME eq "MSWin32") {
        my $process = new PerlACE::ProcessVX ($self, @_);  return $process;
    } else {
        my $process = new PerlACE::ProcessVX (@_, $self);  return $process;
    }
}

# Need a reboot when this target is destroyed.
sub NeedReboot ($)
{
    my $self = shift;
    $self->{REBOOT_NEEDED} = 1;
}

# Reboot target
sub RebootNow ($)
{
    my $self = shift;
    $self->{REBOOT_NEEDED} = undef;
    print STDERR "Attempting to reboot target...\n";
    reboot ();
}

sub WaitForFileTimed ($)
{
    my $self = shift;
    my $file = shift;
    my $timeout = shift;
    my $cwdrel = $file;
    my $prjroot = defined $ENV{'ACE_RUN_VX_PRJ_ROOT'} ? $ENV{'ACE_RUN_VX_PRJ_ROOT'}  : $ENV{'ACE_ROOT'};
    if (length ($cwdrel) > 0) {
        $cwdrel = File::Spec->abs2rel( cwd(), $prjroot );
    }
    else {
        $cwdrel = File::Spec->abs2rel( $cwdrel, $prjroot );
    }
    my $newfile = $self->{HOST_ROOT} . "/" . $cwdrel . "/" . $file;
    if (defined $ENV{'ACE_TEST_VERBOSE'}) {
        print STDERR "WinCE waits for $newfile timeout $timeout\n";
    }
    return PerlACE::waitforfile_timed ($newfile, $timeout);
}

# Put file from a to b
sub PutFile ($)
{
    my $self = shift;
    my $src = shift;
    return 0;
}

sub DeleteFile ($)
{
    my $self = shift;
    my $file = shift;
    my $newfile = $self->LocalFile($file);
    if (defined $ENV{'ACE_TEST_VERBOSE'}) {
        print STDERR "delete $newfile\n";
    }
    unlink ("$newfile");
}

sub KillAll ($)
{
    my $self = shift;
    my $procmask = shift;
    PerlACE::ProcessVX::kill_all ($procmask, $self);
}

1;