Add verbosity levels and printing macros

Add info(), error(), and fail() printing macros. Add verbosity level
futextest_verbosity() function using VQUIET, VCRITICAL (default), and
VINFO. Update the existing tests to use these macros.

Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
diff --git a/functional/futex_requeue_pi.c b/functional/futex_requeue_pi.c
index a20a56d..323ed0a 100644
--- a/functional/futex_requeue_pi.c
+++ b/functional/futex_requeue_pi.c
@@ -80,6 +80,8 @@
 	printf("  -l	Lock the pi futex across requeue\n");
 	printf("  -o	Use a third party pi futex owner during requeue\n");
 	printf("  -t N	Timeout in nanoseconds (default: 100,000)\n");
+	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
+	       VQUIET, VCRITICAL, VINFO);
 }
 
 int create_pi_mutex(pthread_mutex_t *mutex)
@@ -88,34 +90,31 @@
 	pthread_mutexattr_t mutexattr;
 
 	if ((ret = pthread_mutexattr_init(&mutexattr)) != 0) {
-		fprintf(stderr, "\t%s: pthread_mutexattr_init: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_mutexattr_init\n", ret);
 		return -1;
 	}
 	if ((ret = pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT)) != 0) {
-		fprintf(stderr, "\t%s: pthread_mutexattr_setprotocol: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_mutexattr_setprotocol", ret);
 		pthread_mutexattr_destroy(&mutexattr);
 		return -1;
 	}
 	if ((ret = pthread_mutexattr_setpshared(&mutexattr, PSHARED)) != 0) {
-		fprintf(stderr, "\t%s: pthread_mutexattr_setpshared(%d): %s\n",
-			ERROR, PSHARED, strerror(ret));
+		error("pthread_mutexattr_setpshared(%d)\n", ret, PSHARED);
 		pthread_mutexattr_destroy(&mutexattr);
 		return -1;
 	}
 
 	int pshared;
 	pthread_mutexattr_getpshared(&mutexattr, &pshared);
-	fprintf(stderr, "\tpshared set to %d\n", pshared);
+	info("pshared set to %d\n", pshared);
 
 	if ((ret = pthread_mutex_init(mutex, &mutexattr)) != 0) {
-		printf("pthread_mutex_init: %s\n", strerror(ret));
+		error("pthread_mutex_init", ret);
 		pthread_mutexattr_destroy(&mutexattr);
 		return -1;
 	}
 
-	fprintf(stderr, "\tmutex.__data.__kind: %x\n", mutex->__data.__kind);
+	info("mutex.__data.__kind: %x\n", mutex->__data.__kind);
 
 	return 0;
 }
@@ -130,27 +129,23 @@
 	memset(&schedp, 0, sizeof(schedp));
 
 	if ((ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setinheritsched: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setinheritsched\n", ret);
 		return -1;
 	}
 
 	if ((ret = pthread_attr_setschedpolicy(&attr, policy)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setschedpolicy: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setschedpolicy\n", ret);
 		return -1;
 	}
 
 	schedp.sched_priority = prio;
 	if ((ret = pthread_attr_setschedparam(&attr, &schedp)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setschedparam: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setschedparam\n", ret);
 		return -1;
 	}
 
 	if ((ret = pthread_create(pth, &attr, func, arg)) != 0) {
-		fprintf(stderr, "\t%s: pthread_create: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_create\n", ret);
 		return -1;
 	}
 	return 0;
@@ -163,7 +158,7 @@
 	unsigned int old_val;
 	int ret;
 
-	fprintf(stderr, "\tWaiter %ld: running\n", args->id); fflush(stderr);
+	info("Waiter %ld: running\n", args->id);
 	/* Each thread sleeps for a different amount of time
 	 * This is to avoid races, because we don't lock the
 	 * external mutex here */
@@ -176,16 +171,16 @@
 	pthread_barrier_wait(&waiter_barrier);
 	ret = futex_wait_requeue_pi(&wait_q, old_val, &(mutex.__data.__lock),
 				    args->timeout, FUTEX_PRIVATE_FLAG);
-	fprintf(stderr, "\twaiter %ld woke\n", args->id); fflush(stderr);
+	info("waiter %ld woke\n", args->id);
 	if (ret < 0) {
 		ret = -errno;
-		fprintf(stderr, "\t%s: waiterfn: %s\n", ERROR, strerror(errno));
+		error("waiterfn\n", errno);
 		pthread_mutex_lock(&mutex);
 	}
 	waiters_woken++;
 	pthread_mutex_unlock(&mutex);
 
-	fprintf(stderr, "\tWaiter %ld: exiting with %d\n", args->id, ret);
+	info("Waiter %ld: exiting with %d\n", args->id, ret);
 	return (void*)(long)ret;
 }
 
@@ -201,8 +196,8 @@
 	fprintf(stderr, "\tWaker: Calling broadcast\n");
 
 	if (lock) {
-		fprintf(stderr, "\tCalling FUTEX_LOCK_PI on mutex=%x @ %p\n", 
-			mutex.__data.__lock, &mutex.__data.__lock);
+		info("Calling FUTEX_LOCK_PI on mutex=%x @ %p\n", 
+		     mutex.__data.__lock, &mutex.__data.__lock);
 		pthread_mutex_lock(&mutex);
 	}
 	/* cond_broadcast */
@@ -211,18 +206,16 @@
 				   nr_requeue, FUTEX_PRIVATE_FLAG);
 	if (ret < 0) {
 		ret = -errno;
-		fprintf(stderr, "\t%s: FUTEX_CMP_REQUEUE_PI failed: %s\n",
-			ERROR, strerror(errno));
+		error("FUTEX_CMP_REQUEUE_PI failed\n", errno);
 	}
 
 	if (pthread_barrier_wait(&wake_barrier) == -EINVAL)
-		fprintf(stderr, "\t%s: broadcast_wakerfn: %s\n",
-			ERROR, strerror(errno));
+		error("broadcast_wakerfn\n", errno);
 
 	if (lock)
 		pthread_mutex_unlock(&mutex);
 
-	fprintf(stderr, "\tWaker: exiting with %d\n", ret);
+	info("Waker: exiting with %d\n", ret);
 	return (void *)(long)ret;;
 }
 
@@ -238,53 +231,51 @@
 
 	pthread_barrier_wait(&waiter_barrier);
 	while (task_count < THREAD_MAX && waiters_woken < THREAD_MAX) {
-		fprintf(stderr, "\ttask_count: %d, waiters_woken: %d\n",
-			task_count, waiters_woken);
+		info("task_count: %d, waiters_woken: %d\n",
+		     task_count, waiters_woken);
 		if (lock) {
-			fprintf(stderr, "\tCalling FUTEX_LOCK_PI on mutex=%x @ %p\n", 
-				mutex.__data.__lock, &mutex.__data.__lock);
+			info("Calling FUTEX_LOCK_PI on mutex=%x @ %p\n", 
+			     mutex.__data.__lock, &mutex.__data.__lock);
 			pthread_mutex_lock(&mutex);
 		}
-		fprintf(stderr, "\tWaker: Calling signal\n");
+		info("Waker: Calling signal\n");
 		/* cond_signal */
 		old_val = wait_q;
 		ret = futex_cmp_requeue_pi(&wait_q, old_val, &(mutex.__data.__lock),
 					   nr_wake, nr_requeue, FUTEX_PRIVATE_FLAG);
 		if (ret < 0)
 			ret = -errno;
-		fprintf(stderr, "\tfutex: %x\n", mutex.__data.__lock);
+		info("futex: %x\n", mutex.__data.__lock);
 		if (lock) {
-			fprintf(stderr, "\tCalling FUTEX_UNLOCK_PI on mutex=%x @ %p\n", 
-				mutex.__data.__lock, &mutex.__data.__lock);
+			info("Calling FUTEX_UNLOCK_PI on mutex=%x @ %p\n", 
+			     mutex.__data.__lock, &mutex.__data.__lock);
 			pthread_mutex_unlock(&mutex);
 		}
-		fprintf(stderr, "\tfutex: %x\n", mutex.__data.__lock);
+		info("futex: %x\n", mutex.__data.__lock);
 		if (ret < 0) {
-			fprintf(stderr, "\t%s: FUTEX_CMP_REQUEUE_PI failed: %s\n",
-				ERROR, strerror(errno));
+			error("FUTEX_CMP_REQUEUE_PI failed\n", errno);
 			break;
 		}
 		
 		if (!i) {
-			fprintf(stderr, "\twaker waiting on wake_barrier\n");
+			info("waker waiting on wake_barrier\n");
 			if (pthread_barrier_wait(&wake_barrier) == -EINVAL)
-				fprintf(stderr, "\t%s: signal_wakerfn: %s",
-					ERROR, strerror(errno));
+				error("signal_wakerfn", errno);
 		}
 
 		task_count += ret;
 		usleep(SIGNAL_PERIOD_US);
 		i++;
 		if (i > 1000) {
-			fprintf(stderr, "\ti>1000, giving up on pending waiters...\n");
+			info("i>1000, giving up on pending waiters...\n");
 			break;
 		}
 	}
 	if (ret >= 0)
 		ret = task_count;
 
-	fprintf(stderr, "\tWaker: exiting with %d\n", ret);
-	fprintf(stderr, "\tWaker: waiters_woken: %d\n", waiters_woken);
+	info("Waker: exiting with %d\n", ret);
+	info("Waker: waiters_woken: %d\n", waiters_woken);
 	return (void *)(long)ret;
 }
 
@@ -292,8 +283,7 @@
 {
 	pthread_mutex_lock(&mutex);
 	if (pthread_barrier_wait(&wake_barrier) == -EINVAL)
-		fprintf(stderr, "\t%s: third_party_blocker: %s",
-			ERROR, strerror(errno));
+		error("third_party_blocker\n", errno);
 	pthread_mutex_unlock(&mutex);
 	return NULL;
 }
@@ -317,14 +307,12 @@
 
 	if ((ret = pthread_barrier_init(&wake_barrier, NULL,
 					1+third_party_owner))) {
-		fprintf(stderr, "\t%s: pthread_barrier_init(wake_barrier) failed: %s\n",
-			ERROR, strerror(errno));
+		error("pthread_barrier_init(wake_barrier) failed\n", errno);
 		return ret;
 	}
 	if ((ret = pthread_barrier_init(&waiter_barrier, NULL,
 					1+THREAD_MAX))) {
-		fprintf(stderr, "\t%s: pthread_barrier_init(waiter_barrier) failed: %s\n",
-			ERROR, strerror(errno));
+		error("pthread_barrier_init(waiter_barrier) failed\n", errno);
 		return ret;
 	}
 
@@ -334,8 +322,8 @@
 	if (third_party_owner) {
 		if ((ret = create_rt_thread(&blocker, third_party_blocker, NULL,
 					    SCHED_FIFO, 1))) {
-			fprintf(stderr, "\t%s: Creating third party blocker thread failed: %s\n",
-				ERROR, strerror(errno));
+			error("Creating third party blocker thread failed\n",
+			      errno);
 			goto out;
 		}
 	}
@@ -344,18 +332,16 @@
 	for (i = 0; i < THREAD_MAX; i++) {
 		args[i].id = i;
 		args[i].timeout = tsp;
-		fprintf(stderr, "\tStarting thread %ld\n", i); fflush(stderr);
+		info("Starting thread %ld\n", i);
 		if ((ret = create_rt_thread(&waiter[i], waiterfn, (void *)&args[i],
 					    SCHED_FIFO, 1))) {
-			fprintf(stderr, "\t%s: Creating waiting thread failed: %s\n",
-				ERROR, strerror(errno));
+			error("Creating waiting thread failed\n", errno);
 			goto out;
 		}
 	}
 	if ((ret = create_rt_thread(&waker, wakerfn, (void *)lock,
 				    SCHED_FIFO, 1))) {
-		fprintf(stderr, "\t%s: Creating waker thread failed: %s\n",
-			ERROR, strerror(errno));
+		error("Creating waker thread failed\n", errno);
 		goto out;
 	}
 
@@ -369,11 +355,10 @@
 
 out:
 	if ((ret = pthread_barrier_destroy(&wake_barrier)))
-		fprintf(stderr, "\t%s: pthread_barrier_destroy(wake_barrier) failed: %s\n",
-			ERROR, strerror(errno));
+		error("pthread_barrier_destroy(wake_barrier) failed\n", errno);
 	if ((ret = pthread_barrier_destroy(&waiter_barrier)))
-		fprintf(stderr, "\t%s: pthread_barrier_destroy(waiter_barrier) failed: %s\n",
-			ERROR, strerror(errno));
+		error("pthread_barrier_destroy(waiter_barrier) failed\n",
+		      errno);
 	return ret;
 }
 
@@ -381,7 +366,7 @@
 {
 	int c, ret;
 
-	while ((c = getopt(argc, argv, "bchlot:")) != -1) {
+	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {
 		switch(c) {
 		case 'b':
 			broadcast = 1;
@@ -401,6 +386,9 @@
 		case 't':
 			timeout_ns = atoi(optarg);
 			break;
+		case 'v':
+			futextest_verbosity(atoi(optarg));
+			break;
 		default:
 			usage(basename(argv[0]));
 			exit(1);
@@ -412,7 +400,7 @@
 	       broadcast, locked, owner, timeout_ns);
 
 	if ((ret = create_pi_mutex(&mutex)) != 0) {
-		printf("Creating pi mutex failed\n");
+		error("Creating pi mutex failed\n", ret);
 		exit(1);
 	}
 
diff --git a/functional/futex_requeue_pi_mismatched_ops.c b/functional/futex_requeue_pi_mismatched_ops.c
index 14707f2..50bd07b 100644
--- a/functional/futex_requeue_pi_mismatched_ops.c
+++ b/functional/futex_requeue_pi_mismatched_ops.c
@@ -50,6 +50,8 @@
 	printf("Usage: %s\n", prog);
 	printf("  -c	Use color\n");
 	printf("  -h	Display this help message\n");
+	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
+	       VQUIET, VCRITICAL, VINFO);
 }
 
 void *blocking_child(void *arg)
@@ -57,7 +59,7 @@
 	child_ret = futex_wait(&f1, f1, NULL, FUTEX_PRIVATE_FLAG);
 	if (child_ret < 0) {
 		child_ret = -errno;
-		fprintf(stderr, "\t%s: futex_wait: %s\n", ERROR, strerror(errno));
+		error("futex_wait\n", errno);
 	}
 	return (void *)&child_ret;
 }
@@ -68,7 +70,7 @@
 	int ret = 0;
 	int c;
 
-	while ((c = getopt(argc, argv, "ch")) != -1) {
+	while ((c = getopt(argc, argv, "chv:")) != -1) {
 		switch(c) {
 		case 'c':
 			futextest_use_color(1);
@@ -76,6 +78,9 @@
 		case 'h':
 			usage(basename(argv[0]));
 			exit(0);
+		case 'v':
+			futextest_verbosity(atoi(optarg));
+			break;
 		default:
 			usage(basename(argv[0]));
 			exit(1);
@@ -87,8 +92,7 @@
 
 	ret = pthread_create(&child, NULL, blocking_child, NULL);
 	if (ret) {
-		fprintf(stderr, "\t%s: pthread_create: %s\n",
-			ERROR, strerror(errno));
+		error("pthread_create\n", errno);
 		goto out;
 	}
 	/* Allow the child to block in the kernel. */
@@ -113,23 +117,18 @@
 			if (ret == 1)
 				ret = 0;
 			else if (ret < 0)
-				fprintf(stderr, "\t%s: futex_wake: %s\n",
-					ERROR, strerror(errno));
+				error("futex_wake\n", errno);
 			else {
-				fprintf(stderr, "\t%s: futex_wake did not wake"
-					"the child\n", ERROR);
+				error("futex_wake did not wake the child\n", 0);
 				ret = -1;
 			}
 		} else {
-			fprintf(stderr, "\t%s: futex_cmp_requeue_pi: %s\n",
-				ERROR, strerror(errno));
+			error("futex_cmp_requeue_pi\n", errno);
 		}
 	} else if (ret > 0) {
-		fprintf(stderr, "\t%s: futex_cmp_requeue_pi failed to detect "
-			"the mismatch\n", FAIL);
+		fail("futex_cmp_requeue_pi failed to detect the mismatch\n");
 	} else {
-		fprintf(stderr, "\t%s: futex_cmp_requeue_pi found no waiters\n",
-			ERROR);
+		error("futex_cmp_requeue_pi found no waiters\n", 0);
 		ret = -1;
 	}
 
diff --git a/functional/futex_requeue_pi_signal_restart.c b/functional/futex_requeue_pi_signal_restart.c
index dbaf23e..3f85eb5 100644
--- a/functional/futex_requeue_pi_signal_restart.c
+++ b/functional/futex_requeue_pi_signal_restart.c
@@ -54,6 +54,8 @@
 	printf("Usage: %s\n", prog);
 	printf("  -c	Use color\n");
 	printf("  -h	Display this help message\n");
+	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
+	       VQUIET, VCRITICAL, VINFO);
 }
 
 int create_rt_thread(pthread_t *pth, void*(*func)(void*), void *arg, int policy, int prio)
@@ -66,27 +68,23 @@
 	memset(&schedp, 0, sizeof(schedp));
 
 	if ((ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setinheritsched: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setinheritsched\n", ret);
 		return -1;
 	}
 
 	if ((ret = pthread_attr_setschedpolicy(&attr, policy)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setschedpolicy: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setschedpolicy\n", ret);
 		return -1;
 	}
 
 	schedp.sched_priority = prio;
 	if ((ret = pthread_attr_setschedparam(&attr, &schedp)) != 0) {
-		fprintf(stderr, "\t%s: pthread_attr_setschedparam: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_attr_setschedparam\n", ret);
 		return -1;
 	}
 
 	if ((ret = pthread_create(pth, &attr, func, arg)) != 0) {
-		fprintf(stderr, "\t%s: pthread_create: %s\n",
-			ERROR, strerror(ret));
+		error("pthread_create\n", ret);
 		return -1;
 	}
 	return 0;
@@ -94,7 +92,7 @@
 
 void handle_signal(int signo)
 {
-	fprintf(stderr, "\thandled signal: %d\n", signo);
+	info("handled signal: %d\n", signo);
 }
 
 void *waiterfn(void *arg)
@@ -102,24 +100,24 @@
 	unsigned int old_val;
 	int ret;
 
-	fprintf(stderr, "\tWaiter running\n"); 
+	info("Waiter running\n"); 
 
-	fprintf(stderr, "\tCalling FUTEX_LOCK_PI on f2=%x @ %p\n", f2, &f2);
+	info("Calling FUTEX_LOCK_PI on f2=%x @ %p\n", f2, &f2);
 	/* cond_wait */
 	old_val = f1;
 	ret = futex_wait_requeue_pi(&f1, old_val, &(f2), NULL, FUTEX_PRIVATE_FLAG);
 	if (ret < 0) {
 		ret = -errno;
-		fprintf(stderr, "\t%s: waiterfn: %s\n", ERROR, strerror(errno));
+		error("waiterfn\n", errno);
 	}
-	fprintf(stderr, "\tFUTEX_WAIT_REQUEUE_PI returned: %d\n", ret); fflush(stdout);
-	fprintf(stderr, "\tw1:futex: %x\n", f2); fflush(stdout);
+	info("FUTEX_WAIT_REQUEUE_PI returned: %d\n", ret);
+	info("w1:futex: %x\n", f2);
 	if (ret)
 		futex_lock_pi(&f2, 0, 0, FUTEX_PRIVATE_FLAG);
 	futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG);
 
-	fprintf(stderr, "\tWaiter exiting with %d\n", ret); fflush(stdout);
-	fprintf(stderr, "\tw2:futex: %x\n", f2); fflush(stdout);
+	info("Waiter exiting with %d\n", ret);
+	info("w2:futex: %x\n", f2);
 	return (void*)(long)ret;
 }
 
@@ -131,7 +129,7 @@
 	pthread_t waiter;
 	int c, ret = 0;
 
-	while ((c = getopt(argc, argv, "ch")) != -1) {
+	while ((c = getopt(argc, argv, "chv:")) != -1) {
 		switch(c) {
 		case 'c':
 			futextest_use_color(1);
@@ -139,6 +137,9 @@
 		case 'h':
 			usage(basename(argv[0]));
 			exit(0);
+		case 'v':
+			futextest_verbosity(atoi(optarg));
+			break;
 		default:
 			usage(basename(argv[0]));
 			exit(1);
@@ -152,57 +153,57 @@
 	sigemptyset(&sa.sa_mask);
 	sa.sa_flags = 0;
 	if (sigaction(SIGUSR1, &sa, NULL)) {
-		fprintf(stderr, "\t%s: sigaction: %s\n", ERROR, strerror(errno));
+		error("sigaction\n", errno);
 		exit(1);
 	}
 
-	fprintf(stderr, "\tm1:futex: %x\n", f2);
-	fprintf(stderr, "\tCreating waiter\n");
+	info("m1:futex: %x\n", f2);
+	info("Creating waiter\n");
 	if ((ret = create_rt_thread(&waiter, waiterfn, NULL, SCHED_FIFO, 1))) {
-		perror("Creating waiting thread failed");
+		error("Creating waiting thread failed", ret);
 		exit(1);
 	}
-	fprintf(stderr, "\tm2:futex: %x\n", f2);
+	info("m2:futex: %x\n", f2);
 
-	fprintf(stderr, "\tCalling FUTEX_LOCK_PI on mutex=%x @ %p\n", f2, &f2);
+	info("Calling FUTEX_LOCK_PI on mutex=%x @ %p\n", f2, &f2);
 	
 	futex_lock_pi(&f2, 0, 0, FUTEX_PRIVATE_FLAG);
-	fprintf(stderr, "\tm3:futex: %x\n", f2);
+	info("m3:futex: %x\n", f2);
 
-	fprintf(stderr, "\tWaking waiter via FUTEX_CMP_REQUEUE_PI\n");fflush(stdout);
+	info("Waking waiter via FUTEX_CMP_REQUEUE_PI\n");
 	/* cond_signal */
 	old_val = f1;
 	ret = futex_cmp_requeue_pi(&f1, old_val, &(f2),
 				   1, 0, FUTEX_PRIVATE_FLAG);
 	if (ret < 0) {
 		ret = -errno;
-		fprintf(stderr, "\t%s: FUTEX_CMP_REQUEUE_PI failed: %s\n",
-			ERROR, strerror(errno));
+		error("FUTEX_CMP_REQUEUE_PI failed\n", errno);
+		
 		/* FIXME - do something sane.... */
 	}
-	fprintf(stderr, "\tm4:futex: %x\n", f2); 
+	info("m4:futex: %x\n", f2); 
 
 	/* give the waiter time to wake and block on the lock */
 	sleep(2);
-	fprintf(stderr, "\tm5:futex: %x\n", f2);
+	info("m5:futex: %x\n", f2);
 
 	/* 
 	 * signal the waiter to force a syscall restart to
 	 * futex_lock_pi_restart()
 	 */
-	fprintf(stderr, "\tIssuing SIGUSR1 to waiter\n"); 
+	info("Issuing SIGUSR1 to waiter\n"); 
 	pthread_kill(waiter, SIGUSR1);
 
 	/* give the signal time to get to the waiter */
 	sleep(2);
-	fprintf(stderr, "\tm6:futex: %x\n", f2);
-	fprintf(stderr, "\tCalling FUTEX_UNLOCK_PI on mutex=%x @ %p\n", f2, &f2);
+	info("m6:futex: %x\n", f2);
+	info("Calling FUTEX_UNLOCK_PI on mutex=%x @ %p\n", f2, &f2);
 	futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG);
 
 	/* Wait for waiter to finish */
-	fprintf(stderr, "\tWaiting for waiter to return\n");
+	info("Waiting for waiter to return\n");
 	pthread_join(waiter, NULL);
-	fprintf(stderr, "\tm7:futex: %x\n", f2);
+	info("m7:futex: %x\n", f2);
 
 	printf("Result: %s\n", ret ? ERROR : PASS);
 	return ret;
diff --git a/functional/futex_wait_timeout.c b/functional/futex_wait_timeout.c
index d419733..1323f28 100644
--- a/functional/futex_wait_timeout.c
+++ b/functional/futex_wait_timeout.c
@@ -46,6 +46,8 @@
 	printf("  -c	Use color\n");
 	printf("  -h	Display this help message\n");
 	printf("  -t N	Timeout in nanoseconds (default: 100,000)\n");
+	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
+	       VQUIET, VCRITICAL, VINFO);
 }
 
 int main(int argc, char *argv[])
@@ -55,7 +57,7 @@
 	int ret = 0;
 	int c;
 
-	while ((c = getopt(argc, argv, "cht:")) != -1) {
+	while ((c = getopt(argc, argv, "cht:v:")) != -1) {
 		switch(c) {
 		case 'c':
 			futextest_use_color(1);
@@ -66,6 +68,9 @@
 		case 't':
 			timeout_ns = atoi(optarg);
 			break;
+		case 'v':
+			futextest_verbosity(atoi(optarg));
+			break;
 		default:
 			usage(basename(argv[0]));
 			exit(1);
@@ -78,13 +83,14 @@
 	/* 100us relative timeout */
 	to.tv_sec = 0;
 	to.tv_nsec = timeout_ns;
+	info("Calling futex_wait on f1: %u @ %p\n", f1, &f1);
 	ret = futex_wait(&f1, f1, &to, FUTEX_PRIVATE_FLAG);
 	if (ret < 0) {
 		ret = -errno;
 		if (ret == -ETIMEDOUT)
 			ret = 0;
 		else
-			perror("ERROR: futex_wait");
+			error("futex_wait", errno);
 	}
 
 	printf("Result: %s\n", ret ? ERROR : PASS);
diff --git a/include/futextest.h b/include/futextest.h
index 9d1c90f..2b64f79 100644
--- a/include/futextest.h
+++ b/include/futextest.h
@@ -49,12 +49,14 @@
 #define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
 #define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
 #define RESET_COLOR ESC, '0', 'm'
-char PASS_COLOR[] = {BRIGHT_GREEN, ' ', 'P', 'A', 'S', 'S', RESET_COLOR, 0};
-char ERROR_COLOR[] = {BRIGHT_YELLOW, 'E', 'R', 'R', 'O', 'R', RESET_COLOR, 0};
-char FAIL_COLOR[] = {BRIGHT_RED, ' ', 'F', 'A', 'I', 'L', RESET_COLOR, 0};
-char PASS_NORMAL[] = " PASS";
-char ERROR_NORMAL[] = "ERROR";
-char FAIL_NORMAL[] = " FAIL";
+static char PASS_COLOR[] = {BRIGHT_GREEN, ' ', 'P', 'A', 'S', 'S', RESET_COLOR, 0};
+static char ERROR_COLOR[] = {BRIGHT_YELLOW, 'E', 'R', 'R', 'O', 'R', RESET_COLOR, 0};
+static char FAIL_COLOR[] = {BRIGHT_RED, ' ', 'F', 'A', 'I', 'L', RESET_COLOR, 0};
+static char INFO_NORMAL[] = " INFO";
+static char PASS_NORMAL[] = " PASS";
+static char ERROR_NORMAL[] = "ERROR";
+static char FAIL_NORMAL[] = " FAIL";
+char *INFO = INFO_NORMAL;
 char *PASS = PASS_NORMAL;
 char *ERROR = ERROR_NORMAL;
 char *FAIL = FAIL_NORMAL;
@@ -62,6 +64,13 @@
 typedef volatile __uint32_t futex_t;
 #define FUTEX_INITIALIZER 0
 
+/* Verbosity setting for INFO messages */
+#define VQUIET    0
+#define VCRITICAL 1
+#define VINFO     2
+#define VMAX      VINFO
+int _verbose = VCRITICAL;
+
 /* Define the newer op codes if the system header file is not up to date. */
 #ifndef FUTEX_WAIT_REQUEUE_PI
 #define FUTEX_WAIT_REQUEUE_PI		11
@@ -218,3 +227,43 @@
 		FAIL = FAIL_NORMAL;
 	}
 }
+
+/**
+ * futex_test_verbose() - Set verbosity of test output
+ * @verbose:	Enable (1) verbose output or not (0)
+ *
+ * Currently setting verbose=1 will enable INFO messages and 0 will disable
+ * them. FAIL and ERROR messages are always displayed.
+ */
+void futextest_verbosity(int level)
+{
+	if (level > VMAX)
+		level = VMAX;
+	else if (level < 0)
+		level = 0;
+	_verbose = level;
+}
+
+/* Output macros */
+#define info(message, vargs...) \
+do { \
+	if (_verbose >= VINFO) \
+		fprintf(stderr, "\t%s: "message, INFO, ##vargs); \
+} while (0)
+
+#define error(message, err, args...) \
+do { \
+	if (_verbose >= VCRITICAL) {\
+		if (err) \
+			fprintf(stderr, "\t%s: %s: "message, \
+				ERROR, strerror(err), ##args); \
+		else \
+			fprintf(stderr, "\t%s: "message, ERROR, ##args); \
+	} \
+} while (0)
+
+#define fail(message, args...) \
+do { \
+	if (_verbose >= VCRITICAL) \
+		fprintf(stderr, "\t%s: "message, FAIL, ##args); \
+} while (0)