@@ -36,6 +36,8 @@
#include <sys/wait.h>
#include <sys/ptrace.h>
+#include "rt-utils.h"
+
/* do_wait return values */
#define STATE_EXITED 1
#define STATE_STOPPED 2
@@ -65,10 +67,11 @@ static const char *get_state_name(int state)
#define unused __attribute__((unused))
static int quiet;
+static char outfile[MAX_PATH];
static int got_sigchld;
-enum option_value { OPT_NFORKS=1, OPT_NITERS, OPT_HELP, OPT_QUIET };
+enum option_value { OPT_NFORKS=1, OPT_NITERS, OPT_HELP, OPT_OUTPUT, OPT_QUIET };
static void usage(int error)
{
@@ -77,6 +80,7 @@ static void usage(int error)
"ssdd <options>\n\n"
"-f --forks=NUM number of forks\n"
"-h --help print this message\n"
+ " --output=FILENAME write final results into FILENAME, JSON formatted\n"
"-q --quiet suppress running output\n"
"-i --iters=NUM number of iterations\n"
);
@@ -287,6 +291,13 @@ static int forktests(int testid)
exit(0);
}
+static void write_stats(FILE *f, void *data)
+{
+ int *error = data;
+
+ fprintf(f, " \"success\": %d\n", !*error);
+}
+
int main(int argc, char **argv)
{
int i, ret_sig, status;
@@ -295,12 +306,14 @@ int main(int argc, char **argv)
setbuf(stdout, NULL);
+ rt_init(argc, argv);
for (;;) {
int option_index = 0;
static struct option long_options[] = {
{"forks", required_argument, NULL, OPT_NFORKS},
{"help", no_argument, NULL, OPT_HELP},
+ {"output", required_argument, NULL, OPT_OUTPUT},
{"quiet", no_argument, NULL, OPT_QUIET},
{"iters", required_argument, NULL, OPT_NITERS},
{NULL, 0, NULL, 0},
@@ -317,6 +330,9 @@ int main(int argc, char **argv)
case OPT_HELP:
usage(0);
break;
+ case OPT_OUTPUT:
+ strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1));
+ break;
case OPT_QUIET:
case 'q':
quiet = 1;
@@ -348,6 +364,7 @@ int main(int argc, char **argv)
forktests(i);
}
+ rt_test_start();
for (i = 0; i < nforks; i++) {
status = do_wait(&wait_pid, &ret_sig);
if (status != STATE_EXITED) {
@@ -363,5 +380,9 @@ int main(int argc, char **argv)
printf("%s.\n", error ?
"One or more tests FAILED" :
"All tests PASSED");
+
+ if (strlen(outfile) != 0)
+ rt_write_json(outfile, write_stats, &error);
+
exit(error);
}
Write the test results as JSON output to a file. This allows to simplifies any parsing later on. Signed-off-by: Daniel Wagner <dwagner@suse.de> --- src/ssdd/ssdd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)