1 //==========================================================================
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: nickg
46 // Description: Tests the functionality of thread kill() and
48 //####DESCRIPTIONEND####
50 #include <pkgconf/kernel.h>
52 #include <cyg/kernel/thread.hxx>
53 #include <cyg/kernel/thread.inl>
54 #include <cyg/kernel/sched.hxx>
55 #include <cyg/kernel/mutex.hxx>
56 #include <cyg/kernel/sema.hxx>
58 #include <cyg/infra/testcase.h>
60 #ifdef CYGFUN_KERNEL_THREADS_TIMER
62 #include <cyg/kernel/sched.inl>
66 #include "testaux.hxx"
68 // In general, this delay has to be long enough to account for slow targets
69 // and potential problems on e.g. the linux synthetic target to avoid
70 // potential problems due to timing inaccuracy and scheduling of Linux
71 // tasks. It is decreased further below for simulators.
75 static Cyg_Binary_Semaphore s0, s1;
77 volatile cyg_atomic thread0_state;
78 volatile cyg_atomic thread1_state;
79 volatile cyg_atomic thread2_state;
81 static void entry0( CYG_ADDRWORD data )
83 Cyg_Thread *self = Cyg_Thread::self();
91 CYG_TEST_FAIL_FINISH("Thread not killed");
97 static void entry1( CYG_ADDRWORD data )
99 Cyg_Thread *self = Cyg_Thread::self();
103 self->delay(delay_ticks);
105 if( thread2_state != 1 )
106 CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
118 self->delay(delay_ticks);
123 thread[2]->reinitialize();
126 self->delay(delay_ticks);
128 if( thread2_state != 1 )
129 CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
133 self->delay(delay_ticks);
135 if( thread2_state != 2 )
136 CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
142 CYG_TEST_PASS_FINISH("Kill OK");
144 Cyg_Thread::self()->exit();
147 static void entry2( CYG_ADDRWORD data )
151 while( thread1_state != 6 ) continue;
159 void release_main(void)
163 if (cyg_test_is_simulator)
166 new_thread( entry0, 0);
167 new_thread( entry1, 1);
168 new_thread( entry2, 2);
170 thread[0]->set_priority(5);
171 thread[1]->set_priority(6);
172 thread[2]->set_priority(7);
174 Cyg_Scheduler::start();
176 CYG_TEST_FAIL_FINISH("Not reached");
182 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
183 cyg_hal_invoke_constructors();
188 #else // ifdef CYGFUN_KERNEL_THREADS_TIMER
194 CYG_TEST_NA("Kernel threads timer disabled");
197 #endif // ifdef CYGFUN_KERNEL_THREADS_TIMER