Ticket #61: posix-testsuite_killpg_sigpause.diff

File posix-testsuite_killpg_sigpause.diff, 34.5 KB (added by kaoutsis, 16 years ago)
  • build/jam/OptionalTestPackages

     
    5555    # add signal posix tests
    5656    AddFilesToHaikuImage home posixtestsuite conformance interfaces kill
    5757        : kill_2-1 ;
     58    AddFilesToHaikuImage home posixtestsuite conformance interfaces killpg
     59        : killpg_1-1 killpg_1-2 killpg_2-1 killpg_4-1 killpg_5-1 killpg_6-1
     60          killpg_8-1 ;
    5861    AddFilesToHaikuImage home posixtestsuite conformance interfaces sighold
    5962        : sighold_1-1 sighold_2-1 sighold_3-core-buildonly ;
    6063    AddFilesToHaikuImage home posixtestsuite conformance interfaces sigignore
     
    6467        : sigprocmask_8-1 sigprocmask_8-2 sigprocmask_8-3 sigprocmask_12-1 ;
    6568    AddFilesToHaikuImage home posixtestsuite conformance interfaces sigrelse
    6669        : sigrelse_1-1 sigrelse_2-1 sigrelse_3-core-buildonly ;
     70    AddFilesToHaikuImage home posixtestsuite conformance interfaces sigpause
     71        : sigpause_1-1 sigpause_1-2 sigpause_2-1 sigpause_3-1 sigpause_4-1 ;
    6772    AddFilesToHaikuImage home posixtestsuite conformance interfaces signal
    6873        : signal_1-1 signal_2-1 signal_3-1 signal_5-1 signal_6-1 signal_7-1 ;
    6974    AddFilesToHaikuImage home posixtestsuite conformance interfaces sigset
  • src/tests/system/libroot/posix/posixtestsuite/run_posix_tests.sh

     
    8282    echo "kill()"
    8383    conformance/interfaces/kill/kill_2-1
    8484    echo ""
     85    echo "killpg()"
     86    conformance/interfaces/killpg/killpg_1-1
     87    conformance/interfaces/killpg/killpg_1-2
     88    conformance/interfaces/killpg/killpg_2-1
     89    conformance/interfaces/killpg/killpg_4-1
     90    conformance/interfaces/killpg/killpg_5-1
     91    conformance/interfaces/killpg/killpg_6-1
     92    conformance/interfaces/killpg/killpg_8-1
     93    echo ""
    8594    echo "sighold()"
    8695    conformance/interfaces/sighold/sighold_1-1
    8796    conformance/interfaces/sighold/sighold_2-1
     
    114123    conformance/interfaces/sigrelse/sigrelse_3-core-buildonly 3
    115124    conformance/interfaces/sigrelse/sigrelse_3-core-buildonly 4
    116125    echo ""
     126    echo "sigpause()"
     127    conformance/interfaces/sigpause/sigpause_1-1
     128    conformance/interfaces/sigpause/sigpause_1-2
     129    conformance/interfaces/sigpause/sigpause_2-1
     130    conformance/interfaces/sigpause/sigpause_3-1
     131    conformance/interfaces/sigpause/sigpause_4-1
     132    echo ""
    117133    echo "signal()"
    118134    conformance/interfaces/signal/signal_1-1
    119135    conformance/interfaces/signal/signal_2-1
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/1-1.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 This program verifies that sigpause() removes sig from the signal mask.
     9
     10 Steps:
     11 1. From the main() function, create a new thread. Give the new thread a
     12    a second to set up for receiving a signal, and to suspend itself using
     13    sigpause().
     14 2. Have main() send the signal indicated by SIGTOTEST to the new thread,
     15    using pthread_kill(). After doing this, give the new thread a second
     16    to get to the signal handler.
     17 3. In the main() thread, if the handler_called variable wasn't set to 1,
     18    then the test has failed, else it passed.
     19 */
     20
     21#define _XOPEN_SOURCE 600
     22
     23#include <pthread.h>
     24#include <stdio.h>
     25#include <signal.h>
     26#include <errno.h>
     27#include <unistd.h>
     28#include "posixtest.h"
     29
     30#define SIGTOTEST SIGABRT
     31
     32int handler_called = 0;
     33
     34void handler() {
     35    /* printf("signal was called\n"); */
     36    handler_called = 1;
     37    return;
     38}
     39
     40void *a_thread_func()
     41{
     42    struct sigaction act;
     43    act.sa_flags = 0;
     44    act.sa_handler = handler;
     45    sigemptyset(&act.sa_mask);
     46    sigaction(SIGTOTEST, &act, 0);
     47    sighold(SIGTOTEST);
     48    sigpause(SIGTOTEST);
     49    return NULL;
     50}
     51
     52int main()
     53{
     54    pthread_t new_th;
     55
     56    if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
     57    {
     58        printf("%ssigpause_1-1:%s               "
     59            "%sFAILED: Error creating thread: %s%s\n",
     60            boldOn, boldOff, red, strerror(errno), normal);
     61        return PTS_UNRESOLVED;
     62    }
     63
     64    sleep(1);
     65
     66    if(pthread_kill(new_th, SIGTOTEST) != 0)
     67    {
     68        printf("%ssigpause_1-1:%s               "
     69            "%sFAILED: Couldn't send signal to thread: %s%s\n",
     70            boldOn, boldOff, red, strerror(errno), normal);
     71        return PTS_UNRESOLVED;
     72    }
     73
     74    sleep(1);
     75
     76    if(handler_called != 1) {
     77        printf("%ssigpause_1-1:%s               "
     78            "%sFAILED: signal wasn't removed from signal mask: %s%s\n",
     79            boldOn, boldOff, red, strerror(errno), normal);
     80        return PTS_FAIL;
     81    }
     82
     83    printf("%ssigpause_1-1:%s               %sPASSED%s\n", boldOn, boldOff, green, normal);
     84    return PTS_PASS;   
     85}
     86
     87
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/1-2.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 This program verifies that sigpause() suspends the calling process
     9 until it receives a signal.
     10
     11 Steps:
     12 1. From the main() function, create a new thread. Give the new thread a
     13    a second to set up for receiving a signal, and to suspend itself using
     14    sigpause().
     15 2. For about ten seconds, keep checking from main() that the "returned"
     16    variable hasn't been set yet. If it has, that means that sigpause
     17    returned even before a signal was sent to it, thus FAIL the test.
     18 3. After the ten seconds, send the new thread a signal using pthread_kill,
     19    and verify that "returned" has now been set to 1, meaning that the
     20    sigpause returned from suspension.
     21 */
     22
     23#define _XOPEN_SOURCE 600
     24
     25#include <pthread.h>
     26#include <stdio.h>
     27#include <signal.h>
     28#include <errno.h>
     29#include <unistd.h>
     30#include "posixtest.h"
     31
     32#define SIGTOTEST SIGABRT
     33
     34int returned = 0;
     35
     36void handler() {
     37    /* printf("sigpause_1-2: signal was called\n"); */
     38    return;
     39}
     40
     41void *a_thread_func()
     42{
     43    struct sigaction act;
     44    act.sa_flags = 0;
     45    act.sa_handler = handler;
     46    sigemptyset(&act.sa_mask);
     47    sigaction(SIGTOTEST, &act, 0);
     48    sigpause(SIGTOTEST);
     49    returned = 1;
     50    return NULL;
     51}
     52
     53int main()
     54{
     55    pthread_t new_th;
     56    int i;
     57
     58    if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
     59    {
     60        printf("%ssigpause_1-2:%s               "
     61            "%sFAILED: Error creating thread: %s%s\n",
     62            boldOn, boldOff, red, strerror(errno), normal);
     63        return PTS_UNRESOLVED;
     64    }
     65
     66    for (i=0; i<2; i++) {
     67        sleep(1);
     68        if (returned == 1) {
     69            printf("%ssigpause_1-2:%s               "
     70            "%sFAILED: sigpause returned before it received a signal: %s%s\n",
     71            boldOn, boldOff, red, strerror(errno), normal);
     72            return PTS_FAIL;
     73        }
     74    }
     75
     76    if(pthread_kill(new_th, SIGTOTEST) != 0)
     77    {
     78        printf("%ssigpause_1-2:%s               "
     79            "%sFAILED: Couldn't send signal to thread: %s%s\n",
     80            boldOn, boldOff, red, strerror(errno), normal);
     81        return PTS_UNRESOLVED;
     82    }
     83
     84    sleep(1);
     85
     86    if(returned != 1) {
     87        printf("%ssigpause_1-2:%s               "
     88            "%sFAILED: signal was sent, but sigpause never returned: %s%s\n",
     89            boldOn, boldOff, red, strerror(errno), normal);
     90        return PTS_FAIL;
     91    }
     92
     93    printf("%ssigpause_1-2:%s               %sPASSED%s\n", boldOn, boldOff, green, normal);
     94    return PTS_PASS;   
     95}
     96
     97
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/2-1.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 This program verifies that sigpause() restores sig to the signal mask before
     9 returning.
     10
     11 Steps:
     12 1. From the main() function, create a new thread. Give the new thread a
     13    a second to set up for receiving a signal, add SIGTOTEST to its signal
     14    mask and to suspend itself using sigpause(SIGTOTEST).
     15 2. Have main() send the signal indicated by SIGTOTEST to the new thread,
     16    using pthread_kill(), and using the concept of semaphores, have the main()
     17 3. Once the new thread returns from sigpause, have the new thread raise
     18    SIGTOTEST. At this point, SIGTOTEST should be restored to the signal mask, so the
     19    signal handler should not be called yet, and the signal should be pending.
     20    If it is not, set the variable return_value to 1, indicating a test failure.
     21 4. Now, from the new thread, set sem back to INMAIN to allow main to continue running.
     22 5. The PTS exit code that main() will return with will depend on the value of
     23    return_value:
     24    PTS_UNRESOLVED if return value is 2
     25    PTS_PASS if return value is 0
     26    PTS_FAIL if return value is 1
     27 */
     28
     29#define _XOPEN_SOURCE 600
     30
     31#include <pthread.h>
     32#include <stdio.h>
     33#include <signal.h>
     34#include <errno.h>
     35#include <unistd.h>
     36#include "posixtest.h"
     37
     38#define SIGTOTEST SIGABRT
     39#define INMAIN 0
     40#define INTHREAD 1
     41
     42int handler_called = 0;
     43int return_value = 2;
     44int sem = INMAIN;
     45
     46void handler() {
     47    /* printf("sigpause_2-1: signal was called\n"); */
     48    handler_called = 1;
     49    return;
     50}
     51
     52void *a_thread_func()
     53{
     54    struct sigaction act;
     55    sigset_t pendingset;
     56
     57    act.sa_flags = 0;
     58    act.sa_handler = handler;
     59    sigemptyset(&act.sa_mask);
     60    sigaction(SIGTOTEST, &act, 0);
     61    sighold(SIGTOTEST);
     62
     63    if ((sigpause(SIGTOTEST) != -1) || (errno != EINTR)) {
     64        printf("%ssigpause_2-1:%s               "
     65            "%sFAILED: sigpause didn't return -1 and/or didn't set errno correctly: %s%s\n",
     66            boldOn, boldOff, red, strerror(errno), normal);
     67        return_value = 2;
     68        return NULL;
     69    }
     70
     71    sleep(1);
     72
     73    raise (SIGTOTEST);
     74    sigpending(&pendingset);
     75    if (sigismember(&pendingset, SIGTOTEST) == 1) {
     76        /* printf("sigpause_2-1: Test PASSED: signal mask was restored when sigpause returned.\n"); */
     77        return_value = 0;
     78    }
     79   
     80    sem = INMAIN;
     81    return NULL;
     82}
     83
     84int main()
     85{
     86    pthread_t new_th;
     87
     88    if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
     89    {
     90        printf("%ssigpause_2-1:%s               "
     91            "%sFAILED: Error creating thread: %s%s\n",
     92            boldOn, boldOff, red, strerror(errno), normal);
     93        return PTS_UNRESOLVED;
     94    }
     95
     96    sleep(1);
     97
     98    if(pthread_kill(new_th, SIGTOTEST) != 0)
     99    {
     100        printf("%ssigpause_2-1:%s               "
     101            "%sFAILED: Couldn't send signal to thread: %s%s\n",
     102            boldOn, boldOff, red, strerror(errno), normal);
     103        return PTS_UNRESOLVED;
     104    }
     105
     106    sem = INTHREAD;
     107    while (sem == INTHREAD)
     108        sleep(1);
     109   
     110    if(handler_called != 1) {
     111        printf("%ssigpause_2-1:%s               "
     112            "%sFAILED: signal wasn't removed from signal mask: %s%s\n",
     113            boldOn, boldOff, red, strerror(errno), normal);
     114        return PTS_UNRESOLVED;
     115    }
     116
     117    if (return_value != 0) {
     118        if (return_value == 1)
     119            return PTS_FAIL;
     120        if (return_value == 2)
     121            return PTS_UNRESOLVED;
     122        return PTS_UNRESOLVED;
     123    }
     124   
     125    printf("%ssigpause_2-1:%s               %sPASSED%s\n", boldOn, boldOff, green, normal);
     126    return PTS_PASS;   
     127}
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/3-1.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 This program verifies that sigpause() returns -1 and sets errno to EINTR
     9 when it returns.
     10
     11 Steps:
     12 1. From the main() function, create a new thread. Give the new thread a
     13    a second to set up for receiving a signal, and to suspend itself using
     14    sigpause().
     15 2. From the main() thread, send signal to new thread to make sigpause return.
     16 3. Verify that sigpause returns -1 and sets errno to EINTR.
     17 */
     18
     19#define _XOPEN_SOURCE 600
     20
     21#include <pthread.h>
     22#include <stdio.h>
     23#include <signal.h>
     24#include <errno.h>
     25#include <unistd.h>
     26#include "posixtest.h"
     27
     28#define SIGTOTEST SIGABRT
     29#define INTHREAD 0
     30#define INMAIN 1
     31
     32int result = 2;
     33int sem = INMAIN;
     34
     35void handler() {
     36    /* printf("signal was called\n"); */
     37    return;
     38}
     39
     40void *a_thread_func()
     41{
     42    int return_value = 0;
     43    struct sigaction act;
     44    act.sa_flags = 0;
     45    act.sa_handler = handler;
     46    sigemptyset(&act.sa_mask);
     47    sigaction(SIGTOTEST, &act, 0);
     48    return_value = sigpause(SIGTOTEST);
     49    if (return_value == -1) {
     50        if (errno == EINTR) {
     51            /* printf ("Test PASSED: sigpause returned -1 and set errno to EINTR\n"); */
     52            result = 0;
     53        } else {
     54            printf("%ssigpause_3-1:%s               "
     55                "%sFAILED: sigpause did not set errno to EINTR: %s%s\n",
     56                boldOn, boldOff, red, strerror(errno), normal);
     57            result = 1;
     58        }
     59    } else {
     60        if (errno == EINTR) {
     61            printf("%ssigpause_3-1:%s               "
     62            "%sFAILED: sigpause did not return -1: %s%s\n",
     63            boldOn, boldOff, red, strerror(errno), normal);
     64        }
     65        printf("%ssigpause_3-1:%s               "
     66            "%sFAILED: sigpause did not set errno to EINTR: %s%s\n",
     67            boldOn, boldOff, red, strerror(errno), normal);
     68        printf("%ssigpause_3-1:%s               "
     69            "%sFAILED: sigpause did not return -1: %s%s\n",
     70            boldOn, boldOff, red, strerror(errno), normal);
     71        result = 1;
     72
     73    }
     74    sem = INMAIN;
     75    return NULL;
     76}
     77
     78int main()
     79{
     80    pthread_t new_th;
     81
     82    if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
     83    {
     84        printf("%ssigpause_3-1:%s               "
     85            "%sFAILED: Error creating thread: %s%s\n",
     86            boldOn, boldOff, red, strerror(errno), normal);
     87        return PTS_UNRESOLVED;
     88    }
     89
     90    sleep(1);
     91
     92    if(pthread_kill(new_th, SIGTOTEST) != 0)
     93    {
     94        printf("%ssigpause_3-1:%s               "
     95            "%sFAILED: Couldn't send signal to thread: %s%s\n",
     96            boldOn, boldOff, red, strerror(errno), normal);
     97        return PTS_UNRESOLVED;
     98    }
     99
     100    sem = INTHREAD;
     101    while (sem == INTHREAD)
     102        sleep(1);
     103
     104    if(result == 2) {
     105        return PTS_UNRESOLVED;
     106    }
     107    if(result == 1) {
     108        return PTS_FAIL;
     109    }
     110
     111    printf("%ssigpause_3-1:%s               %sPASSED%s\n", boldOn, boldOff, green, normal);
     112    return PTS_PASS;   
     113}
     114
     115
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/4-1.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 This program verifies that sigpause() returns -1 and sets errno to EINVAL
     9 if passed an invalid signal number.
     10
     11 */
     12
     13#define _XOPEN_SOURCE 600
     14
     15#include <pthread.h>
     16#include <stdio.h>
     17#include <signal.h>
     18#include <errno.h>
     19#include <unistd.h>
     20#include "posixtest.h"
     21
     22#define SIGTOTEST SIGABRT
     23
     24int main()
     25{
     26    int return_value = 0;
     27        int result;
     28
     29    return_value = sigpause(-1);
     30    if (return_value == -1) {
     31        if (errno == EINVAL) {
     32            /* printf ("sigpause_4-1: Test PASSED: sigpause returned -1 and set errno to EINVAL\n"); */
     33            result = 0;
     34        } else {
     35            printf("%ssigpause_4-1:%s               "
     36                "%sFAILED: sigpause did not set errno to EINVAL: %s%s\n",
     37                boldOn, boldOff, red, strerror(errno), normal);
     38            result = 1;
     39        }
     40    } else {
     41        printf("%ssigpause_4-1:%s               "
     42            "%sFAILED: sigpause did not return -1: %s%s\n",
     43            boldOn, boldOff, red, strerror(errno), normal);
     44        if (errno == EINVAL) {
     45            printf("%ssigpause_4-1:%s               "
     46            "%sFAILED: sigpause did not set errno to EINVAL: %s%s\n",
     47            boldOn, boldOff, red, strerror(errno), normal);
     48        }
     49        result = 1;
     50    }
     51
     52        if(result == 2) {
     53                return PTS_UNRESOLVED;
     54        }
     55        if(result == 1) {
     56                return PTS_FAIL;
     57        }
     58
     59    printf("%ssigpause_4-1:%s               %sPASSED%s\n", boldOn, boldOff, green, normal);
     60    return PTS_PASS;
     61}
     62
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/Jamfile

     
     1SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigpause ;
     2
     3SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
     4
     5SimpleTest sigpause_1-1 : 1-1.c ;
     6SimpleTest sigpause_1-2 : 1-2.c ;
     7SimpleTest sigpause_2-1 : 2-1.c ;
     8SimpleTest sigpause_3-1 : 3-1.c ;
     9SimpleTest sigpause_4-1 : 4-1.c ;
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigpause/assertions.xml

     
     1<assertions>
     2  <assertion id="1" tag="ref:XSH6:41956:41957 pt:XSI">
     3    The sigpause() function shall remove sig from the signal mask of
     4    the calling process and suspend the calling process until it
     5    receives a signal
     6  </assertion>
     7  <assertion id="2" tag="ref:XSH6:41957:41958 pt:XSI">
     8    The sigpause() function shall restore the signal
     9    mask of the calling process to its original state before it returns.
     10  </assertion>
     11  <assertion id="3" tag="ref:XSH6:41968:41969 pt:XSI">
     12    Execution shall be suspended by sigpause() function until
     13    a signal is received, after which it shall return -1 and set errno to
     14    [EINTR].
     15  </assertion>
     16  <assertion id="4" tag="ref:XSH6:41974:41974 pt:XSI">
     17    If the sig argument is an illegal signal number, then errno will be set to [EINVAL].
     18  </assertion>
     19</assertions>
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/1-1.c

     
     1/*   
     2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *  Test that the killpg() function shall send signal sig to the process
     9    group specified by prgp.
     10    Steps:
     11 *  1. Set up a signal handler for the signal that says we have caught the
     12 *     signal.
     13 *  2. Call killpg on the current process group id, raising the signal.
     14 *  3. If signal handler was called, test passed.
     15
     16 */
     17
     18#define _XOPEN_SOURCE 600
     19#define SIGTOTEST SIGCHLD
     20
     21#include <signal.h>
     22#include <stdio.h>
     23#include <stdlib.h>
     24#include <unistd.h>
     25#include "posixtest.h"
     26
     27void handler(int signo)
     28{
     29    /* printf("Caught signal being tested!\n"); */
     30    printf("%skillpg_1-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     31    exit(0);
     32}
     33
     34int main()
     35{
     36    int pgrp;
     37    struct sigaction act;
     38
     39    act.sa_handler=handler;
     40    act.sa_flags=0;
     41    if (sigemptyset(&act.sa_mask) == -1) {
     42        perror("killpg_1-1: Error calling sigemptyset\n");
     43        return PTS_UNRESOLVED;
     44    }
     45    if (sigaction(SIGTOTEST, &act, 0) == -1) {
     46        perror("killpg_1-1: Error calling sigaction\n");
     47        return PTS_UNRESOLVED;
     48    }
     49
     50    if ((pgrp = getpgrp()) == -1) {
     51        printf("killpg_1-1: Could not get process group number\n");
     52        return PTS_UNRESOLVED;
     53    }
     54
     55    if (killpg(pgrp, SIGTOTEST) != 0) {
     56        printf("killpg_1-1: Could not raise signal being tested\n");
     57        return PTS_UNRESOLVED;
     58    }
     59
     60    printf("killpg_1-1: Should have exited from signal handler\n");
     61    printf("killpg_1-1: Test FAILED\n");
     62    return PTS_FAIL;
     63}
     64
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/1-2.c

     
     1/*   
     2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *   Steps:
     9 *  1) Fork a child process.
     10 *  2) In the parent process, call killpg with signal SIGTOTEST for the
     11 *     process group id of the child. Have the parent ignore such a signal
     12 *     incase the process group id of the parent is the same as process
     13 *     group id of the child.
     14 *  In the child,
     15 *    3) Wait for signal SIGTOTEST.
     16 *    4) Return 1 if SIGTOTEST is found.  Return 0 otherwise.
     17 *  5) In the parent, return success if 1 was returned from child.
     18 *
     19 */
     20
     21#define _XOPEN_SOURCE 600
     22#define SIGTOTEST SIGUSR1
     23
     24#include <signal.h>
     25#include <stdio.h>
     26#include <stdlib.h>
     27#include <unistd.h>
     28#include <sys/wait.h>
     29#include "posixtest.h"
     30
     31void myhandler (int signo) {
     32    exit(1);
     33}
     34
     35int main()
     36{
     37    int child_pid, child_pgid;
     38
     39    if ((child_pid = fork()) == 0) {
     40        /* child here */
     41        struct sigaction act;
     42        act.sa_handler=myhandler;
     43        act.sa_flags=0;
     44        sigemptyset(&act.sa_mask);
     45        sigaction(SIGTOTEST, &act, 0);
     46
     47        /* change child's process group id */
     48        setpgrp();
     49
     50        sigpause(SIGABRT);
     51
     52        return 0;
     53    } else {
     54        /* parent here */
     55        int i;
     56        sigignore(SIGTOTEST);
     57
     58        sleep(1);
     59        if ((child_pgid = getpgid(child_pid)) == -1) {
     60            printf("killpg_1-2: Could not get pgid of child\n");
     61            return PTS_UNRESOLVED;
     62        }
     63
     64
     65        if (killpg(child_pgid, SIGTOTEST) != 0) {
     66            printf("killpg_1-2: Could not raise signal being tested\n");
     67            return PTS_UNRESOLVED;
     68        }
     69
     70        if (wait(&i) == -1) {
     71            perror("killpg_1-2: Error waiting for child to exit\n");
     72            return PTS_UNRESOLVED;
     73        }
     74
     75        if (WEXITSTATUS(i)) {
     76            /* printf("Child exited normally\n"); */
     77            printf("%skillpg_1-2:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     78            return PTS_PASS;
     79        } else {
     80            printf("killpg_1-2: Child did not exit normally.\n");
     81            printf("killpg_1-2: Test FAILED\n");
     82            return PTS_FAIL;
     83        }
     84    }
     85
     86    printf("killpg_1-2: Should have exited from parent\n");
     87    printf("killpg_1-2: Test FAILED\n");
     88    return PTS_FAIL;
     89}
     90
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/2-1.c

     
     1/*   
     2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 Call killpg on the current process with 0 as the signal number. If killpg
     9 returns success, then we pass.
     10 */
     11
     12#define _XOPEN_SOURCE 600
     13
     14#include <signal.h>
     15#include <stdio.h>
     16#include <stdlib.h>
     17#include <unistd.h>
     18#include "posixtest.h"
     19
     20int main()
     21{
     22    if (killpg(getpgrp(), 0) != 0) {
     23        printf("killpg_2-1: Could not call killpg with sig = 0\n");
     24        return PTS_FAIL;
     25    }
     26
     27    printf("%skillpg_2-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     28    return PTS_PASS;
     29}
     30
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/4-1.c

     
     1/*   
     2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *  Test that the killpg() function shall return 0 upon success.
     9
     10 */
     11
     12#define _XOPEN_SOURCE 600
     13
     14#include <signal.h>
     15#include <stdio.h>
     16#include <stdlib.h>
     17#include <unistd.h>
     18#include "posixtest.h"
     19
     20int main()
     21{
     22    int pgrp;
     23
     24    if ((pgrp = getpgrp()) == -1) {
     25        printf("killpg_4-1: Could not get process group number\n");
     26        return PTS_UNRESOLVED;
     27    }
     28
     29    if (killpg(pgrp, 0) != 0) {
     30        printf("killpg_4-1: killpg did not return success.\n");
     31        return PTS_UNRESOLVED;
     32    }
     33
     34    printf("%skillpg_4-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     35    return PTS_PASS;
     36}
     37
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/5-1.c

     
     1/*   
     2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *  Test that the killpg() function shall return -1 on failure.
     9
     10 */
     11
     12#define _XOPEN_SOURCE 600
     13
     14#include <signal.h>
     15#include <stdio.h>
     16#include <stdlib.h>
     17#include <unistd.h>
     18#include <errno.h>
     19#include "posixtest.h"
     20
     21#if 0
     22void handler(int signo)
     23{
     24    printf("Caught signal being tested!\n");
     25    printf("Test PASSED\n");
     26    exit(0);
     27}
     28#endif
     29
     30
     31int main()
     32{
     33    int pgrp;
     34
     35    if ((pgrp = getpgrp()) == -1) {
     36        printf("killpg_5-1: Could not get process group number\n");
     37        return PTS_UNRESOLVED;
     38    }
     39
     40    if (killpg(pgrp, -1) != -1) {
     41        printf("killpg_5-1: Test FAILED: killpg did not return -1 even though it was passed an invalid signal number.");
     42        return PTS_FAIL;
     43    }
     44
     45    printf("%skillpg_5-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     46    return PTS_PASS;
     47}
     48
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/6-1.c

     
     1/*   
     2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *  Test that the killpg() function shall set errno to EINVAL if it is
     9    passed an invalid signal number
     10
     11 */
     12
     13#define _XOPEN_SOURCE 600
     14
     15#include <signal.h>
     16#include <stdio.h>
     17#include <stdlib.h>
     18#include <unistd.h>
     19#include <errno.h>
     20#include "posixtest.h"
     21
     22int main()
     23{
     24    int pgrp;
     25
     26    if ((pgrp = getpgrp()) == -1) {
     27        printf("killpg_6-1: Could not get process group number\n");
     28        return PTS_UNRESOLVED;
     29    }
     30
     31    if (killpg(pgrp, -1) != -1) {
     32        printf("killpg_6-1: killpg did not return -1 even though it was passed an invalid signal number.");
     33        return PTS_UNRESOLVED;
     34    }
     35
     36    if (errno != EINVAL) {
     37        printf("killpg_6-1: killpg did not set errno to EINVAL even though it was passed an invalid signal number.");
     38        return PTS_FAIL;
     39    }
     40
     41    printf("%skillpg_6-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     42    return PTS_PASS;
     43}
     44
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/8-1.c

     
     1/*   
     2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
     3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
     4 * This file is licensed under the GPL license.  For the full content
     5 * of this license, see the COPYING file at the top level of this
     6 * source tree.
     7
     8 *  Test that the killpg() function shall set errno to ESRCH if it is
     9    passed an invalid process group number
     10
     11 */
     12
     13#define _XOPEN_SOURCE 600
     14
     15#include <signal.h>
     16#include <stdio.h>
     17#include <stdlib.h>
     18#include <unistd.h>
     19#include <errno.h>
     20#include "posixtest.h"
     21
     22int main()
     23{
     24
     25    if (killpg(999999, 0) != -1) {
     26        printf("killpg_8-1: killpg did not return -1 even though it was passed an invalid process group id.");
     27        return PTS_UNRESOLVED;
     28    }
     29
     30    if (errno != ESRCH) {
     31        printf("killpg_8-1: killpg did not set errno to ESRCH even though it was passed an invalid signal number.");
     32        return PTS_FAIL;
     33    }
     34
     35    printf("%skillpg_8-1:%s                 %sPASSED%s\n", boldOn, boldOff, green, normal);
     36    return PTS_PASS;
     37}
     38
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/Jamfile

     
     1SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces killpg ;
     2
     3SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
     4
     5SimpleTest killpg_1-1 : 1-1.c ;
     6SimpleTest killpg_1-2 : 1-2.c ;
     7SimpleTest killpg_2-1 : 2-1.c ;
     8SimpleTest killpg_4-1 : 4-1.c ;
     9SimpleTest killpg_5-1 : 5-1.c ;
     10SimpleTest killpg_6-1 : 6-1.c ;
     11SimpleTest killpg_8-1 : 8-1.c ;
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/killpg/assertions.xml

     
     1<assertions>
     2  <assertion id="1" tag="ref:XSH6:22101:22101 pt:XSI">
     3The killpg () function sends the signal sig to the process
     4group pgrp.
     5  </assertion>
     6  <assertion id="2" tag="ref:XSH6:22102:22102 pt:XSI">
     7killpg(pgrp, sig) is equivalent to kill(-pgrp, sig), when pgrp is greater than 1,
     8  </assertion>
     9  <assertion id="3" tag="ref:XSH6:22102:22103 pt:XSI">
     10The behavior of killpg ( ) is undefined if pgrp is less than or equal to 1.
     11  </assertion>
     12  <assertion id="4" tag="ref:XSH6:22105:22105 pt:XSI">
     13killpg returns 0 upon successful completion.
     14  </assertion>
     15  <assertion id="5" tag="ref:XSH6:22105:22106 pt:XSI">
     16killpg returns -1, upon unsuccessful completion.
     17  </assertion>
     18  <assertion id="6" tag="ref:XSH6:22009:22009 pt:XSI">
     19errno shall be set to EINVAL, when tThe value of the sig argument is an
     20invalid or unsupported signal
     21number.
     22  </assertion>
     23  <assertion id="7" tag="ref:XSH6:22010:22011 pt:XSI">
     24errno shall be set to EPERM, when the process does not have permission to
     25send the signal to any
     26receiving process.
     27  </assertion>
     28  <assertion id="8" tag="ref:XSH6:22012:22013 pt:XSI">
     29errno shall be set to ESRCH, when no process or process group can be found
     30corresponding to that specified by pid.
     31  </assertion>
     32</assertions>
     33
  • src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile

     
    33SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces difftime ;
    44SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces fork ;
    55SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces kill ;
     6SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces killpg ;
    67SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_create ;
    78SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_delete ;
    89SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_getspecific ;
     
    1516SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces signal ;
    1617SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigset ;
    1718SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigsuspend ;
     19SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigpause ;