Hi all,

I'm building Dovecot from source of Dovecot 2.3.13. When doing make check, I saw an error:
make[1]: Entering directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
for bin in test-iostream-ssl; do \
  if ! /bin/sh ../../run-test.sh ../.. ./$bin; then exit 1; fi; \
done
collect2: error: ld returned 213 exit status
Failed to run: ./test-iostream-ssl

This is my configuration in spec file:
%configure                       \
    INSTALL_DATA="install -c -p -m644" \
    --docdir=%{_docdir}/%{name}  \
    --disable-static             \
    --disable-rpath              \
    --with-nss                   \
    --with-shadow                \
    --with-pam                   \
    --with-gssapi=plugin         \
    --with-ldap=plugin           \
    --with-sql=plugin            \
    --with-pgsql                 \
    --with-mysql                 \
    --with-sqlite                \
    --with-zlib                  \
    --with-libcap                \
    --with-ssl=openssl           \
    --with-ssldir=%{ssldir}      \
    --with-docs

I installed OpenSSL and Valgrind:
# yum list installed | egrep "valgrind|openssl"
openssl-devel.x86_64                        1:1.1.1g-12.el8_3                        @BaseOS
openssl-libs.x86_64                         1:1.1.1g-12.el8_3                        @BaseOS
valgrind.x86_64                             1:3.16.0-2.el8                           @AppStream
valgrind-devel.x86_64                       1:3.16.0-2.el8                           @AppStream

I investigated the problem and found something:
$ pwd
/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream
$ file test-iostream-ssl
test-iostream-ssl: POSIX shell script, ASCII text executable, with very long lines
$ file .libs/test-iostream-ssl
.libs/test-iostream-ssl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=c6a800c253c38a7eb78886286ef779d871550a6c, with debug_info, not stripped, too many notes (256)

That means when running make check, Valgrind will monitor the shell script generated by libtool instead of the actual test code. And error occurs.
$ pwd
/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream
$ vim Makefile
check-local:
        for bin in $(test_programs); do \
          export LD_LIBRARY_PATH=./.libs; \
          if ! $(RUN_TEST) ./.libs/$$bin; then exit 1; fi; \
        done

Then do make check:
$ cd ~/rpmbuild/BUILD/xxx/dovecot-2.3.13
$ make -C src/lib-ssl-iostream/ clean
$ make -C src/lib-ssl-iostream/ check
make[1]: Entering directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
for bin in test-iostream-ssl; do \
  export LD_LIBRARY_PATH=./.libs; \
  if ! /bin/sh -x ../../run-test.sh ../.. ./.libs/$bin; then exit 1; fi; \
  #if ! /bin/sh -x ../../run-test.sh ../.. ./$bin; then exit 1; fi; \
done
ssl: handshake ....................................................... : ok
ssl: o_stream_get_buffer_avail_size .................................. : ok
ssl: small packets ................................................... : ok
0 / 3 tests failed
+ ret=0
+ test -s test.out~19257
+ test 0 '!=' 0
+ exit 0
+ rm -f test.out~19257
make[1]: Leaving directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
make: Leaving directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
My patch looks like this:
diff --git a/src/lib-ssl-iostream/Makefile.am b/src/lib-ssl-iostream/Makefile.am
index 5aaea5d..17ebf1d 100644
--- a/src/lib-ssl-iostream/Makefile.am
+++ b/src/lib-ssl-iostream/Makefile.am
@@ -56,6 +56,6 @@ noinst_PROGRAMS = $(test_programs)
 
 check-local:
  for bin in $(test_programs); do \
-  if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \
+  if ! $(LIBTOOL) --mode execute $(RUN_TEST) ./$$bin; then exit 1; fi; \
  done
 endif

Result:
make[2]: Entering directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
make  check-local
make[3]: Entering directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
for bin in test-iostream-ssl; do \
  if ! /bin/sh ../../libtool --mode execute /bin/sh ../../run-test.sh ../.. ./$bin; then exit 1; fi; \
done
ssl: handshake ....................................................... : ok
ssl: o_stream_get_buffer_avail_size .................................. : ok
ssl: small packets ................................................... : ok
0 / 3 tests failed
make[3]: Leaving directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'
make[2]: Leaving directory '/home/xxx/rpmbuild/BUILD/xxx/dovecot-2.3.13/src/lib-ssl-iostream'

Can anyone help to correct my understanding and my patch?

Thanks,
Anh Do