From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
To: linux-modules@vger.kernel.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>, Jessica Yu <jeyu@redhat.com>
Subject: [PATCH] testsuite: fix test_array_sort pointers inderection
Date: Tue, 8 Nov 2016 22:57:26 +0200 [thread overview]
Message-ID: <1478638646-5933-1-git-send-email-yauheni.kaliuta@redhat.com> (raw)
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
next reply other threads:[~2016-11-08 20:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 20:57 Yauheni Kaliuta [this message]
2016-11-09 0:24 ` [PATCH] testsuite: fix test_array_sort pointers inderection Lucas De Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478638646-5933-1-git-send-email-yauheni.kaliuta@redhat.com \
--to=yauheni.kaliuta@redhat.com \
--cc=jeyu@redhat.com \
--cc=linux-modules@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).