aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-08 00:47:05 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-08 00:47:05 -0500
commita16fad96ea5de993cca61753198db43789156c7e (patch)
tree30f1341e82d8404a02ce1e01bdef516bf52af564 /tests
parentlibsandbox: let real funcs handle non-existent paths (part 2) (diff)
downloadsandbox-a16fad96ea5de993cca61753198db43789156c7e.tar.gz
sandbox-a16fad96ea5de993cca61753198db43789156c7e.tar.bz2
sandbox-a16fad96ea5de993cca61753198db43789156c7e.zip
sb_printf: get z modifier working and fixup tests
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/sb_printf.at87
-rw-r--r--tests/sb_printf_tst.c9
2 files changed, 36 insertions, 60 deletions
diff --git a/tests/sb_printf.at b/tests/sb_printf.at
index 33a17b0..baa47b6 100644
--- a/tests/sb_printf.at
+++ b/tests/sb_printf.at
@@ -1,62 +1,33 @@
AT_SETUP(sb_printf)
-AT_CHECK([sb_printf_tst], [0], [dnl
-1
--1
-123
--123
-1000
-1
--1
-123
--123
-1000
-0x1
-0xabcdef
-0x1
-0xABCDEF
-a
-0
-K
-wOOf
-CoW
-!HI!
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre} cow{post}
-{pre} cow{post}
-%
-0x0000000000123456
-1
--1
-123
--123
-1000
-1
-4294967295
-123
-4294967173
-1000
-1
-abcdef
-1
-ABCDEF
-a
-0
-K
-wOOf
-CoW
-!HI!
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre} cow{post}
-{pre} cow{post}
-%
-0x123456
-])
+AT_CHECK([dnl
+sb_printf_tst | awk 'BEGIN { ret = 0 }
+{
+ if (G == "") {
+ G = $0
+ next
+ }
+ glibc = G
+ G = ""
+
+ # easy case -- glibc output matches our output
+ if (glibc == $0)
+ next
+ # not so easy -- we format sandbox printf() the way we like
+
+ # %x -- we prefix output with 0x
+ if ($1 ~ /%[[xX]]/)
+ gsub(/\<0x/, "")
+
+ # %p -- we zero pad the output
+ if ($1 ~ /%p/)
+ gsub(/\<0x0+/, "0x")
+
+ if (glibc == $0)
+ next
+ printf "FAIL:\nglibc:%s\nsandbox:%s\n", glibc, $0
+ ret = 1
+}
+END { exit ret }'], [0])
AT_CLEANUP
diff --git a/tests/sb_printf_tst.c b/tests/sb_printf_tst.c
index 71a38aa..d189a30 100644
--- a/tests/sb_printf_tst.c
+++ b/tests/sb_printf_tst.c
@@ -1,14 +1,19 @@
#include "headers.h"
#include "sbutil.h"
+#define _T(func, fmt, args...) func("%i:[%s] " fmt "\n", __LINE__, fmt, ##args)
#define T(fmt, args...) \
do { \
- printf("%i: " fmt "\n", __LINE__, ##args); \
- sb_printf("%i: " fmt "\n", __LINE__, ##args); \
+ _T(printf, fmt, ## args); \
+ _T(sb_printf, fmt, ## args); \
} while (0)
int main(int argc, char *argv[])
{
+ /* sandbox outputs to stderr, so unify it */
+ dup2(STDOUT_FILENO, STDERR_FILENO);
+ setbuf(stdout, NULL);
+
T("%i", argc);
T("%i", -argc);
T("%d", 123);