Skip to content

utest optimization: Allow case data structure to be put in ROM. #4430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 106 additions & 63 deletions features/frameworks/utest/source/utest_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,75 @@

using namespace utest::v1;

// case_t factory used by Case contructor
static inline case_t make_case(
const char *description,
const case_handler_t handler,
const case_control_handler_t control_handler,
const case_call_count_handler_t repeat_count_handler,
const case_setup_handler_t setup_handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler)
{
case_t result = {
description,
handler,
control_handler,
repeat_count_handler,
setup_handler,
teardown_handler,
failure_handler
};

return result;
}

// normal handler
Case::Case(const char *description,
const case_setup_handler_t setup_handler,
const case_handler_t handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(handler),
control_handler(ignore_handler),
repeat_count_handler(ignore_handler),
setup_handler(setup_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
handler,
ignore_handler,
ignore_handler,
setup_handler,
teardown_handler,
failure_handler
))

{}

Case::Case(const char *description,
const case_handler_t handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(handler),
control_handler(ignore_handler),
repeat_count_handler(ignore_handler),
setup_handler(default_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
handler,
ignore_handler,
ignore_handler,
default_handler,
teardown_handler,
failure_handler
))

{}

Case::Case(const char *description,
const case_handler_t handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(handler),
control_handler(ignore_handler),
repeat_count_handler(ignore_handler),
setup_handler(default_handler),
teardown_handler(default_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
handler,
ignore_handler,
ignore_handler,
default_handler,
default_handler,
failure_handler
))
{}

// control handler
Expand All @@ -67,38 +98,44 @@ Case::Case(const char *description,
const case_control_handler_t handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(handler),
repeat_count_handler(ignore_handler),
setup_handler(setup_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
handler,
ignore_handler,
setup_handler,
teardown_handler,
failure_handler
))
{}

Case::Case(const char *description,
const case_control_handler_t handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(handler),
repeat_count_handler(ignore_handler),
setup_handler(default_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
handler,
ignore_handler,
default_handler,
teardown_handler,
failure_handler
))
{}

Case::Case(const char *description,
const case_control_handler_t handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(handler),
repeat_count_handler(ignore_handler),
setup_handler(default_handler),
teardown_handler(default_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
handler,
ignore_handler,
default_handler,
default_handler,
failure_handler
))
{}

// control flow handler
Expand All @@ -107,38 +144,44 @@ Case::Case(const char *description,
const case_call_count_handler_t case_repeat_count_handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(ignore_handler),
repeat_count_handler(case_repeat_count_handler),
setup_handler(setup_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
ignore_handler,
case_repeat_count_handler,
setup_handler,
teardown_handler,
failure_handler
))
{}

Case::Case(const char *description,
const case_call_count_handler_t case_repeat_count_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(ignore_handler),
repeat_count_handler(case_repeat_count_handler),
setup_handler(default_handler),
teardown_handler(default_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
ignore_handler,
case_repeat_count_handler,
default_handler,
default_handler,
failure_handler
))
{}

Case::Case(const char *description,
const case_call_count_handler_t case_repeat_count_handler,
const case_teardown_handler_t teardown_handler,
const case_failure_handler_t failure_handler) :
description(description),
handler(ignore_handler),
control_handler(ignore_handler),
repeat_count_handler(case_repeat_count_handler),
setup_handler(default_handler),
teardown_handler(teardown_handler),
failure_handler(failure_handler)
case_t(make_case(
description,
ignore_handler,
ignore_handler,
case_repeat_count_handler,
default_handler,
teardown_handler,
failure_handler
))
{}

const char*
Expand Down
69 changes: 58 additions & 11 deletions features/frameworks/utest/utest/utest_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,59 @@ namespace utest {
/** \addtogroup frameworks */
/** @{*/
namespace v1 {
/**
* POD data structure of the Case class.
* Unlike the Case class it can be used as a POD and be put in ROM.
*
* @warning Initialization of handlers with either default_handler or
* ignore_handler helpers will prevent the object to be a POD. Prefer usage
* of NULL in favor of ignore_handler or <handler_type>(1) for default
* handler.
*
* @see Case.
*/
struct case_t
{
/**
* Textual description of the test case
*/
const char *description;

/**
* Primitive test case handler
* This is called only if the case setup succeeded. It is followed by
* the test case teardown handler.
*/
const case_handler_t handler;

/**
* @see case_control_handler_t
*/
const case_control_handler_t control_handler;

/**
* @see case_call_count_handler_t
*/
const case_call_count_handler_t repeat_count_handler;

/**
* Handler called before the execution of the case handler. It sets up
* the case environment.
*/
const case_setup_handler_t setup_handler;

/**
* Handler called after the execution of the case handler. It cleans up
* the case environment.
*/
const case_teardown_handler_t teardown_handler;

/**
* Handler called whenever a faillure occur; at any stage of the case
* execution (including setup and teardown).
*/
const case_failure_handler_t failure_handler;
};

/** Test case wrapper class.
*
Expand All @@ -52,7 +105,7 @@ namespace v1 {
* @note While you can specify an empty test case (ie. use `ignore_handler` for all callbacks),
* the harness will abort the test unconditionally.
*/
class Case
class Case : private case_t
{
public:
// overloads for case_handler_t
Expand Down Expand Up @@ -111,18 +164,12 @@ namespace v1 {
bool is_empty() const;

private:
const char *description;

const case_handler_t handler;
const case_control_handler_t control_handler;
const case_call_count_handler_t repeat_count_handler;

const case_setup_handler_t setup_handler;
const case_teardown_handler_t teardown_handler;

const case_failure_handler_t failure_handler;
// IMPORTANT: No data members shall be declared inside this class.
// Data members shall be declared in case_t to preserve the layout
// and the compatibility between the two types.

friend class Harness;
friend class Specification;
};

} // namespace v1
Expand Down
Loading