~upstart-devel/upstart/trunk

« back to all changes in this revision

Viewing changes to init/tests/test_job_process.c

mergeĀ lp:~vorlon/upstart/upstart-fix-racy-tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
494
494
        FILE            *output;
495
495
        struct stat      statbuf;
496
496
        char             filename[PATH_MAX], buf[80];
 
497
        char             fifoname[PATH_MAX];
497
498
        char             function[PATH_MAX];
498
499
        int              status;
499
500
        siginfo_t        info;
1729
1730
        TEST_FEATURE ("with single-line script that is killed");
1730
1731
        TEST_HASH_EMPTY (job_classes);
1731
1732
 
 
1733
        /* Create a fifo that we can use to read from in our scripts,
 
1734
         * so we have a sensible way to block in shell without spawning
 
1735
         * a separate process.
 
1736
         */
 
1737
        TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
 
1738
        TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
 
1739
 
1732
1740
        class = job_class_new (NULL, "test", NULL);
1733
1741
        TEST_NE_P (class, NULL);
1734
1742
 
1738
1746
        class->process[PROCESS_MAIN] = process_new (class);
1739
1747
        class->process[PROCESS_MAIN]->command = nih_sprintf (
1740
1748
                        class->process[PROCESS_MAIN],
1741
 
                        "%s hello world;sleep 999", TEST_CMD_ECHO);
 
1749
                        "%s hello world;read <%s", TEST_CMD_ECHO, fifoname);
1742
1750
        class->process[PROCESS_MAIN]->script = TRUE;
1743
1751
 
1744
1752
        job = job_new (class, "");
1807
1815
        fclose (output);
1808
1816
 
1809
1817
        TEST_EQ (unlink (filename), 0);
 
1818
        TEST_EQ (unlink (fifoname), 0);
1810
1819
        nih_free (class);
1811
1820
 
1812
1821
        /************************************************************/
1913
1922
        TEST_FEATURE ("with multi-line script that is killed");
1914
1923
        TEST_HASH_EMPTY (job_classes);
1915
1924
 
 
1925
        /* Create a fifo that we can use to read from in our scripts,
 
1926
         * so we have a sensible way to block in shell without spawning
 
1927
         * a separate process.
 
1928
         */
 
1929
        TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
 
1930
        TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
 
1931
 
1916
1932
        /* Note we can't use TEST_ALLOC_FAIL() for this test since on
1917
1933
         * the ENOMEM loop all we could do is discard the error and
1918
1934
         * continue since job_process_start() calls job_process_spawn()
1932
1948
        class->process[PROCESS_MAIN] = process_new (class);
1933
1949
        class->process[PROCESS_MAIN]->command = nih_sprintf (
1934
1950
                        class->process[PROCESS_MAIN],
1935
 
                        "%s hello world\nsleep 999", TEST_CMD_ECHO);
 
1951
                        "%s hello world\nread <%s", TEST_CMD_ECHO, fifoname);
1936
1952
        class->process[PROCESS_MAIN]->script = TRUE;
1937
1953
 
1938
1954
        job = job_new (class, "");
1982
1998
        fclose (output);
1983
1999
 
1984
2000
        TEST_EQ (unlink (filename), 0);
 
2001
        TEST_EQ (unlink (fifoname), 0);
1985
2002
        nih_free (class);
1986
2003
 
1987
2004
        /************************************************************/
1988
2005
        TEST_FEATURE ("with single-line script that writes 1 byte and is killed");
1989
2006
        TEST_HASH_EMPTY (job_classes);
1990
2007
 
 
2008
        /* Create a fifo that we can use to read from in our scripts,
 
2009
         * so we have a sensible way to block in shell without spawning
 
2010
         * a separate process.
 
2011
         */
 
2012
        TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
 
2013
        TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
 
2014
 
1991
2015
        class = job_class_new (NULL, "test", NULL);
1992
2016
        TEST_NE_P (class, NULL);
1993
2017
 
1997
2021
        class->process[PROCESS_MAIN] = process_new (class);
1998
2022
        class->process[PROCESS_MAIN]->command = nih_sprintf (
1999
2023
                        class->process[PROCESS_MAIN],
2000
 
                        "%s -ne X;sleep 999", TEST_CMD_ECHO);
 
2024
                        "%s -ne X; read <%s", TEST_CMD_ECHO, fifoname);
2001
2025
        class->process[PROCESS_MAIN]->script = TRUE;
2002
2026
 
2003
2027
        job = job_new (class, "");
2043
2067
        fclose (output);
2044
2068
 
2045
2069
        TEST_EQ (unlink (filename), 0);
 
2070
        TEST_EQ (unlink (fifoname), 0);
2046
2071
        nih_free (class);
2047
2072
 
2048
2073
        /************************************************************/
2055
2080
         */
2056
2081
 
2057
2082
        /************************************************************/
2058
 
        TEST_FEATURE ("with multi-line script that writes 1 byte and is killed");
 
2083
        TEST_FEATURE ("with multi-line script that writes 1 byte");
2059
2084
        TEST_HASH_EMPTY (job_classes);
2060
2085
 
2061
2086
        class = job_class_new (NULL, "multiline", NULL);
2588
2613
        class->process[PROCESS_MAIN]->command = nih_sprintf (
2589
2614
                        class->process[PROCESS_MAIN],
2590
2615
                        "%s if=/dev/zero of=/dev/null bs=1 count=0", TEST_CMD_DD);
2591
 
        class->process[PROCESS_MAIN]->script = TRUE;
 
2616
        class->process[PROCESS_MAIN]->script = FALSE;
2592
2617
 
2593
2618
        job = job_new (class, "");
2594
2619
        job->goal = JOB_START;