OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [signals/] [current/] [tests/] [signal1.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//========================================================================
2
//
3
//      signal1.c
4
//
5
//      ISO C signal handling test
6
//
7
//========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     jlarmour
43
// Contributors:  
44
// Date:          2000-04-18
45
// Purpose:       Test signal functionality
46
// Description:   This file contains a number of tests for ISO C signal
47
//                handling
48
// Usage:         
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================
53
 
54
// CONFIGURATION
55
 
56
#include <pkgconf/libc_signals.h>  // libc signals configuration
57
 
58
// INCLUDES
59
 
60
#include <pkgconf/system.h>
61
#ifdef CYGPKG_ISOINFRA
62
# include <pkgconf/isoinfra.h>
63
#endif
64
#include <cyg/infra/cyg_type.h>    // Common type definitions and support
65
#include <cyg/infra/testcase.h>    // Test infrastructure
66
#include <signal.h>                // Signal functions
67
#include <setjmp.h>                // setjmp(), longjmp()
68
#include <stdlib.h>                // abort()
69
 
70
// STATICS
71
 
72
static int state;
73
static jmp_buf jbuf;
74
 
75
// FUNCTIONS
76
 
77
static void
78
myhandler1(int signal)
79
{
80
    CYG_TEST_INFO("myhandler1 called");
81
    ++state;
82
} // myhandler1()
83
 
84
static void
85
myhandler2(int signal)
86
{
87
    CYG_TEST_INFO("myhandler2 called");
88
    ++state;
89
    longjmp(jbuf, 1);
90
} // myhandler2()
91
 
92
#ifndef CYGPKG_LIBC_STARTUP
93
void cyg_user_start(void)
94
#else
95
int
96
main( int argc, char *argv[] )
97
#endif
98
{
99
    __sighandler_t handler1;
100
    int rc;
101
 
102
    // special callout to request GDB to alter its handling of signals
103
    CYG_TEST_GDBCMD("handle SIGTERM nostop");
104
    CYG_TEST_GDBCMD("handle SIGABRT nostop");
105
 
106
    CYG_TEST_INIT();
107
 
108
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
109
                  "library signal functions");
110
 
111
    // Test 1
112
 
113
    CYG_TEST_INFO("Test 1");
114
    state = 1;
115
    handler1 = signal(SIGTERM, &myhandler1);
116
 
117
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
118
                       "SIGTERM handler initialized to default");
119
 
120
    rc = raise(SIGTERM);
121
 
122
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
123
 
124
    CYG_TEST_PASS_FAIL(2==state, "SIGTERM handler returned correctly");
125
 
126
    // Test 2
127
 
128
    CYG_TEST_INFO("Test 2");
129
 
130
    state = 2;
131
    handler1 = signal(SIGTERM, &myhandler2);
132
 
133
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
134
                       "SIGTERM handler reset to default after test 1");
135
 
136
    handler1 = signal(SIGTERM, &myhandler1);
137
 
138
    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
139
                       "SIGTERM handler was set correctly");
140
 
141
    rc = raise(SIGTERM);
142
 
143
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
144
 
145
    CYG_TEST_PASS_FAIL(3==state, "SIGTERM handler returned correctly");
146
 
147
    // Test 3
148
 
149
    CYG_TEST_INFO("Test 3");
150
 
151
    handler1 = signal(SIGTERM, &myhandler2);
152
 
153
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
154
                       "SIGTERM handler reset to default after test 2");
155
 
156
    handler1 = signal(SIGTERM, SIG_DFL);
157
 
158
    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
159
                       "SIGTERM handler was set correctly");
160
 
161
    // Test 4
162
 
163
    CYG_TEST_INFO("Test 4");
164
 
165
    state = 4;
166
    handler1 = signal(SIGTERM, SIG_IGN);
167
 
168
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
169
                       "SIGTERM handler was set correctly after test 3");
170
    rc = raise(SIGTERM);
171
 
172
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
173
 
174
    CYG_TEST_PASS_FAIL(4==state, "SIGTERM ignored");
175
 
176
    // Test 5
177
 
178
    CYG_TEST_INFO("Test 5");
179
 
180
    state = 5;
181
    handler1 = signal(SIGTERM, &myhandler2);
182
 
183
    // SIG_IGN doesn't reset back to SIG_DFL after a raise()
184
    CYG_TEST_PASS_FAIL(handler1 == SIG_IGN,
185
                       "SIGTERM handler was set correctly after test 4");
186
 
187
    if (0==setjmp(jbuf)) {
188
        raise(SIGTERM);
189
        CYG_TEST_FAIL("raise returned");
190
    }
191
 
192
    CYG_TEST_PASS_FAIL(6==state, "SIGTERM handler returned correctly");
193
 
194
#if defined(CYGINT_ISO_ENVIRON) && (CYGINT_ISO_ENVIRON > 0)    
195
    // Test 6
196
 
197
    CYG_TEST_INFO("Test 6");
198
 
199
    state = 6;
200
    handler1 = signal(SIGABRT, &myhandler2);
201
 
202
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
203
                       "SIGABRT handler initialized to default");
204
 
205
    if (0==setjmp(jbuf)) {
206
        abort();
207
        CYG_TEST_FAIL("abort returned");
208
    }
209
 
210
    CYG_TEST_PASS_FAIL(7==state, "SIGABRT handler returned correctly");
211
#else
212
    CYG_TEST_INFO("skipping abort() test, function not implemented");
213
#endif    
214
 
215
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
216
                    "library signal functions");
217
 
218
} // main()
219
 
220
// EOF signal1.c

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.