Policy for new test suite for BeRTOS modules
Every BeRTOS module should have its own test suite. Each module can be tested in different ways, for example the module could implement an algorithm or a function that is target independent. In this case we should test it directly on a PC, in the other case the module should be tested only on the designed target.
Every test suite should have the following characteristics:
- Provide an interface to be used in existing projects;
- Provide a main() function in test suite module that is compilable stand alone
only when we use the test on a PC (and only if this is allowed from the module to test); - We should be able to compile a test suite with the automatic script on a PC
and we should provide a way to find errors.
To make a new test suite we should define a policy that provide a uniform name and interface.
Generally we assume that:
- The name of test suite is the same of the module name, with suffix _test;
- The test module is placed in the same directory of the module to test;
- The test module should provide a common interface to all test suites.
In detail, a test suite should implement the follow functions:
- int <module_name>_testSetup(void): init the module and all things needed;
- int <module_name>_testRun(void): run the test;
- int <module_name>_testTearDown(void): called after the test, it performs all the operations needed
to end the test correctly.
Below we write an example implementation of a test suite:
File name: <module_name>_test.c
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Test suite module
*
* .. description ..
*
* \version $Id: <module_name>_.c 1312 2008-05-20 16:54:52Z asterix $
*
* \author Daniele Basile <asterix@develer.com>
*/
/*
* #include <foo.h>
*
* ...
*
* Include all files needed to test <module_name>
*/
#include <cfg/test.h> // Test library (needed)
/**
* Setup test suite.
*
* This function provide initializations needed to
* test <module_name>.
*/
int <module_name>_testSetup(void)
{
/* Code to init the module to test */
/* 0 if all is ok, other values for errors */
return code
}
/**
* Test
*
* This function run the test for <module_name>.
*/
int <module_name>_testRun(void)
{
/* Code to test the module */
/* 0 if all is ok, other values for errors */
return code
}
/**
* Tear down the test suite.
*
* This function make all things needed to end a test.
*/
int <module_name>_testTearDown(void)
{
/* Code to close the test */
/* 0 if all is ok, other values for errors */
return code
}
