All tests still running even after IMPORT_TEST_GROUP macro

43 views
Skip to first unread message

Martin Dída

unread,
Apr 2, 2020, 5:12:11 AM4/2/20
to cpputest
Hello everybody

Recently I implemented CppUTest framework on our projects. Projects are for TI platform running on CCSv6 IDE. This is my first touch with it and TDD either. I learned from Mr's. Grenning book Test-Driven Development for Embedded C. Thus, after setting up CCSv6 for CppUTest framework (followed installation manual on eclipse from CppUTest official site, as CCS is based on Eclipse), several compile-time and linker crashes and some project modification. I was successful and finally got our project under CppUTest unity testing. Everything works fine, but on small problem.

If I have more test groups let's say "SciaDriver", "ScibDriver" and "GpioDriver" (they are somehow related to each other, that's reason I left them in on file) under one .cpp file like this:

TEST_GROUP(SciaDriver)
{
void setup()
{
resetSCI(&SciaRegs);
}

void teardown()
{

}
};

TEST_GROUP(ScibDriver)
{
void setup()
{
resetSCI(&ScibRegs);
}

void teardown()
{

}
};

TEST_GROUP(GpioDriver)
{
void setup()
{
resetGPIO(&GpioCtrlRegs);
}

void teardown()
{

}
};

and in AllTests.cpp (or in AllTests.h included in AllTests.cpp) I try to import one of the group let's "ScibDriver" through IMPORT_TEST_GROUP(ScibDriver) all of the test cases run execution even those test cases for SciaDriver and GpioDriver group. Is it because they are all in on object file?
Yes, if I import test group which is completely in stand-alone source file, running tests behaves according to whether I IMPORT_TEST_GROUP(singleTestGroupInFile) or not.

Thank you for advice ;)

Regards

Martin

James Grenning

unread,
Apr 2, 2020, 8:30:58 AM4/2/20
to cpputest

Hi Martin

TESTs and TEST_GROUPs self-install if they are in the build. If you put tests into a library, IMPORT_TEST_GROUP will cause the test group's .o file to be pulled from the library. All TESTs in a file will be installed into the list of all tests.

You can selectively run tests by command line switches (see cpputest.org)

If you do not want all the test groups in a file in the build you need to have them in separate files.

Cheers, James


James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
wingman software

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/5f43dc51-7ce5-4087-befc-8032998f2477%40googlegroups.com.

Martin Dída

unread,
Apr 6, 2020, 3:21:15 AM4/6/20
to cpputest
Hello Mr. Greening

First off, thanks for quick response.

I have one more question. As our project is quite legacy (TI project) there is used a lot of 'volatile' keywords on structs, strings (char arrays), but also on other variables to access MCU's register or variables. Simply objects that could be accessed by interrupts and asynchronous services. However, CppUTest does not take 'volatile' parameters e.g. STRCMP_EQUAL at which two its parameters are const char*.

Since C++ is quite strict in conversions. I always have to cast away 'volatile' qualifier by const_cast. Therefore, I want to ask you. Does not my behavior of casting away 'volatile' qualifier break strict rules of TDD? I suppose, the tests do not care about this nuance between real hardware and register it uses, and thus 'volatile' qualifier. Or should I do it differently to retain 'volatile' nature of objects?

Thank you

Martin ;)

Dňa štvrtok, 2. apríla 2020 14:30:58 UTC+2 James Grenning napísal(a):

To unsubscribe from this group and stop receiving emails from it, send an email to cppu...@googlegroups.com.

James Grenning

unread,
Apr 6, 2020, 11:46:20 AM4/6/20
to cpputest

Hi Martin

You may find some of the articles on this page useful https://wingman-sw.com/articles/tdd-legacy-c

The first few articles under the "ROAD BLOCKS" section were probably about TI dependent code.

Passing volatile variables to CppUTest, (casting away volatile) is not a problem. I cannot think if a case where it would matter.

HTH, James

To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/008bd9fb-2a26-4944-844e-4c2f14d62fce%40googlegroups.com.

张光辉

unread,
Aug 28, 2021, 10:34:18 AM8/28/21
to cpputest
Hi everyone
I am new to CCS. I used to run cpputest in VS according  Mr's. Grenning   book. Now I get a  work from my teacher. The work is to write test case for a project.   Projects are for TI platform running on CCSv5 IDE ().  there are a lot of codes about some register writing and reading in project.  I think it is  not compatible when I copy the CCS code to VS . When I run a simple test, there are many errors. such as can't find some functions. So this method is not feasible, right? So I plan to write test case in CCS, but I don‘t how to set up   CCS for CPPUTest framework. I hope get your help.

Thank you for advice ;)
Regards
GuangHui

Ryan Hartlage

unread,
Aug 28, 2021, 3:26:18 PM8/28/21
to cpputest
Hi GuangHui,

It sounds like your code is vendor- or microcontroller-specific. An important step in testing your code is making it testable. James' book advocates doing this by defining a hardware abstraction layer (HAL). Application code above the hardware layer should use only standard C and interact with the hardware via the HAL. Once you've made this investment, you will be able to run the same code on a PC and on a microcontroller (or microcontrollers!). I can't teach you everything you need to know in this email, but luckily James wrote an entire book about it :)

Thanks,
Ryan

FLASH

unread,
Aug 28, 2021, 11:31:53 PM8/28/21
to cpputest
Hi Ryan
First off, thanks for quick response.
I have one more question. I don't know how to setup CppUtest for CCS In Windows 10.Please give me some suggestions.

Regards
GuangHui


------------------ 原始邮件 ------------------
发件人: "cpputest" <ryanpl...@gmail.com>;
发送时间: 2021年8月29日(星期天) 凌晨3:26
收件人: "cpputest"<cppu...@googlegroups.com>;
主题: Re: All tests still running even after IMPORT_TEST_GROUP macro

Ryan Hartlage

unread,
Aug 29, 2021, 5:57:16 AM8/29/21
to cpputest
Hi Guangzhou,

I've never used CCS. I would focus on making your tests run on a PC first and then decide if you really need to run them on your target hardware.

Thanks,
Ryan


Reply all
Reply to author
Forward
0 new messages