nsprpub/pr/tests/sproc_ch.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/sproc_ch.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Test sproc_ch.c
    1.11 + *
    1.12 + * The purpose of this test and the sproc_p.c test is to test the shutdown
    1.13 + * of all the IRIX sprocs in a program when one of them dies due to an error.
    1.14 + *
    1.15 + * There are three sprocs in this test: the parent, the child, and the 
    1.16 + * grandchild.  The parent and child sprocs never stop on their own.
    1.17 + * The grandchild sproc gets a segmentation fault and dies.  You should
    1.18 + * You should use "ps" to see if the parent and child sprocs are killed
    1.19 + * after the grandchild dies.
    1.20 + */
    1.21 +
    1.22 +#include "prinit.h"
    1.23 +#include <stdio.h>
    1.24 +
    1.25 +#if !defined(IRIX)
    1.26 +
    1.27 +int main(int argc, char **argv)
    1.28 +{
    1.29 +    printf("This test applies to IRIX only.\n");
    1.30 +    return 0;
    1.31 +}
    1.32 +
    1.33 +#else  /* IRIX */
    1.34 +
    1.35 +#include "prthread.h"
    1.36 +#include <sys/types.h>
    1.37 +#include <unistd.h>
    1.38 +
    1.39 +void SegFault(void *unused)
    1.40 +{
    1.41 +    int *p = 0;
    1.42 +
    1.43 +    printf("The grandchild sproc has pid %d.\n", getpid());
    1.44 +    printf("The grandchild sproc will get a segmentation fault and die.\n");
    1.45 +    printf("The parent and child sprocs should be killed after the "
    1.46 +            "grandchild sproc dies.\n");
    1.47 +    printf("Use 'ps' to make sure this is so.\n");
    1.48 +    fflush(stdout);
    1.49 +    /* Force a segmentation fault */
    1.50 +    *p = 0;
    1.51 +}
    1.52 +
    1.53 +void NeverStops(void *unused)
    1.54 +{
    1.55 +    int i = 0;
    1.56 +
    1.57 +    printf("The child sproc has pid %d.\n", getpid());
    1.58 +    printf("The child sproc won't stop on its own.\n");
    1.59 +    fflush(stdout);
    1.60 +
    1.61 +    /* create the grandchild sproc */
    1.62 +    PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
    1.63 +	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    1.64 +
    1.65 +    while (1) {
    1.66 +	i++;
    1.67 +    }
    1.68 +}
    1.69 +
    1.70 +int main()
    1.71 +{
    1.72 +    int i= 0;
    1.73 +
    1.74 +    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    1.75 +
    1.76 +    printf("The parent sproc has pid %d.\n", getpid());
    1.77 +    printf("The parent sproc won't stop on its own.\n");
    1.78 +    fflush(stdout);
    1.79 +
    1.80 +    /* create the child sproc */
    1.81 +    PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
    1.82 +	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    1.83 +
    1.84 +    while (1) {
    1.85 +	i++;
    1.86 +    }
    1.87 +    return 0;
    1.88 +}
    1.89 +
    1.90 +#endif  /* IRIX */

mercurial