include: Introduce winetest_{push,pop}_context and use it in vcomp tests. [RFC]
Sebastian Lackner
sebastian at fds-team.de
Tue Mar 14 13:34:03 CDT 2017
Based on ideas by Mark Jansen.
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---
This is an alternative version of https://source.winehq.org/patches/data/131137
which doesn't introduce a new macro, as suggested by Henri. In this
case usage would be like:
--- snip ---
for (i = 0; i < 100; i++)
{
winetest_push_context("i = %d", i);
ok(cond1, "cond1 failed\n");
ok(cond2, "cond2 failed\n");
ok(cond3, "cond3 failed\n");
winetest_pop_context();
}
--- snip ---
Not sure if its much better than with_context, but its at least more obvious
that no break should be used between corresponding push/pop calls.
dlls/vcomp/tests/vcomp.c | 70 ++++++++++++++++++-----------------------------
include/wine/test.h | 49 ++++++++++++++++++++++++--------
2 files changed, 65 insertions(+), 54 deletions(-)
diff --git a/dlls/vcomp/tests/vcomp.c b/dlls/vcomp/tests/vcomp.c
index f0d8b3ae215..1453e0149d0 100644
--- a/dlls/vcomp/tests/vcomp.c
+++ b/dlls/vcomp/tests/vcomp.c
@@ -770,14 +770,14 @@ static void CDECL for_static_simple_cb(void)
{
unsigned int my_begin, my_end, begin, end;
+ winetest_push_context("test %d, thread %d/%d", i, thread_num, num_threads);
+
begin = end = 0xdeadbeef;
my_for_static_simple_init(FALSE, tests[i].first, tests[i].last, tests[i].step, FALSE, &my_begin, &my_end);
p_vcomp_for_static_simple_init(tests[i].first, tests[i].last, tests[i].step, FALSE, &begin, &end);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %u, got %u\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %u, got %u\n",
- i, thread_num, num_threads, my_end, end);
+ ok(begin == my_begin, "expected begin == %u, got %u\n", my_begin, begin);
+ ok(end == my_end, "expected end == %u, got %u\n", my_end, end);
p_vcomp_for_static_end();
p_vcomp_barrier();
@@ -786,24 +786,18 @@ static void CDECL for_static_simple_cb(void)
my_for_static_simple_init(FALSE, tests[i].first, tests[i].last, tests[i].step, TRUE, &my_begin, &my_end);
p_vcomp_for_static_simple_init(tests[i].first, tests[i].last, tests[i].step, TRUE, &begin, &end);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %u, got %u\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %u, got %u\n",
- i, thread_num, num_threads, my_end, end);
+ ok(begin == my_begin, "expected begin == %u, got %u\n", my_begin, begin);
+ ok(end == my_end, "expected end == %u, got %u\n", my_end, end);
p_vcomp_for_static_end();
p_vcomp_barrier();
- if (tests[i].first == tests[i].last) continue;
-
begin = end = 0xdeadbeef;
my_for_static_simple_init(FALSE, tests[i].last, tests[i].first, tests[i].step, FALSE, &my_begin, &my_end);
p_vcomp_for_static_simple_init(tests[i].last, tests[i].first, tests[i].step, FALSE, &begin, &end);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %u, got %u\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %u, got %u\n",
- i, thread_num, num_threads, my_end, end);
+ ok(begin == my_begin, "expected begin == %u, got %u\n", my_begin, begin);
+ ok(end == my_end, "expected end == %u, got %u\n", my_end, end);
p_vcomp_for_static_end();
p_vcomp_barrier();
@@ -812,13 +806,13 @@ static void CDECL for_static_simple_cb(void)
my_for_static_simple_init(FALSE, tests[i].last, tests[i].first, tests[i].step, TRUE, &my_begin, &my_end);
p_vcomp_for_static_simple_init(tests[i].last, tests[i].first, tests[i].step, TRUE, &begin, &end);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %u, got %u\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %u, got %u\n",
- i, thread_num, num_threads, my_end, end);
+ ok(begin == my_begin, "expected begin == %u, got %u\n", my_begin, begin);
+ ok(end == my_end, "expected end == %u, got %u\n", my_end, end);
p_vcomp_for_static_end();
p_vcomp_barrier();
+
+ winetest_pop_context();
}
}
@@ -973,6 +967,8 @@ static void CDECL for_static_cb(void)
unsigned int my_loops, loops;
DWORD broken_flags;
+ winetest_push_context("test %d, thread %d/%d", i, thread_num, num_threads);
+
my_loops = my_begin = my_end = my_next = my_lastchunk = 0xdeadbeef;
loops = begin = end = next = lastchunk = 0xdeadbeef;
broken_flags = my_for_static_init(tests[i].first, tests[i].last, tests[i].step, tests[i].chunksize,
@@ -982,28 +978,21 @@ static void CDECL for_static_cb(void)
if (broken_flags & VCOMP_FOR_STATIC_BROKEN_LOOP)
{
- ok(loops == 0 || loops == 1, "test %d, thread %d/%d: expected loops == 0 or 1, got %u\n",
- i, thread_num, num_threads, loops);
+ ok(loops == 0 || loops == 1, "expected loops == 0 or 1, got %u\n", loops);
}
else
{
- ok(loops == my_loops, "test %d, thread %d/%d: expected loops == %u, got %u\n",
- i, thread_num, num_threads, my_loops, loops);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %d, got %d\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %d, got %d\n",
- i, thread_num, num_threads, my_end, end);
+ ok(loops == my_loops, "expected loops == %u, got %u\n", my_loops, loops);
+ ok(begin == my_begin, "expected begin == %d, got %d\n", my_begin, begin);
+ ok(end == my_end, "expected end == %d, got %d\n", my_end, end);
ok(next == my_next || broken(broken_flags & VCOMP_FOR_STATIC_BROKEN_NEXT),
- "test %d, thread %d/%d: expected next == %d, got %d\n", i, thread_num, num_threads, my_next, next);
- ok(lastchunk == my_lastchunk, "test %d, thread %d/%d: expected lastchunk == %d, got %d\n",
- i, thread_num, num_threads, my_lastchunk, lastchunk);
+ "expected next == %d, got %d\n", my_next, next);
+ ok(lastchunk == my_lastchunk, "expected lastchunk == %d, got %d\n", my_lastchunk, lastchunk);
}
p_vcomp_for_static_end();
p_vcomp_barrier();
- if (tests[i].first == tests[i].last) continue;
-
my_loops = my_begin = my_end = my_next = my_lastchunk = 0xdeadbeef;
loops = begin = end = next = lastchunk = 0xdeadbeef;
broken_flags = my_for_static_init(tests[i].last, tests[i].first, tests[i].step, tests[i].chunksize,
@@ -1013,25 +1002,22 @@ static void CDECL for_static_cb(void)
if (broken_flags & VCOMP_FOR_STATIC_BROKEN_LOOP)
{
- ok(loops == 0 || loops == 1, "test %d, thread %d/%d: expected loops == 0 or 1, got %u\n",
- i, thread_num, num_threads, loops);
+ ok(loops == 0 || loops == 1, "expected loops == 0 or 1, got %u\n", loops);
}
else
{
- ok(loops == my_loops, "test %d, thread %d/%d: expected loops == %u, got %u\n",
- i, thread_num, num_threads, my_loops, loops);
- ok(begin == my_begin, "test %d, thread %d/%d: expected begin == %d, got %d\n",
- i, thread_num, num_threads, my_begin, begin);
- ok(end == my_end, "test %d, thread %d/%d: expected end == %d, got %d\n",
- i, thread_num, num_threads, my_end, end);
+ ok(loops == my_loops, "expected loops == %u, got %u\n", my_loops, loops);
+ ok(begin == my_begin, "expected begin == %d, got %d\n", my_begin, begin);
+ ok(end == my_end, "expected end == %d, got %d\n", my_end, end);
ok(next == my_next || broken(broken_flags & VCOMP_FOR_STATIC_BROKEN_NEXT),
- "test %d, thread %d/%d: expected next == %d, got %d\n", i, thread_num, num_threads, my_next, next);
- ok(lastchunk == my_lastchunk, "test %d, thread %d/%d: expected lastchunk == %d, got %d\n",
- i, thread_num, num_threads, my_lastchunk, lastchunk);
+ "expected next == %d, got %d\n", my_next, next);
+ ok(lastchunk == my_lastchunk, "expected lastchunk == %d, got %d\n", my_lastchunk, lastchunk);
}
p_vcomp_for_static_end();
p_vcomp_barrier();
+
+ winetest_pop_context();
}
}
diff --git a/include/wine/test.h b/include/wine/test.h
index af602c0fac0..5f8398577f9 100644
--- a/include/wine/test.h
+++ b/include/wine/test.h
@@ -109,6 +109,9 @@ extern void __winetest_cdecl winetest_skip( const char *msg, ... ) WINETEST_PRIN
extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
extern void __winetest_cdecl winetest_trace( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
+extern void __winetest_cdecl winetest_push_context( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
+extern void winetest_pop_context(void);
+
#define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
#define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
#define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
@@ -175,6 +178,7 @@ extern void __winetest_cdecl winetest_trace( const char *msg, ... ) WINETEST_PRI
#ifdef STANDALONE
#include <stdio.h>
+#include <string.h>
#include <excpt.h>
#if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
@@ -225,6 +229,7 @@ struct tls_data
unsigned int todo_level; /* current todo nesting level */
int todo_do_loop;
char *str_pos; /* position in debug buffer */
+ char context[2000]; /* buffer for debug context */
char strings[2000]; /* buffer for debug strings */
};
static DWORD tls_index;
@@ -307,8 +312,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
{
if (condition)
{
- printf( "%s:%d: Test succeeded inside todo block: ",
- data->current_file, data->current_line );
+ printf( "%s:%d%s: Test succeeded inside todo block: ",
+ data->current_file, data->current_line, data->context );
vprintf(msg, args);
InterlockedIncrement(&todo_failures);
return 0;
@@ -317,8 +322,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
{
if (winetest_debug > 0)
{
- printf( "%s:%d: Test marked todo: ",
- data->current_file, data->current_line );
+ printf( "%s:%d%s: Test marked todo: ",
+ data->current_file, data->current_line, data->context );
vprintf(msg, args);
}
InterlockedIncrement(&todo_successes);
@@ -329,8 +334,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
{
if (!condition)
{
- printf( "%s:%d: Test failed: ",
- data->current_file, data->current_line );
+ printf( "%s:%d%s: Test failed: ",
+ data->current_file, data->current_line, data->context );
vprintf(msg, args);
InterlockedIncrement(&failures);
return 0;
@@ -338,8 +343,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
else
{
if (report_success)
- printf( "%s:%d: Test succeeded\n",
- data->current_file, data->current_line);
+ printf( "%s:%d%s: Test succeeded\n",
+ data->current_file, data->current_line, data->context );
InterlockedIncrement(&successes);
return 1;
}
@@ -362,7 +367,7 @@ void __winetest_cdecl winetest_trace( const char *msg, ... )
if (winetest_debug > 0)
{
- printf( "%s:%d: ", data->current_file, data->current_line );
+ printf( "%s:%d%s: ", data->current_file, data->current_line, data->context );
__winetest_va_start(valist, msg);
vprintf(msg, valist);
__winetest_va_end(valist);
@@ -373,7 +378,7 @@ void winetest_vskip( const char *msg, __winetest_va_list args )
{
struct tls_data *data = get_tls_data();
- printf( "%s:%d: Tests skipped: ", data->current_file, data->current_line );
+ printf( "%s:%d%s: Tests skipped: ", data->current_file, data->current_line, data->context );
vprintf(msg, args);
skipped++;
}
@@ -418,6 +423,26 @@ void winetest_end_todo(void)
data->todo_level >>= 1;
}
+void __winetest_cdecl winetest_push_context( const char *msg, ... )
+{
+ __winetest_va_list valist;
+ struct tls_data *data = get_tls_data();
+ char *buf = data->context + strlen(data->context);
+
+ *buf++ = ':';
+ __winetest_va_start(valist, msg);
+ vsprintf(buf, msg, valist);
+ __winetest_va_end(valist);
+ if ((buf = strchr(buf, ':'))) *buf = 0;
+}
+
+void winetest_pop_context(void)
+{
+ struct tls_data *data = get_tls_data();
+ char *buf = strrchr(data->context, ':');
+ *buf = 0;
+}
+
int winetest_get_mainargs( char*** pargv )
{
*pargv = winetest_argv;
@@ -616,8 +641,8 @@ static LONG CALLBACK exc_filter( EXCEPTION_POINTERS *ptrs )
struct tls_data *data = get_tls_data();
if (data->current_file)
- printf( "%s:%d: this is the last test seen before the exception\n",
- data->current_file, data->current_line );
+ printf( "%s:%d%s: this is the last test seen before the exception\n",
+ data->current_file, data->current_line, data->context );
printf( "%04x:%s: unhandled exception %08x at %p\n",
GetCurrentProcessId(), current_test->name,
ptrs->ExceptionRecord->ExceptionCode, ptrs->ExceptionRecord->ExceptionAddress );
--
2.11.0
More information about the wine-patches
mailing list