Path: blob/main/tools/test/stress2/testcases/run/run.c
39566 views
/*-1* Copyright (c) 2008 Peter Holm <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25*/2627/* Control program to run all the other test cases */2829#include <sys/param.h>30#include <sys/wait.h>3132#include <err.h>33#include <libgen.h>34#include <stdio.h>35#include <stdlib.h>36#include <time.h>37#include <unistd.h>3839#include "stress.h"4041#define MAXAV 1042static char *av[MAXAV];43static int loop = 1;4445int46setup(int nb __unused)47{48return (0);49}5051void52cleanup(void)53{54}5556static char **57mkargv(char *name)58{59av[0] = name;60av[1] = 0;61return (av);62}6364static void65clean(void)66{67char buf[132];6869snprintf(buf, sizeof(buf),70"cd %s; rm -rf syscall.[0-9]* fifo.[0-9]* creat.[0-9]* "71"p[0-9]*.d1 df lock", op->cd);72(void)system(buf);73}7475int76test(void)77{78struct tm *tm;79pid_t *r;80time_t t;81int i;82int s;83char fullpath[MAXPATHLEN+1];84char ct[80];8586r = (pid_t *)malloc(op->argc * sizeof(pid_t));8788(void)time(&t);89tm = localtime(&t);90(void) strftime(ct, sizeof(ct), "%T", tm);91printf("%s Loop #%d\n", ct, loop++);92fflush(stdout);9394for (i = 0; i < op->argc; i++) {95r[i] = 0;96if (op->argv[i][0] == 0)97continue;98if ((r[i] = fork()) == 0) {99snprintf(fullpath, sizeof(fullpath), "%s/%s", home,100op->argv[i]);101if (execv(fullpath, mkargv(basename(op->argv[i]))) == -1)102err(1, "execl(%s), %s:%d", fullpath, __FILE__,103__LINE__);104}105if (r[i] < 0)106err(1, "fork(), %s:%d", __FILE__, __LINE__);107}108for (i = 0; i < op->argc; i++)109if (r[i] != 0 && waitpid(r[i], &s, 0) == -1)110err(1, "waitpid(%d), %s:%d", r[i], __FILE__, __LINE__);111free(r);112113clean();114115return (0);116}117118119