summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Makefile6
-rw-r--r--configure.ac8
-rw-r--r--src/Makefile4
-rw-r--r--src/autoconf.make.in1
-rw-r--r--test/Makefile28
-rw-r--r--test/lib-test-args.c180
-rw-r--r--test/lib-test-args.conf40
-rw-r--r--test/lib-test-args.h45
-rw-r--r--test/lib-test-common.c5
-rw-r--r--test/sysdeps/i686/test-args.c68
-rw-r--r--test/sysdeps/x86_64/test-args.c68
-rw-r--r--test/test-args.c222
-rw-r--r--test/test-args.h31
-rw-r--r--test/test-common.c48
-rw-r--r--test/test-lib.c194
-rw-r--r--test/test-lib.h65
-rwxr-xr-xtest/test.sh7
18 files changed, 1021 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 2a03241..5a238ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
-2011-04-19 Jiri Olsa <olsajiri@gmail.com>
+2011-04-20 Jiri Olsa <olsajiri@gmail.com>
* prevent gcc warning with single printf like arg passing
+ * adding automated test support, so far for x86 and x86_64,
+ others are disabled. From this time on, I'll try to force
+ addition of automated test for each fix/feature.. ;)
2011-04-16 Jiri Olsa <olsajiri@gmail.com>
* fix display of char arguments
diff --git a/Makefile b/Makefile
index a153d53..3488008 100644
--- a/Makefile
+++ b/Makefile
@@ -142,7 +142,11 @@ OBJS=
include src/Makefile
include doc/Makefile
-INCLUDES= -Isrc -Isrc/sysdeps/$(CONFIG_SYSDEP_DIR)
+ifeq ($(CONFIG_ARCH_HAVE_TEST),y)
+include test/Makefile
+endif
+
+INCLUDES= -I. -Isrc -Isrc/sysdeps/$(CONFIG_SYSDEP_DIR)
ALL_CFLAGS=$(CPPFLAGS) $(CFLAGS) -O2 -fPIC -Wall $(INCLUDES) -D_GNU_SOURCE
diff --git a/configure.ac b/configure.ac
index 966f6bb..bc2a8bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,14 @@ else
AC_MSG_WARN([Arguments display support disabled])
fi
+# for following architectures we have automated tests support
+if test "$unamem" = "x86_64" -o\
+ "$unamem" = "i686"; then
+ AC_SUBST(CONFIG_ARCH_HAVE_TEST, "y")
+else
+ AC_MSG_WARN([No automated test support])
+fi
+
AC_SEARCH_LIBS([cplus_demangle], [iberty_pic iberty],
[AC_DEFINE(CONFIG_LIBERTY, 1, "Liberty found.")],
[AC_MSG_WARN([libiberty not found, no demangle support (install binutils-dev)])])
diff --git a/src/Makefile b/src/Makefile
index dd7b56f..5e58da0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -44,7 +44,7 @@ OBJS+=$(AUDIT_OBJS)
PROGRAMS+= $(AUDIT_BIN)
$(AUDIT_BIN): $(AUDIT_OBJS)
- $(QUIET_LD)$(CC) $(CFLAGS) $(AUDIT_LDFLAGS) -o $@ $(AUDIT_OBJS) $(AUDIT_LIBS)
+ $(QUIET_LD)$(CC) $(CFLAGS) $(AUDIT_LDFLAGS) -o $@ $^ $(AUDIT_LIBS)
install::
$(call install,$(AUDIT_BIN),$(libdir),755)
@@ -75,7 +75,7 @@ CPPFLAGS+=-DLT_CONF_HEADERS_DIR=\"$(sysconfdir)/latrace.d/headers\"
CPPFLAGS+=-DLT_CONF_HEADERS_FILE=\"$(sysconfdir)/latrace.d/headers/latrace.h\"
$(LATRACE_BIN): $(LATRACE_OBJS)
- $(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LATRACE_OBJS) $(LATRACE_LIBS) $(LATRACE_LIB)
+ $(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LATRACE_LIB)
install::
$(call install,$(LATRACE_BIN),$(bindir),755)
diff --git a/src/autoconf.make.in b/src/autoconf.make.in
index 7ce5cbf..a49c37e 100644
--- a/src/autoconf.make.in
+++ b/src/autoconf.make.in
@@ -46,3 +46,4 @@ CONFIG_SYSDEP_DIR = @CONFIG_SYSDEP_DIR@
CONFIG_VERSION = @CONFIG_VERSION@
CONFIG_ARCH_HAVE_ARGS = @CONFIG_ARCH_HAVE_ARGS@
+CONFIG_ARCH_HAVE_TEST = @CONFIG_ARCH_HAVE_TEST@
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..2849b40
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,28 @@
+
+LDFLAGS+=-L.
+
+lib-test-common.so: test/lib-test-common.o
+ $(QUIET_LD)$(CC) $(CFLAGS) -fPIC -shared $(LDFLAGS) -o $@ $^
+
+lib-test-args.so: test/lib-test-args.o
+ $(QUIET_LD)$(CC) $(CFLAGS) -fPIC -shared $(LDFLAGS) -o $@ $^
+
+test-common: test/test-lib.o test/test-common.o
+ $(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ lib-test-common.so
+
+test-args: test/test-lib.o test/test-args.o test/sysdeps/$(CONFIG_SYSDEP_DIR)/test-args.o
+ $(QUIET_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ lib-test-args.so
+
+OBJS+=test/test-lib.o
+
+OBJS+=\
+ test/lib-test-args.o \
+ test/test-args.o \
+ test/sysdeps/$(CONFIG_SYSDEP_DIR)/test-args.o
+
+OBJS+=\
+ test/lib-test-common.o \
+ test/test-common.o
+
+PROGRAMS+=lib-test-common.so test-common
+PROGRAMS+=lib-test-args.so test-args
diff --git a/test/lib-test-args.c b/test/lib-test-args.c
new file mode 100644
index 0000000..84b5c29
--- /dev/null
+++ b/test/lib-test-args.c
@@ -0,0 +1,180 @@
+
+char test_char_1(char a)
+{
+ return a*a;
+}
+
+char test_char_2(char a, char b)
+{
+ return a - b;
+}
+
+char test_char_3(char a, char b, char c)
+{
+ return a * b - c;
+}
+
+char test_char_4(char a, char b, char c, char d)
+{
+ return a + b - c * d;
+}
+
+char test_char_5(char a, char b, char c, char d, char e)
+{
+ return a + b * c / d * e;
+}
+
+char test_char_6(char a, char b, char c, char d, char e, char f)
+{
+ return a / b * c / d * e - f;
+}
+
+char test_char_7(char a, char b, char c, char d, char e, char f, char g)
+{
+ return a / b + c - d * e + f * g;
+}
+
+char test_char_8(char a, char b, char c, char d, char e, char f, char g, char h)
+{
+ return a + b + c - d + e - f + g / h;
+}
+
+char test_char_9(char a, char b, char c, char d, char e, char f, char g, char h, char i)
+{
+ return a - b + c - d * e - f / g - h - i;
+}
+
+short test_short_1(short a)
+{
+ return -a;
+}
+
+short test_short_2(short a, short b)
+{
+ return a + b;
+}
+
+short test_short_3(short a, short b, short c)
+{
+ return a + b - c;
+}
+
+short test_short_4(short a, short b, short c, short d)
+{
+ return a + b * c + d;
+}
+
+short test_short_5(short a, short b, short c, short d, short e)
+{
+ return a + b - c + d * e;
+}
+
+short test_short_6(short a, short b, short c, short d, short e, short f)
+{
+ return a * b * c + d * e - f;
+}
+
+short test_short_7(short a, short b, short c, short d, short e, short f, short g)
+{
+ return a / b + c + d * e - f * g;
+}
+
+short test_short_8(short a, short b, short c, short d, short e, short f, short g, short h)
+{
+ return a + b + c + d + e + f + g + h;
+}
+
+short test_short_9(short a, short b, short c, short d, short e, short f, short g, short h, short i)
+{
+ return a - b - c - d - e - f - g - h - i;
+}
+
+int test_int_1(int a)
+{
+ return -a;
+}
+
+int test_int_2(int a, int b)
+{
+ return a + b;
+}
+
+int test_int_3(int a, int b, int c)
+{
+ return a + b - c;
+}
+
+int test_int_4(int a, int b, int c, int d)
+{
+ return a + b * c + d;
+}
+
+int test_int_5(int a, int b, int c, int d, int e)
+{
+ return a + b - c + d * e;
+}
+
+int test_int_6(int a, int b, int c, int d, int e, int f)
+{
+ return a * b * c + d * e - f;
+}
+
+int test_int_7(int a, int b, int c, int d, int e, int f, int g)
+{
+ return a / b + c + d * e - f * g;
+}
+
+int test_int_8(int a, int b, int c, int d, int e, int f, int g, int h)
+{
+ return a + b + c + d + e + f + g + h;
+}
+
+int test_int_9(int a, int b, int c, int d, int e, int f, int g, int h, int i)
+{
+ return a - b - c - d - e - f - g - h - i;
+}
+
+long test_long_1(long a)
+{
+ return -a;
+}
+
+long test_long_2(long a, long b)
+{
+ return a + b;
+}
+
+long test_long_3(long a, long b, long c)
+{
+ return a + b - c;
+}
+
+long test_long_4(long a, long b, long c, long d)
+{
+ return a + b * c + d;
+}
+
+long test_long_5(long a, long b, long c, long d, long e)
+{
+ return a + b - c + d * e;
+}
+
+long test_long_6(long a, long b, long c, long d, long e, long f)
+{
+ return a * b * c + d * e - f;
+}
+
+long test_long_7(long a, long b, long c, long d, long e, long f, long g)
+{
+ return a / b + c + d * e - f * g;
+}
+
+long test_long_8(long a, long b, long c, long d, long e, long f, long g, long h)
+{
+ return a + b + c + d + e + f + g + h;
+}
+
+long test_long_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
+{
+ return a - b - c - d - e - f - g - h - i;
+}
diff --git a/test/lib-test-args.conf b/test/lib-test-args.conf
new file mode 100644
index 0000000..5a5ef07
--- /dev/null
+++ b/test/lib-test-args.conf
@@ -0,0 +1,40 @@
+
+char test_char_1(char a);
+char test_char_2(char a, char b);
+char test_char_3(char a, char b, char c);
+char test_char_4(char a, char b, char c, char d);
+char test_char_5(char a, char b, char c, char d, char e);
+char test_char_6(char a, char b, char c, char d, char e, char f);
+char test_char_7(char a, char b, char c, char d, char e, char f, char g);
+char test_char_8(char a, char b, char c, char d, char e, char f, char g, char h);
+char test_char_9(char a, char b, char c, char d, char e, char f, char g, char h, char i);
+
+short test_short_1(short a);
+short test_short_2(short a, short b);
+short test_short_3(short a, short b, short c);
+short test_short_4(short a, short b, short c, short d);
+short test_short_5(short a, short b, short c, short d, short e);
+short test_short_6(short a, short b, short c, short d, short e, short f);
+short test_short_7(short a, short b, short c, short d, short e, short f, short g);
+short test_short_8(short a, short b, short c, short d, short e, short f, short g, short h);
+short test_short_9(short a, short b, short c, short d, short e, short f, short g, short h, short i);
+
+int test_int_1(int a);
+int test_int_2(int a, int b);
+int test_int_3(int a, int b, int c);
+int test_int_4(int a, int b, int c, int d);
+int test_int_5(int a, int b, int c, int d, int e);
+int test_int_6(int a, int b, int c, int d, int e, int f);
+int test_int_7(int a, int b, int c, int d, int e, int f, int g);
+int test_int_8(int a, int b, int c, int d, int e, int f, int g, int h);
+int test_int_9(int a, int b, int c, int d, int e, int f, int g, int h, int i);
+
+long test_long_1(long a);
+long test_long_2(long a, long b);
+long test_long_3(long a, long b, long c);
+long test_long_4(long a, long b, long c, long d);
+long test_long_5(long a, long b, long c, long d, long e);
+long test_long_6(long a, long b, long c, long d, long e, long f);
+long test_long_7(long a, long b, long c, long d, long e, long f, long g);
+long test_long_8(long a, long b, long c, long d, long e, long f, long g, long h);
+long test_long_9(long a, long b, long c, long d, long e, long f, long g, long h, long i);
diff --git a/test/lib-test-args.h b/test/lib-test-args.h
new file mode 100644
index 0000000..2f3792a
--- /dev/null
+++ b/test/lib-test-args.h
@@ -0,0 +1,45 @@
+
+#ifndef LIB_TEST_ARGS_H
+#define LIB_TEST_ARGS_H
+
+char test_char_1(char a);
+char test_char_2(char a, char b);
+char test_char_3(char a, char b, char c);
+char test_char_4(char a, char b, char c, char d);
+char test_char_5(char a, char b, char c, char d, char e);
+char test_char_6(char a, char b, char c, char d, char e, char f);
+char test_char_7(char a, char b, char c, char d, char e, char f, char g);
+char test_char_8(char a, char b, char c, char d, char e, char f, char g, char h);
+char test_char_9(char a, char b, char c, char d, char e, char f, char g, char h, char i);
+
+short test_short_1(short a);
+short test_short_2(short a, short b);
+short test_short_3(short a, short b, short c);
+short test_short_4(short a, short b, short c, short d);
+short test_short_5(short a, short b, short c, short d, short e);
+short test_short_6(short a, short b, short c, short d, short e, short f);
+short test_short_7(short a, short b, short c, short d, short e, short f, short g);
+short test_short_8(short a, short b, short c, short d, short e, short f, short g, short h);
+short test_short_9(short a, short b, short c, short d, short e, short f, short g, short h, short i);
+
+int test_int_1(int a);
+int test_int_2(int a, int b);
+int test_int_3(int a, int b, int c);
+int test_int_4(int a, int b, int c, int d);
+int test_int_5(int a, int b, int c, int d, int e);
+int test_int_6(int a, int b, int c, int d, int e, int f);
+int test_int_7(int a, int b, int c, int d, int e, int f, int g);
+int test_int_8(int a, int b, int c, int d, int e, int f, int g, int h);
+int test_int_9(int a, int b, int c, int d, int e, int f, int g, int h, int i);
+
+long test_long_1(long a);
+long test_long_2(long a, long b);
+long test_long_3(long a, long b, long c);
+long test_long_4(long a, long b, long c, long d);
+long test_long_5(long a, long b, long c, long d, long e);
+long test_long_6(long a, long b, long c, long d, long e, long f);
+long test_long_7(long a, long b, long c, long d, long e, long f, long g);
+long test_long_8(long a, long b, long c, long d, long e, long f, long g, long h);
+long test_long_9(long a, long b, long c, long d, long e, long f, long g, long h, long i);
+
+#endif /* LIB_TEST_ARGS_H */
diff --git a/test/lib-test-common.c b/test/lib-test-common.c
new file mode 100644
index 0000000..36f5b3f
--- /dev/null
+++ b/test/lib-test-common.c
@@ -0,0 +1,5 @@
+
+
+void test_common_f1(void)
+{
+}
diff --git a/test/sysdeps/i686/test-args.c b/test/sysdeps/i686/test-args.c
new file mode 100644
index 0000000..f19a064
--- /dev/null
+++ b/test/sysdeps/i686/test-args.c
@@ -0,0 +1,68 @@
+
+#include <test/test-args.h>
+
+int test_long(struct lt_config_shared *sh)
+{
+ struct re_test_data data1[] = {
+ { RE_TEST_TYPE_STR, 0, 27, "test_long_1\\(a = 1294967294\\)" },
+ { RE_TEST_TYPE_STR, 28, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_1 = -1294967294" },
+ };
+ struct re_test_data data2[] = {
+ { RE_TEST_TYPE_STR, 0, 39, "test_long_2\\(a = 123410, b = -268435455\\)" },
+ { RE_TEST_TYPE_STR, 40, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_2 = -268312045" },
+ };
+ struct re_test_data data3[] = {
+ { RE_TEST_TYPE_STR, 0, 38, "test_long_3\\(a = 1, b = -2, c = 234217\\)" },
+ { RE_TEST_TYPE_STR, 39, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_3 = -234218" },
+ };
+ struct re_test_data data4[] = {
+ { RE_TEST_TYPE_STR, 0, 55, "test_long_4\\(a = 2025479151, b = 2, c = 9119999, d = -1\\)" },
+ { RE_TEST_TYPE_STR, 56, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_4 = 2043719148" },
+ };
+ struct re_test_data data5[] = {
+ { RE_TEST_TYPE_STR, 0, 63, "test_long_5\\(a = -1, b = 2147483647, c = 13, d = 100, e = 34121\\)" },
+ { RE_TEST_TYPE_STR, 64, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_5 = -2144071563" },
+ };
+ struct re_test_data data6[] = {
+ { RE_TEST_TYPE_STR, 0, 79, "test_long_6\\(a = 100, b = 102143210, c = -345436543, d = 12, e = -45, f = -1324\\)" },
+ { RE_TEST_TYPE_STR, 80, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_6 = -1913679240" },
+ };
+ struct re_test_data data7[] = {
+ { RE_TEST_TYPE_STR, 0, 71, "test_long_7\\(a = 1, b = 24321, c = -3, d = 4, e = 432145, f = 6, g = 27\\)" },
+ { RE_TEST_TYPE_STR, 72, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_7 = 1728415" },
+ };
+ struct re_test_data data8[] = {
+ { RE_TEST_TYPE_STR, 0, 96, "test_long_8\\(a = -11111, b = 214321543, c = 30, d = -4, e = 51432123, f = -123, g = 7000, h = 76\\)" },
+ { RE_TEST_TYPE_STR, 97, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_8 = 265749534" },
+ };
+ struct re_test_data data9[] = {
+ { RE_TEST_TYPE_STR, 0, 93, "test_long_9\\(a = -10, b = 1, c = 3, d = 12424234, e = 9, f = 3, g = 14321311, h = -99, i = 10\\)" },
+ { RE_TEST_TYPE_STR, 94, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_9 = -26745482" },
+ };
+ #define DATA_CNT(num) (sizeof(data ## num)/sizeof(struct re_test_data))
+
+ CONFIG_CLEAR_ARGS(sh);
+
+ LOCAL_TEST(data1, DATA_CNT(1), test_long_1(1294967294));
+ LOCAL_TEST(data2, DATA_CNT(2), test_long_2(123410, -268435455));
+ LOCAL_TEST(data3, DATA_CNT(3), test_long_3(1, -2, 234217));
+ LOCAL_TEST(data4, DATA_CNT(4), test_long_4(2025479151, 2, 9119999, -1));
+ LOCAL_TEST(data5, DATA_CNT(5), test_long_5(-1, 2147483647, 13, 100, 34121));
+ LOCAL_TEST(data6, DATA_CNT(6), test_long_6(100, 102143210, -345436543, 12, -45, -1324));
+ LOCAL_TEST(data7, DATA_CNT(7), test_long_7(1, 24321, -3, 4, 432145, 6, 27));
+ LOCAL_TEST(data8, DATA_CNT(8), test_long_8(-11111, 214321543, 30, -4, 51432123, -123, 7000, 76));
+ LOCAL_TEST(data9, DATA_CNT(9), test_long_9(-10, 1, 3, 12424234, 9, 3, 14321311, -99, 10));
+
+ PASSED();
+ return 0;
+}
+
diff --git a/test/sysdeps/x86_64/test-args.c b/test/sysdeps/x86_64/test-args.c
new file mode 100644
index 0000000..b05f084
--- /dev/null
+++ b/test/sysdeps/x86_64/test-args.c
@@ -0,0 +1,68 @@
+
+#include <test/test-args.h>
+
+int test_long(struct lt_config_shared *sh)
+{
+ struct re_test_data data1[] = {
+ { RE_TEST_TYPE_STR, 0, 36, "test_long_1\\(a = 1152921504606846975\\)" },
+ { RE_TEST_TYPE_STR, 37, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_1 = -1152921504606846975" },
+ };
+ struct re_test_data data2[] = {
+ { RE_TEST_TYPE_STR, 0, 47, "test_long_2\\(a = 123410, b = -12391243214298120\\)" },
+ { RE_TEST_TYPE_STR, 48, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_2 = -12391243214174710" },
+ };
+ struct re_test_data data3[] = {
+ { RE_TEST_TYPE_STR, 0, 38, "test_long_3\\(a = 1, b = -2, c = 234217\\)" },
+ { RE_TEST_TYPE_STR, 39, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_3 = -234218" },
+ };
+ struct re_test_data data4[] = {
+ { RE_TEST_TYPE_STR, 0, 61, "test_long_4\\(a = 1999990880043210, b = 2, c = 9119999, d = -1\\)" },
+ { RE_TEST_TYPE_STR, 62, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_4 = 1999990898283207" },
+ };
+ struct re_test_data data5[] = {
+ { RE_TEST_TYPE_STR, 0, 63, "test_long_5\\(a = -1, b = 2147483647, c = 13, d = 100, e = 34121\\)" },
+ { RE_TEST_TYPE_STR, 64, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_5 = 2150895733" },
+ };
+ struct re_test_data data6[] = {
+ { RE_TEST_TYPE_STR, 0, 91, "test_long_6\\(a = 100, b = 20432143210, c = -345436543, d = 12, e = 9999999999999, f = -1324\\)" },
+ { RE_TEST_TYPE_STR, 92, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_6 = -4824496853369340280" },
+ };
+ struct re_test_data data7[] = {
+ { RE_TEST_TYPE_STR, 0, 71, "test_long_7\\(a = 1, b = 24321, c = -3, d = 4, e = 432145, f = 6, g = 27\\)" },
+ { RE_TEST_TYPE_STR, 72, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_7 = 1728415" },
+ };
+ struct re_test_data data8[] = {
+ { RE_TEST_TYPE_STR, 0, 96, "test_long_8\\(a = -11111, b = 214321543, c = 30, d = -4, e = 51432123, f = -123, g = 7000, h = 76\\)" },
+ { RE_TEST_TYPE_STR, 97, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_8 = 265749534" },
+ };
+ struct re_test_data data9[] = {
+ { RE_TEST_TYPE_STR, 0, 100, "test_long_9\\(a = -10, b = 1, c = 3, d = 124321432234134, e = 9, f = 3, g = 14321311, h = -99, i = 10\\)" },
+ { RE_TEST_TYPE_STR, 101, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_long_9 = -124321446555382" },
+ };
+ #define DATA_CNT(num) (sizeof(data ## num)/sizeof(struct re_test_data))
+
+ CONFIG_CLEAR_ARGS(sh);
+
+ LOCAL_TEST(data1, DATA_CNT(1), test_long_1(1152921504606846975));
+ LOCAL_TEST(data2, DATA_CNT(2), test_long_2(123410, -12391243214298120));
+ LOCAL_TEST(data3, DATA_CNT(3), test_long_3(1, -2, 234217));
+ LOCAL_TEST(data4, DATA_CNT(4), test_long_4(1999990880043210, 2, 9119999, -1));
+ LOCAL_TEST(data5, DATA_CNT(5), test_long_5(-1, 2147483647, 13, 100, 34121));
+ LOCAL_TEST(data6, DATA_CNT(6), test_long_6(100, 20432143210, -345436543, 12, 9999999999999, -1324));
+ LOCAL_TEST(data7, DATA_CNT(7), test_long_7(1, 24321, -3, 4, 432145, 6, 27));
+ LOCAL_TEST(data8, DATA_CNT(8), test_long_8(-11111, 214321543, 30, -4, 51432123, -123, 7000, 76));
+ LOCAL_TEST(data9, DATA_CNT(9), test_long_9(-10, 1, 3, 124321432234134, 9, 3, 14321311, -99, 10));
+
+ PASSED();
+ return 0;
+}
+
diff --git a/test/test-args.c b/test/test-args.c
new file mode 100644
index 0000000..a29c86c
--- /dev/null
+++ b/test/test-args.c
@@ -0,0 +1,222 @@
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#include <test/test-args.h>
+
+static int test_char(struct lt_config_shared *sh)
+{
+ struct re_test_data data1[] = {
+ { RE_TEST_TYPE_STR, 0, 21, "test_char_1\\(a = 0x0a\\)" },
+ { RE_TEST_TYPE_STR, 22, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_1 = 0x64 'd'" },
+ };
+ struct re_test_data data2[] = {
+ { RE_TEST_TYPE_STR, 0, 31, "test_char_2\\(a = 0x0a, b = 0x14\\)" },
+ { RE_TEST_TYPE_STR, 32, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_2 = 0xf6" },
+ };
+ struct re_test_data data3[] = {
+ { RE_TEST_TYPE_STR, 0, 41, "test_char_3\\(a = 0x01, b = 0xfe, c = 0x07\\)" },
+ { RE_TEST_TYPE_STR, 42, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_3 = 0xf7" },
+ };
+ struct re_test_data data4[] = {
+ { RE_TEST_TYPE_STR, 0, 59, "test_char_4\\(a = 0x64 'd', b = 0x02, c = 0x63 'c', d = 0xff\\)" },
+ { RE_TEST_TYPE_STR, 60, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_4 = 0xc9" },
+ };
+ struct re_test_data data5[] = {
+ { RE_TEST_TYPE_STR, 0, 65, "test_char_5\\(a = 0xff, b = 0x15, c = 0x0d, d = 0x20, e = 0x79 'y'\\)" },
+ { RE_TEST_TYPE_STR, 66, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_5 = 0xc7" },
+ };
+ struct re_test_data data6[] = {
+ { RE_TEST_TYPE_STR, 0, 75, "test_char_6\\(a = 0x64 'd', b = 0xc8, c = 0xd5, d = 0x0c, e = 0xc7, f = 0xf2\\)" },
+ { RE_TEST_TYPE_STR, 76, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_6 = 0x63 'c'" },
+ };
+ struct re_test_data data7[] = {
+ { RE_TEST_TYPE_STR, 0, 81, "test_char_7\\(a = 0x01, b = 0x02, c = 0x03, d = 0x04, e = 0x05, f = 0x06, g = 0x07\\)" },
+ { RE_TEST_TYPE_STR, 82, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_7 = 0x19" },
+ };
+ struct re_test_data data8[] = {
+ { RE_TEST_TYPE_STR, 0, 95, "test_char_8\\(a = 0xf5, b = 0x15, c = 0x1e, d = 0xfc, e = 0x17, f = 0x85, g = 0x46 'F', h = 0x06\\)" },
+ { RE_TEST_TYPE_STR, 96, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_8 = 0xc9" },
+ };
+ struct re_test_data data9[] = {
+ { RE_TEST_TYPE_STR, 0, 109, "test_char_9\\(a = 0xf6, b = 0x01, c = 0x03, d = 0x04, e = 0x09, f = 0x63 'c', g = 0x4e 'N', h = 0xf7, i = 0x0c\\)" },
+ { RE_TEST_TYPE_STR, 110, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_char_9 = 0xd0" },
+ };
+ #define DATA_CNT(num) (sizeof(data ## num)/sizeof(struct re_test_data))
+
+ CONFIG_CLEAR_ARGS(sh);
+
+ LOCAL_TEST(data1, DATA_CNT(1), test_char_1(10));
+ LOCAL_TEST(data2, DATA_CNT(2), test_char_2(10, 20));
+ LOCAL_TEST(data3, DATA_CNT(3), test_char_3(1, -2, 7));
+ LOCAL_TEST(data4, DATA_CNT(4), test_char_4(100, 2, 99, -1));
+ LOCAL_TEST(data5, DATA_CNT(5), test_char_5(-1, 21, 13, 32, 121));
+ LOCAL_TEST(data6, DATA_CNT(6), test_char_6(100, 200, -43, 12, 199, -14));
+ LOCAL_TEST(data7, DATA_CNT(7), test_char_7(1, 2, 3, 4, 5, 6, 7));
+ LOCAL_TEST(data8, DATA_CNT(8), test_char_8(-11, 21, 30, -4, 23, -123, 70, 6));
+ LOCAL_TEST(data9, DATA_CNT(9), test_char_9(-10, 1, 3, 4, 9, 99, 78, -9, 12));
+
+ PASSED();
+ return 0;
+}
+
+static int test_short(struct lt_config_shared *sh)
+{
+ struct re_test_data data1[] = {
+ { RE_TEST_TYPE_STR, 0, 21, "test_short_1\\(a = 100\\)" },
+ { RE_TEST_TYPE_STR, 22, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_1 = -100" },
+ };
+ struct re_test_data data2[] = {
+ { RE_TEST_TYPE_STR, 0, 28, "test_short_2\\(a = 10, b = 20\\)" },
+ { RE_TEST_TYPE_STR, 29, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_2 = 30" },
+ };
+ struct re_test_data data3[] = {
+ { RE_TEST_TYPE_STR, 0, 34, "test_short_3\\(a = 1, b = -2, c = 7\\)" },
+ { RE_TEST_TYPE_STR, 35, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_3 = -8" },
+ };
+ struct re_test_data data4[] = {
+ { RE_TEST_TYPE_STR, 0, 45, "test_short_4\\(a = 100, b = 2, c = 999, d = -1\\)" },
+ { RE_TEST_TYPE_STR, 46, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_4 = 2097" },
+ };
+ struct re_test_data data5[] = {
+ { RE_TEST_TYPE_STR, 0, 60, "test_short_5\\(a = -1, b = 21477, c = 4313, d = 100, e = 3121\\)" },
+ { RE_TEST_TYPE_STR, 61, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_5 = 1583" },
+ };
+ struct re_test_data data6[] = {
+ { RE_TEST_TYPE_STR, 0, 70, "test_short_6\\(a = 100, b = 200, c = -3543, d = 12, e = 9999, f = -1324\\)" },
+ { RE_TEST_TYPE_STR, 71, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_6 = -25344" },
+ };
+ struct re_test_data data7[] = {
+ { RE_TEST_TYPE_STR, 0, 61, "test_short_7\\(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7\\)" },
+ { RE_TEST_TYPE_STR, 62, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_7 = -19" },
+ };
+ struct re_test_data data8[] = {
+ { RE_TEST_TYPE_STR, 0, 88, "test_short_8\\(a = -11111, b = 2143, c = 30, d = -4, e = 5123, f = -123, g = 7000, h = 76\\)" },
+ { RE_TEST_TYPE_STR, 89, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_8 = 3134" },
+ };
+ struct re_test_data data9[] = {
+ { RE_TEST_TYPE_STR, 0, 86, "test_short_9\\(a = -10, b = 1, c = 3, d = 1234, e = 9, f = 3, g = 1311, h = -99, i = 10\\)" },
+ { RE_TEST_TYPE_STR, 87, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_short_9 = -2482" },
+ };
+ #define DATA_CNT(num) (sizeof(data ## num)/sizeof(struct re_test_data))
+
+ CONFIG_CLEAR_ARGS(sh);
+
+ LOCAL_TEST(data1, DATA_CNT(1), test_short_1(100));
+ LOCAL_TEST(data2, DATA_CNT(2), test_short_2(10, 20));
+ LOCAL_TEST(data3, DATA_CNT(3), test_short_3(1, -2, 7));
+ LOCAL_TEST(data4, DATA_CNT(4), test_short_4(100, 2, 999, -1));
+ LOCAL_TEST(data5, DATA_CNT(5), test_short_5(-1, 21477, 4313, 100, 3121));
+ LOCAL_TEST(data6, DATA_CNT(6), test_short_6(100, 200, -3543, 12, 9999, -1324));
+ LOCAL_TEST(data7, DATA_CNT(7), test_short_7(1, 2, 3, 4, 5, 6, 7));
+ LOCAL_TEST(data8, DATA_CNT(8), test_short_8(-11111, 2143, 30, -4, 5123, -123, 7000, 76));
+ LOCAL_TEST(data9, DATA_CNT(9), test_short_9(-10, 1, 3, 1234, 9, 3, 1311, -99, 10));
+
+ PASSED();
+ return 0;
+}
+
+static int test_int(struct lt_config_shared *sh)
+{
+ struct re_test_data data1[] = {
+ { RE_TEST_TYPE_STR, 0, 19, "test_int_1\\(a = 100\\)" },
+ { RE_TEST_TYPE_STR, 20, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_1 = -100" },
+ };
+ struct re_test_data data2[] = {
+ { RE_TEST_TYPE_STR, 0, 26, "test_int_2\\(a = 10, b = 20\\)" },
+ { RE_TEST_TYPE_STR, 27, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_2 = 30" },
+ };
+ struct re_test_data data3[] = {
+ { RE_TEST_TYPE_STR, 0, 32, "test_int_3\\(a = 1, b = -2, c = 7\\)" },
+ { RE_TEST_TYPE_STR, 33, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_3 = -8" },
+ };
+ struct re_test_data data4[] = {
+ { RE_TEST_TYPE_STR, 0, 46, "test_int_4\\(a = 1000, b = 2, c = 99999, d = -1\\)" },
+ { RE_TEST_TYPE_STR, 47, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_4 = 200997" },
+ };
+ struct re_test_data data5[] = {
+ { RE_TEST_TYPE_STR, 0, 66, "test_int_5\\(a = -1, b = 2147483647, c = 654313, d = 100, e = 34121\\)" },
+ { RE_TEST_TYPE_STR, 67, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_5 = -2144725863" },
+ };
+ struct re_test_data data6[] = {
+ { RE_TEST_TYPE_STR, 0, 77, "test_int_6\\(a = 100, b = 200, c = -345436543, d = 12, e = 99999999, f = -1324\\)" },
+ { RE_TEST_TYPE_STR, 78, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_6 = -1223446720" },
+ };
+ struct re_test_data data7[] = {
+ { RE_TEST_TYPE_STR, 0, 59, "test_int_7\\(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7\\)" },
+ { RE_TEST_TYPE_STR, 60, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_7 = -19" },
+ };
+ struct re_test_data data8[] = {
+ { RE_TEST_TYPE_STR, 0, 91, "test_int_8\\(a = -11111, b = 214321543, c = 30, d = -4, e = 5123, f = -123, g = 7000, h = 76\\)" },
+ { RE_TEST_TYPE_STR, 92, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_8 = 214322534" },
+ };
+ struct re_test_data data9[] = {
+ { RE_TEST_TYPE_STR, 0, 84, "test_int_9\\(a = -10, b = 1, c = 3, d = 1234, e = 9, f = 3, g = 1311, h = -99, i = 10\\)" },
+ { RE_TEST_TYPE_STR, 85, -1, "\\[.*lib-test-args.so\\] \\{" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\} test_int_9 = -2482" },
+ };
+ #define DATA_CNT(num) (sizeof(data ## num)/sizeof(struct re_test_data))
+
+ CONFIG_CLEAR_ARGS(sh);
+
+ LOCAL_TEST(data1, DATA_CNT(1), test_int_1(100));
+ LOCAL_TEST(data2, DATA_CNT(2), test_int_2(10, 20));
+ LOCAL_TEST(data3, DATA_CNT(3), test_int_3(1, -2, 7));
+ LOCAL_TEST(data4, DATA_CNT(4), test_int_4(1000, 2, 99999, -1));
+ LOCAL_TEST(data5, DATA_CNT(5), test_int_5(-1, 2147483647, 654313, 100, 34121));
+ LOCAL_TEST(data6, DATA_CNT(6), test_int_6(100, 200, -345436543, 12, 99999999, -1324));
+ LOCAL_TEST(data7, DATA_CNT(7), test_int_7(1, 2, 3, 4, 5, 6, 7));
+ LOCAL_TEST(data8, DATA_CNT(8), test_int_8(-11111, 214321543, 30, -4, 5123, -123, 7000, 76));
+ LOCAL_TEST(data9, DATA_CNT(9), test_int_9(-10, 1, 3, 1234, 9, 3, 1311, -99, 10));
+
+ PASSED();
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct lt_config_shared *sh;
+
+ sh = config_init();
+ if (!sh)
+ return -1;
+
+ TEST(test_char);
+ TEST(test_short);
+ TEST(test_int);
+
+ /*
+ * test_long is arch specific, since long differes within x86 32 and
+ * 64 bits (not sure about ARM), while char/short/int are same.
+ * */
+ extern int test_long(struct lt_config_shared *sh);
+ TEST(test_long);
+
+ return 0;
+}
diff --git a/test/test-args.h b/test/test-args.h
new file mode 100644
index 0000000..d116382
--- /dev/null
+++ b/test/test-args.h
@@ -0,0 +1,31 @@
+#ifndef TEST_ARGS_H
+#define TEST_ARGS_H
+
+#include <config.h>
+
+#include <test/test-lib.h>
+#include <test/lib-test-args.h>
+
+#define CONFIG_CLEAR_ARGS(sh) \
+do { \
+ config_clear(sh); \
+ sh->args_enabled = 1; \
+ sh->hide_tid = 1; \
+} while(0)
+
+#define LOCAL_TEST(data, cnt, test) \
+do { \
+ char buf[BUFSIZE]; \
+ int ret; \
+ TEST_START(); \
+ test; \
+ TEST_STOP(); \
+ ret = fout_read(sh, buf, BUFSIZE); \
+ if (!ret) \
+ return -1; \
+ ret = re_test(buf, data, cnt); \
+ if (RE_TEST_OK != ret) \
+ FAILED("test %i, pattern '%s'\n", ret, data[ret].pat); \
+} while(0)
+
+#endif /* TEST_ARGS_H */
diff --git a/test/test-common.c b/test/test-common.c
new file mode 100644
index 0000000..d125ad4
--- /dev/null
+++ b/test/test-common.c
@@ -0,0 +1,48 @@
+
+#include <stdio.h>
+#include "test/test-lib.h"
+#include <sys/types.h>
+
+extern void test_common_f1(void);
+#define BUFSIZE 1000
+
+static int test_function(struct lt_config_shared *sh)
+{
+ char buf[BUFSIZE];
+ int ret;
+ struct re_test_data data[] = {
+ { RE_TEST_TYPE_PID, 1, -1, "[0-9]+" },
+ { RE_TEST_TYPE_STR, -1, -1, "test_common_f1" },
+ { RE_TEST_TYPE_STR, -1, -1, "\\[.*lib-test-common.so\\]" }
+ };
+ #define DATA_CNT (sizeof(data)/sizeof(struct re_test_data))
+
+ config_clear(sh);
+
+ TEST_START();
+ test_common_f1();
+ TEST_STOP();
+
+ ret = fout_read(sh, buf, BUFSIZE);
+ if (!ret)
+ return -1;
+
+ ret = re_test(buf, data, DATA_CNT);
+ if (RE_TEST_OK != ret)
+ FAILED("test %i, pattern '%s'\n", ret, data[ret].pat);
+
+ PASSED();
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct lt_config_shared *sh;
+
+ sh = config_init();
+ if (!sh)
+ return -1;
+
+ TEST(test_function);
+ return 0;
+}
diff --git a/test/test-lib.c b/test/test-lib.c
new file mode 100644
index 0000000..a9e9706
--- /dev/null
+++ b/test/test-lib.c
@@ -0,0 +1,194 @@
+
+#include <stdio.h>
+#include <config.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <regex.h>
+#include <string.h>
+#include <strings.h>
+
+#include <test/test-lib.h>
+
+static struct lt_config_shared *get_config(char *config_dir)
+{
+ struct lt_config_shared* sh;
+ int page = sysconf(_SC_PAGE_SIZE);
+ int fd, len;
+ char config_file[LT_MAXFILE];
+
+ snprintf(config_file, LT_MAXFILE, "%s/config", config_dir);
+
+ if (-1 == (fd = open(config_file, O_RDWR))) {
+ perror("open failed");
+ return NULL;
+ }
+
+ /* align the shared config length */
+ len = sizeof(struct lt_config_shared);
+ len = (len + page) & ~(page - 1);
+
+ sh = mmap(NULL, len,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+
+ if ((void *) -1 == sh) {
+ perror("mmap failed");
+ return NULL;
+ }
+
+ sh->sh = sh;
+ return sh;
+}
+
+static int fout_init(struct lt_config_shared *sh, char *config_dir)
+{
+ char output_file[LT_MAXFILE];
+ FILE *file;
+
+ snprintf(output_file, LT_MAXFILE, "%s/test-output", config_dir);
+
+ file = fopen(output_file, "w+");
+ if (!file) {
+ perror("fopen failed");
+ return -1;
+ }
+
+ sh->fout = file;
+ return 0;
+}
+
+int fout_read(struct lt_config_shared *sh, char *buf, int size)
+{
+ FILE *file = sh->fout;
+
+ /* XXX ugly, but I could not get work pipe/fifo with
+ * streams.. maybe to get rid of streams completely
+ * would be the solution */
+ bzero(buf, size);
+ rewind(file);
+ fread(buf, size, 1, file);
+ rewind(file);
+ ftruncate(fileno(file), 0);
+ return strlen(buf);
+}
+
+struct lt_config_shared *config_init(void)
+{
+ struct lt_config_shared *sh;
+ char *config_dir;
+
+ config_dir = getenv("LT_DIR");
+ if (!config_dir) {
+ printf("failed: could not get config dir\n");
+ return NULL;
+ }
+
+ sh = get_config(config_dir);
+ if (!sh)
+ return NULL;
+
+ if (fout_init(sh, config_dir))
+ return NULL;
+
+ sh->pipe = 0;
+ return sh;
+}
+
+void config_clear(struct lt_config_shared *sh)
+{
+ sh->args_enabled = 0;
+ sh->args_detailed = 0;
+ sh->disabled = 1;
+ sh->verbose = 0;
+ sh->timestamp = 0;
+ sh->debug = 0;
+ sh->indent_sym = 0;
+ sh->indent_size = 0;
+ sh->braces = 0;
+ sh->demangle = 0;
+ sh->counts = 0;
+ sh->pipe = 0;
+ sh->hide_tid = 0;
+ sh->not_follow_exec = 0;
+ sh->not_follow_fork = 0;
+ sh->framesize_check = 0;
+ sh->framesize = 1000;
+ sh->pid = 0;
+}
+
+static void re_err(regex_t *re, int errcode)
+{
+ char ebuf[BUFSIZE];
+ int ret;
+
+ ret = regerror(errcode, re, ebuf, BUFSIZE);
+ if (!ret)
+ return;
+
+ printf("regex failed: %s\n", ebuf);
+}
+
+int re_test(char *line, struct re_test_data *data, int cnt)
+{
+ int i;
+
+ for(i = 0; i < cnt; i++) {
+ int ret;
+ struct re_test_data *d = &data[i];
+ regmatch_t m[1];
+ regex_t re;
+ unsigned long val;
+
+ memset(&re, 0x0, sizeof(re));
+
+ ret = regcomp(&re,
+ d->pat,
+ REG_EXTENDED);
+ if (ret) {
+ re_err(&re, ret);
+ return i;
+ }
+
+ ret = regexec(&re, line, 1, m, 0);
+ if (ret == REG_NOMATCH) {
+ printf("failed: did not match\n");
+ return i;
+ }
+
+ switch(d->type) {
+ case RE_TEST_TYPE_STR:
+ /* start offset check */
+ if (d->so != RE_TEST_OFF_UNDEF) {
+ if (d->so != m[0].rm_so) {
+ printf("failed: so mismatch %d <> %d\n",
+ d->so, m[0].rm_so);
+ return i;
+ }
+ }
+
+ /* end offset check */
+ if (d->eo != RE_TEST_OFF_UNDEF) {
+ if (d->eo != m[0].rm_eo) {
+ printf("failed: eo mismatch %d <> %d\n",
+ d->eo, m[0].rm_eo);
+ return i;
+ }
+ }
+ break;
+ case RE_TEST_TYPE_INT:
+ case RE_TEST_TYPE_PID:
+ val = strtoul(&line[m[0].rm_so], NULL, 10);
+ if (val != getpid())
+ return i;
+ break;
+ }
+ }
+
+ return RE_TEST_OK;
+}
+
diff --git a/test/test-lib.h b/test/test-lib.h
new file mode 100644
index 0000000..54c1472
--- /dev/null
+++ b/test/test-lib.h
@@ -0,0 +1,65 @@
+#ifndef TEST_LIB
+#define TEST_LIB
+
+#include <config.h>
+#include <stdlib.h>
+
+struct lt_config_shared *config_init(void);
+void config_clear(struct lt_config_shared *sh);
+int fout_read(struct lt_config_shared *sh, char *buf, int size);
+
+enum {
+ RE_TEST_TYPE_STR = 1,
+ RE_TEST_TYPE_INT = 2,
+ RE_TEST_TYPE_PID = 3,
+};
+
+enum {
+ RE_TEST_OFF_UNDEF = -1,
+};
+
+enum {
+ RE_TEST_OK = -1,
+};
+
+struct re_test_data {
+ int type;
+ int so;
+ int eo;
+ char *pat;
+};
+
+int re_test(char *line, struct re_test_data *data, int cnt);
+
+#define TEST_START() sh->disabled = 0
+#define TEST_STOP() sh->disabled = 1
+
+#define PASSED() \
+do { \
+ printf("."); \
+ fflush(NULL); \
+} while(0)
+
+#define FAILED(fmt, args...) \
+do { \
+ char lpbuf[1024]; \
+ sprintf(lpbuf, "%s:%d failed - %s", \
+ __FUNCTION__, \
+ __LINE__, \
+ fmt); \
+ printf(lpbuf, ## args); \
+ fflush(NULL); \
+ exit(-1); \
+} while(0)
+
+#define TEST(testfn) \
+do { \
+ if (testfn(sh)) { \
+ printf("FAILED %s\n", #testfn); \
+ return -1; \
+ } \
+} while(0)
+
+#define BUFSIZE 1000
+
+#endif
diff --git a/test/test.sh b/test/test.sh
new file mode 100755
index 0000000..055a449
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# common tests
+LD_LIBRARY_PATH=$PWD ./latrace -q ./test-common
+
+# arguments tests
+LD_LIBRARY_PATH=$PWD ./latrace -q -a $PWD/test/lib-test-args.conf ./test-args