Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Test Syntax and Test creation

Unknown edited this page Jul 1, 2020 · 1 revision

Without Code-Generator

To write the test-cases direct you have to create an InvoceAll function which calls all test-cases. It is advisable to divide the test-cases into groups. So that the invoceAll function do the setup and calls each test-group. Test-Setup

Before any test could be executed the function MessageToDebugger(startTesting) must be called. This function establishes the connection to the GDB-Server and blocks until an test-mode gets configured by the GDB-Manipulator. Test-Execution

Program execution plan :

Alt text Asserts

Supported Asserts are defined in assets.h :

ASSERT_EQ(should, is)

Check if “should” is equals to “is” For : uint8_t , int, uint32_t

ASSERT_NEQ(should, is)

Check if “should” is not equals to “is” For : uint8_t , int, uint32_t

Assert_EQ_Mem(is*, sizeIs, should* , sizeShould)

Check of the “is” memory is equals to the “should” memory. Tests-Teardown

The GDB-Manipulator has to be informed about the executing of all test-cases. This is done by the calling the Function “MessageToDebugger(finishAllTest)”

Mocks and Stubs

Please see the corresponding wiki entry for further information’s

Mocks and Stubs are active until function deleteAllMocks() gets called. Automatically Test-code Generation

To simplify the test generation (test setup, invokeAll test cases, test teardown) a test file parser has been built with “awk” with this parser it is possible to generate googleTest like tests.

Test creation

An test-case has following setup:

TEST(<testGroup>,<testName>){ … <Asserts etc.> }

e.g. test.c

#include "testSuite/asserts.h"
#include "testSuite/testSuite.h"

 TEST(classSuccess,NEQ_SUCCESS){
  	uint8_t u1 = 1;
	uint32_t u2 = -1;
	ASSERT_NEQ(0,1);
	ASSERT_NEQ(1,0);
	ASSERT_NEQ(-1,0);
	ASSERT_NEQ(-1,1);
	ASSERT_NEQ(u1,u2);
}

To generate “c”-compatible Code call the awk script: “parseSingleFile.awk” e.g.

awk -f awk/parseSingleFile.awk test.c

This prints the generated test-code to the cli.

Filter Test Groups out

It is possible to filter test Groups on compile time out by setting the variable: testFilter with

 awk -v testFilter="<group>"  -f awk/parseSingleFile.awk test.c

stands for the start of each group to be filtered.

To filter several groups it is possible to to separate the groups with ,

awk -v testFilter="<group1>,<group2>,<group3>"  -f awk/parseSingleFile.awk  test.c

For further information’s see Test Filter Invoke All Tests

With the script “generateInvokeAll.awk” it possible to generate an function that calls all test groups. e.g.

ls targetExamples/testexamples/withParser/*.c | awk -f awk/generateInvokeAll.awk

Clone this wiki locally