[dm-devel] [PATCH 4/5] libmultipath tests: fix strerror() difference between musl and glibc

Benjamin Marzinski bmarzins at redhat.com
Mon Nov 2 19:58:39 UTC 2020


On Tue, Oct 27, 2020 at 11:45:35PM +0100, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
> 
> If an error occurs with errno=0, strerror() on musl returns a different
> string than "Success". Make sure the test doesn't fail for that reason.
> 
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
>  tests/alias.c    | 2 +-
>  tests/test-log.c | 5 ++++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/alias.c b/tests/alias.c
> index 5624138..7fda679 100644
> --- a/tests/alias.c
> +++ b/tests/alias.c
> @@ -712,7 +712,7 @@ static void al_write_err(void **state)
>  	will_return(__wrap_write, strlen(ln) - 1);
>  	expect_value(__wrap_ftruncate, length, offset);
>  	will_return(__wrap_ftruncate, 0);
> -	expect_condlog(0, "Cannot write binding to bindings file : Success\n");
> +	expect_condlog(0, "Cannot write binding to bindings file :");
>  
>  	alias = allocate_binding(0, "WWIDa", 1, "MPATH");
>  	assert_ptr_equal(alias, NULL);
> diff --git a/tests/test-log.c b/tests/test-log.c
> index 051491e..1c901cb 100644
> --- a/tests/test-log.c
> +++ b/tests/test-log.c
> @@ -2,6 +2,7 @@
>  #include <stddef.h>
>  #include <stdarg.h>
>  #include <stdio.h>
> +#include <string.h>
>  #include <cmocka.h>
>  #include "log.h"
>  #include "test-log.h"
> @@ -11,12 +12,14 @@ void __wrap_dlog (int sink, int prio, const char * fmt, ...)
>  {
>  	char buff[MAX_MSG_SIZE];
>  	va_list ap;
> +	char *expected;
>  
>  	check_expected(prio);
>  	va_start(ap, fmt);
>  	vsnprintf(buff, MAX_MSG_SIZE, fmt, ap);
>  	va_end(ap);
> -	assert_string_equal(buff, mock_ptr_type(char *));
> +	expected = mock_ptr_type(char *);
> +	assert_memory_equal(buff, expected, strlen(expected));

This looks fine. I'm just wondering the purpose. Is it just to deal with
bad, non-null terminated strings?

-Ben

>  }
>  
>  void expect_condlog(int prio, char *string)
> -- 
> 2.29.0




More information about the dm-devel mailing list