Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/configs/parsebools.cfa

    r481f882 rfd90096  
    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/parsebools.cfa
    8 // Testing parsing of boolean 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>
    1916
    20 #include "../meta/fork+exec.hfa"
     17int true_main(const char * exec);
    2118
    2219int main(int argc, char * argv[]) {
    23         check_main(argv[0]);
     20        if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);
    2421
    2522        bool YN = false;
     
    5148}
    5249
    53 int true_main(const char * path, char * env[]) {
     50int do_wait(pid_t pid) {
     51        int wstatus;
     52        int options = 0;
     53        pid_t ret = waitpid(pid, &wstatus, options);
     54        fflush(stdout);
     55        if(ret < 0) {
     56                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
     57                exit(1);
     58        }
     59        return wstatus;
     60}
     61
     62pid_t strict_fork(void) {
     63        fflush(stdout);
     64        pid_t ret = fork();
     65        if(ret < 0) {
     66                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
     67                exit(1);
     68        }
     69        return ret;
     70}
     71
     72void print_status(int wstatus) {
     73        printf("Child status:\n");
     74        printf("    WIFEXITED   : %d", WIFEXITED(wstatus));
     75        printf("    WEXITSTATUS : %d", WEXITSTATUS(wstatus));
     76        printf("    WIFSIGNALED : %d", WIFSIGNALED(wstatus));
     77        printf("    WTERMSIG    : %d", WTERMSIG(wstatus));
     78        printf("    WCOREDUMP   : %d", WCOREDUMP(wstatus));
     79        printf("    WIFSTOPPED  : %d", WIFSTOPPED(wstatus));
     80        printf("    WSTOPSIG    : %d", WSTOPSIG(wstatus));
     81        printf("    WIFCONTINUED: %d\n", WIFCONTINUED(wstatus));
     82}
     83
     84int true_main(const char * path) {
     85        char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
     86
    5487        printf("no arg:\n");
    5588        if(pid_t child = strict_fork(); child == 0) {
     
    6497                print_status(status);
    6598        }
     99        printf("\n");
    66100
    67101        printf("all true/set arg:\n");
     
    77111                print_status(status);
    78112        }
     113        printf("\n");
    79114
    80115        printf("all false/unset arg:\n");
     
    90125                print_status(status);
    91126        }
     127        printf("\n");
    92128
    93129        printf("gibberish arg 1:\n");
     
    103139                print_status(status);
    104140        }
     141        printf("\n");
    105142
    106143        printf("gibberish arg 2:\n");
     
    116153                print_status(status);
    117154        }
     155        printf("\n");
    118156
    119157        printf("gibberish arg 3:\n");
     
    129167                print_status(status);
    130168        }
     169        printf("\n");
    131170
    132171        printf("gibberish arg 4:\n");
     
    142181                print_status(status);
    143182        }
     183        printf("\n");
    144184
    145185        printf("All Done!\n");
Note: See TracChangeset for help on using the changeset viewer.