linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] testsuite: fix test_array_sort pointers inderection
@ 2016-11-08 20:57 Yauheni Kaliuta
  2016-11-09  0:24 ` Lucas De Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Yauheni Kaliuta @ 2016-11-08 20:57 UTC (permalink / raw)
  To: linux-modules; +Cc: Lucas De Marchi, Jessica Yu

The array elements in the tests are strings, what means "char *"
in С. The comparation funtion takes pointers to the elements, so
the arguments become "char **". It means, that strcmp() cannot be
used directrly.

The patch creates a wrapper on strcmp() which perfoms
dereferencing of the "char **" to supply the actual strings to
strcmp(), and uses the wrapper as a comparation function for the
qsort() call.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 testsuite/test-array.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/testsuite/test-array.c b/testsuite/test-array.c
index 3c72a8a109c5..ef1e1e9922c9 100644
--- a/testsuite/test-array.c
+++ b/testsuite/test-array.c
@@ -90,6 +90,13 @@ static int test_array_append_unique(const struct test *t)
 DEFINE_TEST(test_array_append_unique,
 		.description = "test array append unique");
 
+static int strptrcmp(const void *pa, const void *pb) {
+	const char *a = *(const char **)pa;
+	const char *b = *(const char **)pb;
+
+	return strcmp(a, b);
+}
+
 static int test_array_sort(const struct test *t)
 {
 	struct array array;
@@ -104,7 +111,7 @@ static int test_array_sort(const struct test *t)
 	array_append(&array, c2);
 	array_append(&array, c3);
 	array_append(&array, c1);
-	array_sort(&array, (int (*)(const void *a, const void *b)) strcmp);
+	array_sort(&array, strptrcmp);
 	assert_return(array.count == 6, EXIT_FAILURE);
 	assert_return(array.array[0] == c1, EXIT_FAILURE);
 	assert_return(array.array[1] == c1, EXIT_FAILURE);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] testsuite: fix test_array_sort pointers inderection
  2016-11-08 20:57 [PATCH] testsuite: fix test_array_sort pointers inderection Yauheni Kaliuta
@ 2016-11-09  0:24 ` Lucas De Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Lucas De Marchi @ 2016-11-09  0:24 UTC (permalink / raw)
  To: Yauheni Kaliuta; +Cc: linux-modules, Lucas De Marchi, Jessica Yu

On Tue, Nov 8, 2016 at 6:57 PM, Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
> The array elements in the tests are strings, what means "char *"
> in =D0=A1. The comparation funtion takes pointers to the elements, so
> the arguments become "char **". It means, that strcmp() cannot be
> used directrly.
>
> The patch creates a wrapper on strcmp() which perfoms
> dereferencing of the "char **" to supply the actual strings to
> strcmp(), and uses the wrapper as a comparation function for the
> qsort() call.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---

Applied, thanks.


Lucas De Marchi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-09  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-08 20:57 [PATCH] testsuite: fix test_array_sort pointers inderection Yauheni Kaliuta
2016-11-09  0:24 ` Lucas De Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).