From 8e7e5bf7104df691217eda520b727470045cafcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 13 Oct 2022 19:38:14 +0200 Subject: [PATCH] tests: Add tests to ensure that we don't duplicate symbols in libraries We have an issue where some symbols are exposed by both the tod library and the public one, and this may lead to big issues like GType's being defined multiple times. So add a test checking whether this is working See: 3v1n0/libfprint#1 --- libfprint/tod/tests/check-library-symbols.sh | 65 ++++++++++++++++++++ tests/meson.build | 11 ++++ 2 files changed, 76 insertions(+) create mode 100755 libfprint/tod/tests/check-library-symbols.sh diff --git a/libfprint/tod/tests/check-library-symbols.sh b/libfprint/tod/tests/check-library-symbols.sh new file mode 100755 index 00000000..61f44c3d --- /dev/null +++ b/libfprint/tod/tests/check-library-symbols.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +library1=$1 +library2=$2 + +function cleanup_results() { + grep -F -w '.text' | cut -s -f2 | awk '{print $(NF)}' +} + +function dump_exported_symbols() { + objdump -TC "$1" | cleanup_results +} + +function dump_defined_symbols() { + objdump -t "$1" | cleanup_results +} + +function in_array() { + local target=$1 + shift + + local i; + for i in "$@"; do + if [[ "$i" == "$target" ]]; then + return 0 + fi + done + + return 1 +} + +function is_fatal() { + if [[ "$1" == "fp_"* ]] || [[ "$1" == "fpi_"* ]]; then + return 0 + fi + return 1 +} + +lib1_exported=($(dump_exported_symbols "$library1")) +lib2_exported=($(dump_exported_symbols "$library2")) + +lib1_defined=("$(dump_defined_symbols "$library1")") +lib2_defined=("$(dump_defined_symbols "$library2")") + +valid=true + +for f in ${lib1_exported[*]}; do + if in_array "$f" ${lib2_exported[*]}; then + echo "$f function exported in both $library1 and $library2" + if is_fatal "$f"; then + valid=false + fi + fi +done + +for f in ${lib1_defined[*]}; do + if in_array "$f" ${lib2_defined[*]}; then + echo "$f function defined in both $library1 and $library2" + if is_fatal "$f"; then + valid=false + fi + fi +done + +[[ "$valid" == true ]] && exit 0 diff --git a/tests/meson.build b/tests/meson.build index 48fece68..0670cf8b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -392,4 +392,15 @@ if get_option('tod') ) endif endforeach + + if find_program('objdump', required: false).found() + check_libs_symbols = find_program(meson.source_root() / + 'libfprint/tod/tests/check-library-symbols.sh') + test('check-tod-lib-sybmbols', + check_libs_symbols, + args: [libfprint.full_path(), libfprint_tod.full_path()], + depends: [libfprint, libfprint_tod], + suite: ['abi-check', tod_suites ], + ) + endif endif