Ignore:
Timestamp:
Oct 12, 2022, 4:32:49 PM (20 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
38cc59f
Parents:
a51b8f6
Message:

Added some missing headers and cleaned up some of the fork+exec stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/configs/parsenums.cfa

    ra51b8f6 r481f882  
    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include <string.h>
    4 
    5 #include <errno.h>
    6 #include <signal.h>
    7 
    8 extern "C" {
    9         #include <sys/types.h>
    10         #include <sys/wait.h>
    11         #include <unistd.h>
    12 }
     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//
    1316
    1417#include <parseargs.hfa>
    1518#include <fstream.hfa>
     19
     20#include "../meta/fork+exec.hfa"
    1621
    1722#if __SIZEOF_LONG__ == 4
     
    2833
    2934int main(int argc, char * argv[]) {
    30         if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);
     35        check_main(argv[0]);
    3136
    3237        int i = -3;
     
    5661}
    5762
    58 int 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 
    70 pid_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 
    80 void 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 
    92 int true_main(const char * path) {
    93         char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
    94 
     63int true_main(const char * path, char * env[]) {
    9564        printf("no arg:\n");
    9665        if(pid_t child = strict_fork(); child == 0) {
     
    10574                print_status(status);
    10675        }
    107         printf("\n");
    10876
    10977        printf("all 0 arg:\n");
     
    11987                print_status(status);
    12088        }
    121         printf("\n");
    12289
    12390        printf("negative vals arg:\n");
     
    133100                print_status(status);
    134101        }
    135         printf("\n");
    136102
    137103        printf("funky notation arg:\n");
     
    147113                print_status(status);
    148114        }
    149         printf("\n");
    150115
    151116        printf("big values arg:\n");
     
    161126                print_status(status);
    162127        }
    163         printf("\n");
    164128
    165129        printf("too big values arg:\n");
     
    175139                print_status(status);
    176140        }
    177         printf("\n");
    178141
    179142        if(pid_t child = strict_fork(); child == 0) {
     
    188151                print_status(status);
    189152        }
    190         printf("\n");
    191153
    192154        if(pid_t child = strict_fork(); child == 0) {
     
    201163                print_status(status);
    202164        }
    203         printf("\n");
    204165
    205166        if(pid_t child = strict_fork(); child == 0) {
     
    214175                print_status(status);
    215176        }
    216         printf("\n");
    217177
    218178        printf("negative errors arg:\n");
     
    228188                print_status(status);
    229189        }
    230         printf("\n");
    231190
    232191        if(pid_t child = strict_fork(); child == 0) {
     
    241200                print_status(status);
    242201        }
    243         printf("\n");
    244202
    245203        if(pid_t child = strict_fork(); child == 0) {
     
    254212                print_status(status);
    255213        }
    256         printf("\n");
    257214
    258215        printf("All Done!\n");
Note: See TracChangeset for help on using the changeset viewer.