Using meson unittest in OE SDK environment

Lei YU mine260309 at gmail.com
Fri Aug 2 20:21:26 AEST 2019


It looks like more and more OpenBMC repos are going to use meson to replace
autotools.
I tried to use meson in a new repo, it works fine for builds, but I got some
problems on running tests in OE SDK environment.

I tried to pass rpath to link_args, but meson seems a bit weird on using this.
(If interested) Please check the details in
https://github.com/mine260309/phosphor-psu-code-mgmt/blob/cc35c10b5416dbcec0dfd6eaaa7d096d9ec4e733/test/meson.build#L45

I was gathering correct `-Wl,-rpath,` options, save it in `testcase_flags`, and
pass it to `link_args`.
It is expected to work, and it's really close...

However, meson passes the `testcase_flags` to the link command, but with an
extra single-quote `'`, and unfortunately, it does not work as expected.

See below detailed command meson executes:

```
x86_64-openbmc-linux-g++ -m64 -march=core2 -mtune=core2 -msse3
-mfpmath=sse --sysroot=/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux
 -o test/utest 'test/9f86d08@@utest at exe/.._src_ut
ils.cpp.o' 'test/9f86d08@@utest at exe/test_utils.cpp.o'
-Wl,--no-undefined -Wl,--as-needed -Wl,--start-group -lstdc++fs
-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -flto
'-Wl,-rpath,/usr/local/oecore
-x86_64/sysroots/core2-64-openbmc-linux/lib
-Wl,-rpath,/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib
-Wl,-dynamic-linker,/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/l
ib/ld-2.29.so' /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgtest_main.a
-pthread /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgtest.a
/usr/local/oecore
-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgmock.a
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libphosphor_logging.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-
linux/usr/lib/libsdbusplus.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libsystemd.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libphosphor_dbus.so
-Wl,--en
d-group

$ ldd ./x86-build/test/utest
./x86-build/test/utest: /usr/lib/x86_64-linux-gnu/libstdc++.so.6:
version `GLIBCXX_3.4.26' not found (required by
./x86-build/test/utest)
        linux-vdso.so.1 (0x00007ffd569f9000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(0x00007ff67df87000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
(0x00007ff67dd6f000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x00007ff67db50000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff67d75f000)
        libsdbusplus.so.1 => not found
        libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0
(0x00007ff67d4db000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff67d13d000)
        /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/ld-2.29.so
=> /lib64/ld-linux-x86-64.so.2 (0x00007ff67e310000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff67cf35000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff67cd0f000)
        liblz4.so.1 => /usr/lib/x86_64-linux-gnu/liblz4.so.1
(0x00007ff67caf3000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20
(0x00007ff67c7d8000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff67c5d4000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0
(0x00007ff67c3bf000)
```

If I manually remove the extra single-quote `'`, it works just fine:

```
x86_64-openbmc-linux-g++ -m64 -march=core2 -mtune=core2 -msse3
-mfpmath=sse --sysroot=/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux
 -o test/utest 'test/9f86d08@@utest at exe/.._src_ut
ils.cpp.o' 'test/9f86d08@@utest at exe/test_utils.cpp.o'
-Wl,--no-undefined -Wl,--as-needed -Wl,--start-group -lstdc++fs
-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -flto
-Wl,-rpath,/usr/local/oecore
-x86_64/sysroots/core2-64-openbmc-linux/lib
-Wl,-rpath,/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib
-Wl,-dynamic-linker,/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/l
ib/ld-2.29.so /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgtest_main.a
-pthread /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgtest.a
/usr/local/oecore
-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libgmock.a
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libphosphor_logging.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-
linux/usr/lib/libsdbusplus.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libsystemd.so
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libphosphor_dbus.so
-Wl,--en
d-group

$ ldd ./x86-build/test/utest
        linux-vdso.so.1 (0x00007ffe3fdef000)
        libstdc++.so.6 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libstdc++.so.6
(0x00007fde0340d000)
        libgcc_s.so.1 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libgcc_s.so.1
(0x00007fde033f4000)
        libpthread.so.0 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libpthread.so.0
(0x00007fde033a0000)
        libc.so.6 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libc.so.6
(0x00007fde031e8000)
        libsdbusplus.so.1 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/libsdbusplus.so.1
(0x00007fde033ea000)
        libsystemd.so.0 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libsystemd.so.0
(0x00007fde03131000)
        libm.so.6 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libm.so.6
(0x00007fde02fee000)
        /usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/ld-2.29.so
=> /lib64/ld-linux-x86-64.so.2 (0x00007fde033c0000)
        librt.so.1 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/librt.so.1
(0x00007fde02fe3000)
        liblzma.so.5 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/usr/lib/liblzma.so.5
(0x00007fde02fbb000)
        libcap.so.2 =>
/usr/local/oecore-x86_64/sysroots/core2-64-openbmc-linux/lib/libcap.so.2
(0x00007fde02fb3000)

```

So my question is, has anyone successfully run a unit test case in OE SDK
environment? And if yes, how it is done?


More information about the openbmc mailing list