[RFC PATCH 4/4] Add test for trie

Dmitry V. Levin ldv at altlinux.org
Sat Aug 15 15:18:26 UTC 2020


On Thu, Aug 13, 2020 at 05:32:42PM +0200, Ákos Uzonyi wrote:
[...]
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -29,6 +29,7 @@ AM_CPPFLAGS = $(ARCH_MFLAGS) \
>  AM_LDFLAGS = $(ARCH_MFLAGS)
>  
>  libtests_a_SOURCES = \
> +	../trie.c ../trie.h \

There is no need to include the header.

By the way, the code linked into the test is not going to be shown
in the test coverage.

> --- /dev/null
> +++ b/tests/trie.test
> @@ -0,0 +1,12 @@
> +#!/bin/sh
> +#
> +# Test trie.
> +#
> +# Copyright (c) 2020 The strace developers.
> +# All rights reserved.
> +#
> +# SPDX-License-Identifier: LGPL-2.1-or-later
> +
> +. "${srcdir=.}/init.sh"
> +
> +run_prog

I suppose you can add something like

	trie	. "${srcdir=.}/init.sh"; run_prog

to tests/gen_tests.in with the same effect.

> diff --git a/trie.c b/trie.c
> index b2d421cd..e55c5027 100644
> --- a/trie.c
> +++ b/trie.c
> @@ -7,8 +7,6 @@
>   * SPDX-License-Identifier: LGPL-2.1-or-later
>   */
>  
> -#include "defs.h"
> -
>  #include <stdbool.h>
>  #include <stdint.h>
>  #include <stdlib.h>

This is not correct unless you prepend it with

	#ifdef HAVE_CONFIG_H
	# include "config.h"
	#endif

Also, consider moving

	#include <stdbool.h>
	#include <stdint.h>

to trie.h

> @@ -103,7 +101,7 @@ trie_get_node(struct trie *t, uint64_t key, bool auto_create)
>  			if (!auto_create)
>  				return NULL;
>  
> -			*cur_node = xcalloc(1 << sz, 1);
> +			*cur_node = calloc(1 << sz, 1);
>  		}
>  
>  		if (cur_depth >= t->max_depth)

This doesn't look correct either: the return value check is lost.


-- 
ldv


More information about the Strace-devel mailing list