Hi everyone,
I'm adding a new unit test file named webrtc_apm_unittest.cc under src/third_party/webrtc-apm.
I managed to run a simple test, but as soon as the I include the relevant library to test, I get a linker error.
Sharing what I did and the error I get in case someone knows how to solve.
Changes
1. I added a src_test() entry in webrtc-apm-9999.ebuild
2. I added the lines below in
https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/webrtc-apm/Makefile
webrtc_apm_unittest_DEPS = libchrome
webrtc_apm_unittest_CFLAGS := \
$(shell $(PKG_CONFIG) --cflags $(webrtc_apm_unittest_DEPS))
webrtc_apm_unittest_LIBS := \
$(shell $(PKG_CONFIG) --libs $(webrtc_apm_unittest_DEPS))
webrtc_apm_unittest_LIBS += -lgtest
CXX_BINARY(webrtc_apm_unittest): CPPFLAGS += $(webrtc_apm_unittest_CFLAGS)
CXX_BINARY(webrtc_apm_unittest): LDLIBS += $(webrtc_apm_unittest_LIBS)
CXX_BINARY(webrtc_apm_unittest): \
webrtc_apm_unittest.o \
CXX_LIBRARY(libwebrtc_apm.so) \
testrunner.o
TEST(CXX_BINARY(webrtc_apm_unittest)): CXX_LIBRARY(libwebrtc_apm.so)
Note that CXX_LIBRARY(libwebrtc_apm.so) is defined in the same file and, as far as I understand, to add it as a dependency of CXX_BINARY(webrtc_apm_unittest) one must list it together with the .o files and also as a dep of TEST(CXX_BINARY(webrtc_apm_unittest)).
Below you can see part of webrtc_apm_unittest.cc:
#include "webrtc_apm.h"
...
TEST(WebRtcApm, CreateApm) {
webrtc_apm apm = webrtc_apm_create_with_enforced_effects(...);
...
}
As I said, if webrtc_apm_unittest.cc doesn't call any function from webrtc_apm.h, the unit test binary is compiled and it runs. However, when I switched to the code above, I started to get this error:
LDCXX webrtc_apm_unittest
ld.lld: error: undefined symbol: webrtc_apm_create_with_enforced_effects(unsigned int, unsigned int, _dictionary_*, _dictionary_*, unsigned int, unsigned int, unsigned int)
>>> referenced by webrtc_apm_unittest.cc:42 (/build/celes/tmp/portage/media-libs/webrtc-apm-9999/work/webrtc-apm-9999/webrtc_apm_unittest.cc:42)
>>> webrtc_apm_unittest.pie.o:((anonymous namespace)::WebRtcApmParametrizedTest_CreateApm_Test::TestBody())
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [common.mk:476: CXX_BINARY(webrtc_apm_unittest)] Error 1
Not sure how to tell Makefile that libwebrtc_apm.so is a shared lib dependency for the binary I'm adding. Any suggestion?
Cheers,
Alessio