• No results found

Running an eCos Test Case

In document Ecos User Guide a4 (Page 39-43)

III. Programming With eCos

12. Running an eCos Test Case

Figure 12-2. Properties dialog box

Click OK on this dialog and go back to the Run Tests dialog. Press the Run button and the selected test will be downloaded and run. The Output tab will show you how this is progressing. If it seems to stop for a long time, check that the target board is correctly connected, and that eCos has been correctly configured -- especially the start-up type.

When the program runs you should see a couple of line similar to this appear: PASS:<Binary Semaphore 0 OK>

EXIT:<done>

This indicates that the test has run successfully. SeeChapter 22for further details.

Using the command line

Start a command shell (such as a Cygwin shell window in Windows) with the environment variables set as described in the toolchain documentation. Change to the directory in which you set up your build tree, and invoke GDB on the test program.

To run the bin_sem0 test (which will test the kernel for the correct creation and destruction of binary semaphores) type:

$ TARGET-gdb -nw install/tests/kernel/<version>/tests/bin_sem0

You should see output similar to the following in the command window: GNU gdb THIS-GDB-VERSION

Copyright 2001 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=THIS-HOST --target=THIS-TARGET".

If you are trying to run a synthetic target test on Linux, skip the following connection and download steps. Otherwise, connect to the target by typing:

(gdb) set remotebaud 38400 (gdb) target remote /dev/ttyS0

on Linux or

(gdb) set remotebaud 38400 (gdb) target remote com1

on Windows or (gdb) target sim

to use a simulator in either host O/S.

Check the documentation for the target board for the actual baud rate to use when connecting to real targets. You will see output similar to the following:

Remote debugging using /dev/ttyS1 0x0000d50c in ?? ()

at BASE_DIR/kernel/<version>/src/common/kapi.cxx:345

Current language: auto; currently c++ (gdb)

Or if you are using the simulator: Connected to the simulator. (gdb)

Now download the program to the target with (gdb) load

You should see output similar to the following on your screen: Loading section .text, size 0x4b04 lma 0x108000 Loading section .rodata, size 0x738 lma 0x10cb08 Loading section .data, size 0x1c0 lma 0x10d240 Start address 0x108000, load size 21500

Transfer rate: 24571 bits/sec, 311 bytes/write. (gdb)

You are now ready to run your program. If you type: (gdb) continue

you will see output similar to the following: Continuing.

PASS:<Binary Semaphore 0 OK> EXIT:<done>

Note: If you are using a simulator or the synthetic target rather than real hardware, you must use the GDB

Chapter 12. Running an eCos Test Case

You can terminate your GDB session with Control+C, otherwise it will sit in the “idle” thread and use up CPU time. This is not a problem with real targets, but may have undesirable effects in simulated or synthetic targets. Type quit and you are done.

Testing Filters

While most test cases today run solely in the target environment, some packages may require external testing infrastructure and/or feedback from the external environment to do complete testing.

The serial package is an example of this. The network package also contains some tests that require programs to be run on a host. See the network Tests and Demonstrations section in the network documentation in the

eCos Reference Guide. Here we will concentrate on the serial tests since these are applicable to more targets.

Since the serial line is also used for communication with GDB, a filter is inserted in the communication pathway between GDB and the serial device which is connected to the hardware target. The filter forwards all communication between the two, but also listens for special commands embedded in the data stream from the target.

When such a command is seen, the filter stops forwarding data to GDB from the target and enters a special mode. In this mode the test case running on the target is able to control the filter, commanding it to run various tests. While these tests run, GDB is isolated from the target.

As the test completes (or if the filter detects a target crash) the communication path between GDB and the hardware target is re-established, allowing GDB to resume control.

In theory, it is possible to extend the filter to provide a generic framework for other target-external testing com- ponents, thus decoupling the testing infrastructure from the (possibly limited) communication means provided by the target (serial, JTAG, Ethernet, etc).

Another advantage is that the host tools do not need to know about the various testing environments required by the eCos packages, since all contact with the target continues to happen via GDB.

Applications

The example programs in this tutorial are included, along with aMakefile, in theexamplesdirectory of the eCos distribution. The first program you will run is a hello world-style application, then you will run a more complex application that demonstrates the creation of threads and the use of cyg_thread_delay(), and finally you will run one that uses clocks and alarm handlers.

TheMakefiledepends on an externally defined variable to find the eCos library and header files. This vari- able is INSTALL_DIRand must be set to the pathname of the install directory created in the section called

Configuration Tool on Windows and Linux Quick Start in Chapter 11.

INSTALL_DIRmay be either be set in the shell environment or may be supplied on the command line. To set it in the shell do the following in a bash shell:

$ export INSTALL_DIR=BASE_DIR/ecos-work/arm_install

You can then run make without any extra parameters to build the examples. Alternatively, if you can do the following:

$ make INSTALL_DIR=BASE_DIR/ecos-work/arm_install

eCos Hello World

The following code is found in the filehello.cin theexamplesdirectory:

eCos hello world program listing

/* this is a simple hello world program */ #include <stdio.h>

int main(void) {

printf("Hello, eCos world!\n"); return 0;

}

To compile this or any other program that is not part of the eCos distribution, you can follow the procedures described below. Type this explicit compilation command (assuming your current working directory is also where you built the eCos kernel):

$ TARGET-gcc -g -IBASE_DIR/ecos-work/install/include hello.c -LBASE_DIR/ecos-work/install/lib -Ttarget.ld -nostdlib

The compilation command above contains some standard GCC options (for example, -g enables debugging), as well as some mention of paths (-IBASE_DIR/ecos-work/install/includeallows files like cyg/kernel/kapi.h to be found, and -LBASE_DIR/ecos-work/install/lib allows the linker to find -Ttarget.ld).

The executable program will be calleda.out.

Note: Some target systems require special options to be passed to gcc to compile correctly for that system.

In document Ecos User Guide a4 (Page 39-43)