From patchwork Tue Nov 8 20:57:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 9418115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3509560585 for ; Tue, 8 Nov 2016 20:56:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 270B628A28 for ; Tue, 8 Nov 2016 20:56:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BB7B28A56; Tue, 8 Nov 2016 20:56:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE34D28A28 for ; Tue, 8 Nov 2016 20:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbcKHU4e (ORCPT ); Tue, 8 Nov 2016 15:56:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48410 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbcKHU4d (ORCPT ); Tue, 8 Nov 2016 15:56:33 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46E574E8AB; Tue, 8 Nov 2016 20:56:33 +0000 (UTC) Received: from astarta.redhat.com (vpn1-6-16.ams2.redhat.com [10.36.6.16]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA8KuVr2011663 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 8 Nov 2016 15:56:32 -0500 From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: Lucas De Marchi , Jessica Yu Subject: [PATCH] testsuite: fix test_array_sort pointers inderection Date: Tue, 8 Nov 2016 22:57:26 +0200 Message-Id: <1478638646-5933-1-git-send-email-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 Nov 2016 20:56:33 +0000 (UTC) Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);