Ceedling basic question

63 views
Skip to first unread message

rouxfe...@gmail.com

unread,
Jun 16, 2020, 10:30:08 AM6/16/20
to ThrowTheSwitch Forums
Hi,

I'm also relatively new to ceedling. I've doing some testing with example projects, but now I'm trying to apply testing to an existing LPC1769 project. And as I can't get it working, a basic question raised: if I need to test only one function, for example, AddTwoNumbers(int a, int b) in math.c, ceedling needs to compile the entire project? or only needs to compile that file?

thanks a lot!

Mark Vander Voord

unread,
Jun 16, 2020, 10:45:11 AM6/16/20
to ThrowTheSwitch Forums
Each test file becomes its own executable in Ceedling. It knows what needs to be built and linked together by looking at your #includes in that test.

So, if you have a single function AddTwoNumbers and it's in math.c, then test_math.c will have your tests for it. That file might look something like this:

#include "unity.h"
#include "math.c"

void setUp(void) {}
void tearDown(void) {}

void test_AddTwoNumbers_SHOULD_AddTwoNumbersTogether(void)
{
    TEST_ASSERT_EQUAL_INT( 15, AddTwoNumbers(7, 8) );
}

That becomes a single executable and doesn't need anything else in your system to work.

Another unit test might make calls to functions in other files. That's where mocks come in. Again, it's going to build just the unit under test, the test itself, and a MOCK version of the dependencies, to avoid pulling in your entire system. That's a much bigger topic for another day. :)

I hope that helps.

Mark

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/f505d996-b998-4f61-b596-a7ccfdce1bbco%40googlegroups.com.

rouxfe...@gmail.com

unread,
Jun 17, 2020, 9:08:06 AM6/17/20
to ThrowTheSwitch Forums
Hi Mark! thank you for your response! it was very clear.

I think that my issue now is how to mock freeRTOS files. I'm working with a .c file that has a lot of functions using freertos queues, semaphores, etc. but the function I want to test doesn't use that. So I try to mock that files as following:

#include "mock_FreeRTOS.h"
#include "mock_task.h"
#include "mock_queue.h"
#include "mock_semphr.h"

When I execute "ceedling test:all" I get the following:

Test 'test_apps.c'
------------------
Generating include list for board.h...
Generating include list for FreeRTOS.h...
Generating include list for task.h...
./test/build/temp/_task.h:71:3: error: #error "include FreeRTOS.h must appear in source files before include task.h"
 
#error "include FreeRTOS.h must appear in source files before include task.h"

I've also tried including the FREERTOS define in proyect.yml:

:defines:
 
:test_preprocess:
   
- INC_FREERTOS_H

but it thows an error because I think it searchs for some predefined files like "rtos_portable.h", "rtos_portmacro.h", etc, but in my system(lpc1769) that files are called "portable.h", "portmacro.h", etc., without "rtos" prefix.



El martes, 16 de junio de 2020, 11:45:11 (UTC-3), mvandervoord escribió:
Each test file becomes its own executable in Ceedling. It knows what needs to be built and linked together by looking at your #includes in that test.

So, if you have a single function AddTwoNumbers and it's in math.c, then test_math.c will have your tests for it. That file might look something like this:

#include "unity.h"
#include "math.c"

void setUp(void) {}
void tearDown(void) {}

void test_AddTwoNumbers_SHOULD_AddTwoNumbersTogether(void)
{
    TEST_ASSERT_EQUAL_INT( 15, AddTwoNumbers(7, 8) );
}

That becomes a single executable and doesn't need anything else in your system to work.

Another unit test might make calls to functions in other files. That's where mocks come in. Again, it's going to build just the unit under test, the test itself, and a MOCK version of the dependencies, to avoid pulling in your entire system. That's a much bigger topic for another day. :)

I hope that helps.

Mark

On Tue, Jun 16, 2020 at 10:30 AM <rouxfe...@gmail.com> wrote:
Hi,

I'm also relatively new to ceedling. I've doing some testing with example projects, but now I'm trying to apply testing to an existing LPC1769 project. And as I can't get it working, a basic question raised: if I need to test only one function, for example, AddTwoNumbers(int a, int b) in math.c, ceedling needs to compile the entire project? or only needs to compile that file?

thanks a lot!

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwth...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages