Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

serial.reference

Klemens David Morgenstern edited this page May 6, 2018 · 1 revision

METAL_SERIAL_INIT()

This macro needs to be put in front of any usage of the metal.serial tool.

METAL_SERIAL_PRINTF(Format, ...)

This macro provides printf-like output, where the actual formatting is done on the host side. It does required the passed parameters to declare there type.

METAL_SERIAL_PRINTF("%s - %d", STR("test"), INT(42));

Allowed types are:

  • BYTE Bytes
  • INT Integers
  • UINT Unsigned integers
  • STR CStrings
  • PTR Pointers

METAL_SERIAL_EXIT(Code)

The METAL_SERIAL_EXIT provides a way to tell the tool the execution has finished while setting an explicit exit-code. This causes metal.serial to exit as well. By default, metal.serial will use the same exit-code.

METAL_SERIAL_TEST_EXIT()

This macros does the same as METAL_SERIAL_EXIT but will take deduce the exit code from tests executed prior. That is, it metal.serial will exit with 1 when any test failed, and 0 if all succeeded.

METAL_SERIAL_CALL(Function, Message)

This macro enters a test case, which is important for the handling critical tests.

  • Function The function
  • Message The name of the test case as a string

\note This function uses a pointer and is not a template, so it can be defined in another place and reduces the amount of needed breakpoints. Though not used yet, it is reserved for future use. This might however be discarded, to any functionobject can be passed.

Example

void test_func()
{
    METAL_SERIAL_ASSERT(some_test());
}

int main(int argc, char * argv[])
{
	METAL_SERIAL_INIT();
    METAL_SERIAL_CALL(&test_func, "first test func");
    METAL_SERIAL_CALL(+[]{METAL_SERIAL_ASSERT(something_else);}, "lambda case");
    METAL_SERIAL_TEST_EXIT();
	return 0;
}

METAL_SERIAL_ASSERT_MESSAGE(Condition, Message)

This macro provides a assertion with a custom error message. The plain \ref METAL_SERIAL_ASSERT will output the code given as the condition.

  • Condition The condition to be checked.
  • Message the custom message.

Example

std::string str;
METAL_SERIAL_ASSERT_MESSAGE(str.empty(), "string empty");

See also

METAL_SERIAL_EXPECT_MESSAGE(Condition, Message)

This macro provides a expectation with a custom error message. The plain #METAL_SERIAL_EXPECT will output the code given as the condition.

  • Condition The condition to be checked.
  • Message the custom message.

Example

std::string str;
METAL_SERIAL_EXPECT_MESSAGE(str.empty(), "string empty");

See also

METAL_SERIAL_ASSERT(Condition)

This macro provides a plain assertion.

  • Condition The condition to be checked.

Example

std::string str = "some data";
METAL_SERIAL_ASSERT(str.empty());

See also

METAL_SERIAL_EXPECT(Condition)

This macro provides a plain expectation.

  • Condition The condition to be checked.

Example

std::string str = "some data";
METAL_SERIAL_EXPECT(str.empty(), "string empty");

See also

METAL_SERIAL_ASSERT_EQUAL(15, 0xF);

See also

METAL_SERIAL_EXPECT_EQUAL(Lhs, Rhs)

This test expects the equality of two values, through operator==. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_EQUAL(15, 0xF);

See also

METAL_SERIAL_ASSERT_NOT_EQUAL(Lhs, Rhs)

This test asserts the equality of two values, through operator==. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_ASSERT_NOT_EQUAL(15, 0xF);

See also

METAL_SERIAL_EXPECT_NOT_EQUAL(Lhs, Rhs)

This test expects the equality of two values, through operator!=. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_NOT_EQUAL(15, 0xF);

See also

METAL_SERIAL_EXPECT_GE(Lhs, Rhs)

This test expects Lhs to be greater or equal to Rhs, through operator>=. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_GE(15, 0xF);

See also

METAL_SERIAL_ASSERT_GE(Lhs, Rhs)

This test expects Lhs to be greater or equal to Rhs, through operator>=. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.
METAL_SERIAL_ASSERT_GE(4, 0b100);

See also

METAL_SERIAL_EXPECT_LE(Lhs, Rhs)

This test expects Lhs to be lesser or equal to Rhs, through operator<=. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_LE(15, 0xF);

See also

METAL_SERIAL_ASSERT_LE(Lhs, Rhs)

This test expects Lhs to be lesser or equal to Rhs, through operator<=. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.
METAL_SERIAL_ASSERT_LE(4, 0b100);

See also

METAL_SERIAL_EXPECT_GREATER(Lhs, Rhs)

This test expects Lhs to be greater than Rhs, through operator>. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_GREATER(15, 0xE);

See also

METAL_SERIAL_ASSERT_GREATER(Lhs, Rhs)

This test expects Lhs to be greater than Rhs, through operator>. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.
METAL_SERIAL_ASSERT_GREATER(4, 0b10);

See also

METAL_SERIAL_EXPECT_LESSER(Lhs, Rhs)

This test expects Lhs to be lesser than Rhs, through operator>. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.

Example

METAL_SERIAL_EXPECT_LESSER(13, 0xF);

See also

METAL_SERIAL_ASSERT_LESSER(Lhs, Rhs)

This test expects Lhs to be lesser than Rhs, through operator>. It provides output of the actual values when used in hosted mode.

  • Lhs Left hand-side value to compare.
  • Rhs Right hand-side value to compare.
METAL_SERIAL_ASSERT_LESSER(1, 0b100);

See also

METAL_SERIAL_ASSERT_NO_EXECUTE()

This macro can be used to assert a certain line is not executed. Fails when executed.

**Example **

if (false)
    METAL_SERIAL_ASSERT_NO_EXECUTE()

See also

METAL_SERIAL_EXPECT_NO_EXECUTE()

This macro can be used to assert a certain line is not executed. Fails when executed.

**Example **

if (false)
    METAL_SERIAL_EXPECT_NO_EXECUTE()

See also

Clone this wiki locally