Changes in / [4af5396:a25bcf8]


Ignore:
Files:
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseargs.cfa

    r4af5396 ra25bcf8  
    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 // parseargs.cfa
    8 // implementation of arguments parsing (argc, argv)
    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 //
    16 
    171#include "parseargs.hfa"
    182
    19 #include <assert.h>
    203#include <ctype.h>
    214#include <stdint.h>
     
    163146}
    164147
    165 static inline int next_newline(const char * str) {
    166         int ret;
    167         const char * ptr = strstr(str, "\n");
    168         if(!ptr) return MAX;
    169 
    170         /* paranoid */ verify( str <= ptr);
    171         intptr_t low = (intptr_t)str;
    172         intptr_t hi  = (intptr_t)ptr;
    173         ret = hi - low;
    174 
    175         return ret;
    176 }
    177 
    178148//-----------------------------------------------------------------------------
    179149// Print usage
    180150static void printopt(FILE * out, int width, int max, char sn, const char * ln, const char * help) {
    181         // check how wide we should be printing
    182         // this includes all options and the help message
    183151        int hwidth = max - (11 + width);
    184152        if(hwidth <= 0) hwidth = max;
    185153
    186         // check which pieces we have
    187         bool has_ln = ln && strcmp("", ln);
    188         bool has_help = help && strcmp("", help);
    189 
    190         // print the small name if present
    191         if(sn != '\0') fprintf(out, "  -%c", sn);
    192         else fprintf(out, "    ");
    193 
    194         // print a comma if we have both short and long names
    195         if(sn != '\0' && has_ln) fprintf(out, ", ");
    196         else fprintf(out, "  ");
    197 
    198         // print the long name if present
    199         if(has_ln)        fprintf(out, "--%-*s", width, ln);
    200         else if(has_help) fprintf(out, "  %-*s", width, "");
    201 
    202         if(has_help) {
    203                 // print the help
    204                 // We need to wrap at the max width, and also indent newlines so everything is nice and pretty
    205 
    206                 // for each line to print
    207                 for() {
    208                         //find out if there is a newline
    209                         int nextnl = next_newline(help);
    210                         int real = min(min(strlen(help), hwidth), nextnl);
    211 
    212                         fprintf(out, "   %.*s", real, help);
    213                         // printf("%d %d\n", real, nextnl);
    214                         help += real;
    215                         if( nextnl == real ) help++;
    216                         if('\0' == *help) break;
    217                         fprintf(out, "\n%*s", width + 8, "");
    218                 }
    219         }
    220         fprintf(out, "\n");
     154        char sname[4] = { ' ', ' ', ' ', '\0' };
     155        if(sn != '\0') {
     156                sname[0] = '-';
     157                sname[1] = sn;
     158                sname[2] = ',';
     159        }
     160
     161        fprintf(out, "  %s --%-*s   %.*s\n", sname, width, ln, hwidth, help);
     162        for() {
     163                help += min(strlen(help), hwidth);
     164                if('\0' == *help) break;
     165                fprintf(out, "%*s%.*s\n", width + 11, "", hwidth, help);
     166        }
    221167}
    222168
  • libcfa/src/parseargs.hfa

    r4af5396 ra25bcf8  
    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 // parseargs.cfa -- PUBLIC
    8 // API for arguments parsing (argc, argv)
    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 //
    161#pragma once
    172
  • tests/configs/.expect/parsebools.txt

    r4af5396 ra25bcf8  
    77set false  :true
    88Child status:
    9 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     9    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    1010
    1111all true/set arg:
     
    1717set false  :false
    1818Child status:
    19 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     19    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    2020
    2121all false/unset arg:
     
    2727set false  :true
    2828Child status:
    29 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     29    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    3030
    3131gibberish arg 1:
     
    4343  -h, --help        print this help message
    4444Child status:
    45 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     45    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    4646
    4747gibberish arg 2:
     
    5959  -h, --help        print this help message
    6060Child status:
    61 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     61    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    6262
    6363gibberish arg 3:
     
    7474  -h, --help        print this help message
    7575Child status:
    76 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     76    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    7777
    7878gibberish arg 4:
     
    8989  -h, --help        print this help message
    9090Child status:
    91 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     91    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    9292
    9393All Done!
  • tests/configs/.expect/parsenums.x64.txt

    r4af5396 ra25bcf8  
    66double             :3.3
    77Child status:
    8 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     8    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    99
    1010all 0 arg:
     
    1515double             :0.
    1616Child status:
    17 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     17    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    1818
    1919negative vals arg:
     
    2424double             :-1.
    2525Child status:
    26 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     26    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    2727
    2828funky notation arg:
     
    3333double             :5000000.
    3434Child status:
    35 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     35    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    3636
    3737big values arg:
     
    4242double             :5000000.
    4343Child status:
    44 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     44    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    4545
    4646too big values arg:
     
    5757  -h, --help               print this help message
    5858Child status:
    59 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     59    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    6060
    6161Argument '4294967296' for option u could not be parsed
     
    7171  -h, --help               print this help message
    7272Child status:
    73 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     73    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    7474
    7575Argument '18446744073709551616' for option l could not be parsed
     
    8585  -h, --help               print this help message
    8686Child status:
    87 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     87    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    8888
    8989Argument '18446744073709551616' for option L could not be parsed
     
    9999  -h, --help               print this help message
    100100Child status:
    101 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     101    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    102102
    103103negative errors arg:
     
    114114  -h, --help               print this help message
    115115Child status:
    116 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     116    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    117117
    118118Argument '-1' for option l could not be parsed
     
    128128  -h, --help               print this help message
    129129Child status:
    130 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     130    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    131131
    132132Argument '-1' for option L could not be parsed
     
    142142  -h, --help               print this help message
    143143Child status:
    144 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     144    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    145145
    146146All Done!
  • tests/configs/.expect/parsenums.x86.txt

    r4af5396 ra25bcf8  
    66double             :3.3
    77Child status:
    8 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     8    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    99
    1010all 0 arg:
     
    1515double             :0.
    1616Child status:
    17 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     17    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    1818
    1919negative vals arg:
     
    2424double             :-1.
    2525Child status:
    26 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     26    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    2727
    2828funky notation arg:
     
    3333double             :5000000.
    3434Child status:
    35 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     35    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    3636
    3737big values arg:
     
    4242double             :5000000.
    4343Child status:
    44 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
     44    WIFEXITED   : 1    WEXITSTATUS : 0    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 0    WIFCONTINUED: 0
    4545
    4646too big values arg:
     
    5757  -h, --help               print this help message
    5858Child status:
    59 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     59    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    6060
    6161Argument '4294967296' for option u could not be parsed
     
    7171  -h, --help               print this help message
    7272Child status:
    73 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     73    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    7474
    7575Argument '4294967296' for option l could not be parsed
     
    8585  -h, --help               print this help message
    8686Child status:
    87 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     87    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    8888
    8989Argument '18446744073709551616' for option L could not be parsed
     
    9999  -h, --help               print this help message
    100100Child status:
    101 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     101    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    102102
    103103negative errors arg:
     
    114114  -h, --help               print this help message
    115115Child status:
    116 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     116    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    117117
    118118Argument '-1' for option l could not be parsed
     
    128128  -h, --help               print this help message
    129129Child status:
    130 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     130    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    131131
    132132Argument '-1' for option L could not be parsed
     
    142142  -h, --help               print this help message
    143143Child status:
    144 IFEXITED   : 1, EXITSTATUS : 1, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 1, IFCONTINUED: 0
     144    WIFEXITED   : 1    WEXITSTATUS : 1    WIFSIGNALED : 0    WTERMSIG    : 0    WCOREDUMP   : 0    WIFSTOPPED  : 0    WSTOPSIG    : 1    WIFCONTINUED: 0
    145145
    146146All Done!
  • tests/configs/parsebools.cfa

    r4af5396 ra25bcf8  
    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");
  • tests/configs/parsenums.cfa

    r4af5396 ra25bcf8  
    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");
  • tests/meta/.expect/fork+exec.txt

    r4af5396 ra25bcf8  
    44Success!
    55Child status:
    6 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
    7 
     6    WIFEXITED   : 1
     7    WEXITSTATUS : 0
     8    WIFSIGNALED : 0
     9    WTERMSIG    : 0
     10    WCOREDUMP   : 0
     11    WIFSTOPPED  : 0
     12    WSTOPSIG    : 0
     13    WIFCONTINUED: 0
    8141 arg:
    915arguments are:
     
    1117Success!
    1218Child status:
    13 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
    14 
     19    WIFEXITED   : 1
     20    WEXITSTATUS : 0
     21    WIFSIGNALED : 0
     22    WTERMSIG    : 0
     23    WCOREDUMP   : 0
     24    WIFSTOPPED  : 0
     25    WSTOPSIG    : 0
     26    WIFCONTINUED: 0
    15275 arg:
    1628arguments are:
     
    2234Success!
    2335Child status:
    24 IFEXITED   : 1, EXITSTATUS : 0, IFSIGNALED : 0, TERMSIG    : 0, COREDUMP   : 0, IFSTOPPED  : 0, STOPSIG    : 0, IFCONTINUED: 0
    25 
     36    WIFEXITED   : 1
     37    WEXITSTATUS : 0
     38    WIFSIGNALED : 0
     39    WTERMSIG    : 0
     40    WCOREDUMP   : 0
     41    WIFSTOPPED  : 0
     42    WSTOPSIG    : 0
     43    WIFCONTINUED: 0
    2644All Done!
  • tests/meta/fork+exec.hfa

    r4af5396 ra25bcf8  
    2828}
    2929
    30 static int true_main(const char * path, char * env[]);
     30static int true_main(const char * exec, char * env[]);
    3131
    3232static int do_wait(pid_t pid) {
     
    5555static void print_status(int wstatus) {
    5656        printf("Child status:\n");
    57         printf("IFEXITED   : %d, ", WIFEXITED(wstatus));
    58         printf("EXITSTATUS : %d, ", WEXITSTATUS(wstatus));
    59         printf("IFSIGNALED : %d, ", WIFSIGNALED(wstatus));
    60         printf("TERMSIG    : %d, ", WTERMSIG(wstatus));
    61         printf("COREDUMP   : %d, ", WCOREDUMP(wstatus));
    62         printf("IFSTOPPED  : %d, ", WIFSTOPPED(wstatus));
    63         printf("STOPSIG    : %d, ", WSTOPSIG(wstatus));
    64         printf("IFCONTINUED: %d", WIFCONTINUED(wstatus));
    65         printf("\n");
    66         printf("\n");
     57        printf("    WIFEXITED   : %d\n", WIFEXITED(wstatus));
     58        printf("    WEXITSTATUS : %d\n", WEXITSTATUS(wstatus));
     59        printf("    WIFSIGNALED : %d\n", WIFSIGNALED(wstatus));
     60        printf("    WTERMSIG    : %d\n", WTERMSIG(wstatus));
     61        printf("    WCOREDUMP   : %d\n", WCOREDUMP(wstatus));
     62        printf("    WIFSTOPPED  : %d\n", WIFSTOPPED(wstatus));
     63        printf("    WSTOPSIG    : %d\n", WSTOPSIG(wstatus));
     64        printf("    WIFCONTINUED: %d\n", WIFCONTINUED(wstatus));
    6765}
    6866
  • tests/test.py

    r4af5396 ra25bcf8  
    7272                                # this is a valid name, let's check if it already exists
    7373                                found = [test for test in all_tests if canonical_path( test.target() ) == testname]
    74                                 setup = settings.all_arch if options.arch else [None]
     74                                setup = itertools.product(settings.all_arch if options.arch else [None])
    7575                                if not found:
    7676                                        # it's a new name, create it according to the name and specified architecture
Note: See TracChangeset for help on using the changeset viewer.