Menu

#231 Android: unit tests (and compilation issues)

5.2
open
nobody
5
2010-03-17
2010-03-17
Emmanuel
No

### Versions:
STLport 5.2 branch, Android 1.6, G1 dev phone

### Modification of the compilation:

- using the static form of libstlport (because LD_LIBRARY_PATH not used on Android and /system/lib readonly - if this appears to be compulsory, this means that we would need the static targets in the general Makefile - I had to do: make -C build/lib stldbg-static dbg-static release-static)
- defining env variable SYSROOT (/opt/android-ndk/build/platforms/android-4/arch-arm)

- adding -lstdc++ (at the end - at the beginning, it's not taken into account),
and putting -lstlport also at the end
(note: if compiling with no modifications and simply using OPT="-lstdc++" make : I get a runtime ld error: reloc_library[1186]: 390 In './stl_unit_test', shndx=0 && value=0x00000001. We do not handle this yetCANNOT LINK EXECUTABLE)

### Testing
Running the whole test sequence freezes after ConfigTest::new_throw_bad_alloc IGNORED (0% cpu, but no crash ?? tests are in reversed alphabetical order). (I can try to break and get a stack dump there).
Instead I launched individual tests with -t (I extracted the classes containing Test using ctags: I may have missed some?)

### Results
They are some errors specially about numbers and wchar. They are nearly the same in release and debug version.

../../../test/unit/cmath_test.cpp(124) : CPPUNIT_CHECK(are_equals(float_val * std::pow(2.0f, int_val), 8.0f));

CodecvtTest::variable_encoding
../../../test/unit/codecvt_test.cpp(297) : CPPUNIT_ASSERT(ostr.good());

LimitTest::test
++tmp < lim::max()
../../../test/unit/limits_test.cpp(282) : CPPUNIT_CHECK(test_integral_limits(wchar_t()));

(only in release version) ListTest::allocator_with_state
../../../test/unit/list_test.cpp(394) : CPPUNIT_ASSERT(lint1.size() == 20);

Many errors in ctype_facets_test (for each char), like:
../../../test/unit/ctype_facets_test.cpp(66) : CPPUNIT_ASSERT((res[3] & ctype_base::digit) == 0);
../../../test/unit/ctype_facets_test.cpp(210) : CPPUNIT_CHECK((res[3] & ctype_base::digit) == 0);
../../../test/unit/ctype_facets_test.cpp(254) : CPPUNIT_CHECK(*res == L'a');

NumPutGetTest::num_put_float
../../../test/unit/num_put_get_test.cpp(465) : CPPUNIT_CHECK(output == string("1.23456780e-") + digits);
a few ../../../test/unit/num_put_get_test.cpp(224) : CPPUNIT_ASSERT(!limits::has_infinity || str.str() == "inf");

NumPutGetTest::custom_numpunct
../../../test/unit/num_put_get_test.cpp(1253) : CPPUNIT_ASSERT(os.str() == "+inf");

### Note:
Some tests are ignored (for instance because exceptions are not available on Android).
num_put_get_test.cpp is quite long to compile with the optimization option

Discussion

  • Emmanuel

    Emmanuel - 2010-03-17

    Results of the unit tests

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2010-03-17

    Usage of static library really dangerous and may lead to unpredictable results (some builds may run fine, while some may crash on start). This is related to locale and streams. The reason is undefined order of ctors calls for global objects in different modules. In case of shared library, loader has a chance to resolve symbol dependencies (i.e. STLport's ctors for globals will be called before usage of object, that use this globals).

     
  • Emmanuel

    Emmanuel - 2010-03-18

    I started a discussion about compiling and testing STLport on Android:
    http://groups.google.com/group/android-ndk/browse_thread/thread/5d4192c6f0826598

    Have you been able to run a program with STLport on Android? STLport seems to use an unimplemented feature in Android dynamic loader... (No way to use static linking really?)

    I get a runtime error:
    link_image[1638]: 474 could not load needed library 'libstlport.so' for './stl_unit_test' (reloc_library[1186]: 474 In 'libstlport.so', shndx=0 && value=0x00000001. We do not handle this yet)CANNOT LINK EXECUTABLE
    This seems to be an undefined symbol with a non-null address, according to http://docsrv.sco.com/SDK_cprog/OF_SymTable.html, what does this case mean? (a random though: perhaps a prelink address? - I've no specific knowledge about dynamic linking).
    http://gitorious.org/0xdroid/bionic/blobs/fde8642fc43bdd224e43e5ee9583a49a758fb03c/linker/linker.c
    if ((s->st_shndx == SHN_UNDEF) && (s->st_value != 0)) {

    So what would be possible linking options for STLport which would avoid using this unimplemented linking feature?

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2010-03-19

    > Have you been able to run a program with STLport on Android? STLport seems
    to use an unimplemented feature in Android dynamic loader...

    Road map:

    1. Build and use _any_ own shared library (as simple as possible) on Android.
    Just C, without C++.
    2. If (1) work, let's discuss c++-related issues of shared libs (i.e. exceptions, ctor/dtor of statics/globals, __at_exit).

    > (No way to use static linking really?)
    If you hasn't C++ globals/static, then static linkage will work. Otherwise, result depends upon what you use and stars on the sky. (Really, there are ways to live with it, but solutions are unique to application---control over priority of static ctors/dtors, elf's .init, .ctor, ... ).

     
  • Emmanuel

    Emmanuel - 2010-03-25

    Unit tests with the shared library

     
  • Emmanuel

    Emmanuel - 2010-03-25

    *** Tests with the dynamic library

    I've been able to run the STLport and the unit tests as a dynamic library, on Android 1.6 and 2, using the Ndk compilation makefiles (Android.mk: see http://groups.google.com/group/android-ndk/browse_thread/thread/5d4192c6f0826598 ).

    What about using the Android.mk instead of the makefiles in the STLport package? It would permit to get the compilation options right (but it may be more difficult to use the existing STLport options in the present build system?).

    See attachement for the new test results: the results are nearly the same as with the static library, without this one:
    CPPUNIT_CHECK(are_equals(float_val * std::pow(2.0f, int_val), 8.0f));

    The freezing test is Codecvt. So I excluded it with -x= . Note that it runs well under gdb (!), giving the attached assert error.

     
  • Emmanuel

    Emmanuel - 2010-03-25

    If it's needed to use the STLport makefiles instead of Android.mk, here is the comparison of the compilation options:

    With Android.mk:

    Android NDK: Building for application 'stlport'
    make: entrant dans le répertoire « /opt/android-ndk-r3 »
    Compile thumb : stlport <= apps/stlport/cxa.c
    build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Iapps/stlport -DANDROID -Iapps/stlport/include -mandroid -DTARGET_OS=android -isystem build/platforms/android-3/arch-arm/usr/include -O2 -DNDEBUG -g -c -MMD -MP -MF out/apps/stlport/armeabi/objs/stlport/cxa.o.d.tmp apps/stlport/cxa.c -o out/apps/stlport/armeabi/objs/stlport/cxa.o

    build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc -nostdlib -Wl,-soname,libstlport.so -Wl,-shared,-Bsymbolic out/apps/stlport/armeabi/objs/stlport/...o -Wl,--whole-archive -Wl,--no-whole-archive /opt/android-ndk-r3/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/libgcc.a build/platforms/android-3/arch-arm/usr/lib/libc.so build/platforms/android-3/arch-arm/usr/lib/libstdc++.so build/platforms/android-3/arch-arm/usr/lib/libm.so -Wl,--no-undefined -Wl,-rpath-link=build/platforms/android-3/arch-arm/usr/lib -o out/apps/stlport/armeabi/libstlport.so

    With the STLport makefiles:

    android-c++ -mandroid --sysroot=/opt/android-ndk/build/platforms/android-4/arch-arm/ -fno-exceptions -fno-rtti -fPIC -O2 -fuse-cxa-atexit -fvisibility=hidden -I../../stlport -c -o obj/android-gcc/so/time_facets.o ../../src/time_facets.cpp

    android-c++ -mandroid --sysroot=/opt/android-ndk/build/platforms/android-4/arch-arm/ -fno-exceptions -fno-rtti -fPIC -O2 -fuse-cxa-atexit -fvisibility=hidden -I../../stlport -shared -o obj/android-gcc/so/libstlport.so.5.2.2 (all the .o) -lgcc -Wl,-Bstatic -lthread_db -Wl,-Bdynamic -lc -lm

     
  • Emmanuel

    Emmanuel - 2010-04-09

    (for unit tests)

     
  • Emmanuel

    Emmanuel - 2010-04-09

    (for unit tests)

     
  • Emmanuel

    Emmanuel - 2010-04-09

    To compile Stlport as a shared library (copy both in stlport/src directory and link it to NDK_DIR/apps/stlport)

     
  • Emmanuel

    Emmanuel - 2010-04-09

    To compile Stlport as a shared library (copy both in stlport/src directory and link it to NDK_DIR/apps/stlport)

     

Log in to post a comment.