1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
5
>A first remote test</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
12
HREF="book1.html"><LINK
14
TITLE="Getting DejaGnu up and running"
15
HREF="c203.html"><LINK
17
TITLE="Our first automated tests"
18
HREF="x276.html"><LINK
21
HREF="c401.html"></HEAD
32
SUMMARY="Header navigation table"
41
>DejaGnu: The GNU Testing Framework</TH
51
><<< Previous</A
57
>Getting DejaGnu up and running</TD
65
>Next >>></A
79
>A first remote test</H1
81
>Testing remote targets is a lot trickier especially if you are using an
83
which has no built in support for things like a compiler, ftp server or a Bash-shell.
84
Before you can test calc on a remote target you have to acquire a few basics skills.</P
92
>Setup telnet to your own host</H2
94
>The easiest remote host is usually the host you are working on.
95
In this example we will use telnet to login in your own workstation.
96
For security reason you should never have a telnet deamon running on
97
machine connected on the internet, as password and usernames are transmitted
99
We assume you know how to setup your machine for a telnet daemon.</P
101
>Next try whether you may login in your own host by issuing the
102
command “telnet localhost.1”. In order to be able to
103
distinguish between a normal session an a telnet login add the following lines to /home/dgt/.bashrc.</P
111
CLASS="PROGRAMLISTING"
112
>if [ "$REMOTEHOST" ]
120
>Now on the machine a “remote” login looks like this:</P
128
>Example 11. Sample log of a telnet login to localhost</B
137
CLASS="PROGRAMLISTING"
138
>dgt:~/dejagnu.test$ telnet localhost
140
Connected to 127.0.0.1.
141
Escape character is '^]'.
142
Debian GNU/Linux testing/unstable Linux
145
Last login: Sun Nov 25 22:46:34 2001 from localhost on pts/4
146
Linux K6Linux 2.4.14 #1 Fre Nov 16 19:28:25 CET 2001 i586 unknown
150
Connection closed by foreign host.</PRE
163
>A test case for login via telnet</H2
165
>In order to define a correct setup we have add a line containing
166
“set target unix” either to ~/.dejagnurc or to ~/my_dejagnu.exp.
167
In ~/boards/standard.exp add the following four lines to define a few patterns for the DejaGnu telnet login procedure.</P
175
>Example 12. Defining a remote target board</B
184
CLASS="PROGRAMLISTING"
185
>set_board_info shell_prompt "remote:"
186
set_board_info telnet_username "dgt"
187
set_board_info telnet_password "top_secret"
188
set_board_info hostname "localhost" </PRE
194
>As DejaGnu will be parsing the telnet session output for some well
195
known pattern the output there are a lot of things that can go wrong.
196
If you have any problems verify your setup:</P
223
>The LANG environment variable must be either empty or set to “C”. </P
227
>To test the login via telnet write a sample test case.
228
Create the file ~/dejagnu.test/testsuite/calc.test/remote_echo.exp and
229
add the following few lines:</P
237
>Example 13. DejaGnu script for logging in into a remote target</B
246
CLASS="PROGRAMLISTING"
247
>puts "this is remote_echo.exp target for $target "
250
set shell_id [remote_open $target]
251
set test "Remote login to $target"
253
puts "Spawn id for remote shell is $shell_id"
254
if { $shell_id > 0 } {
257
fail "Remote open to $target"
264
>In the runtest output you should find something like:</P
272
CLASS="PROGRAMLISTING"
273
>Running ./testsuite/calc.test/local_echo.exp ...
274
Running ./testsuite/calc.test/remote_echoo.exp ...
275
this is remote_echo.exp target is unix
276
Spawn id for remote shell is exp7</PRE
281
>Have again a look at calc.log to get a feeling how DejaGnu and expect
291
>Remote testing “Hello world”</H2
293
>Next you will transform the above “hello world” example to
294
its remote equivalent.
295
This can be done by adding the following lines to our file remote_echo.exp.</P
303
>Example 14. A first (local) remote "Hello world" test</B
312
CLASS="PROGRAMLISTING"
313
>set test "Remote_send Hello World"
314
set status [remote_send $target "echo \"Hello\" \"World\"\n" ]
316
set test "Remote_expect Hello World"
317
remote_expect $target 5 {
318
-re "Hello World" { pass "$test" }
325
>Call make check. The output should contain
326
“# of expected passes 9” and “# of unexcpected failures 1”.</P
328
>Have a look at the procedures in /usr/share/dejagnu/remote.exp to have an overview of the offered procedures and their features. </P
330
>Now setup a real target.
331
In the following example we assume as target a PowerBook running Debian.
332
As above add a test user "dgt", install telnet and FTP servers.
333
In order to distinguish it from the host add the line
341
CLASS="PROGRAMLISTING"
342
>PS1='test:>'</PRE
346
> to /home/dgt/.bash_profile.
347
Also add a corresponding entry "powerbook" to /etc/hosts and verify that you
348
are able to ping, telnet and ftp to the target "powerbook".</P
350
>In order to let runtest run its test on the "powerbook" target change the following lines in ~/boards/standard.exp:</P
358
>Example 15. Board definition for a remote target</B
367
CLASS="PROGRAMLISTING"
368
>set_board_info protocol "telnet"
369
set_board_info telnet_username "dgt"
370
set_board_info telnet_password "top_secret"
371
set_board_info shell_prompt "test:> "
372
set_board_info hostname "powerbook"</PRE
378
>Now call runtest again with the same arguments and verify whether all went okay by taking a close look at calc.log.</P
387
>Transferring files from/to the target</H2
389
>A simple procedure like this will do the job for you:</P
397
>Example 16. Test script to transfer a file to a remote target</B
406
CLASS="PROGRAMLISTING"
407
>set test "Remote_download"
408
puts "Running Remote_download"
410
set remfile /home/dgt/dejagnu2
412
set status [remote_download $target /home/dgt/.dejagnurc $remfile]
413
if { "$status" == "" } {
414
fail "Remote download to $remfile on $target"
419
puts "status of remote_download ist $status"
426
>After running runtest again, check whether the file dejagnu2 exists on the target.
428
This example will only work if the rcp command works with your target.
430
If you have a working FTP-server on the target you can use it by adding the
431
following lines to ~/boards/standard.exp:</P
439
>Example 17. Defining a board to use FTP as file transport</B
448
CLASS="PROGRAMLISTING"
449
>set_board_info file_transfer "ftp"
450
set_board_info ftp_username "dgt"
451
set_board_info ftp_password "1234"</PRE
464
>Preparing for crosscompilation</H2
466
>For crosscompiling you need working binutils, gcc and a base library like
467
libc or glib for your target.
468
It is beyond the scope of this document to describe how to get it working.
469
The following examples assume a cross compiler for PowerPC which is called linux-powerpc-gcc.</P
471
>Add AC_CANONICAL_TARGET in dejagnu.test/configure.in at the following location. Copy config.guess from /usr/share/automake to dejagnu.test.</P
479
CLASS="PROGRAMLISTING"
480
>AM_CONFIG_HEADER(calc.h)
481
AC_CANONICAL_TARGET([])
482
AM_INIT_AUTOMAKE(calc, 1.1)</PRE
487
>You need to run automake 2.5 or later.
488
Depending on your installation calling autoconf2.5 instead of autoconf is not needed.
489
The sequence to regenerate all files is:</P
497
>Example 18. Using autotools for cross development</B
506
CLASS="PROGRAMLISTING"
510
$ ./configure --host=powerpc-linux --target=powerpc-linux
511
configure: WARNING: If you wanted to set the --build type, don't use --host.
512
If a cross compiler is detected then cross compile mode will be used.
513
checking build system type... ./config.guess: ./config.guess: No such file or directory
514
configure: error: cannot guess build type; you must specify one
515
$ cp /usr/share/automake/config.guess .
516
$ ./configure --host=powerpc-linux --target=powerpc-linux
517
configure: WARNING: If you wanted to set the --build type, don't use --host.
518
If a cross compiler is detected then cross compile mode will be used. \
519
checking build system type... i586-pc-linux-gnu
520
checking host system type... powerpc-unknown-linux-gnu
522
checking whether we are cross compiling... yes
525
Source code location: .
526
C Compiler: powerpc-linux-gcc
527
C Compiler flags: -g -O2 </PRE
533
>Everything should be ready to recompile for the target:</P
541
CLASS="PROGRAMLISTING"
543
powerpc-linux-gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c calc.c
544
powerpc-linux-gcc -g -O2 -o calc calc.o </PRE
556
>Remote testing of calc</H2
558
>Not yet written, as I have problem getting libc6-dev-powerpc to work. Probably I first have to build my cross compiler. </P
567
>Using Windows as host and vxWorks as target</H2
569
>A more thorough walk-through will be written in a few weeks.</P
571
>In order to test the vxWorks as a target I changed boards/standards.exp to reflect my settings (IP, username, password). Then I reconfigured vxWorks to include a FTP and telnet server (using the same username/password combination ad in boards/standard.exp).</P
573
>With this setup and some minor modification (e.g. replacing echo by printf) in my test cases I could test my vxWorks system. It sure does not seem to be a correct setup by DejaGnu standard. For instance, it still loading /usr/share/dejagnu/baseboards/unix.exp instead of vxWorks. In any case I found that (at least under Windows) I did not find out how the command line would let me override settings in my personal config files.</P
581
SUMMARY="Footer navigation table"
594
><<< Previous</A
612
>Next >>></A
620
>Our first automated tests</TD
b'\\ No newline at end of file'