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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [signal/] [signal.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* vi: set sw=4 ts=4: */
2
/*
3
 * signal testing function for uClibc
4
 *
5
 * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
6
 * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
7
 * Written by Erik Andersen <andersen@uclibc.org>
8
 *
9
 * This program is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU Library General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or (at your
12
 * option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
17
 * for more details.
18
 *
19
 * You should have received a copy of the GNU Library General Public License
20
 * along with this program; if not, write to the Free Software Foundation,
21
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
 *
23
 */
24
 
25
 
26
#include <errno.h>
27
#include <stdio.h>
28
#include <stdlib.h>
29
#include <string.h>
30
#include <strings.h>
31
#include <fcntl.h>
32
#include <signal.h>
33
 
34
 
35
/* -------------------------------------------------*/
36
/* This stuff is common to all the testing routines */
37
/* -------------------------------------------------*/
38
const char *it = "<UNSET>";             /* Routine name for message routines. */
39
size_t errors = 0;
40
 
41
void check(int thing, int number)
42
{
43
        if (!thing) {
44
                printf("%s: flunked test %d\n", it, number);
45
                ++errors;
46
        }
47
}
48
 
49
void equal(const char *a, const char *b, int number)
50
{
51
        check(a != NULL && b != NULL && (strcmp(a, b) == 0), number);
52
}
53
 
54
 
55
/* -------------------------------------------------*/
56
/* Let the tests begin....                          */
57
/* -------------------------------------------------*/
58
 
59
int global_int = 0;
60
 
61
void set_global_int_to_one(int signum)
62
{
63
        printf ("Received signal %d (%s).\n", signum, strsignal(signum));
64
        global_int = 1;
65
        return;
66
}
67
 
68
void signal_test_1(void)
69
{
70
        global_int = 0;
71
 
72
        it = "global variable set from signal handler";
73
        signal(SIGUSR1, set_global_int_to_one);
74
        raise(SIGUSR1);
75
 
76
        /* This should already have jumped to the signal handler */
77
        check((global_int == 1), 1);
78
 
79
        global_int = 0;
80
        signal(SIGUSR1, SIG_IGN);
81
        raise(SIGUSR1);
82
        /* This should not go to the signal handler this time since we  */
83
        check((global_int == 0), 1);
84
}
85
 
86
 
87
int main(void)
88
{
89
        int status;
90
 
91
        signal_test_1();
92
 
93
        if (errors == 0) {
94
                status = EXIT_SUCCESS;
95
                printf("No errors.\n");
96
        } else {
97
                status = EXIT_FAILURE;
98
                printf("%d errors.\n", errors);
99
        }
100
        exit(status);
101
}

powered by: WebSVN 2.1.0

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