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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [signals/] [v2_0/] [tests/] [signal1.c] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//========================================================================
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 Red Hat, 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 version.
16
//
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
20
// for more details.
21
//
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.
25
//
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.
32
//
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.
35
//
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####
42
//
43
// Author(s):     jlarmour
44
// Contributors:  
45
// Date:          2000-04-18
46
// Purpose:       Test signal functionality
47
// Description:   This file contains a number of tests for ISO C signal
48
//                handling
49
// Usage:         
50
//
51
//####DESCRIPTIONEND####
52
//
53
//========================================================================
54
 
55
// CONFIGURATION
56
 
57
#include <pkgconf/libc_signals.h>  // libc signals configuration
58
 
59
// INCLUDES
60
 
61
#include <cyg/infra/cyg_type.h>    // Common type definitions and support
62
#include <cyg/infra/testcase.h>    // Test infrastructure
63
#include <signal.h>                // Signal functions
64
#include <setjmp.h>                // setjmp(), longjmp()
65
#include <stdlib.h>                // abort()
66
 
67
// STATICS
68
 
69
static int state;
70
static jmp_buf jbuf;
71
 
72
// FUNCTIONS
73
 
74
static void
75
myhandler1(int signal)
76
{
77
    CYG_TEST_INFO("myhandler1 called");
78
    ++state;
79
} // myhandler1()
80
 
81
static void
82
myhandler2(int signal)
83
{
84
    CYG_TEST_INFO("myhandler2 called");
85
    ++state;
86
    longjmp(jbuf, 1);
87
} // myhandler2()
88
 
89
int
90
main( int argc, char *argv[] )
91
{
92
    __sighandler_t handler1;
93
    int rc;
94
 
95
    // special callout to request GDB to alter its handling of signals
96
    CYG_TEST_GDBCMD("handle SIGTERM nostop");
97
    CYG_TEST_GDBCMD("handle SIGABRT nostop");
98
 
99
    CYG_TEST_INIT();
100
 
101
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
102
                  "library signal functions");
103
 
104
    // Test 1
105
 
106
    CYG_TEST_INFO("Test 1");
107
    state = 1;
108
    handler1 = signal(SIGTERM, &myhandler1);
109
 
110
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
111
                       "SIGTERM handler initialized to default");
112
 
113
    rc = raise(SIGTERM);
114
 
115
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
116
 
117
    CYG_TEST_PASS_FAIL(2==state, "SIGTERM handler returned correctly");
118
 
119
    // Test 2
120
 
121
    CYG_TEST_INFO("Test 2");
122
 
123
    state = 2;
124
    handler1 = signal(SIGTERM, &myhandler2);
125
 
126
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
127
                       "SIGTERM handler reset to default after test 1");
128
 
129
    handler1 = signal(SIGTERM, &myhandler1);
130
 
131
    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
132
                       "SIGTERM handler was set correctly");
133
 
134
    rc = raise(SIGTERM);
135
 
136
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
137
 
138
    CYG_TEST_PASS_FAIL(3==state, "SIGTERM handler returned correctly");
139
 
140
    // Test 3
141
 
142
    CYG_TEST_INFO("Test 3");
143
 
144
    handler1 = signal(SIGTERM, &myhandler2);
145
 
146
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
147
                       "SIGTERM handler reset to default after test 2");
148
 
149
    handler1 = signal(SIGTERM, SIG_DFL);
150
 
151
    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
152
                       "SIGTERM handler was set correctly");
153
 
154
    // Test 4
155
 
156
    CYG_TEST_INFO("Test 4");
157
 
158
    state = 4;
159
    handler1 = signal(SIGTERM, SIG_IGN);
160
 
161
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
162
                       "SIGTERM handler was set correctly after test 3");
163
    rc = raise(SIGTERM);
164
 
165
    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");
166
 
167
    CYG_TEST_PASS_FAIL(4==state, "SIGTERM ignored");
168
 
169
    // Test 5
170
 
171
    CYG_TEST_INFO("Test 5");
172
 
173
    state = 5;
174
    handler1 = signal(SIGTERM, &myhandler2);
175
 
176
    // SIG_IGN doesn't reset back to SIG_DFL after a raise()
177
    CYG_TEST_PASS_FAIL(handler1 == SIG_IGN,
178
                       "SIGTERM handler was set correctly after test 4");
179
 
180
    if (0==setjmp(jbuf)) {
181
        raise(SIGTERM);
182
        CYG_TEST_FAIL("raise returned");
183
    }
184
 
185
    CYG_TEST_PASS_FAIL(6==state, "SIGTERM handler returned correctly");
186
 
187
    // Test 6
188
 
189
    CYG_TEST_INFO("Test 6");
190
 
191
    state = 6;
192
    handler1 = signal(SIGABRT, &myhandler2);
193
 
194
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
195
                       "SIGABRT handler initialized to default");
196
 
197
    if (0==setjmp(jbuf)) {
198
        abort();
199
        CYG_TEST_FAIL("abort returned");
200
    }
201
 
202
    CYG_TEST_PASS_FAIL(7==state, "SIGABRT handler returned correctly");
203
 
204
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
205
                    "library signal functions");
206
 
207
    return 0;
208
} // main()
209
 
210
// EOF signal1.c

powered by: WebSVN 2.1.0

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