Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/configs/parsenums.cfa

    r481f882 ra46f7b6  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
    3 //
    4 // The contents of this file are covered under the licence agreement in the
    5 // file "LICENCE" distributed with Cforall.
    6 //
    7 // configs/parsenums.cfa
    8 // Testing parsing of integer arguments
    9 //
    10 // Author           : Thierry Delisle
    11 // Created On       : Wed Oct 12 15:28:01 2022
    12 // Last Modified By :
    13 // Last Modified On :
    14 // Update Count     :
    15 //
     1#include <stdlib.h>
     2#include <stdio.h>
     3#include <string.h>
     4
     5#include <errno.h>
     6#include <signal.h>
     7
     8extern "C" {
     9        #include <sys/types.h>
     10        #include <sys/wait.h>
     11        #include <unistd.h>
     12}
    1613
    1714#include <parseargs.hfa>
    1815#include <fstream.hfa>
    19 
    20 #include "../meta/fork+exec.hfa"
    2116
    2217#if __SIZEOF_LONG__ == 4
     
    3328
    3429int main(int argc, char * argv[]) {
    35         check_main(argv[0]);
     30        if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);
    3631
    3732        int i = -3;
     
    6156}
    6257
    63 int true_main(const char * path, char * env[]) {
     58int do_wait(pid_t pid) {
     59        int wstatus;
     60        int options = 0;
     61        pid_t ret = waitpid(pid, &wstatus, options);
     62        fflush(stdout);
     63        if(ret < 0) {
     64                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
     65                exit(1);
     66        }
     67        return wstatus;
     68}
     69
     70pid_t strict_fork(void) {
     71        fflush(stdout);
     72        pid_t ret = fork();
     73        if(ret < 0) {
     74                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
     75                exit(1);
     76        }
     77        return ret;
     78}
     79
     80void print_status(int wstatus) {
     81        printf("Child status:\n");
     82        printf("    WIFEXITED   : %d", WIFEXITED(wstatus));
     83        printf("    WEXITSTATUS : %d", WEXITSTATUS(wstatus));
     84        printf("    WIFSIGNALED : %d", WIFSIGNALED(wstatus));
     85        printf("    WTERMSIG    : %d", WTERMSIG(wstatus));
     86        printf("    WCOREDUMP   : %d", WCOREDUMP(wstatus));
     87        printf("    WIFSTOPPED  : %d", WIFSTOPPED(wstatus));
     88        printf("    WSTOPSIG    : %d", WSTOPSIG(wstatus));
     89        printf("    WIFCONTINUED: %d\n", WIFCONTINUED(wstatus));
     90}
     91
     92int true_main(const char * path) {
     93        char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
     94
    6495        printf("no arg:\n");
    6596        if(pid_t child = strict_fork(); child == 0) {
     
    74105                print_status(status);
    75106        }
     107        printf("\n");
    76108
    77109        printf("all 0 arg:\n");
     
    87119                print_status(status);
    88120        }
     121        printf("\n");
    89122
    90123        printf("negative vals arg:\n");
     
    100133                print_status(status);
    101134        }
     135        printf("\n");
    102136
    103137        printf("funky notation arg:\n");
     
    113147                print_status(status);
    114148        }
     149        printf("\n");
    115150
    116151        printf("big values arg:\n");
     
    126161                print_status(status);
    127162        }
     163        printf("\n");
    128164
    129165        printf("too big values arg:\n");
     
    139175                print_status(status);
    140176        }
     177        printf("\n");
    141178
    142179        if(pid_t child = strict_fork(); child == 0) {
     
    151188                print_status(status);
    152189        }
     190        printf("\n");
    153191
    154192        if(pid_t child = strict_fork(); child == 0) {
     
    163201                print_status(status);
    164202        }
     203        printf("\n");
    165204
    166205        if(pid_t child = strict_fork(); child == 0) {
     
    175214                print_status(status);
    176215        }
     216        printf("\n");
    177217
    178218        printf("negative errors arg:\n");
     
    188228                print_status(status);
    189229        }
     230        printf("\n");
    190231
    191232        if(pid_t child = strict_fork(); child == 0) {
     
    200241                print_status(status);
    201242        }
     243        printf("\n");
    202244
    203245        if(pid_t child = strict_fork(); child == 0) {
     
    212254                print_status(status);
    213255        }
     256        printf("\n");
    214257
    215258        printf("All Done!\n");
Note: See TracChangeset for help on using the changeset viewer.