test_common.c revision 538aa54d819fa7751ca82bcc30d4ed8c57ec2ef2
/*
* 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 2014 Garrett D'Amore <garrett@damore.org>
*/
/*
* Common handling for test programs.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <pthread.h>
#include "test_common.h"
static int debug = 0;
static int force = 0;
static pthread_mutex_t lk;
struct test {
char *name;
int ntids;
int fails;
void *arg;
};
void
test_set_debug(void)
{
debug++;
}
void
test_set_force(void)
{
force++;
}
test_start(const char *format, ...)
{
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);
#endif
return (t);
}
void
{
(void) pthread_mutex_lock(&lk);
} 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->ntids > 0) {
if (debug) {
(void) pthread_mutex_lock(&lk);
(void) pthread_mutex_unlock(&lk);
}
return;
}
(void) pthread_mutex_lock(&lk);
if (t->fails == 0) {
} else {
}
(void) pthread_mutex_unlock(&lk);
if (t->tids) {
}
free(t);
}
void
{
if (!debug)
return;
(void) pthread_mutex_lock(&lk);
(void) printf("\n");
(void) pthread_mutex_unlock(&lk);
}
static void *
test_thr_one(void *arg)
{
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);
}