Changeset 68456fa for tests/meta


Ignore:
Timestamp:
Oct 10, 2022, 2:47:35 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
fd90096
Parents:
affb51b
Message:

First step at refactoring fork+exec to be reused across tests

Location:
tests/meta
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tests/meta/fork+exec.cfa

    raffb51b r68456fa  
    1313// Update Count     :
    1414//
    15 #include <stdlib.h>
    16 #include <stdio.h>
    17 #include <string.h>
    1815
    19 #include <errno.h>
    20 #include <signal.h>
    21 
    22 extern "C" {
    23         #include <sys/types.h>
    24         #include <sys/wait.h>
    25         #include <unistd.h>
    26 }
    27 
    28 int true_main(const char * exec);
     16#include "fork+exec.hfa"
    2917
    3018int main(int argc, char * argv[]) {
    31         if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);
     19        check_main(argv[0]);
    3220
    3321        printf("arguments are:\n");
     
    4230}
    4331
    44 int do_wait(pid_t pid) {
    45         int wstatus;
    46         int options = 0;
    47         pid_t ret = waitpid(pid, &wstatus, options);
    48         fflush(stdout);
    49         if(ret < 0) {
    50                 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
    51                 exit(1);
    52         }
    53         return wstatus;
    54 }
    5532
    56 pid_t strict_fork(void) {
    57         fflush(stdout);
    58         pid_t ret = fork();
    59         if(ret < 0) {
    60                 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
    61                 exit(1);
    62         }
    63         return ret;
    64 }
    6533
    66 void print_status(int wstatus) {
    67         printf("Child status:\n");
    68         printf("    WIFEXITED   : %d\n", WIFEXITED(wstatus));
    69         printf("    WEXITSTATUS : %d\n", WEXITSTATUS(wstatus));
    70         printf("    WIFSIGNALED : %d\n", WIFSIGNALED(wstatus));
    71         printf("    WTERMSIG    : %d\n", WTERMSIG(wstatus));
    72         printf("    WCOREDUMP   : %d\n", WCOREDUMP(wstatus));
    73         printf("    WIFSTOPPED  : %d\n", WIFSTOPPED(wstatus));
    74         printf("    WSTOPSIG    : %d\n", WSTOPSIG(wstatus));
    75         printf("    WIFCONTINUED: %d\n", WIFCONTINUED(wstatus));
    76 }
    77 
    78 int true_main(const char * path) {
    79         char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
    80 
     34int true_main(const char * path, char * env[]) {
    8135        printf("no arg:\n");
    8236        if(pid_t child = strict_fork(); child == 0) {
Note: See TracChangeset for help on using the changeset viewer.