Split out logging facilities from futextest.h
The logging code was mucking up the futex wrappers in futextest.h.
Create a new header called logging.h and update the test cases
accordingly.
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
diff --git a/functional/futex_requeue_pi.c b/functional/futex_requeue_pi.c
index aca4b82..d452721 100644
--- a/functional/futex_requeue_pi.c
+++ b/functional/futex_requeue_pi.c
@@ -41,21 +41,14 @@
#include <signal.h>
#include <string.h>
#include "futextest.h"
-
-#define PRIVATE 1
-#ifdef PRIVATE
-#define FUTEX_PRIVATE_FLAG 128
-#define PSHARED PTHREAD_PROCESS_PRIVATE
-#else
-#define FUTEX_PRIVATE_FLAG 0
-#define PSHARED PTHREAD_PROCESS_SHARED
-#endif
+#include "logging.h"
#define THREAD_MAX 10
#define SIGNAL_PERIOD_US 100
pthread_barrier_t wake_barrier;
pthread_barrier_t waiter_barrier;
+volatile int waiters_blocked = 0;
int waiters_woken;
futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER;
@@ -346,7 +339,7 @@
broadcast = 1;
break;
case 'c':
- futextest_use_color(1);
+ log_color(1);
break;
case 'h':
usage(basename(argv[0]));
@@ -361,7 +354,7 @@
timeout_ns = atoi(optarg);
break;
case 'v':
- futextest_verbosity(atoi(optarg));
+ log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
diff --git a/functional/futex_requeue_pi_mismatched_ops.c b/functional/futex_requeue_pi_mismatched_ops.c
index 529f5a8..10633a7 100644
--- a/functional/futex_requeue_pi_mismatched_ops.c
+++ b/functional/futex_requeue_pi_mismatched_ops.c
@@ -40,6 +40,7 @@
#include <string.h>
#include <time.h>
#include "futextest.h"
+#include "logging.h"
futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER;
@@ -73,13 +74,13 @@
while ((c = getopt(argc, argv, "chv:")) != -1) {
switch(c) {
case 'c':
- futextest_use_color(1);
+ log_color(1);
break;
case 'h':
usage(basename(argv[0]));
exit(0);
case 'v':
- futextest_verbosity(atoi(optarg));
+ log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
diff --git a/functional/futex_requeue_pi_signal_restart.c b/functional/futex_requeue_pi_signal_restart.c
index 3f85eb5..febcd3d 100644
--- a/functional/futex_requeue_pi_signal_restart.c
+++ b/functional/futex_requeue_pi_signal_restart.c
@@ -40,6 +40,7 @@
#include <stdlib.h>
#include <string.h>
#include "futextest.h"
+#include "logging.h"
futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER;
@@ -132,13 +133,13 @@
while ((c = getopt(argc, argv, "chv:")) != -1) {
switch(c) {
case 'c':
- futextest_use_color(1);
+ log_color(1);
break;
case 'h':
usage(basename(argv[0]));
exit(0);
case 'v':
- futextest_verbosity(atoi(optarg));
+ log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
diff --git a/functional/futex_wait_timeout.c b/functional/futex_wait_timeout.c
index af43847..4892f29 100644
--- a/functional/futex_wait_timeout.c
+++ b/functional/futex_wait_timeout.c
@@ -37,6 +37,7 @@
#include <string.h>
#include <time.h>
#include "futextest.h"
+#include "logging.h"
static long timeout_ns = 100000; /* 100us default timeout */
@@ -60,7 +61,7 @@
while ((c = getopt(argc, argv, "cht:v:")) != -1) {
switch(c) {
case 'c':
- futextest_use_color(1);
+ log_color(1);
break;
case 'h':
usage(basename(argv[0]));
@@ -69,7 +70,7 @@
timeout_ns = atoi(optarg);
break;
case 'v':
- futextest_verbosity(atoi(optarg));
+ log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
diff --git a/functional/futex_wait_wouldblock.c b/functional/futex_wait_wouldblock.c
index ee70302..1326439 100644
--- a/functional/futex_wait_wouldblock.c
+++ b/functional/futex_wait_wouldblock.c
@@ -38,6 +38,7 @@
#include <string.h>
#include <time.h>
#include "futextest.h"
+#include "logging.h"
#define timeout_ns 100000
@@ -60,13 +61,13 @@
while ((c = getopt(argc, argv, "cht:v:")) != -1) {
switch(c) {
case 'c':
- futextest_use_color(1);
+ log_color(1);
break;
case 'h':
usage(basename(argv[0]));
exit(0);
case 'v':
- futextest_verbosity(atoi(optarg));
+ log_verbosity(atoi(optarg));
break;
default:
usage(basename(argv[0]));
diff --git a/include/futextest.h b/include/futextest.h
index df174aa..d469f9c 100644
--- a/include/futextest.h
+++ b/include/futextest.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* NAME
- * futex.h
+ * futextest.h
*
* DESCRIPTION
* Glibc independent futex library for testing kernel functionality.
@@ -35,42 +35,9 @@
#include <sys/types.h>
#include <linux/futex.h>
-/*
- * Define PASS, ERROR, and FAIL strings with and without color escape
- * sequences, default to no color.
- */
-#define ESC 0x1B, '['
-#define BRIGHT '1'
-#define GREEN '3', '2'
-#define YELLOW '3', '3'
-#define RED '3', '1'
-#define ESCEND 'm'
-#define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND
-#define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
-#define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
-#define RESET_COLOR ESC, '0', 'm'
-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;
-
typedef volatile u_int32_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
@@ -258,60 +225,3 @@
{
return __sync_val_compare_and_swap(uaddr, oldval, newval);
}
-
-/**
- * futextest_use_color() - Use colored output for PASS, ERROR, and FAIL strings
- * @use_color: use color (1) or not (0)
- */
-void futextest_use_color(int use_color)
-{
- if (use_color) {
- PASS = PASS_COLOR;
- ERROR = ERROR_COLOR;
- FAIL = FAIL_COLOR;
- } else {
- PASS = PASS_NORMAL;
- ERROR = ERROR_NORMAL;
- 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)
diff --git a/include/logging.h b/include/logging.h
new file mode 100644
index 0000000..558daf5
--- /dev/null
+++ b/include/logging.h
@@ -0,0 +1,124 @@
+/******************************************************************************
+ *
+ * Copyright © International Business Machines Corp., 2009
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * NAME
+ * logging.h
+ *
+ * DESCRIPTION
+ * Glibc independent futex library for testing kernel functionality.
+ *
+ * AUTHOR
+ * Darren Hart <dvhltc@us.ibm.com>
+ *
+ * HISTORY
+ * 2009-Nov-6: Initial version by Darren Hart <dvhltc@us.ibm.com>
+ *
+ *****************************************************************************/
+
+#include <unistd.h>
+#include <linux/futex.h>
+
+/*
+ * Define PASS, ERROR, and FAIL strings with and without color escape
+ * sequences, default to no color.
+ */
+#define ESC 0x1B, '['
+#define BRIGHT '1'
+#define GREEN '3', '2'
+#define YELLOW '3', '3'
+#define RED '3', '1'
+#define ESCEND 'm'
+#define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND
+#define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
+#define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
+#define RESET_COLOR ESC, '0', 'm'
+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;
+
+/* Verbosity setting for INFO messages */
+#define VQUIET 0
+#define VCRITICAL 1
+#define VINFO 2
+#define VMAX VINFO
+int _verbose = VCRITICAL;
+
+/**
+ * log_color() - Use colored output for PASS, ERROR, and FAIL strings
+ * @use_color: use color (1) or not (0)
+ */
+void log_color(int use_color)
+{
+ if (use_color) {
+ PASS = PASS_COLOR;
+ ERROR = ERROR_COLOR;
+ FAIL = FAIL_COLOR;
+ } else {
+ PASS = PASS_NORMAL;
+ ERROR = ERROR_NORMAL;
+ FAIL = FAIL_NORMAL;
+ }
+}
+
+/**
+ * log_verbosity() - 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 log_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)