Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

undefined reference to `myFunc'

115 views
Skip to first unread message

kafkaaaa

unread,
Apr 30, 2024, 5:02:02 AM4/30/24
to ThrowTheSwitch Forums
Hello, I'm so glad I found this community.
I'm a big Ceedling fan, and I'm looking forward to the 0.32 version.

---------------------------------
To explain my situation..

< test_foo.c >
#include "foo.h"
#include "mylib.h"
...

void test_aaa(void) { ... }  // aaa( ) is in "foo.h"

void test_bbb(void) { ... }  // bbb( ) is in "bar.h"  <- here is problem
---------------------------------
--> undefined reference to `bbb'
(It's a question that has nothing to do with the topic, start `(0x63)  end ' (0x27) is this bug?)


Because there is no declaration inside the header file directly included in this test file. but "mylib.h" have header file. like  #include "bar.h"

In this situation, how can I successfully build a test?
Ceedling can know about header files in header files?
Or is this outside of what Ceedling can control?


p.s.  I've read docs. so plz apologize for my previous questions on github issue. 

Mark Vander Voord

unread,
Apr 30, 2024, 6:39:36 AM4/30/24
to throwth...@googlegroups.com
Hi.

First, a quick aside: It appears that you're planning to test multiple files from the same test file. As unit tests, this is rarely what you want. Occasionally there are some files that are so dependent on one another that this might be worthwhile, but most often it just makes brittle tests. Very likely, you want different test files here.

Back to the inclusion problem you've identified: Ceedling purposefully doesn't dig into the headers included with headers because it can't know which functions you're going to want directly vs want to be mocked vs not need at all.

If you're still using the 0.31 release, you really have two options: You need to include the header that specifies the real functions you need OR you need to include a mock for them if you're not testing them directly. In your case, that would mean adding one of the two following after your other includes:

#include "bar.h" // Use this if you want to use the functions in this file directly
#include "mock_bar.h" // OR use this if you want to use them to test foo.h

If you install a 0.32 release candidate, you have another option: You can use this macro to specify a C file to use:

TEST_SOURCE_FILE("bar.c");

Any of these options should solve your problem... best of luck!

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/cf0f5bb6-9c03-4344-a34f-c627978421cen%40googlegroups.com.

kafkaaaa

unread,
May 1, 2024, 2:58:13 AM5/1/24
to ThrowTheSwitch Forums
I'm appreciate your prompt reply.

yes, it is close to Integration Test than Unit Test... but you know legacy project has complex dependencies and i really want to make test.

I've made about 200 test cases so far and with CI (Jenkins) is also successful. but that 200 cases are about terminal functions and i am trying to another parts. 

The reason why I ask for you is that It is very hard to add all needed files for each test targets.

ceedling paths:  &  ceedling files:  <- this command spit out correct results but its because It is just written in project.yml.

In compile phase If I want to include object file of [foo.c], there must be [foo.h] in test file, right?  -> #include  /  TEST_FILE(0.31v)  /  TEST_SOURCE_FILE(0.32v)

TEST_SOURCE_FILE(" ") <- can i use multiple of this in one test file?

and.. can't I substitute it with my static/dynamic library file instead of including a lot of needed files?
(in project.yml, there are -l, -L options and i use it but it doesn't seem to apply) 

I'm sorry today is holiday, so I will go to work tomorrow morning and try it right away.

Could I keep updating my situation here? Thank you.

2024년 4월 30일 화요일 오후 7시 39분 36초 UTC+9에 Mark Vander Voord님이 작성:

Mark Vander Voord

unread,
May 1, 2024, 9:11:00 AM5/1/24
to throwth...@googlegroups.com
I understand. It can definitely get complicated when you need to test a file that has many dependencies. I also understand. Legacy projects usually can't be restructured to make the code better... so you're stuck testing what is there.

TEST_SOURCE_FILE(" ") <- can i use multiple of this in one test file?

Yes, you can include as many files as needed AND you can mix it with #includes if you want to (using some of each).

To keep these tests from getting too complicated, though, you're probably going to need to do a lot of mocking. You're pulling in numerous header files, and those header files are including header files, etc... at some point, it's not going to make sense to be running all that real code, because it's going to be too hard to test anything meaningful. This is where mocks come in. Some of those interfaces should probably become mocks. Then, instead of continuing the repeated inclusion, you can stop the chain and test against the interface of those modules.

In any case, as you progress, please feel free to ask questions here. We're here to help.

Mark
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages