2016-09-21 03:57:24 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Józef Kucia for CodeWeavers
|
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2016-09-21 03:57:24 -07:00
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2016-09-21 03:57:24 -07:00
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2016-09-21 03:57:24 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VKD3D_TEST_H
|
|
|
|
#define __VKD3D_TEST_H
|
|
|
|
|
2017-12-14 02:45:54 -08:00
|
|
|
#include "vkd3d_common.h"
|
2016-11-09 05:46:37 -08:00
|
|
|
#include <assert.h>
|
2016-10-10 02:22:50 -07:00
|
|
|
#include <inttypes.h>
|
2016-09-21 03:57:24 -07:00
|
|
|
#include <stdarg.h>
|
2016-10-24 04:20:09 -07:00
|
|
|
#include <stdbool.h>
|
2016-09-21 03:57:24 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
static void vkd3d_test_main(int argc, char **argv);
|
2016-09-21 03:57:24 -07:00
|
|
|
static const char *vkd3d_test_name;
|
2017-12-14 02:45:57 -08:00
|
|
|
static const char *vkd3d_test_platform = "other";
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2018-12-03 02:31:27 -08:00
|
|
|
static void vkd3d_test_start_todo(bool is_todo);
|
|
|
|
static int vkd3d_test_loop_todo(void);
|
|
|
|
static void vkd3d_test_end_todo(void);
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#define START_TEST(name) \
|
|
|
|
static const char *vkd3d_test_name = #name; \
|
|
|
|
static void vkd3d_test_main(int argc, char **argv)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define ok ok_(__LINE__)
|
|
|
|
#define skip skip_(__LINE__)
|
|
|
|
#define trace trace_(__LINE__)
|
|
|
|
|
|
|
|
#define ok_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_OK
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_OK(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_ok(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2016-09-28 00:42:49 -07:00
|
|
|
#define todo_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_TODO
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
#define VKD3D_TEST_TODO(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_todo(vkd3d_line, args); } while (0)
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
#define skip_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_SKIP
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_SKIP(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_skip(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define trace_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_TRACE
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_TRACE(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_trace(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2018-12-03 02:31:27 -08:00
|
|
|
#define todo_if(is_todo) \
|
|
|
|
for (vkd3d_test_start_todo(is_todo); vkd3d_test_loop_todo(); vkd3d_test_end_todo())
|
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
#define bug_if(is_bug) \
|
|
|
|
for (vkd3d_test_start_bug(is_bug); vkd3d_test_loop_bug(); vkd3d_test_end_bug())
|
|
|
|
|
2018-12-03 02:31:27 -08:00
|
|
|
#define todo todo_if(true)
|
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
static struct
|
|
|
|
{
|
2016-10-10 02:22:50 -07:00
|
|
|
LONG success_count;
|
|
|
|
LONG failure_count;
|
|
|
|
LONG skip_count;
|
|
|
|
LONG todo_count;
|
|
|
|
LONG todo_success_count;
|
2019-03-04 04:15:20 -08:00
|
|
|
LONG bug_count;
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
unsigned int debug_level;
|
2018-12-03 02:31:27 -08:00
|
|
|
|
|
|
|
unsigned int todo_level;
|
|
|
|
bool todo_do_loop;
|
2018-12-11 06:47:57 -08:00
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
unsigned int bug_level;
|
|
|
|
bool bug_do_loop;
|
|
|
|
|
2018-12-11 06:47:57 -08:00
|
|
|
char context[1024];
|
2016-09-21 03:57:24 -07:00
|
|
|
} vkd3d_test_state;
|
|
|
|
|
2017-12-14 02:45:57 -08:00
|
|
|
static bool
|
|
|
|
vkd3d_test_platform_is_windows(void)
|
|
|
|
{
|
|
|
|
return !strcmp(vkd3d_test_platform, "windows");
|
|
|
|
}
|
|
|
|
|
2018-10-01 04:57:12 -07:00
|
|
|
static inline bool
|
|
|
|
broken(bool condition)
|
|
|
|
{
|
|
|
|
return condition && vkd3d_test_platform_is_windows();
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:45:57 -08:00
|
|
|
static void
|
|
|
|
vkd3d_test_check_ok(unsigned int line, bool result, const char *fmt, va_list args)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
2018-12-03 02:31:27 -08:00
|
|
|
bool is_todo = vkd3d_test_state.todo_level && !vkd3d_test_platform_is_windows();
|
2019-03-04 04:15:20 -08:00
|
|
|
bool is_bug = vkd3d_test_state.bug_level && !vkd3d_test_platform_is_windows();
|
2018-12-03 02:31:27 -08:00
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
if (is_bug)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&vkd3d_test_state.bug_count);
|
|
|
|
if (is_todo)
|
|
|
|
result = !result;
|
|
|
|
if (result)
|
|
|
|
printf("%s:%d%s: Fixed bug: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
|
|
|
else
|
|
|
|
printf("%s:%d%s: Bug: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
}
|
|
|
|
else if (is_todo)
|
2018-12-03 02:31:27 -08:00
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&vkd3d_test_state.todo_success_count);
|
2019-03-04 04:15:20 -08:00
|
|
|
printf("%s:%d%s: Todo succeeded: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
2018-12-03 02:31:27 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&vkd3d_test_state.todo_count);
|
2019-03-04 04:15:20 -08:00
|
|
|
printf("%s:%d%s: Todo: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
2018-12-03 02:31:27 -08:00
|
|
|
}
|
2019-03-04 04:15:20 -08:00
|
|
|
vprintf(fmt, args);
|
2018-12-03 02:31:27 -08:00
|
|
|
}
|
|
|
|
else if (result)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
2019-03-04 04:15:20 -08:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.success_count);
|
2016-11-09 05:46:37 -08:00
|
|
|
if (vkd3d_test_state.debug_level > 1)
|
2018-12-11 06:47:57 -08:00
|
|
|
printf("%s:%d%s: Test succeeded.\n", vkd3d_test_name, line, vkd3d_test_state.context);
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 04:15:20 -08:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.failure_count);
|
2018-12-11 06:47:57 -08:00
|
|
|
printf("%s:%d%s: Test failed: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
2016-09-21 03:57:24 -07:00
|
|
|
vprintf(fmt, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:45:57 -08:00
|
|
|
static void VKD3D_PRINTF_FUNC(3, 4) VKD3D_UNUSED
|
|
|
|
vkd3d_test_ok(unsigned int line, bool result, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vkd3d_test_check_ok(line, result, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(2, 3) VKD3D_UNUSED
|
|
|
|
vkd3d_test_skip(unsigned int line, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2018-12-11 06:47:57 -08:00
|
|
|
printf("%s:%d%s: Test skipped: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
2016-09-21 03:57:24 -07:00
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.skip_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(2, 3) VKD3D_UNUSED
|
|
|
|
vkd3d_test_trace(unsigned int line, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2018-12-11 06:47:57 -08:00
|
|
|
printf("%s:%d%s: ", vkd3d_test_name, line, vkd3d_test_state.context);
|
2016-09-21 03:57:24 -07:00
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
static void VKD3D_PRINTF_FUNC(1, 2) VKD3D_UNUSED
|
|
|
|
vkd3d_test_debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
va_list args;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = snprintf(buffer, sizeof(buffer), "%s: ", vkd3d_test_name);
|
|
|
|
if (0 < size && size < sizeof(buffer))
|
|
|
|
{
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buffer + size, sizeof(buffer) - size, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugStringA(buffer);
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
if (vkd3d_test_state.debug_level > 0)
|
2016-11-09 05:46:37 -08:00
|
|
|
printf("%s\n", buffer);
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
int main(int argc, char **argv)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
2016-11-09 05:46:37 -08:00
|
|
|
const char *debug_level = getenv("VKD3D_TEST_DEBUG");
|
2017-12-14 02:45:57 -08:00
|
|
|
char *test_platform = getenv("VKD3D_TEST_PLATFORM");
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
memset(&vkd3d_test_state, 0, sizeof(vkd3d_test_state));
|
2016-11-09 05:46:37 -08:00
|
|
|
vkd3d_test_state.debug_level = !debug_level ? 0 : atoi(debug_level);
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2017-12-14 02:45:57 -08:00
|
|
|
if (test_platform)
|
|
|
|
{
|
|
|
|
test_platform = strdup(test_platform);
|
|
|
|
vkd3d_test_platform = test_platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vkd3d_test_state.debug_level > 1)
|
|
|
|
printf("Test platform: '%s'.\n", vkd3d_test_platform);
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
vkd3d_test_main(argc, argv);
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
printf("%s: %lu tests executed (%lu failures, %lu skipped, %lu todo, %lu bugs).\n",
|
2016-09-21 03:57:24 -07:00
|
|
|
vkd3d_test_name,
|
2016-10-10 02:22:50 -07:00
|
|
|
(unsigned long)(vkd3d_test_state.success_count
|
|
|
|
+ vkd3d_test_state.failure_count + vkd3d_test_state.todo_count
|
|
|
|
+ vkd3d_test_state.todo_success_count),
|
|
|
|
(unsigned long)(vkd3d_test_state.failure_count
|
|
|
|
+ vkd3d_test_state.todo_success_count),
|
|
|
|
(unsigned long)vkd3d_test_state.skip_count,
|
2019-03-04 04:15:20 -08:00
|
|
|
(unsigned long)vkd3d_test_state.todo_count,
|
|
|
|
(unsigned long)vkd3d_test_state.bug_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2017-12-14 02:45:57 -08:00
|
|
|
if (test_platform)
|
|
|
|
free(test_platform);
|
|
|
|
|
2016-09-28 00:42:49 -07:00
|
|
|
return vkd3d_test_state.failure_count || vkd3d_test_state.todo_success_count;
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
static char *vkd3d_test_strdupWtoA(WCHAR *str)
|
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!(len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL)))
|
|
|
|
return NULL;
|
|
|
|
if (!(out = malloc(len)))
|
|
|
|
return NULL;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, str, -1, out, len, NULL, NULL);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:45:58 -08:00
|
|
|
static bool running_under_wine(void)
|
|
|
|
{
|
|
|
|
HMODULE module = GetModuleHandleA("ntdll.dll");
|
|
|
|
return module && GetProcAddress(module, "wine_server_call");
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
int wmain(int argc, WCHAR **wargv)
|
|
|
|
{
|
|
|
|
char **argv;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
argv = malloc(argc * sizeof(*argv));
|
|
|
|
assert(argv);
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (!(argv[i] = vkd3d_test_strdupWtoA(wargv[i])))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(i == argc);
|
|
|
|
|
2017-12-14 02:45:58 -08:00
|
|
|
vkd3d_test_platform = running_under_wine() ? "wine" : "windows";
|
2017-12-14 02:45:57 -08:00
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
ret = main(argc, argv);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
free(argv[i]);
|
|
|
|
free(argv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
typedef void (*vkd3d_test_pfn)(void);
|
|
|
|
|
|
|
|
static inline void vkd3d_run_test(const char *name, vkd3d_test_pfn test_pfn)
|
|
|
|
{
|
2018-01-17 03:48:12 -08:00
|
|
|
vkd3d_test_debug("%s", name);
|
2016-11-09 05:46:37 -08:00
|
|
|
test_pfn();
|
|
|
|
}
|
|
|
|
|
2018-12-03 02:31:27 -08:00
|
|
|
static inline void vkd3d_test_start_todo(bool is_todo)
|
|
|
|
{
|
|
|
|
vkd3d_test_state.todo_level = (vkd3d_test_state.todo_level << 1) | is_todo;
|
|
|
|
vkd3d_test_state.todo_do_loop = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int vkd3d_test_loop_todo(void)
|
|
|
|
{
|
|
|
|
bool do_loop = vkd3d_test_state.todo_do_loop;
|
|
|
|
vkd3d_test_state.todo_do_loop = false;
|
|
|
|
return do_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void vkd3d_test_end_todo(void)
|
|
|
|
{
|
|
|
|
vkd3d_test_state.todo_level >>= 1;
|
|
|
|
}
|
|
|
|
|
2019-03-04 04:15:20 -08:00
|
|
|
static inline void vkd3d_test_start_bug(bool is_bug)
|
|
|
|
{
|
|
|
|
vkd3d_test_state.bug_level = (vkd3d_test_state.bug_level << 1) | is_bug;
|
|
|
|
vkd3d_test_state.bug_do_loop = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int vkd3d_test_loop_bug(void)
|
|
|
|
{
|
|
|
|
bool do_loop = vkd3d_test_state.bug_do_loop;
|
|
|
|
vkd3d_test_state.bug_do_loop = false;
|
|
|
|
return do_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void vkd3d_test_end_bug(void)
|
|
|
|
{
|
|
|
|
vkd3d_test_state.bug_level >>= 1;
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:47:57 -08:00
|
|
|
static inline void vkd3d_test_set_context(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!fmt)
|
|
|
|
{
|
|
|
|
vkd3d_test_state.context[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vkd3d_test_state.context[0] = ':';
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(&vkd3d_test_state.context[1], sizeof(vkd3d_test_state.context) - 1, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
vkd3d_test_state.context[sizeof(vkd3d_test_state.context) - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#define run_test(test_pfn) \
|
|
|
|
vkd3d_run_test(#test_pfn, test_pfn)
|
|
|
|
|
2016-10-24 04:20:09 -07:00
|
|
|
#endif /* __VKD3D_TEST_H */
|