~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/tests/sproc_ch.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* 
 
3
 * The contents of this file are subject to the Mozilla Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/MPL/
 
7
 * 
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 * 
 
13
 * The Original Code is the Netscape Portable Runtime (NSPR).
 
14
 * 
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation.  Portions created by Netscape are 
 
17
 * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
 
18
 * Rights Reserved.
 
19
 * 
 
20
 * Contributor(s):
 
21
 * 
 
22
 * Alternatively, the contents of this file may be used under the
 
23
 * terms of the GNU General Public License Version 2 or later (the
 
24
 * "GPL"), in which case the provisions of the GPL are applicable 
 
25
 * instead of those above.  If you wish to allow use of your 
 
26
 * version of this file only under the terms of the GPL and not to
 
27
 * allow others to use your version of this file under the MPL,
 
28
 * indicate your decision by deleting the provisions above and
 
29
 * replace them with the notice and other provisions required by
 
30
 * the GPL.  If you do not delete the provisions above, a recipient
 
31
 * may use your version of this file under either the MPL or the
 
32
 * GPL.
 
33
 */
 
34
 
 
35
/*
 
36
 * Test sproc_ch.c
 
37
 *
 
38
 * The purpose of this test and the sproc_p.c test is to test the shutdown
 
39
 * of all the IRIX sprocs in a program when one of them dies due to an error.
 
40
 *
 
41
 * There are three sprocs in this test: the parent, the child, and the 
 
42
 * grandchild.  The parent and child sprocs never stop on their own.
 
43
 * The grandchild sproc gets a segmentation fault and dies.  You should
 
44
 * You should use "ps" to see if the parent and child sprocs are killed
 
45
 * after the grandchild dies.
 
46
 */
 
47
 
 
48
#include "prinit.h"
 
49
#include <stdio.h>
 
50
 
 
51
#if !defined(IRIX)
 
52
 
 
53
int main()
 
54
{
 
55
    printf("This test applies to IRIX only.\n");
 
56
    return 0;
 
57
}
 
58
 
 
59
#else  /* IRIX */
 
60
 
 
61
#include "prthread.h"
 
62
#include <sys/types.h>
 
63
#include <unistd.h>
 
64
 
 
65
void SegFault(void *unused)
 
66
{
 
67
    int *p = 0;
 
68
 
 
69
    printf("The grandchild sproc has pid %d.\n", getpid());
 
70
    printf("The grandchild sproc will get a segmentation fault and die.\n");
 
71
    printf("The parent and child sprocs should be killed after the "
 
72
            "grandchild sproc dies.\n");
 
73
    printf("Use 'ps' to make sure this is so.\n");
 
74
    fflush(stdout);
 
75
    /* Force a segmentation fault */
 
76
    *p = 0;
 
77
}
 
78
 
 
79
void NeverStops(void *unused)
 
80
{
 
81
    int i = 0;
 
82
 
 
83
    printf("The child sproc has pid %d.\n", getpid());
 
84
    printf("The child sproc won't stop on its own.\n");
 
85
    fflush(stdout);
 
86
 
 
87
    /* create the grandchild sproc */
 
88
    PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
 
89
            PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
 
90
 
 
91
    while (1) {
 
92
        i++;
 
93
    }
 
94
}
 
95
 
 
96
int main()
 
97
{
 
98
    int i= 0;
 
99
 
 
100
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
 
101
 
 
102
    printf("The parent sproc has pid %d.\n", getpid());
 
103
    printf("The parent sproc won't stop on its own.\n");
 
104
    fflush(stdout);
 
105
 
 
106
    /* create the child sproc */
 
107
    PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
 
108
            PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
 
109
 
 
110
    while (1) {
 
111
        i++;
 
112
    }
 
113
    return 0;
 
114
}
 
115
 
 
116
#endif  /* IRIX */