/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
*/
/*
* Copyright 2015 Garrett D'Amore <garrett@damore.org>
*/
/*
* Common handling for test programs.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <ctype.h>
#include <unistd.h>
#include "test_common.h"
static int debug = 0;
static int force = 0;
static int passes;
static int tests;
struct test {
char *name;
int ntids;
int fails;
void *arg;
};
void
test_set_debug(void)
{
debug++;
}
void
test_set_force(void)
{
force++;
}
{
test_t t;
char *s;
t = calloc(1, sizeof (*t));
free(s);
(void) pthread_mutex_lock(&lk);
(void) pthread_mutex_unlock(&lk);
#ifdef LINT
/* We inject references to make avoid name unused warnings */
test_debugf(t, NULL);
test_failed(t, NULL);
test_passed(t);
test_summary();
#endif
tests++;
return (t);
}
void
{
(void) pthread_mutex_lock(&lk);
if (t == NULL) {
(void) printf("FAILURE: ");
(void) printf("\n");
(void) pthread_mutex_unlock(&lk);
return;
}
} else {
}
(void) printf("\n");
(void) pthread_mutex_unlock(&lk);
t->fails++;
if (!force) {
if (t->ntids > 0) {
} else {
(void) exit(EXIT_FAILURE);
}
}
}
void
{
if (t == NULL) {
return;
}
if (t->ntids > 0) {
if (debug) {
(void) pthread_mutex_lock(&lk);
(void) pthread_mutex_unlock(&lk);
}
return;
}
(void) pthread_mutex_lock(&lk);
if (t->fails == 0) {
passes++;
} else {
}
(void) pthread_mutex_unlock(&lk);
if (t->tids) {
}
free(t);
}
void
test_summary(void)
{
} else {
(void) printf("TEST SUMMARY: %d / %d (%d failing)\n",
}
}
void
{
if (!debug)
return;
(void) pthread_mutex_lock(&lk);
if (t) {
} else {
(void) printf("TEST DEBUG: ");
}
(void) printf("\n");
(void) pthread_mutex_unlock(&lk);
}
static void *
{
return (NULL);
}
void
const char *tname, ...)
{
test_t t;
char *s;
t = calloc(1, sizeof (*t));
free(s);
(void) pthread_mutex_lock(&lk);
(void) pthread_mutex_unlock(&lk);
for (int i = 0; i < nthr; i++) {
test_debugf(t, "started thread %d", i);
}
for (int i = 0; i < nthr; i++) {
test_debugf(t, "thread %d joined", i);
t->ntids--;
}
test_passed(t);
}
void
{
char *p = *ptr;
while (isspace(*p)) {
p++;
}
*ptr = p;
p += strlen(p);
*p = '\0';
}
}
int
{
int nfields;
int done;
char *ptr;
char *tok;
char *err;
int lineno;
int rv;
int found;
int i;
for (i = 0; i < MAXCB; i++) {
break;
}
if (i == MAXCB) {
}
found = 0;
found++;
}
stf = "../..";
}
found++;
} else {
found++;
}
}
}
return (-1);
}
line[0] = 0;
done = 0;
lineno = 0;
while (!done) {
lineno++;
done++;
} else {
/*
* Continuation. This isn't quite right,
* as it doesn't allow for a "\" at the
* end of line (no escaping).
*/
continue;
}
}
/* got a line */
/* skip comments and empty lines */
line[0] = 0;
continue;
}
break;
}
break;
}
}
found = 0;
rv = 0;
found++;
}
}
if (!found) {
rv = -1;
}
if (rv != 0) {
if (err) {
} else {
test_failed(t, "%s:%d: unknown error",
}
return (rv);
}
line[0] = 0;
}
return (0);
}