mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2025-12-20 03:30:19 +01:00
tests: Remove zunitc testing framework
This framework isn't used anymore. Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
parent
9373e76655
commit
fbe2f27915
16 changed files with 0 additions and 4583 deletions
|
|
@ -99,49 +99,6 @@ exe_plugin_test = shared_library(
|
||||||
install: false,
|
install: false,
|
||||||
)
|
)
|
||||||
|
|
||||||
deps_zuc = [ dep_libshared ]
|
|
||||||
config_h.set10('ENABLE_JUNIT_XML', get_option('test-junit-xml'))
|
|
||||||
if get_option('test-junit-xml')
|
|
||||||
d = dependency('libxml-2.0', version: '>= 2.6', required: false)
|
|
||||||
if not d.found()
|
|
||||||
error('JUnit XML support requires libxml-2.0 >= 2.6 which was not found. Or, you can use \'-Dtest-junit-xml=false\'.')
|
|
||||||
endif
|
|
||||||
deps_zuc += d
|
|
||||||
endif
|
|
||||||
|
|
||||||
lib_zuc = static_library(
|
|
||||||
'zunitc',
|
|
||||||
'../tools/zunitc/inc/zunitc/zunitc.h',
|
|
||||||
'../tools/zunitc/inc/zunitc/zunitc_impl.h',
|
|
||||||
'../tools/zunitc/src/zuc_base_logger.c',
|
|
||||||
'../tools/zunitc/src/zuc_base_logger.h',
|
|
||||||
'../tools/zunitc/src/zuc_context.h',
|
|
||||||
'../tools/zunitc/src/zuc_event.h',
|
|
||||||
'../tools/zunitc/src/zuc_event_listener.h',
|
|
||||||
'../tools/zunitc/src/zuc_junit_reporter.c',
|
|
||||||
'../tools/zunitc/src/zuc_junit_reporter.h',
|
|
||||||
'../tools/zunitc/src/zuc_types.h',
|
|
||||||
'../tools/zunitc/src/zunitc_impl.c',
|
|
||||||
include_directories: [ common_inc, include_directories('../tools/zunitc/inc') ],
|
|
||||||
dependencies: deps_zuc,
|
|
||||||
)
|
|
||||||
dep_zuc = declare_dependency(
|
|
||||||
link_with: lib_zuc,
|
|
||||||
dependencies: dep_libshared,
|
|
||||||
include_directories: include_directories('../tools/zunitc/inc')
|
|
||||||
)
|
|
||||||
|
|
||||||
lib_zucmain = static_library(
|
|
||||||
'zunitcmain',
|
|
||||||
'../tools/zunitc/src/main.c',
|
|
||||||
include_directories: [ common_inc, include_directories('../tools/zunitc/inc') ],
|
|
||||||
dependencies: [ dep_libshared, dep_zuc ],
|
|
||||||
)
|
|
||||||
dep_zucmain = declare_dependency(
|
|
||||||
link_with: lib_zucmain,
|
|
||||||
dependencies: dep_zuc
|
|
||||||
)
|
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
{
|
{
|
||||||
'name': 'alpha-blending',
|
'name': 'alpha-blending',
|
||||||
|
|
@ -328,17 +285,6 @@ if get_option('color-management-lcms')
|
||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
tests_standalone = [
|
|
||||||
['zuc',
|
|
||||||
[
|
|
||||||
'../tools/zunitc/test/fixtures_test.c',
|
|
||||||
'../tools/zunitc/test/zunitc_test.c'
|
|
||||||
],
|
|
||||||
[ dep_zucmain ]
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
if get_option('xwayland')
|
if get_option('xwayland')
|
||||||
xcb_dep = dependency('xcb', required: false)
|
xcb_dep = dependency('xcb', required: false)
|
||||||
xcb_cursor_dep = dependency('xcb-cursor', required: false)
|
xcb_cursor_dep = dependency('xcb-cursor', required: false)
|
||||||
|
|
@ -498,42 +444,6 @@ foreach t : tests
|
||||||
)
|
)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
# FIXME: the multiple loops is lame. rethink this.
|
|
||||||
foreach t : tests_standalone
|
|
||||||
if t[0] != 'zuc'
|
|
||||||
srcs_t = [
|
|
||||||
'@0@-test.c'.format(t.get(0)),
|
|
||||||
weston_test_client_protocol_h,
|
|
||||||
]
|
|
||||||
else
|
|
||||||
srcs_t = []
|
|
||||||
endif
|
|
||||||
|
|
||||||
if t.length() > 1
|
|
||||||
srcs_t += t.get(1)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if t.length() > 2
|
|
||||||
deps_t = t[2]
|
|
||||||
else
|
|
||||||
deps_t = [ dep_test_client ]
|
|
||||||
endif
|
|
||||||
|
|
||||||
exe_t = executable(
|
|
||||||
'test-@0@'.format(t.get(0)),
|
|
||||||
srcs_t,
|
|
||||||
build_by_default: true,
|
|
||||||
include_directories: common_inc,
|
|
||||||
dependencies: deps_t,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
|
|
||||||
# matrix-test is a manual test
|
|
||||||
if t[0] != 'matrix'
|
|
||||||
test(t.get(0), exe_t)
|
|
||||||
endif
|
|
||||||
endforeach
|
|
||||||
|
|
||||||
if get_option('backend-drm')
|
if get_option('backend-drm')
|
||||||
executable(
|
executable(
|
||||||
'setbacklight',
|
'setbacklight',
|
||||||
|
|
|
||||||
|
|
@ -1,220 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@page zunitc zunitc
|
|
||||||
|
|
||||||
- @ref zunitc_overview
|
|
||||||
- @ref zunitc_overview_return
|
|
||||||
- @ref zunitc_execution
|
|
||||||
- @ref zunitc_execution_commandline
|
|
||||||
- @ref zunitc_execution_matching
|
|
||||||
- @ref zunitc_execution_wildcards
|
|
||||||
- @ref zunitc_execution_repeat
|
|
||||||
- @ref zunitc_execution_randomize
|
|
||||||
- @ref zunitc_fixtures
|
|
||||||
- @ref zunitc_functions
|
|
||||||
|
|
||||||
@section zunitc_overview Overview
|
|
||||||
|
|
||||||
A simple test framework in plain C suitable for basic unit and integration
|
|
||||||
testing.
|
|
||||||
|
|
||||||
The main rationale for creating this framework was to have a simple to use
|
|
||||||
testing framework with tests implemented in C using common patterns and under a
|
|
||||||
compatible license. The structure of the test code and macro use is intended to
|
|
||||||
follow common patterns established by frameworks such as Boost Test and Google
|
|
||||||
Test.
|
|
||||||
|
|
||||||
|
|
||||||
To get started, one or more tests should be defined via ZUC_TEST() and/or
|
|
||||||
ZUC_TEST_F(), which set up automatic test registration via gcc extensions.
|
|
||||||
To actually execute tests, ZUC_RUN_TESTS() should be called.
|
|
||||||
|
|
||||||
|
|
||||||
Tests can use several ZUC_ASSERT_* or ZUC_ASSERTG_* checks to validate
|
|
||||||
conditions. The ZUC_ASSERT_* ones upon failure will mark the current test
|
|
||||||
as failing and immediately execute a return. On the other hand, the
|
|
||||||
ZUC_ASSERTG_* tests will mark the current test as failed and then execute a
|
|
||||||
'goto' targeting the specified label. See @ref zunitc_overview_return for more
|
|
||||||
detail.
|
|
||||||
|
|
||||||
The set of fatal test checks are
|
|
||||||
|
|
||||||
- ZUC_ASSERT_TRUE()
|
|
||||||
- ZUC_ASSERT_FALSE()
|
|
||||||
- ZUC_ASSERT_NULL()
|
|
||||||
- ZUC_ASSERT_NOT_NULL()
|
|
||||||
- ZUC_ASSERT_EQ()
|
|
||||||
- ZUC_ASSERT_NE()
|
|
||||||
- ZUC_ASSERT_LT()
|
|
||||||
- ZUC_ASSERT_LE()
|
|
||||||
- ZUC_ASSERT_GT()
|
|
||||||
- ZUC_ASSERT_GE()
|
|
||||||
- ZUC_ASSERT_STREQ()
|
|
||||||
- ZUC_ASSERT_STRNE()
|
|
||||||
|
|
||||||
and
|
|
||||||
|
|
||||||
- ZUC_ASSERTG_TRUE()
|
|
||||||
- ZUC_ASSERTG_FALSE()
|
|
||||||
- ZUC_ASSERTG_NULL()
|
|
||||||
- ZUC_ASSERTG_NOT_NULL()
|
|
||||||
- ZUC_ASSERTG_EQ()
|
|
||||||
- ZUC_ASSERTG_NE()
|
|
||||||
- ZUC_ASSERTG_LT()
|
|
||||||
- ZUC_ASSERTG_LE()
|
|
||||||
- ZUC_ASSERTG_GT()
|
|
||||||
- ZUC_ASSERTG_GE()
|
|
||||||
- ZUC_ASSERTG_STREQ()
|
|
||||||
- ZUC_ASSERTG_STRNE()
|
|
||||||
|
|
||||||
Unconditional test values for logging and termination are
|
|
||||||
- ZUC_SKIP()
|
|
||||||
- ZUC_FATAL()
|
|
||||||
|
|
||||||
Unconditional message logging for failure cases only is
|
|
||||||
- ZUC_TRACEPOINT()
|
|
||||||
|
|
||||||
@subsection zunitc_overview_return Test Termination and Return
|
|
||||||
|
|
||||||
One key point where this framework differs from some others (especially many
|
|
||||||
common ad hoc test programs) is that it does not use assert() nor exceptions.
|
|
||||||
|
|
||||||
- does not use assert()
|
|
||||||
- can not use throw
|
|
||||||
|
|
||||||
One main implication of this is that when a check fails the current function
|
|
||||||
will be terminated via a 'return' statement and control passed back to the
|
|
||||||
calling function. If the check fails in an individual ZUC_TEST() or ZUC_TEST_F()
|
|
||||||
test function then control is returned to the framework and the current test is
|
|
||||||
deemed completed (either successfully or with failure).
|
|
||||||
|
|
||||||
On the other hand, if a check fails that is being executed in a function called
|
|
||||||
by an individual test, then control will stay in the current test. In order to
|
|
||||||
successfully exit the current test a follow-up check needs to be done after
|
|
||||||
calling functions that might cause a failure.
|
|
||||||
|
|
||||||
@code{.c}
|
|
||||||
...
|
|
||||||
|
|
||||||
/* Call a function that might contain ZUC_ASSERT_* use. */
|
|
||||||
some_helper_function();
|
|
||||||
|
|
||||||
/* Stop the current test if something failed. */
|
|
||||||
ZUC_ASSERT_FALSE(zuc_has_failure());
|
|
||||||
|
|
||||||
/* execution will only reach this point if no failures occurred. */
|
|
||||||
|
|
||||||
...
|
|
||||||
@endcode
|
|
||||||
|
|
||||||
Use of the ZUC_ASSERTG_*() variants can help in certain situations as check
|
|
||||||
failure will trigger a 'goto' statement as opposed to a general 'return'.
|
|
||||||
|
|
||||||
@code{.c}
|
|
||||||
...
|
|
||||||
|
|
||||||
/* Call a function that might contain ZUC_ASSERT_* use. */
|
|
||||||
some_helper_function();
|
|
||||||
|
|
||||||
/* Stop the current test if something failed. */
|
|
||||||
ZUC_ASSERTG_FALSE(zuc_has_failure(), err);
|
|
||||||
|
|
||||||
/* execution will only reach this point if no failures occurred. */
|
|
||||||
...
|
|
||||||
|
|
||||||
err:
|
|
||||||
free(str_a);
|
|
||||||
}
|
|
||||||
...
|
|
||||||
@endcode
|
|
||||||
|
|
||||||
@section zunitc_execution Controlling Execution
|
|
||||||
|
|
||||||
To control execution, the various zuc_set_* functions can be called
|
|
||||||
before invoking ZUC_RUN_TESTS().
|
|
||||||
|
|
||||||
@subsection zunitc_execution_commandline Command-line Parameters
|
|
||||||
|
|
||||||
The current implementation defers processing of command-line parameters
|
|
||||||
to the main application hosting the testing. It is possible that a
|
|
||||||
helper function to process certain parameters may be added.
|
|
||||||
|
|
||||||
@subsection zunitc_execution_matching Matching Patterns for Tests
|
|
||||||
|
|
||||||
The function zuc_set_filter() can be used to specify a pattern for
|
|
||||||
matching or excluding tests from a run. The general form is
|
|
||||||
match1[:match2[:match3..n]][:-exclude1[:exclude2[:exclude3..n]]]
|
|
||||||
|
|
||||||
@subsection zunitc_execution_wildcards Matching Wildcards
|
|
||||||
|
|
||||||
Wildcards can be used in the match/exclude patterns and recognize the
|
|
||||||
following two special characters:
|
|
||||||
- '*' matches any number of characters including zero.
|
|
||||||
- '?' matches any single character.
|
|
||||||
|
|
||||||
This pattern matching is consistent with other testing frameworks and
|
|
||||||
has been chosen in order to make it easier for developers to move
|
|
||||||
between different testing frameworks.
|
|
||||||
|
|
||||||
Calling zuc_list_tests() after zuc_set_filter() can be done to show the
|
|
||||||
effects of the matching without needing to actually run tests.
|
|
||||||
|
|
||||||
@subsection zunitc_execution_repeat Repeating Tests
|
|
||||||
|
|
||||||
Setting the repeat count higher than 1 ( via zuc_set_repeat() ) will
|
|
||||||
cause the tests to be executed several times in a row. This can be
|
|
||||||
useful for stress testing, checking for leaks, etc.
|
|
||||||
|
|
||||||
@subsection zunitc_execution_randomize Randomizing Tests
|
|
||||||
|
|
||||||
Test ordering can be randomized by setting a non-zero positive value to
|
|
||||||
zuc_set_random(). Setting it to 1 will cause the framework to pick a
|
|
||||||
random seed based on the time. A value greater than 1 will be taken as a
|
|
||||||
random seed itself. And setting it to 0 will disable randomization and
|
|
||||||
allow the tests to be executed in their natural ordering.
|
|
||||||
|
|
||||||
@section zunitc_fixtures Fixtures
|
|
||||||
|
|
||||||
Per-suite and per-test setup and teardown fixtures can be implemented by
|
|
||||||
defining an instance of struct zuc_fixture and using it as the first
|
|
||||||
parameter to ZUC_TEST_F().
|
|
||||||
|
|
||||||
@section zunitc_functions Functions
|
|
||||||
|
|
||||||
- ZUC_TEST()
|
|
||||||
- ZUC_TEST_F()
|
|
||||||
- ZUC_RUN_TESTS()
|
|
||||||
- zuc_cleanup()
|
|
||||||
- zuc_list_tests()
|
|
||||||
- zuc_set_filter()
|
|
||||||
- zuc_set_random()
|
|
||||||
- zuc_set_spawn()
|
|
||||||
- zuc_set_output_junit()
|
|
||||||
- zuc_has_skip()
|
|
||||||
- zuc_has_failure()
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
@ -1,733 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef Z_UNIT_C_H
|
|
||||||
#define Z_UNIT_C_H
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "zunitc/zunitc_impl.h"
|
|
||||||
|
|
||||||
#if !__GNUC__
|
|
||||||
#error Framework currently requires gcc or compatible compiler.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if INTPTR_MAX < INT_MAX
|
|
||||||
#error Odd platform requires rework of value type from intptr_t to custom.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Simple unit test framework declarations.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @page zunitc
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Structure to use when defining a test fixture.
|
|
||||||
* @note likely pending refactoring as use cases are refined.
|
|
||||||
* @see ZUC_TEST_F()
|
|
||||||
*/
|
|
||||||
struct zuc_fixture {
|
|
||||||
/**
|
|
||||||
* Initial optional seed data to pass to setup functions and/or tests.
|
|
||||||
*/
|
|
||||||
const void *data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Per-suite setup called before invoking any of the tests
|
|
||||||
* contained in the suite.
|
|
||||||
*
|
|
||||||
* @return a pointer to test data, or NULL.
|
|
||||||
*/
|
|
||||||
void *(*set_up_test_case)(const void *data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Per-suite tear-down called after invoking all of the tests
|
|
||||||
* contained in the suite.
|
|
||||||
*
|
|
||||||
* @param data pointer returned from the setup function.
|
|
||||||
*/
|
|
||||||
void (*tear_down_test_case)(void *data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup called before running each of the tests in the suite.
|
|
||||||
*
|
|
||||||
* @param data optional data from suite setup, or NULL.
|
|
||||||
* @return a pointer to test data, or NULL.
|
|
||||||
*/
|
|
||||||
void *(*set_up)(void *data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear-down called after running each of the tests in the suite.
|
|
||||||
*
|
|
||||||
* @param data pointer returned from the setup function.
|
|
||||||
*/
|
|
||||||
void (*tear_down)(void *data);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process exit code to mark skipped tests, consistent with
|
|
||||||
* automake tests.
|
|
||||||
*/
|
|
||||||
#define ZUC_EXIT_SKIP 77
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accesses the test executable program name.
|
|
||||||
* This version will include any full or partial path used to
|
|
||||||
* launch the executable.
|
|
||||||
*
|
|
||||||
* @note This depends on zuc_initialize() having been called.
|
|
||||||
*
|
|
||||||
* @return the name of the running program.
|
|
||||||
* The caller should not free nor hold this pointer. It will not stay
|
|
||||||
* valid across calls to zuc_initialize() or zuc_cleanup().
|
|
||||||
* @see zuc_get_program_basename()
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
zuc_get_program_name(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accesses the test executable program name in trimmed format.
|
|
||||||
* If the program is launched via a partial or full path, this
|
|
||||||
* version trims to return only the basename.
|
|
||||||
*
|
|
||||||
* @note This depends on zuc_initialize() having been called.
|
|
||||||
*
|
|
||||||
* @return the name of the running program.
|
|
||||||
* The caller should not free nor hold this pointer. It will not stay
|
|
||||||
* valid across calls to zuc_initialize() or zuc_cleanup().
|
|
||||||
* @see zuc_get_program_name()
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
zuc_get_program_basename(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the test framework and consumes any known command-line
|
|
||||||
* parameters from the list.
|
|
||||||
* The exception is 'h/help' which will be left in place for follow-up
|
|
||||||
* processing by the hosting app if so desired.
|
|
||||||
*
|
|
||||||
* @param argc pointer to argc value to read and possibly change.
|
|
||||||
* @param argv array of parameter pointers to read and possibly change.
|
|
||||||
* @param help_flagged if non-NULL will be set to true if the user
|
|
||||||
* specifies the help flag (and framework help has been output).
|
|
||||||
* @return EXIT_SUCCESS upon success setting or help, EXIT_FAILURE otherwise.
|
|
||||||
*/
|
|
||||||
int zuc_initialize(int *argc, char *argv[], bool *help_flagged);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs all tests that have been registered.
|
|
||||||
* Expected return values include EXIT_FAILURE if any errors or failures
|
|
||||||
* have occurred, ::ZUC_EXIT_SKIP if no failures have occurred but at least
|
|
||||||
* one test reported skipped, otherwise EXIT_SUCCESS if nothing of note
|
|
||||||
* was recorded.
|
|
||||||
*
|
|
||||||
* @note for consistency with other frameworks and to allow for additional
|
|
||||||
* cleanup to be added later this is implemented as a wrapper macro.
|
|
||||||
*
|
|
||||||
* @return expected exit status - normally EXIT_SUCCESS, ::ZUC_EXIT_SKIP,
|
|
||||||
* or EXIT_FAILURE.
|
|
||||||
* Normally an application can use this value directly in calling exit(),
|
|
||||||
* however there could be cases where some additional processing such as
|
|
||||||
* resource cleanup or library shutdown that a program might want to do
|
|
||||||
* first.
|
|
||||||
*/
|
|
||||||
#define ZUC_RUN_TESTS() \
|
|
||||||
zucimpl_run_tests()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the test system in preparation for application shutdown.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_cleanup(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays all known tests.
|
|
||||||
* The list returned is affected by any filtering in place.
|
|
||||||
*
|
|
||||||
* @see zuc_set_filter()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_list_tests(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter string to use for tests.
|
|
||||||
* The format is a series of patterns separated by a colon, with wildcards
|
|
||||||
* and an optional flag for negative matching. For wildcards, the '*'
|
|
||||||
* character will match any sequence and the '?' character will match any
|
|
||||||
* single character.
|
|
||||||
* The '-' character at the start of a pattern marks the end of the
|
|
||||||
* patterns required to match and the beginning of patterns that names
|
|
||||||
* must not match.
|
|
||||||
* Defaults to use all tests.
|
|
||||||
*
|
|
||||||
* @param filter the filter string to apply to tests.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_set_filter(const char *filter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger specific failure/signal upon test failures; useful when
|
|
||||||
* running under a debugger.
|
|
||||||
* Currently this is implemented to raise a SIGABRT signal when any
|
|
||||||
* failure is reported.
|
|
||||||
* Defaults to false.
|
|
||||||
*
|
|
||||||
* @param break_on_failure true to cause a break when tests fail, false to
|
|
||||||
* allow normal operation upon failures.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_set_break_on_failure(bool break_on_failure);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the number of times to repeat the tests.
|
|
||||||
* Any number higher than 1 will cause the tests to be repeated the
|
|
||||||
* specified number of times.
|
|
||||||
* Defaults to 1/no repeating.
|
|
||||||
*
|
|
||||||
* @param repeat number of times to repeat the tests.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_set_repeat(int repeat);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Randomizes the order in which tests are executed.
|
|
||||||
* A value of 0 (the default) means tests are executed in their natural
|
|
||||||
* ordering. A value of 1 will pick a random seed based on the time to
|
|
||||||
* use for running tests in a pseudo-random order. A value greater than 1
|
|
||||||
* will be used directly for the initial seed.
|
|
||||||
*
|
|
||||||
* If the tests are also repeated, the seed will be incremented for each
|
|
||||||
* subsequent run.
|
|
||||||
* Defaults to 0/not randomize.
|
|
||||||
*
|
|
||||||
* @param random 0|1|seed value.
|
|
||||||
* @see zuc_set_repeat()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_set_random(int random);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables output in the JUnit XML format.
|
|
||||||
* Defaults to false.
|
|
||||||
*
|
|
||||||
* @param enable true to generate JUnit XML output, false to disable.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_set_output_junit(bool enable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines a test case that can be registered to run.
|
|
||||||
*
|
|
||||||
* @param tcase name to use as the containing test case.
|
|
||||||
* @param test name used for the test under a given test case.
|
|
||||||
*/
|
|
||||||
#define ZUC_TEST(tcase, test) \
|
|
||||||
static void zuctest_##tcase##_##test(void); \
|
|
||||||
\
|
|
||||||
const struct zuc_registration zzz_##tcase##_##test \
|
|
||||||
__attribute__ ((used, section ("zuc_tsect"))) = \
|
|
||||||
{ \
|
|
||||||
#tcase, #test, 0, \
|
|
||||||
zuctest_##tcase##_##test, \
|
|
||||||
0 \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
static void zuctest_##tcase##_##test(void)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines a test case that can be registered to run along with setup/teardown
|
|
||||||
* support per-test and/or per test case.
|
|
||||||
*
|
|
||||||
* @note This defines a test that *uses* a fixture, it does not
|
|
||||||
* actually define a test fixture itself.
|
|
||||||
*
|
|
||||||
* @param tcase name to use as the containing test case/fixture.
|
|
||||||
* The name used must represent a test fixture instance. It also
|
|
||||||
* must not duplicate any name used in a non-fixture ZUC_TEST()
|
|
||||||
* test.
|
|
||||||
* @note the test case name must be the name of a fixture struct
|
|
||||||
* to be passed to the test.
|
|
||||||
* @param test name used for the test under a given test case.
|
|
||||||
* @param param name for the fixture data pointer.
|
|
||||||
* @see struct zuc_fixture
|
|
||||||
*/
|
|
||||||
#define ZUC_TEST_F(tcase, test, param) \
|
|
||||||
static void zuctest_##tcase##_##test(void *param); \
|
|
||||||
\
|
|
||||||
const struct zuc_registration zzz_##tcase##_##test \
|
|
||||||
__attribute__ ((used, section ("zuc_tsect"))) = \
|
|
||||||
{ \
|
|
||||||
#tcase, #test, &tcase, \
|
|
||||||
0, \
|
|
||||||
zuctest_##tcase##_##test \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
static void zuctest_##tcase##_##test(void *param)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the currently executing test has encountered any skips.
|
|
||||||
*
|
|
||||||
* @return true if there is currently a test executing and it has
|
|
||||||
* encountered any skips.
|
|
||||||
* @see zuc_has_failure
|
|
||||||
* @see ZUC_SKIP()
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
zuc_has_skip(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the currently executing test has encountered any failures.
|
|
||||||
*
|
|
||||||
* @return true if there is currently a test executing and it has
|
|
||||||
* encountered any failures.
|
|
||||||
* @see zuc_has_skip
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
zuc_has_failure(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the running test as skipped without marking it as failed, and returns
|
|
||||||
* from the current function.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param message the message to log as to why the test has been skipped.
|
|
||||||
*/
|
|
||||||
#define ZUC_SKIP(message) \
|
|
||||||
do { \
|
|
||||||
zucimpl_terminate(__FILE__, __LINE__, false, false, #message); \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the running test as failed and returns from the current function.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param message the message to log as to why the test has failed.
|
|
||||||
*/
|
|
||||||
#define ZUC_FATAL(message) \
|
|
||||||
do { \
|
|
||||||
zucimpl_terminate(__FILE__, __LINE__, true, true, #message); \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the current test as failed with a fatal issue, but does not
|
|
||||||
* immediately return from the current function. ZUC_FATAL() is normally
|
|
||||||
* preferred, but when further cleanup is needed, or the current function
|
|
||||||
* needs to return a value, this macro may be required.
|
|
||||||
*
|
|
||||||
* @param message the message to log as to why the test has failed.
|
|
||||||
* @see ZUC_FATAL()
|
|
||||||
*/
|
|
||||||
#define ZUC_MARK_FATAL(message) \
|
|
||||||
do { \
|
|
||||||
zucimpl_terminate(__FILE__, __LINE__, true, true, #message); \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a message that will be processed in the case of failure.
|
|
||||||
* If the test encounters any failures (fatal or non-fatal) then these
|
|
||||||
* messages are included in output. Otherwise they are discarded at the
|
|
||||||
* end of the test run.
|
|
||||||
*
|
|
||||||
* @param message the format string style message.
|
|
||||||
*/
|
|
||||||
#define ZUC_TRACEPOINT(message, ...) \
|
|
||||||
zucimpl_tracepoint(__FILE__, __LINE__, message, ##__VA_ARGS__);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal use macro for ASSERT implementation.
|
|
||||||
* Should not be used directly in code.
|
|
||||||
*/
|
|
||||||
#define ZUCIMPL_ASSERT(opcode, valtype, lhs, rhs) \
|
|
||||||
do { \
|
|
||||||
if (zucimpl_expect_pred2(__FILE__, __LINE__, \
|
|
||||||
(opcode), (valtype), true, \
|
|
||||||
(intptr_t)(lhs), (intptr_t)(rhs), \
|
|
||||||
#lhs, #rhs)) { \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal use macro for ASSERT with Goto implementation.
|
|
||||||
* Should not be used directly in code.
|
|
||||||
*/
|
|
||||||
#define ZUCIMPL_ASSERTG(label, opcode, valtype, lhs, rhs) \
|
|
||||||
do { \
|
|
||||||
if (zucimpl_expect_pred2(__FILE__, __LINE__, \
|
|
||||||
(opcode), (valtype), true, \
|
|
||||||
(intptr_t)(lhs), (intptr_t)(rhs), \
|
|
||||||
#lhs, #rhs)) { \
|
|
||||||
goto label; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is true, marks the test as failed
|
|
||||||
* and exits the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be true.
|
|
||||||
* @note it is far better to use a more specific check when possible
|
|
||||||
* (e.g. ZUC_ASSERT_EQ(), ZUC_ASSERT_NE(), etc.)
|
|
||||||
* @see ZUC_ASSERTG_TRUE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_TRUE(condition) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_TRUE, ZUC_VAL_INT, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is false, marks the test as
|
|
||||||
* failed and exits the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be false.
|
|
||||||
* @note it is far better to use a more specific check when possible
|
|
||||||
* (e.g. ZUC_ASSERT_EQ(), ZUC_ASSERT_NE(), etc.)
|
|
||||||
* @see ZUC_ASSERTG_FALSE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_FALSE(condition) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_FALSE, ZUC_VAL_INT, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is NULL, marks the test as failed
|
|
||||||
* and exits the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be a NULL pointer.
|
|
||||||
* @see ZUC_ASSERTG_NULL()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_NULL(condition) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_NULL, ZUC_VAL_PTR, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is non-NULL, marks the test as
|
|
||||||
* failed and exits the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be a non-NULL pointer.
|
|
||||||
* @see ZUC_ASSERTG_NOT_NULL()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_NOT_NULL(condition) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_NOT_NULL, ZUC_VAL_PTR, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions match, marks the
|
|
||||||
* test as failed and exits the current function via 'return' if they do not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @see ZUC_ASSERTG_EQ()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_EQ(expected, actual) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_EQ, ZUC_VAL_INT, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions differ, marks the
|
|
||||||
* test as failed and exits the current function via 'return' if they do not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should not hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @see ZUC_ASSERTG_NE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_NE(expected, actual) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_NE, ZUC_VAL_INT, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is less than the value
|
|
||||||
* of the second expression, marks the test as failed and exits the current
|
|
||||||
* function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param lesser the expression whose value should be lesser than the other.
|
|
||||||
* @param greater the expression whose value should be greater than the other.
|
|
||||||
* @see ZUC_ASSERTG_LT()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_LT(lesser, greater) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_LT, ZUC_VAL_INT, lesser, greater)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is less than or equal
|
|
||||||
* to the value of the second expression, marks the test as failed and
|
|
||||||
* exits the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param lesser the expression whose value should be lesser than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param greater the expression whose value should be greater than or equal to
|
|
||||||
* the other.
|
|
||||||
* @see ZUC_ASSERTG_LE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_LE(lesser, greater) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_LE, ZUC_VAL_INT, lesser, greater)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is greater than the
|
|
||||||
* value of the second expression, marks the test as failed and exits the
|
|
||||||
* current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param greater the expression whose value should be greater than the other.
|
|
||||||
* @param lesser the expression whose value should be lesser than the other.
|
|
||||||
* @see ZUC_ASSERTG_GT()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_GT(greater, lesser) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_GT, ZUC_VAL_INT, greater, lesser)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is greater than or equal
|
|
||||||
* to the value of the second expression, marks the test as failed and exits
|
|
||||||
* the current function via 'return' if it is not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param greater the expression whose value should be greater than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param lesser the expression whose value should be lesser than or equal to
|
|
||||||
* the other.
|
|
||||||
* @see ZUC_ASSERTG_GE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_GE(greater, lesser) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_GE, ZUC_VAL_INT, greater, lesser)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions match when
|
|
||||||
* compared as null-terminated C-style strings, marks the test as failed
|
|
||||||
* and exits the current function via 'return' if they do not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @see ZUC_ASSERTG_STREQ()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_STREQ(expected, actual) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_EQ, ZUC_VAL_CSTR, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions differ when
|
|
||||||
* compared as null-terminated C-style strings, marks the test as failed
|
|
||||||
* and exits the current function via 'return' if they do not.
|
|
||||||
*
|
|
||||||
* For details on return and test termination see @ref zunitc_overview_return.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should not hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @see ZUC_ASSERTG_STRNE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERT_STRNE(expected, actual) \
|
|
||||||
ZUCIMPL_ASSERT(ZUC_OP_NE, ZUC_VAL_CSTR, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is true, marks the test as failed
|
|
||||||
* and interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be true.
|
|
||||||
* @note it is far better to use a more specific check when possible
|
|
||||||
* (e.g. ZUC_ASSERTG_EQ(), ZUC_ASSERTG_NE(), etc.)
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_TRUE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_TRUE(condition, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_TRUE, ZUC_VAL_INT, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is false, marks the test as
|
|
||||||
* failed and interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be false.
|
|
||||||
* @note it is far better to use a more specific check when possible
|
|
||||||
* (e.g. ZUC_ASSERTG_EQ(), ZUC_ASSERTG_NE(), etc.)
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_FALSE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_FALSE(condition, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_FALSE, ZUC_VAL_INT, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is NULL, marks the test as failed
|
|
||||||
* and interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be a NULL pointer.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_NULL()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_NULL(condition, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_NULL, ZUC_VAL_PTR, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the specified expression is non-NULL, marks the test as
|
|
||||||
* failed and interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param condition the expression that is expected to be a non-NULL pointer.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_NOT_NULL()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_NOT_NULL(condition, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_NOT_NULL, ZUC_VAL_PTR, condition, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions match, marks the
|
|
||||||
* test as failed and interrupts the current execution via a 'goto' if they
|
|
||||||
* do not.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_EQ()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_EQ(expected, actual, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_EQ, ZUC_VAL_INT, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions differ, marks the
|
|
||||||
* test as failed and interrupts the current execution via a 'goto' if they
|
|
||||||
* do not.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should not hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_NE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_NE(expected, actual, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_NE, ZUC_VAL_INT, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is less than the value
|
|
||||||
* of the second expression, marks the test as failed and interrupts the
|
|
||||||
* current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param lesser the expression whose value should be lesser than the other.
|
|
||||||
* @param greater the expression whose value should be greater than the other.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_LT()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_LT(lesser, greater, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_LT, ZUC_VAL_INT, lesser, greater)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is less than or equal
|
|
||||||
* to the value of the second expression, marks the test as failed and
|
|
||||||
* interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param lesser the expression whose value should be lesser than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param greater the expression whose value should be greater than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_LE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_LE(lesser, greater, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_LE, ZUC_VAL_INT, lesser, greater)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is greater than the
|
|
||||||
* value of the second expression, marks the test as failed and interrupts the
|
|
||||||
* current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param greater the expression whose value should be greater than the other.
|
|
||||||
* @param lesser the expression whose value should be lesser than the other.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_GT()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_GT(greater, lesser, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_GT, ZUC_VAL_INT, greater, lesser)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the value of the first expression is greater than or equal
|
|
||||||
* to the value of the second expression, marks the test as failed and
|
|
||||||
* interrupts the current execution via a 'goto' if it is not.
|
|
||||||
*
|
|
||||||
* @param greater the expression whose value should be greater than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param lesser the expression whose value should be lesser than or equal to
|
|
||||||
* the other.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_GE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_GE(greater, lesser, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_GE, ZUC_VAL_INT, greater, lesser)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions match when
|
|
||||||
* compared as null-terminated C-style strings, marks the test as failed
|
|
||||||
* and interrupts the current execution via a 'goto' if they do not.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_STREQ()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_STREQ(expected, actual, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_EQ, ZUC_VAL_CSTR, expected, actual)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the values of the specified expressions differ when
|
|
||||||
* compared as null-terminated C-style strings, marks the test as failed
|
|
||||||
* and interrupts the current execution via a 'goto' if they do not.
|
|
||||||
*
|
|
||||||
* @param expected the value the result should not hold.
|
|
||||||
* @param actual the actual value seen in testing.
|
|
||||||
* @param label the target for 'goto' if the assertion fails.
|
|
||||||
* @see ZUC_ASSERT_STRNE()
|
|
||||||
*/
|
|
||||||
#define ZUC_ASSERTG_STRNE(expected, actual, label) \
|
|
||||||
ZUCIMPL_ASSERTG(label, ZUC_OP_NE, ZUC_VAL_CSTR, expected, actual)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* Z_UNIT_C_H */
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef Z_UNIT_C_IMPL_H
|
|
||||||
#define Z_UNIT_C_IMPL_H
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Internal details to bridge the public API - should not be used
|
|
||||||
* directly in user code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum zuc_check_op
|
|
||||||
{
|
|
||||||
ZUC_OP_TRUE,
|
|
||||||
ZUC_OP_FALSE,
|
|
||||||
ZUC_OP_NULL,
|
|
||||||
ZUC_OP_NOT_NULL,
|
|
||||||
ZUC_OP_EQ,
|
|
||||||
ZUC_OP_NE,
|
|
||||||
ZUC_OP_GE,
|
|
||||||
ZUC_OP_GT,
|
|
||||||
ZUC_OP_LE,
|
|
||||||
ZUC_OP_LT,
|
|
||||||
ZUC_OP_TERMINATE,
|
|
||||||
ZUC_OP_TRACEPOINT
|
|
||||||
};
|
|
||||||
|
|
||||||
enum zuc_check_valtype
|
|
||||||
{
|
|
||||||
ZUC_VAL_INT,
|
|
||||||
ZUC_VAL_CSTR,
|
|
||||||
ZUC_VAL_PTR,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*zucimpl_test_fn)(void);
|
|
||||||
|
|
||||||
typedef void (*zucimpl_test_fn_f)(void *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal use structure for automatic test case registration.
|
|
||||||
* Should not be used directly in code.
|
|
||||||
*/
|
|
||||||
struct zuc_registration {
|
|
||||||
const char *tcase; /**< Name of the test case. */
|
|
||||||
const char *test; /**< Name of the specific test. */
|
|
||||||
const struct zuc_fixture* fxt; /**< Optional fixture for test/case. */
|
|
||||||
zucimpl_test_fn fn; /**< function implementing base test. */
|
|
||||||
zucimpl_test_fn_f fn_f; /**< function implementing test with
|
|
||||||
fixture. */
|
|
||||||
} __attribute__ ((aligned (64)));
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
zucimpl_run_tests(void);
|
|
||||||
|
|
||||||
void
|
|
||||||
zucimpl_terminate(char const *file, int line,
|
|
||||||
bool fail, bool fatal, const char *msg);
|
|
||||||
|
|
||||||
int
|
|
||||||
zucimpl_tracepoint(char const *file, int line, const char *fmt, ...)
|
|
||||||
__attribute__ ((format (printf, 3, 4)));
|
|
||||||
|
|
||||||
int
|
|
||||||
zucimpl_expect_pred2(char const *file, int line,
|
|
||||||
enum zuc_check_op, enum zuc_check_valtype valtype,
|
|
||||||
bool fatal,
|
|
||||||
intptr_t lhs, intptr_t rhs,
|
|
||||||
const char *lhs_str, const char* rhs_str);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* Z_UNIT_C_IMPL_H */
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Common main() for test programs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "zunitc/zunitc.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
bool helped = false;
|
|
||||||
int rc = zuc_initialize(&argc, argv, &helped);
|
|
||||||
|
|
||||||
if ((rc == EXIT_SUCCESS) && !helped) {
|
|
||||||
/* Stop if any unrecognized parameters were encountered. */
|
|
||||||
if (argc > 1) {
|
|
||||||
printf("%s: unrecognized option '%s'\n",
|
|
||||||
argv[0], argv[1]);
|
|
||||||
printf("Try '%s --help' for more information.\n",
|
|
||||||
argv[0]);
|
|
||||||
rc = EXIT_FAILURE;
|
|
||||||
} else {
|
|
||||||
rc = ZUC_RUN_TESTS();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zuc_cleanup();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
@ -1,401 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "zuc_base_logger.h"
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <memory.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "zuc_event_listener.h"
|
|
||||||
#include "zuc_types.h"
|
|
||||||
|
|
||||||
#include <libweston/zalloc.h>
|
|
||||||
|
|
||||||
/* a few sequences for rudimentary ANSI graphics. */
|
|
||||||
#define CSI_GRN "\x1b[0;32m"
|
|
||||||
#define CSI_RED "\x1b[0;31m"
|
|
||||||
#define CSI_YLW "\x1b[0;33m"
|
|
||||||
#define CSI_RST "\x1b[m"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logical mappings of style levels.
|
|
||||||
*/
|
|
||||||
enum style_level {
|
|
||||||
STYLE_GOOD,
|
|
||||||
STYLE_WARN,
|
|
||||||
STYLE_BAD
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Structure for internal context.
|
|
||||||
*/
|
|
||||||
struct base_data {
|
|
||||||
bool use_color;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a formatted string with optional ANSI coloring.
|
|
||||||
*
|
|
||||||
* @param use_color true to colorize the output, false to output normally.
|
|
||||||
* @param slevel the logical type to color for.
|
|
||||||
* @param fmt the format string to print with.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
styled_printf(bool use_color, enum style_level slevel, const char *fmt, ...);
|
|
||||||
|
|
||||||
static void
|
|
||||||
destroy(void *data);
|
|
||||||
|
|
||||||
static void
|
|
||||||
pre_run(void *data, int pass_count, int pass_num, int seed, const char *filter);
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_started(void *data, int live_case_count,
|
|
||||||
int live_test_count, int disabled_count);
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_ended(void *data, int case_count, struct zuc_case **cases,
|
|
||||||
int live_case_count, int live_test_count, int total_passed,
|
|
||||||
int total_failed, int total_disabled, long total_elapsed);
|
|
||||||
|
|
||||||
static void
|
|
||||||
case_started(void *data, struct zuc_case *test_case, int live_test_count,
|
|
||||||
int disabled_count);
|
|
||||||
|
|
||||||
static void
|
|
||||||
case_ended(void *data, struct zuc_case *test_case);
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_started(void *data, struct zuc_test *test);
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_ended(void *data, struct zuc_test *test);
|
|
||||||
|
|
||||||
static void
|
|
||||||
check_triggered(void *data, char const *file, int line,
|
|
||||||
enum zuc_fail_state state, enum zuc_check_op op,
|
|
||||||
enum zuc_check_valtype valtype,
|
|
||||||
intptr_t val1, intptr_t val2,
|
|
||||||
const char *expr1, const char *expr2);
|
|
||||||
|
|
||||||
struct zuc_event_listener *
|
|
||||||
zuc_base_logger_create(void)
|
|
||||||
{
|
|
||||||
struct zuc_event_listener *listener =
|
|
||||||
zalloc(sizeof(struct zuc_event_listener));
|
|
||||||
|
|
||||||
listener->data = zalloc(sizeof(struct base_data));
|
|
||||||
listener->destroy = destroy;
|
|
||||||
listener->pre_run = pre_run;
|
|
||||||
listener->run_started = run_started;
|
|
||||||
listener->run_ended = run_ended;
|
|
||||||
listener->case_started = case_started;
|
|
||||||
listener->case_ended = case_ended;
|
|
||||||
listener->test_started = test_started;
|
|
||||||
listener->test_ended = test_ended;
|
|
||||||
listener->check_triggered = check_triggered;
|
|
||||||
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
styled_printf(bool use_color, enum style_level slevel, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list argp;
|
|
||||||
|
|
||||||
if (use_color)
|
|
||||||
switch (slevel) {
|
|
||||||
case STYLE_GOOD:
|
|
||||||
printf(CSI_GRN);
|
|
||||||
break;
|
|
||||||
case STYLE_WARN:
|
|
||||||
printf(CSI_YLW);
|
|
||||||
break;
|
|
||||||
case STYLE_BAD:
|
|
||||||
printf(CSI_RED);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_start(argp, fmt);
|
|
||||||
vprintf(fmt, argp);
|
|
||||||
va_end(argp);
|
|
||||||
|
|
||||||
if (use_color)
|
|
||||||
printf(CSI_RST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
destroy(void *data)
|
|
||||||
{
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
pre_run(void *data, int pass_count, int pass_num, int seed, const char *filter)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
|
|
||||||
bdata->use_color = isatty(fileno(stdout))
|
|
||||||
&& getenv("TERM") && strcmp(getenv("TERM"), "dumb");
|
|
||||||
|
|
||||||
if (pass_count > 1)
|
|
||||||
printf("\nRepeating all tests (iteration %d) . . .\n\n",
|
|
||||||
pass_num);
|
|
||||||
|
|
||||||
if (filter && filter[0])
|
|
||||||
styled_printf(bdata->use_color, STYLE_WARN,
|
|
||||||
"Note: test filter = %s\n",
|
|
||||||
filter);
|
|
||||||
|
|
||||||
if (seed > 0)
|
|
||||||
styled_printf(bdata->use_color, STYLE_WARN,
|
|
||||||
"Note: Randomizing tests' orders"
|
|
||||||
" with a seed of %u .\n",
|
|
||||||
seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
run_started(void *data, int live_case_count,
|
|
||||||
int live_test_count, int disabled_count)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[==========]");
|
|
||||||
printf(" Running %d %s from %d test %s.\n",
|
|
||||||
live_test_count,
|
|
||||||
(live_test_count == 1) ? "test" : "tests",
|
|
||||||
live_case_count,
|
|
||||||
(live_case_count == 1) ? "case" : "cases");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
run_ended(void *data, int case_count, struct zuc_case **cases,
|
|
||||||
int live_case_count, int live_test_count, int total_passed,
|
|
||||||
int total_failed, int total_disabled, long total_elapsed)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[==========]");
|
|
||||||
printf(" %d %s from %d test %s ran. (%ld ms)\n",
|
|
||||||
live_test_count,
|
|
||||||
(live_test_count == 1) ? "test" : "tests",
|
|
||||||
live_case_count,
|
|
||||||
(live_case_count == 1) ? "case" : "cases",
|
|
||||||
total_elapsed);
|
|
||||||
|
|
||||||
if (total_passed) {
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[ PASSED ]");
|
|
||||||
printf(" %d %s.\n", total_passed,
|
|
||||||
(total_passed == 1) ? "test" : "tests");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_failed) {
|
|
||||||
int case_num;
|
|
||||||
styled_printf(bdata->use_color, STYLE_BAD, "[ FAILED ]");
|
|
||||||
printf(" %d %s, listed below:\n",
|
|
||||||
total_failed, (total_failed == 1) ? "test" : "tests");
|
|
||||||
|
|
||||||
for (case_num = 0; case_num < case_count; ++case_num) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < cases[case_num]->test_count; ++i) {
|
|
||||||
struct zuc_test *curr =
|
|
||||||
cases[case_num]->tests[i];
|
|
||||||
if (curr->failed || curr->fatal) {
|
|
||||||
styled_printf(bdata->use_color,
|
|
||||||
STYLE_BAD,
|
|
||||||
"[ FAILED ]");
|
|
||||||
printf(" %s.%s\n",
|
|
||||||
cases[case_num]->name,
|
|
||||||
curr->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_failed || total_disabled)
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
if (total_failed)
|
|
||||||
printf(" %d FAILED %s\n",
|
|
||||||
total_failed,
|
|
||||||
(total_failed == 1) ? "TEST" : "TESTS");
|
|
||||||
|
|
||||||
if (total_disabled)
|
|
||||||
styled_printf(bdata->use_color, STYLE_WARN,
|
|
||||||
" YOU HAVE %d DISABLED %s\n",
|
|
||||||
total_disabled,
|
|
||||||
(total_disabled == 1) ? "TEST" : "TESTS");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
case_started(void *data, struct zuc_case *test_case, int live_test_count,
|
|
||||||
int disabled_count)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[----------]");
|
|
||||||
printf(" %d %s from %s.\n",
|
|
||||||
live_test_count,
|
|
||||||
(live_test_count == 1) ? "test" : "tests",
|
|
||||||
test_case->name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
case_ended(void *data, struct zuc_case *test_case)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[----------]");
|
|
||||||
printf(" %d %s from %s (%ld ms)\n",
|
|
||||||
test_case->test_count,
|
|
||||||
(test_case->test_count == 1) ? "test" : "tests",
|
|
||||||
test_case->name,
|
|
||||||
test_case->elapsed);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
test_started(void *data, struct zuc_test *test)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[ RUN ]");
|
|
||||||
printf(" %s.%s\n", test->test_case->name, test->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
test_ended(void *data, struct zuc_test *test)
|
|
||||||
{
|
|
||||||
struct base_data *bdata = data;
|
|
||||||
if (test->failed || test->fatal) {
|
|
||||||
styled_printf(bdata->use_color, STYLE_BAD, "[ FAILED ]");
|
|
||||||
printf(" %s.%s (%ld ms)\n",
|
|
||||||
test->test_case->name, test->name, test->elapsed);
|
|
||||||
} else {
|
|
||||||
styled_printf(bdata->use_color, STYLE_GOOD, "[ OK ]");
|
|
||||||
printf(" %s.%s (%ld ms)\n",
|
|
||||||
test->test_case->name, test->name, test->elapsed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
|
||||||
zuc_get_opstr(enum zuc_check_op op)
|
|
||||||
{
|
|
||||||
switch (op) {
|
|
||||||
case ZUC_OP_EQ:
|
|
||||||
return "=";
|
|
||||||
case ZUC_OP_NE:
|
|
||||||
return "!=";
|
|
||||||
case ZUC_OP_GE:
|
|
||||||
return ">=";
|
|
||||||
case ZUC_OP_GT:
|
|
||||||
return ">";
|
|
||||||
case ZUC_OP_LE:
|
|
||||||
return "<=";
|
|
||||||
case ZUC_OP_LT:
|
|
||||||
return "<";
|
|
||||||
default:
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
check_triggered(void *data, char const *file, int line,
|
|
||||||
enum zuc_fail_state state, enum zuc_check_op op,
|
|
||||||
enum zuc_check_valtype valtype,
|
|
||||||
intptr_t val1, intptr_t val2,
|
|
||||||
const char *expr1, const char *expr2)
|
|
||||||
{
|
|
||||||
switch (op) {
|
|
||||||
case ZUC_OP_TRUE:
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line, expr1);
|
|
||||||
printf(" Actual: false\n");
|
|
||||||
printf("Expected: true\n");
|
|
||||||
break;
|
|
||||||
case ZUC_OP_FALSE:
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line, expr1);
|
|
||||||
printf(" Actual: true\n");
|
|
||||||
printf("Expected: false\n");
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NULL:
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line, expr1);
|
|
||||||
printf(" Actual: %p\n", (void *)val1);
|
|
||||||
printf("Expected: %p\n", NULL);
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NOT_NULL:
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line, expr1);
|
|
||||||
printf(" Actual: %p\n", (void *)val1);
|
|
||||||
printf("Expected: not %p\n", NULL);
|
|
||||||
break;
|
|
||||||
case ZUC_OP_EQ:
|
|
||||||
if (valtype == ZUC_VAL_CSTR) {
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line,
|
|
||||||
expr2);
|
|
||||||
printf(" Actual: %s\n", (const char *)val2);
|
|
||||||
printf("Expected: %s\n", expr1);
|
|
||||||
printf("Which is: %s\n", (const char *)val1);
|
|
||||||
} else {
|
|
||||||
printf("%s:%d: error: Value of: %s\n", file, line,
|
|
||||||
expr2);
|
|
||||||
printf(" Actual: %"PRIdPTR"\n", val2);
|
|
||||||
printf("Expected: %s\n", expr1);
|
|
||||||
printf("Which is: %"PRIdPTR"\n", val1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NE:
|
|
||||||
if (valtype == ZUC_VAL_CSTR) {
|
|
||||||
printf("%s:%d: error: ", file, line);
|
|
||||||
printf("Expected: (%s) %s (%s), actual: %s == %s\n",
|
|
||||||
expr1, zuc_get_opstr(op), expr2,
|
|
||||||
(char *)val1, (char *)val2);
|
|
||||||
} else {
|
|
||||||
printf("%s:%d: error: ", file, line);
|
|
||||||
printf("Expected: (%s) %s (%s), actual: %"PRIdPTR" vs "
|
|
||||||
"%"PRIdPTR"\n", expr1, zuc_get_opstr(op), expr2,
|
|
||||||
val1, val2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_TERMINATE: {
|
|
||||||
char const *level = (val1 == 0) ? "error"
|
|
||||||
: (val1 == 1) ? "warning"
|
|
||||||
: "note";
|
|
||||||
printf("%s:%d: %s: %s\n", file, line, level, expr1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ZUC_OP_TRACEPOINT:
|
|
||||||
printf("%s:%d: note: %s\n", file, line, expr1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("%s:%d: error: ", file, line);
|
|
||||||
printf("Expected: (%s) %s (%s), actual: %"PRIdPTR" vs "
|
|
||||||
"%"PRIdPTR"\n", expr1, zuc_get_opstr(op), expr2, val1,
|
|
||||||
val2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_BASE_LOGGER_H
|
|
||||||
#define ZUC_BASE_LOGGER_H
|
|
||||||
|
|
||||||
struct zuc_event_listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new logger that outputs data to console in the default
|
|
||||||
* format.
|
|
||||||
*/
|
|
||||||
struct zuc_event_listener *
|
|
||||||
zuc_base_logger_create(void);
|
|
||||||
|
|
||||||
#endif /* ZUC_BASE_LOGGER_H */
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_CONTEXT_H
|
|
||||||
#define ZUC_CONTEXT_H
|
|
||||||
|
|
||||||
#include "zuc_types.h"
|
|
||||||
|
|
||||||
struct zuc_slinked;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal context for processing.
|
|
||||||
* Collecting data members here minimizes use of globals.
|
|
||||||
*/
|
|
||||||
struct zuc_context {
|
|
||||||
int case_count;
|
|
||||||
struct zuc_case **cases;
|
|
||||||
|
|
||||||
bool fatal;
|
|
||||||
int repeat;
|
|
||||||
int random;
|
|
||||||
unsigned int seed;
|
|
||||||
bool break_on_failure;
|
|
||||||
bool output_tap;
|
|
||||||
bool output_junit;
|
|
||||||
char *filter;
|
|
||||||
|
|
||||||
struct zuc_slinked *listeners;
|
|
||||||
|
|
||||||
struct zuc_case *curr_case;
|
|
||||||
struct zuc_test *curr_test;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* ZUC_CONTEXT_H */
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_EVENT_H
|
|
||||||
#define ZUC_EVENT_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "zunitc/zunitc_impl.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
enum zuc_event_type
|
|
||||||
{
|
|
||||||
ZUC_EVENT_IMMEDIATE,
|
|
||||||
ZUC_EVENT_DEFERRED
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status enum for posted events.
|
|
||||||
*/
|
|
||||||
enum zuc_fail_state
|
|
||||||
{
|
|
||||||
ZUC_CHECK_OK, /**< no problem. */
|
|
||||||
ZUC_CHECK_SKIP, /**< runtime skip directive encountered. */
|
|
||||||
ZUC_CHECK_FAIL, /**< non-fatal check fails. */
|
|
||||||
ZUC_CHECK_FATAL, /**< fatal assertion/check fails. */
|
|
||||||
ZUC_CHECK_ERROR /**< internal level problem. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record of an event that occurs during testing such as assert macro
|
|
||||||
* failures.
|
|
||||||
*/
|
|
||||||
struct zuc_event
|
|
||||||
{
|
|
||||||
char *file;
|
|
||||||
int32_t line;
|
|
||||||
enum zuc_fail_state state;
|
|
||||||
enum zuc_check_op op;
|
|
||||||
enum zuc_check_valtype valtype;
|
|
||||||
intptr_t val1;
|
|
||||||
intptr_t val2;
|
|
||||||
char *expr1;
|
|
||||||
char *expr2;
|
|
||||||
|
|
||||||
struct zuc_event *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches an event to the specified test.
|
|
||||||
*
|
|
||||||
* @param test the test to attach to.
|
|
||||||
* @param event the event to attach.
|
|
||||||
* @param event_type of event (immediate or deferred) to attach.
|
|
||||||
* @param transferred true if the event has been processed elsewhere and
|
|
||||||
* is being transferred for storage, false otherwise.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_attach_event(struct zuc_test *test, struct zuc_event *event,
|
|
||||||
enum zuc_event_type event_type, bool transferred);
|
|
||||||
|
|
||||||
#endif /* ZUC_EVENT_H */
|
|
||||||
|
|
@ -1,174 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_EVENT_HANDLER_H
|
|
||||||
#define ZUC_EVENT_HANDLER_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "zuc_context.h"
|
|
||||||
#include "zuc_event.h"
|
|
||||||
|
|
||||||
struct zuc_test;
|
|
||||||
struct zuc_case;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface to allow components to process testing events as they occur.
|
|
||||||
*
|
|
||||||
* Event listeners that will stream output as testing progresses are often
|
|
||||||
* named "*_logger" whereas those that produce their output upon test run
|
|
||||||
* completion are named "*_reporter".
|
|
||||||
*/
|
|
||||||
struct zuc_event_listener {
|
|
||||||
/**
|
|
||||||
* User data pointer.
|
|
||||||
*/
|
|
||||||
void *data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*destroy)(void *data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for simple pre-run state.
|
|
||||||
*
|
|
||||||
* @param pass_count total number of expected test passes.
|
|
||||||
* @param pass_num current pass iteration number.
|
|
||||||
* @param seed random seed being used, or 0 for no randomization.
|
|
||||||
* @param filter filter string used for tests, or NULL/blank for none.
|
|
||||||
*/
|
|
||||||
void (*pre_run)(void *data,
|
|
||||||
int pass_count,
|
|
||||||
int pass_num,
|
|
||||||
int seed,
|
|
||||||
const char *filter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test runs starting.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
* @param live_case_count number of active test cases in this run.
|
|
||||||
* @param live_test_count number of active tests in this run.
|
|
||||||
* @param disabled_count number of disabled tests in this run.
|
|
||||||
*/
|
|
||||||
void (*run_started)(void *data,
|
|
||||||
int live_case_count,
|
|
||||||
int live_test_count,
|
|
||||||
int disabled_count);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test runs ending.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*run_ended)(void *data,
|
|
||||||
int case_count,
|
|
||||||
struct zuc_case** cases,
|
|
||||||
int live_case_count,
|
|
||||||
int live_test_count,
|
|
||||||
int total_passed,
|
|
||||||
int total_failed,
|
|
||||||
int total_disabled,
|
|
||||||
long total_elapsed);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test case starting.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*case_started)(void *data,
|
|
||||||
struct zuc_case *test_case,
|
|
||||||
int live_test_count,
|
|
||||||
int disabled_count);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test case ending.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*case_ended)(void *data,
|
|
||||||
struct zuc_case *test_case);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test starting.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*test_started)(void *data,
|
|
||||||
struct zuc_test *test);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for test ending.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*test_ended)(void *data,
|
|
||||||
struct zuc_test *test);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for disabled test notification.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*test_disabled)(void *data,
|
|
||||||
struct zuc_test *test);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for check/assertion fired due to failure, warning, etc.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*check_triggered)(void *data,
|
|
||||||
char const *file,
|
|
||||||
int line,
|
|
||||||
enum zuc_fail_state state,
|
|
||||||
enum zuc_check_op op,
|
|
||||||
enum zuc_check_valtype valtype,
|
|
||||||
intptr_t val1,
|
|
||||||
intptr_t val2,
|
|
||||||
const char *expr1,
|
|
||||||
const char *expr2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for tracepoints and such that may be displayed later.
|
|
||||||
*
|
|
||||||
* @param data the user data associated with this instance.
|
|
||||||
*/
|
|
||||||
void (*collect_event)(void *data,
|
|
||||||
char const *file,
|
|
||||||
int line,
|
|
||||||
const char *expr1);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers an event listener instance to be called.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zuc_add_event_listener(struct zuc_event_listener *event_listener);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* ZUC_EVENT_HANDLER_H */
|
|
||||||
|
|
@ -1,479 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "zuc_junit_reporter.h"
|
|
||||||
|
|
||||||
#if ENABLE_JUNIT_XML
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <libxml/parser.h>
|
|
||||||
#include <memory.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "zuc_event_listener.h"
|
|
||||||
#include "zuc_types.h"
|
|
||||||
|
|
||||||
#include <libweston/zalloc.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hardcoded output name.
|
|
||||||
* @todo follow-up with refactoring to avoid filename hardcoding.
|
|
||||||
* Will allow for better testing in parallel etc. in general.
|
|
||||||
*/
|
|
||||||
#define XML_FNAME "test_detail.xml"
|
|
||||||
|
|
||||||
#define ISO_8601_FORMAT "%Y-%m-%dT%H:%M:%SZ"
|
|
||||||
|
|
||||||
#if LIBXML_VERSION >= 20904
|
|
||||||
#define STRPRINTF_CAST
|
|
||||||
#else
|
|
||||||
#define STRPRINTF_CAST BAD_CAST
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal data.
|
|
||||||
*/
|
|
||||||
struct junit_data
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
time_t begin;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_64BIT_STRLEN 20
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_attribute(xmlNodePtr node, const char *name, int value)
|
|
||||||
{
|
|
||||||
xmlChar scratch[MAX_64BIT_STRLEN + 1] = {};
|
|
||||||
xmlStrPrintf(scratch, sizeof(scratch), STRPRINTF_CAST "%d", value);
|
|
||||||
xmlSetProp(node, BAD_CAST name, scratch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the given event.
|
|
||||||
*
|
|
||||||
* @param parent the parent node to add new content to.
|
|
||||||
* @param event the event to write out.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
emit_event(xmlNodePtr parent, struct zuc_event *event)
|
|
||||||
{
|
|
||||||
char *msg = NULL;
|
|
||||||
|
|
||||||
switch (event->op) {
|
|
||||||
case ZUC_OP_TRUE:
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: false\n"
|
|
||||||
"Expected: true\n", event->file, event->line,
|
|
||||||
event->expr1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_FALSE:
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: true\n"
|
|
||||||
"Expected: false\n", event->file, event->line,
|
|
||||||
event->expr1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NULL:
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: %p\n"
|
|
||||||
"Expected: %p\n", event->file, event->line,
|
|
||||||
event->expr1, (void *)event->val1, NULL) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NOT_NULL:
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: %p\n"
|
|
||||||
"Expected: not %p\n", event->file, event->line,
|
|
||||||
event->expr1, (void *)event->val1, NULL) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_EQ:
|
|
||||||
if (event->valtype == ZUC_VAL_CSTR) {
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: %s\n"
|
|
||||||
"Expected: %s\n"
|
|
||||||
"Which is: %s\n",
|
|
||||||
event->file, event->line, event->expr2,
|
|
||||||
(char *)event->val2, event->expr1,
|
|
||||||
(char *)event->val1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (asprintf(&msg, "%s:%d: error: Value of: %s\n"
|
|
||||||
" Actual: %"PRIdPTR"\n"
|
|
||||||
"Expected: %s\n"
|
|
||||||
"Which is: %"PRIdPTR"\n",
|
|
||||||
event->file, event->line, event->expr2,
|
|
||||||
event->val2, event->expr1,
|
|
||||||
event->val1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_NE:
|
|
||||||
if (event->valtype == ZUC_VAL_CSTR) {
|
|
||||||
if (asprintf(&msg, "%s:%d: error: "
|
|
||||||
"Expected: (%s) %s (%s),"
|
|
||||||
" actual: %s == %s\n",
|
|
||||||
event->file, event->line,
|
|
||||||
event->expr1, zuc_get_opstr(event->op),
|
|
||||||
event->expr2, (char *)event->val1,
|
|
||||||
(char *)event->val2) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (asprintf(&msg, "%s:%d: error: "
|
|
||||||
"Expected: (%s) %s (%s),"
|
|
||||||
" actual: %"PRIdPTR" vs %"PRIdPTR"\n",
|
|
||||||
event->file, event->line,
|
|
||||||
event->expr1, zuc_get_opstr(event->op),
|
|
||||||
event->expr2, event->val1,
|
|
||||||
event->val2) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZUC_OP_TERMINATE:
|
|
||||||
{
|
|
||||||
char const *level = (event->val1 == 0) ? "error"
|
|
||||||
: (event->val1 == 1) ? "warning"
|
|
||||||
: "note";
|
|
||||||
if (asprintf(&msg, "%s:%d: %s: %s\n",
|
|
||||||
event->file, event->line, level,
|
|
||||||
event->expr1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ZUC_OP_TRACEPOINT:
|
|
||||||
if (asprintf(&msg, "%s:%d: note: %s\n",
|
|
||||||
event->file, event->line, event->expr1) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (asprintf(&msg, "%s:%d: error: "
|
|
||||||
"Expected: (%s) %s (%s), actual: %"PRIdPTR" vs "
|
|
||||||
"%"PRIdPTR"\n",
|
|
||||||
event->file, event->line,
|
|
||||||
event->expr1, zuc_get_opstr(event->op),
|
|
||||||
event->expr2, event->val1, event->val2) < 0) {
|
|
||||||
msg = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((event->op == ZUC_OP_TERMINATE) && (event->val1 > 1)) {
|
|
||||||
xmlNewChild(parent, NULL, BAD_CAST "skipped", NULL);
|
|
||||||
} else {
|
|
||||||
xmlNodePtr node = xmlNewChild(parent, NULL,
|
|
||||||
BAD_CAST "failure", NULL);
|
|
||||||
|
|
||||||
if (msg) {
|
|
||||||
xmlSetProp(node, BAD_CAST "message", BAD_CAST msg);
|
|
||||||
}
|
|
||||||
xmlSetProp(node, BAD_CAST "type", BAD_CAST "");
|
|
||||||
if (msg) {
|
|
||||||
xmlNodePtr cdata = xmlNewCDataBlock(node->doc,
|
|
||||||
BAD_CAST msg,
|
|
||||||
strlen(msg));
|
|
||||||
xmlAddChild(node, cdata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a time in milliseconds to the normal JUnit elapsed form, or
|
|
||||||
* NULL if there is a problem.
|
|
||||||
* The caller should release this with free()
|
|
||||||
*
|
|
||||||
* @return the formatted time string upon success, NULL otherwise.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
as_duration(long ms)
|
|
||||||
{
|
|
||||||
char *str = NULL;
|
|
||||||
|
|
||||||
if (asprintf(&str, "%1.3f", ms / 1000.0) < 0) {
|
|
||||||
str = NULL;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Special case to match behavior of standard JUnit output
|
|
||||||
* writers. Assumption is certain readers might have
|
|
||||||
* limitations, etc. so it is best to keep 100% identical
|
|
||||||
* output.
|
|
||||||
*/
|
|
||||||
if (!strcmp("0.000", str)) {
|
|
||||||
free(str);
|
|
||||||
str = strdup("0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the status string for the tests (run/notrun).
|
|
||||||
*
|
|
||||||
* @param test the test to check status of.
|
|
||||||
* @return the status string.
|
|
||||||
*/
|
|
||||||
static char const *
|
|
||||||
get_test_status(struct zuc_test *test)
|
|
||||||
{
|
|
||||||
if (test->disabled || test->skipped)
|
|
||||||
return "notrun";
|
|
||||||
else
|
|
||||||
return "run";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the given test.
|
|
||||||
*
|
|
||||||
* @param parent the parent node to add new content to.
|
|
||||||
* @param test the test to write out.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
emit_test(xmlNodePtr parent, struct zuc_test *test)
|
|
||||||
{
|
|
||||||
char *time_str = as_duration(test->elapsed);
|
|
||||||
xmlNodePtr node = xmlNewChild(parent, NULL, BAD_CAST "testcase", NULL);
|
|
||||||
|
|
||||||
xmlSetProp(node, BAD_CAST "name", BAD_CAST test->name);
|
|
||||||
xmlSetProp(node, BAD_CAST "status", BAD_CAST get_test_status(test));
|
|
||||||
|
|
||||||
if (time_str) {
|
|
||||||
xmlSetProp(node, BAD_CAST "time", BAD_CAST time_str);
|
|
||||||
|
|
||||||
free(time_str);
|
|
||||||
time_str = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlSetProp(node, BAD_CAST "classname", BAD_CAST test->test_case->name);
|
|
||||||
|
|
||||||
if ((test->failed || test->fatal || test->skipped) && test->events) {
|
|
||||||
struct zuc_event *evt;
|
|
||||||
for (evt = test->events; evt; evt = evt->next)
|
|
||||||
emit_event(node, evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the given test case.
|
|
||||||
*
|
|
||||||
* @param parent the parent node to add new content to.
|
|
||||||
* @param test_case the test case to write out.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
emit_case(xmlNodePtr parent, struct zuc_case *test_case)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int skipped = 0;
|
|
||||||
int disabled = 0;
|
|
||||||
int failures = 0;
|
|
||||||
xmlNodePtr node = NULL;
|
|
||||||
char *time_str = as_duration(test_case->elapsed);
|
|
||||||
|
|
||||||
for (i = 0; i < test_case->test_count; ++i) {
|
|
||||||
if (test_case->tests[i]->disabled )
|
|
||||||
disabled++;
|
|
||||||
if (test_case->tests[i]->skipped )
|
|
||||||
skipped++;
|
|
||||||
if (test_case->tests[i]->failed
|
|
||||||
|| test_case->tests[i]->fatal )
|
|
||||||
failures++;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = xmlNewChild(parent, NULL, BAD_CAST "testsuite", NULL);
|
|
||||||
xmlSetProp(node, BAD_CAST "name", BAD_CAST test_case->name);
|
|
||||||
|
|
||||||
set_attribute(node, "tests", test_case->test_count);
|
|
||||||
set_attribute(node, "failures", failures);
|
|
||||||
set_attribute(node, "disabled", disabled);
|
|
||||||
set_attribute(node, "skipped", skipped);
|
|
||||||
|
|
||||||
if (time_str) {
|
|
||||||
xmlSetProp(node, BAD_CAST "time", BAD_CAST time_str);
|
|
||||||
free(time_str);
|
|
||||||
time_str = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < test_case->test_count; ++i)
|
|
||||||
emit_test(node, test_case->tests[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a time in milliseconds to the full ISO-8601 date/time string
|
|
||||||
* format, or NULL if there is a problem.
|
|
||||||
* The caller should release this with free()
|
|
||||||
*
|
|
||||||
* @return the formatted time string upon success, NULL otherwise.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
as_iso_8601(time_t const *t)
|
|
||||||
{
|
|
||||||
char *result = NULL;
|
|
||||||
char buf[32] = {};
|
|
||||||
struct tm when;
|
|
||||||
|
|
||||||
if (gmtime_r(t, &when) != NULL)
|
|
||||||
if (strftime(buf, sizeof(buf), ISO_8601_FORMAT, &when))
|
|
||||||
result = strdup(buf);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_started(void *data, int live_case_count, int live_test_count,
|
|
||||||
int disabled_count)
|
|
||||||
{
|
|
||||||
struct junit_data *jdata = data;
|
|
||||||
|
|
||||||
jdata->begin = time(NULL);
|
|
||||||
jdata->fd = open(XML_FNAME, O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC,
|
|
||||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_ended(void *data, int case_count, struct zuc_case **cases,
|
|
||||||
int live_case_count, int live_test_count, int total_passed,
|
|
||||||
int total_failed, int total_disabled, long total_elapsed)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
long time = 0;
|
|
||||||
char *time_str = NULL;
|
|
||||||
char *timestamp = NULL;
|
|
||||||
xmlNodePtr root = NULL;
|
|
||||||
xmlDocPtr doc = NULL;
|
|
||||||
xmlChar *xmlchars = NULL;
|
|
||||||
int xmlsize = 0;
|
|
||||||
struct junit_data *jdata = data;
|
|
||||||
|
|
||||||
for (i = 0; i < case_count; ++i)
|
|
||||||
time += cases[i]->elapsed;
|
|
||||||
|
|
||||||
time_str = as_duration(time);
|
|
||||||
timestamp = as_iso_8601(&jdata->begin);
|
|
||||||
|
|
||||||
/* here would be where to add errors? */
|
|
||||||
|
|
||||||
doc = xmlNewDoc(BAD_CAST "1.0");
|
|
||||||
root = xmlNewNode(NULL, BAD_CAST "testsuites");
|
|
||||||
xmlDocSetRootElement(doc, root);
|
|
||||||
|
|
||||||
set_attribute(root, "tests", live_test_count);
|
|
||||||
set_attribute(root, "failures", total_failed);
|
|
||||||
set_attribute(root, "disabled", total_disabled);
|
|
||||||
|
|
||||||
if (timestamp) {
|
|
||||||
xmlSetProp(root, BAD_CAST "timestamp", BAD_CAST timestamp);
|
|
||||||
free(timestamp);
|
|
||||||
timestamp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time_str) {
|
|
||||||
xmlSetProp(root, BAD_CAST "time", BAD_CAST time_str);
|
|
||||||
free(time_str);
|
|
||||||
time_str = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlSetProp(root, BAD_CAST "name", BAD_CAST "AllTests");
|
|
||||||
|
|
||||||
for (i = 0; i < case_count; ++i) {
|
|
||||||
emit_case(root, cases[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlDocDumpFormatMemoryEnc(doc, &xmlchars, &xmlsize, "UTF-8", 1);
|
|
||||||
dprintf(jdata->fd, "%s", (char *) xmlchars);
|
|
||||||
xmlFree(xmlchars);
|
|
||||||
xmlchars = NULL;
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
|
|
||||||
if ((jdata->fd != fileno(stdout))
|
|
||||||
&& (jdata->fd != fileno(stderr))
|
|
||||||
&& (jdata->fd != -1)) {
|
|
||||||
close(jdata->fd);
|
|
||||||
jdata->fd = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
destroy(void *data)
|
|
||||||
{
|
|
||||||
xmlCleanupParser();
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct zuc_event_listener *
|
|
||||||
zuc_junit_reporter_create(void)
|
|
||||||
{
|
|
||||||
struct zuc_event_listener *listener =
|
|
||||||
zalloc(sizeof(struct zuc_event_listener));
|
|
||||||
|
|
||||||
struct junit_data *data = zalloc(sizeof(struct junit_data));
|
|
||||||
data->fd = -1;
|
|
||||||
|
|
||||||
listener->data = data;
|
|
||||||
listener->destroy = destroy;
|
|
||||||
listener->run_started = run_started;
|
|
||||||
listener->run_ended = run_ended;
|
|
||||||
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* ENABLE_JUNIT_XML */
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "zuc_event_listener.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Simple stub version if junit output (including libxml2 support) has
|
|
||||||
* been disabled.
|
|
||||||
* Will return NULL to cause failures as calling this when the #define
|
|
||||||
* has not been enabled is an invalid scenario.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct zuc_event_listener *
|
|
||||||
zuc_junit_reporter_create(void)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* ENABLE_JUNIT_XML */
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_JUNIT_REPORTER_H
|
|
||||||
#define ZUC_JUNIT_REPORTER_H
|
|
||||||
|
|
||||||
struct zuc_event_listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of a reporter that will write data in the JUnit
|
|
||||||
* XML format.
|
|
||||||
*/
|
|
||||||
struct zuc_event_listener *
|
|
||||||
zuc_junit_reporter_create(void);
|
|
||||||
|
|
||||||
#endif /* ZUC_JUNIT_REPORTER_H */
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZUC_TYPES_H
|
|
||||||
#define ZUC_TYPES_H
|
|
||||||
|
|
||||||
#include "zunitc/zunitc_impl.h"
|
|
||||||
|
|
||||||
struct zuc_case;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a specific test.
|
|
||||||
*/
|
|
||||||
struct zuc_test
|
|
||||||
{
|
|
||||||
int order;
|
|
||||||
struct zuc_case *test_case;
|
|
||||||
zucimpl_test_fn fn;
|
|
||||||
zucimpl_test_fn_f fn_f;
|
|
||||||
char *name;
|
|
||||||
int disabled;
|
|
||||||
int skipped;
|
|
||||||
int failed;
|
|
||||||
int fatal;
|
|
||||||
long elapsed;
|
|
||||||
struct zuc_event *events;
|
|
||||||
struct zuc_event *deferred;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a test case that can hold a collection of tests.
|
|
||||||
*/
|
|
||||||
struct zuc_case
|
|
||||||
{
|
|
||||||
int order;
|
|
||||||
char *name;
|
|
||||||
const struct zuc_fixture* fxt;
|
|
||||||
int disabled;
|
|
||||||
int skipped;
|
|
||||||
int failed;
|
|
||||||
int fatal;
|
|
||||||
int passed;
|
|
||||||
long elapsed;
|
|
||||||
int test_count;
|
|
||||||
struct zuc_test **tests;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a human-readable version of the comparison opcode.
|
|
||||||
*
|
|
||||||
* @param op the opcode to get a string version of.
|
|
||||||
* @return a human-readable string of the opcode.
|
|
||||||
* (This value should not be freed)
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
zuc_get_opstr(enum zuc_check_op op);
|
|
||||||
|
|
||||||
#endif /* ZUC_TYPES_H */
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,106 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests of fixtures.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "zunitc/zunitc.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Use a simple string for a simplistic fixture */
|
|
||||||
static struct zuc_fixture fixture_minimal = {
|
|
||||||
.data = "for all good men to",
|
|
||||||
};
|
|
||||||
|
|
||||||
ZUC_TEST_F(fixture_minimal, just_as_is, data)
|
|
||||||
{
|
|
||||||
const char *str = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(str);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(0, strcmp("for all good men to", str));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Not important what or how data is manipulated, just that this function
|
|
||||||
* does something non-transparent to it.
|
|
||||||
*/
|
|
||||||
static void *
|
|
||||||
setup_test_config(void *data)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
const char *str = data;
|
|
||||||
char *upper = NULL;
|
|
||||||
ZUC_ASSERTG_NOT_NULL(data, out);
|
|
||||||
|
|
||||||
upper = strdup(str);
|
|
||||||
ZUC_ASSERTG_NOT_NULL(upper, out);
|
|
||||||
|
|
||||||
for (i = 0; upper[i]; ++i)
|
|
||||||
upper[i] = (char)toupper(upper[i]);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return upper;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
teardown_test_config(void *data)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_NOT_NULL(data);
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct zuc_fixture fixture_data0 = {
|
|
||||||
.data = "Now is the time",
|
|
||||||
.set_up = setup_test_config,
|
|
||||||
.tear_down = teardown_test_config
|
|
||||||
};
|
|
||||||
|
|
||||||
ZUC_TEST_F(fixture_data0, base, data)
|
|
||||||
{
|
|
||||||
const char *str = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(str);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(0, strcmp("NOW IS THE TIME", str));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use the same fixture for a second test. */
|
|
||||||
ZUC_TEST_F(fixture_data0, no_lower, data)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
const char *str = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(str);
|
|
||||||
|
|
||||||
for (i = 0; str[i]; ++i)
|
|
||||||
ZUC_ASSERT_EQ(0, islower(str[i]));
|
|
||||||
}
|
|
||||||
|
|
@ -1,464 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice (including the
|
|
||||||
* next paragraph) shall be included in all copies or substantial
|
|
||||||
* portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A simple file to show tests being setup and run.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "zunitc/zunitc.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The SKIP and FAIL sets of tests are those that will cause 'make check'
|
|
||||||
* to fail so are disabled by default. They can be re-enabled when working
|
|
||||||
* on the test framework itself.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* #define ENABLE_FAIL_TESTS */
|
|
||||||
/* #define ENABLE_SKIP_TESTS */
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, math_is_sane)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_EQ(4, 2 + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, math_is_hard)
|
|
||||||
{
|
|
||||||
ZUC_TRACEPOINT("Tracepoint here.");
|
|
||||||
|
|
||||||
ZUC_TRACEPOINT("Checking %d", 4);
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(5, 2 + 2);
|
|
||||||
ZUC_TRACEPOINT("flip %1.3f", 3.1415927); /* not seen */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(base_test, tracepoint_after_assert)
|
|
||||||
{
|
|
||||||
ZUC_TRACEPOINT("Should be seen in output");
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(5, 2 + 2);
|
|
||||||
|
|
||||||
ZUC_TRACEPOINT("Should NOT be seen in output");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(base_test, math_is_more_hard)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_EQ(5, 2 + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, math_is_more_hard2)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_EQ(7, 9);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, time_counted)
|
|
||||||
{
|
|
||||||
ZUC_TRACEPOINT("Never seen");
|
|
||||||
|
|
||||||
ZUC_TRACEPOINT("Sleepy Time %d", 10000 * 5);
|
|
||||||
ZUC_ASSERT_EQ(0, usleep(10000 * 5)); /* 50ms to show up in reporting */
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(other_test, math_monkey)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_TRUE(1);
|
|
||||||
ZUC_ASSERT_TRUE(3);
|
|
||||||
ZUC_ASSERT_FALSE(0);
|
|
||||||
|
|
||||||
ZUC_ASSERT_TRUE(1);
|
|
||||||
ZUC_ASSERT_TRUE(3);
|
|
||||||
ZUC_ASSERT_FALSE(0);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(5, 2 + 3);
|
|
||||||
ZUC_ASSERT_EQ(5, 2 + 3);
|
|
||||||
|
|
||||||
int b = 9;
|
|
||||||
ZUC_ASSERT_NE(1, 2);
|
|
||||||
ZUC_ASSERT_NE(b, b + 2);
|
|
||||||
|
|
||||||
ZUC_ASSERT_NE(1, 2);
|
|
||||||
ZUC_ASSERT_NE(b, b + 1);
|
|
||||||
|
|
||||||
ZUC_ASSERT_LT(1, 2);
|
|
||||||
ZUC_ASSERT_LT(1, 3);
|
|
||||||
|
|
||||||
ZUC_ASSERT_LE(1, 2);
|
|
||||||
ZUC_ASSERT_LE(1, 3);
|
|
||||||
|
|
||||||
ZUC_ASSERT_LE(1, 1);
|
|
||||||
ZUC_ASSERT_LE(1, 1);
|
|
||||||
|
|
||||||
ZUC_ASSERT_GT(2, 1);
|
|
||||||
ZUC_ASSERT_GT(3, 1);
|
|
||||||
|
|
||||||
ZUC_ASSERT_GE(1, 1);
|
|
||||||
ZUC_ASSERT_GE(1, 1);
|
|
||||||
|
|
||||||
ZUC_ASSERT_GE(2, 1);
|
|
||||||
ZUC_ASSERT_GE(3, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
force_fatal_failure(void)
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
bool expected_to_fail_here = true;
|
|
||||||
ZUC_ASSERT_FALSE(expected_to_fail_here);
|
|
||||||
|
|
||||||
ZUC_FATAL("Should never reach here");
|
|
||||||
ZUC_ASSERT_NE(1, 1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(infrastructure, fail_keeps_testing)
|
|
||||||
{
|
|
||||||
ZUC_FATAL("Should always reach here");
|
|
||||||
ZUC_ASSERT_NE(1, 1); /* in case ZUC_FATAL doesn't work. */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(infrastructure, fatal_stops_test)
|
|
||||||
{
|
|
||||||
ZUC_FATAL("Time to kill testing");
|
|
||||||
|
|
||||||
ZUC_FATAL("Should never reach here");
|
|
||||||
ZUC_ASSERT_NE(1, 1); /* in case ZUC_FATAL doesn't work. */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_SKIP_TESTS
|
|
||||||
ZUC_TEST(infrastructure, skip_stops_test)
|
|
||||||
{
|
|
||||||
ZUC_SKIP("Time to skip testing");
|
|
||||||
|
|
||||||
ZUC_FATAL("Should never reach here");
|
|
||||||
ZUC_ASSERT_NE(1, 1); /* in case ZUC_FATAL doesn't work. */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct fixture_data {
|
|
||||||
int case_counter;
|
|
||||||
int test_counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct fixture_data fixture_info = {0, 0};
|
|
||||||
|
|
||||||
static void *
|
|
||||||
complex_test_set_up_case(const void *data)
|
|
||||||
{
|
|
||||||
fixture_info.case_counter++;
|
|
||||||
return &fixture_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
complex_test_tear_down_case(void *data)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_TRUE(&fixture_info == data);
|
|
||||||
fixture_info.case_counter--;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
complex_test_set_up(void *data)
|
|
||||||
{
|
|
||||||
fixture_info.test_counter = fixture_info.case_counter;
|
|
||||||
return &fixture_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
complex_test_tear_down(void *data)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_EQ(1, fixture_info.case_counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct zuc_fixture complex_test = {
|
|
||||||
.set_up = complex_test_set_up,
|
|
||||||
.tear_down = complex_test_tear_down,
|
|
||||||
.set_up_test_case = complex_test_set_up_case,
|
|
||||||
.tear_down_test_case = complex_test_tear_down_case
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note that these next cases all try to modify the test_counter member,
|
|
||||||
* but the fixture should reset that.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ZUC_TEST_F(complex_test, bases_cenario, data)
|
|
||||||
{
|
|
||||||
struct fixture_data *fdata = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(fdata);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(4, 3 + 1);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->case_counter);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->test_counter);
|
|
||||||
fdata->test_counter++;
|
|
||||||
ZUC_ASSERT_EQ(2, fdata->test_counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST_F(complex_test, something, data)
|
|
||||||
{
|
|
||||||
struct fixture_data *fdata = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(fdata);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(4, 3 + 1);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->case_counter);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->test_counter);
|
|
||||||
fdata->test_counter++;
|
|
||||||
ZUC_ASSERT_EQ(2, fdata->test_counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST_F(complex_test, else_here, data)
|
|
||||||
{
|
|
||||||
struct fixture_data *fdata = data;
|
|
||||||
ZUC_ASSERT_NOT_NULL(fdata);
|
|
||||||
|
|
||||||
ZUC_ASSERT_EQ(4, 3 + 1);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->case_counter);
|
|
||||||
ZUC_ASSERT_EQ(1, fdata->test_counter);
|
|
||||||
fdata->test_counter++;
|
|
||||||
ZUC_ASSERT_EQ(2, fdata->test_counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(more, DISABLED_not_run)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_EQ(1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(more, failure_states)
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
bool expected_to_fail_here = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_ASSERT_FALSE(zuc_has_failure());
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_ASSERT_FALSE(expected_to_fail_here); /* should fail */
|
|
||||||
|
|
||||||
ZUC_ASSERT_TRUE(zuc_has_failure());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(more, failure_sub_fatal)
|
|
||||||
{
|
|
||||||
ZUC_ASSERT_FALSE(zuc_has_failure());
|
|
||||||
|
|
||||||
force_fatal_failure();
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_ASSERT_TRUE(zuc_has_failure());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(pointers, null)
|
|
||||||
{
|
|
||||||
const char *a = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_NULL(NULL);
|
|
||||||
ZUC_ASSERT_NULL(0);
|
|
||||||
ZUC_ASSERT_NULL(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(pointers, null_fail)
|
|
||||||
{
|
|
||||||
const char *a = "a";
|
|
||||||
|
|
||||||
ZUC_ASSERT_NULL(!NULL);
|
|
||||||
ZUC_ASSERT_NULL(!0);
|
|
||||||
ZUC_ASSERT_NULL(a);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_TEST(pointers, not_null)
|
|
||||||
{
|
|
||||||
const char *a = "a";
|
|
||||||
|
|
||||||
ZUC_ASSERT_NOT_NULL(!NULL);
|
|
||||||
ZUC_ASSERT_NOT_NULL(!0);
|
|
||||||
ZUC_ASSERT_NOT_NULL(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(pointers, not_null_fail)
|
|
||||||
{
|
|
||||||
const char *a = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_NOT_NULL(NULL);
|
|
||||||
ZUC_ASSERT_NOT_NULL(0);
|
|
||||||
ZUC_ASSERT_NOT_NULL(a);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_TEST(strings, eq)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STREQ(str_a, str_a);
|
|
||||||
ZUC_ASSERT_STREQ("a", str_a);
|
|
||||||
ZUC_ASSERT_STREQ(str_a, "a");
|
|
||||||
|
|
||||||
ZUC_ASSERT_STREQ(str_nil, str_nil);
|
|
||||||
ZUC_ASSERT_STREQ(NULL, str_nil);
|
|
||||||
ZUC_ASSERT_STREQ(str_nil, NULL);
|
|
||||||
|
|
||||||
free(str_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(strings, eq_fail)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
char *str_b = strdup("b");
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STREQ(str_a, str_b);
|
|
||||||
ZUC_ASSERT_STREQ("b", str_a);
|
|
||||||
ZUC_ASSERT_STREQ(str_a, "b");
|
|
||||||
|
|
||||||
ZUC_ASSERT_STREQ(str_nil, str_a);
|
|
||||||
ZUC_ASSERT_STREQ(str_nil, str_b);
|
|
||||||
ZUC_ASSERT_STREQ(str_a, str_nil);
|
|
||||||
ZUC_ASSERT_STREQ(str_b, str_nil);
|
|
||||||
|
|
||||||
ZUC_ASSERT_STREQ(NULL, str_a);
|
|
||||||
ZUC_ASSERT_STREQ(NULL, str_b);
|
|
||||||
ZUC_ASSERT_STREQ(str_a, NULL);
|
|
||||||
ZUC_ASSERT_STREQ(str_b, NULL);
|
|
||||||
|
|
||||||
free(str_a);
|
|
||||||
free(str_b);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
char *str_b = strdup("b");
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(str_a, str_b);
|
|
||||||
ZUC_ASSERT_STRNE("b", str_a);
|
|
||||||
ZUC_ASSERT_STRNE(str_a, "b");
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(str_nil, str_a);
|
|
||||||
ZUC_ASSERT_STRNE(str_nil, str_b);
|
|
||||||
ZUC_ASSERT_STRNE(str_a, str_nil);
|
|
||||||
ZUC_ASSERT_STRNE(str_b, str_nil);
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(NULL, str_a);
|
|
||||||
ZUC_ASSERT_STRNE(NULL, str_b);
|
|
||||||
ZUC_ASSERT_STRNE(str_a, NULL);
|
|
||||||
ZUC_ASSERT_STRNE(str_b, NULL);
|
|
||||||
|
|
||||||
free(str_a);
|
|
||||||
free(str_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_FAIL_TESTS
|
|
||||||
ZUC_TEST(strings, ne_fail01)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
|
|
||||||
ZUC_ASSERTG_STRNE(str_a, str_a, err);
|
|
||||||
|
|
||||||
err:
|
|
||||||
free(str_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne_fail02)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
|
|
||||||
ZUC_ASSERTG_STRNE("a", str_a, err);
|
|
||||||
|
|
||||||
err:
|
|
||||||
free(str_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne_fail03)
|
|
||||||
{
|
|
||||||
/* Note that we use strdup() to ensure different addresses. */
|
|
||||||
char *str_a = strdup("a");
|
|
||||||
|
|
||||||
ZUC_ASSERTG_STRNE(str_a, "a", err);
|
|
||||||
|
|
||||||
err:
|
|
||||||
free(str_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne_fail04)
|
|
||||||
{
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(str_nil, str_nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne_fail05)
|
|
||||||
{
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(NULL, str_nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(strings, ne_fail06)
|
|
||||||
{
|
|
||||||
const char *str_nil = NULL;
|
|
||||||
|
|
||||||
ZUC_ASSERT_STRNE(str_nil, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, later)
|
|
||||||
{
|
|
||||||
/* an additional test for the same case but later in source */
|
|
||||||
ZUC_ASSERT_EQ(3, 5 - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZUC_TEST(base_test, zed)
|
|
||||||
{
|
|
||||||
/* an additional test for the same case but later in source */
|
|
||||||
ZUC_ASSERT_EQ(3, 5 - 2);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue