1 /* =================================================================
5 * Test program for the object loader.
7 * =================================================================
8 * ####ECOSGPLCOPYRIGHTBEGIN####
9 * -------------------------------------------
10 * This file is part of eCos, the Embedded Configurable Operating
12 * Copyright (C) 2005 eCosCentric Ltd.
14 * eCos is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 or (at your option)
19 * eCos is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with eCos; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 * As a special exception, if other files instantiate templates or
29 * use macros or inline functions from this file, or you compile this
30 * file and link it with other works to produce a work based on this
31 * file, this file does not by itself cause the resulting work to be
32 * covered by the GNU General Public License. However the source code
33 * for this file must still be made available in accordance with
34 * section (3) of the GNU General Public License.
36 * This exception does not invalidate any other reasons why a work
37 * based on this file might be covered by the GNU General Public
40 * -------------------------------------------
41 * ####ECOSGPLCOPYRIGHTEND####
42 * =================================================================
43 * #####DESCRIPTIONBEGIN####
45 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
50 * ####DESCRIPTIONEND####
52 * =================================================================
55 #include <pkgconf/system.h>
56 #include <cyg/kernel/kapi.h> // Kernel API.
57 #include <cyg/infra/diag.h> // For diagnostic printing.
58 #include <cyg/infra/testcase.h>
68 #include <cyg/objloader/elf.h>
69 #include <cyg/objloader/objelf.h>
71 #ifdef CYGPKG_IO_FILEIO
72 #include <cyg/fileio/fileio.h>
75 // Test ROMFS data. Two example data files are generated so that
76 // the test will work on both big-endian and little-endian targets.
77 #if (CYG_BYTEORDER == CYG_LSBFIRST)
78 # include <cyg/objloader/testromfs_le.h>
80 # include <cyg/objloader/testromfs_be.h>
83 //==========================================================================
85 MTAB_ENTRY(romfs_mte1,
89 (CYG_ADDRWORD) &filedata[0]);
92 //==========================================================================
94 #define THREAD_STACK_SIZE 8192
95 #define THREAD_PRIORITY 12
97 cyg_uint8 thread_a_stack[THREAD_STACK_SIZE] __attribute__((__aligned__ (16)));
98 cyg_uint8 thread_b_stack[THREAD_STACK_SIZE] __attribute__((__aligned__ (16)));
100 cyg_thread thread_a_obj;
101 cyg_thread thread_b_obj;
102 cyg_handle_t thread_a_hdl;
103 cyg_handle_t thread_b_hdl;
105 #define SHOW_RESULT(_fn, _res) \
106 diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):"");
108 int weak_fn_called = 0;
110 void weak_function(void)
112 CYG_TEST_PASS("Applications weak function called");
116 void (*thread_a)(cyg_addrword_t);
117 void (*thread_b)(cyg_addrword_t);
119 // This is the main starting point for our example application.
120 void cyg_user_start(void)
128 CYG_TEST_INFO("Object loader module test started");
133 SHOW_RESULT(chdir, err);
135 lib_handle = cyg_ldr_open_library((CYG_ADDRWORD)"/hello.o", 0);
136 CYG_TEST_CHECK(lib_handle , "Unable to load object file to load");
138 fn = cyg_ldr_find_symbol(lib_handle, "print_message");
139 CYG_TEST_CHECK(fn , "Unable to find print_message function");
143 fn = cyg_ldr_find_symbol(lib_handle, "weak_function");
144 CYG_TEST_CHECK(fn , "Unable to find weak_function");
148 fn = cyg_ldr_find_symbol (lib_handle, "unresolvable_symbol");
149 CYG_TEST_CHECK(!fn , "Found none existing symbol!");
151 thread_a = cyg_ldr_find_symbol(lib_handle, "thread_a");
152 thread_b = cyg_ldr_find_symbol(lib_handle, "thread_b");
153 CYG_TEST_CHECK(thread_a && thread_b , "Unable to find thread functions");
155 // Create our two threads.
156 cyg_thread_create(THREAD_PRIORITY,
160 (void *)thread_a_stack,
165 cyg_thread_create(THREAD_PRIORITY + 1,
169 (void *)thread_b_stack,
174 // Resume the threads so they start when the scheduler begins.
175 cyg_thread_resume(thread_a_hdl);
176 cyg_thread_resume(thread_b_hdl);
178 cyg_scheduler_start();
181 // -----------------------------------------------------------------------------
183 // -----------------------------------------------------------------------------
184 CYG_LDR_TABLE_KAPI_ALARM()
185 CYG_LDR_TABLE_KAPI_CLOCK()
186 CYG_LDR_TABLE_KAPI_COND()
187 CYG_LDR_TABLE_KAPI_COUNTER()
188 CYG_LDR_TABLE_KAPI_EXCEPTIONS()
189 CYG_LDR_TABLE_KAPI_FLAG()
190 CYG_LDR_TABLE_KAPI_INTERRUPTS()
191 CYG_LDR_TABLE_KAPI_MBOX()
192 CYG_LDR_TABLE_KAPI_MEMPOOL_FIX()
193 CYG_LDR_TABLE_KAPI_MEMPOOL_VAR()
194 CYG_LDR_TABLE_KAPI_MUTEX()
195 CYG_LDR_TABLE_KAPI_SCHEDULER()
196 CYG_LDR_TABLE_KAPI_SEMAPHORE()
197 CYG_LDR_TABLE_KAPI_THREAD()
198 CYG_LDR_TABLE_STRING()
199 CYG_LDR_TABLE_STDIO()
200 CYG_LDR_TABLE_INFRA_DIAG()
202 // Test case infrastructure function
203 CYG_LDR_TABLE_ENTRY(cyg_test_output_entry, "cyg_test_output", cyg_test_output);
204 CYG_LDR_TABLE_ENTRY(cyg_test_exit_entry, "cyg_test_exit", cyg_test_exit);
207 CYG_LDR_TABLE_ENTRY(weak_function_entry, "weak_function", weak_function);
210 CYG_LDR_TABLE_ENTRY(weak_fn_called_entry, "weak_fn_called", &weak_fn_called);