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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [compat/] [posix/] [v2_0/] [tests/] [signal3.c] - Blame information for rev 559

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        signal3.cxx
4
//
5
//        POSIX signal test 3
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):     nickg
44
// Contributors:  nickg
45
// Date:          2003-01-30
46
// Description:   Tests POSIX signal functionality.
47
//
48
//####DESCRIPTIONEND####
49
//==========================================================================
50
 
51
#include <cyg/infra/testcase.h>
52
#include <pkgconf/posix.h>
53
 
54
#if !defined(CYGPKG_POSIX_SIGNALS)
55
#define NA_MSG "POSIX signals not enabled"
56
#elif !defined(CYGPKG_POSIX_PTHREAD)
57
#define NA_MSG "POSIX threads not enabled"
58
#endif
59
 
60
#ifdef NA_MSG
61
void
62
cyg_start(void)
63
{
64
    CYG_TEST_INIT();
65
    CYG_TEST_NA(NA_MSG);
66
}
67
#else
68
 
69
#include <signal.h>
70
#include <pthread.h>
71
#include <stdio.h>
72
#include <errno.h>
73
#include <cyg/infra/diag.h>
74
 
75
volatile int sigusr1_called = 0;
76
 
77
//--------------------------------------------------------------------------
78
// Signal handler functions
79
 
80
static void sigusr1( int signo )
81
{
82
    CYG_TEST_INFO( "sigusr1() handler called" );
83
    CYG_TEST_CHECK( signo == SIGUSR1, "Signal not SIGUSR1");
84
 
85
    sigusr1_called++;
86
}
87
 
88
//--------------------------------------------------------------------------
89
 
90
int main (int argc, char **argv)
91
{
92
    int ret_val;
93
    sigset_t set;
94
    int sig;
95
    struct itimerspec timerValue;       // Timeout value on eCos
96
    timer_t timer1;                     // Timer
97
    struct sigevent sev;
98
 
99
    CYG_TEST_INIT();
100
 
101
    {
102
        struct sigaction sa;
103
 
104
        sa.sa_handler = sigusr1;
105
        sigfillset( &sa.sa_mask );
106
        sa.sa_flags = 0;
107
 
108
        ret_val = sigaction( SIGUSR1, &sa, NULL );
109
 
110
        CYG_TEST_CHECK( ret_val == 0 , "sigaction returned error");
111
    }
112
 
113
    // unblock all the signals
114
    sigfillset (&set);
115
    pthread_sigmask (SIG_UNBLOCK, &set, (sigset_t*)NULL);
116
 
117
    //--------------------------------------------------------------------
118
    // <start of timer initialization section>
119
    //--------------------------------------------------------------------
120
 
121
    // Notification type --- Deliver the signal
122
    sev.sigev_notify                = SIGEV_SIGNAL;
123
    sev.sigev_signo                 = SIGUSR1;
124
    sev.sigev_value.sival_int       = 0xABCDEF01;
125
 
126
    // Timer values     --- 1 Second
127
    timerValue.it_value.tv_sec           = 1;
128
    timerValue.it_value.tv_nsec          = 0;
129
    timerValue.it_interval.tv_sec        = 1;
130
    timerValue.it_interval.tv_nsec       = 0;
131
 
132
    ret_val = timer_create (CLOCK_REALTIME, &sev, &timer1);
133
 
134
    CYG_TEST_CHECK( ret_val==0, "Error in creating the timer");
135
 
136
    ret_val = timer_settime (timer1, 0, &timerValue, NULL );
137
    CYG_TEST_CHECK( ret_val==0,"Error in setting the time");
138
 
139
    //--------------------------------------------------------------------
140
    // <end of timer initialization section>
141
    //--------------------------------------------------------------------
142
 
143
    CYG_TEST_INFO ("Timer initialisation is completed..");
144
 
145
    CYG_TEST_INFO ("Calling pause()");
146
    ret_val = pause();
147
    CYG_TEST_CHECK( ret_val==-1, "pause() did not return -1");
148
    CYG_TEST_CHECK( EINTR==errno, "errno set to EINTR");
149
    CYG_TEST_CHECK( sigusr1_called==1, "Siguser1 handler not called");
150
 
151
    // Block all the signals
152
    sigfillset (&set);
153
    pthread_sigmask (SIG_BLOCK, &set, (sigset_t*)NULL);
154
 
155
    CYG_TEST_INFO ("Calling sigwait()");
156
    // Wait for any signal to arrive
157
    sigfillset (&set);
158
    ret_val = sigwait (&set, &sig);
159
 
160
    CYG_TEST_CHECK( ret_val==0, "sigwait returned error");
161
    CYG_TEST_CHECK( sig==SIGUSR1, "sigwait returned wrong signo!");
162
    CYG_TEST_CHECK( sigusr1_called==1, "Siguser1 handler called!");
163
 
164
    CYG_TEST_INFO ("Program terminating");
165
 
166
    CYG_TEST_PASS_FINISH( "signal3" );
167
    return 0;
168
}
169
 
170
 
171
#endif
172
 
173
//--------------------------------------------------------------------------
174
// end of signal3.c

powered by: WebSVN 2.1.0

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