From patchwork Fri May 7 05:09:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12243955 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37DAAC433B4 for ; Fri, 7 May 2021 05:09:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F8A0613E8 for ; Fri, 7 May 2021 05:09:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233118AbhEGFKT (ORCPT ); Fri, 7 May 2021 01:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232410AbhEGFKT (ORCPT ); Fri, 7 May 2021 01:10:19 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0ACC061574 for ; Thu, 6 May 2021 22:09:20 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id u7-20020a259b470000b02904dca50820c2so8736422ybo.11 for ; Thu, 06 May 2021 22:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=jSTI64CJ1fjEq5OTPDv3eN3+6glJnRm4XHS+PKPJDqQ=; b=JVIXRhcjz7NCzpFAcvQ+vpKLDHmL3+gV0tpn3h+3lYDO6SgFnmFaCx5Aa8B8YGhYQL XYbXHEpkJ2BastYVJE5UxO5ocwv+ghKnd6Y5sO6OcjMzAwRGdkvZ19A7NCWJyHTnzsR5 7Muwz5cO+4J0doAO4LKM/W6Pkd31Emd19Kj/TIINVihz7ASMCUo55GwyPWFxEG1TL9Ce DXUxq49XNginaHoHcdFrIMxf8LpSO5TbrSuE9Lnjg28YgClK98Q5V/RYkK0W5jl4tWMX Gp+iw9aBR6SZ35PZLiB7tQlwhPLPR5NSVZfed9scnvw81usR4vm1G8RZGcBoGeubfzOj WRDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=jSTI64CJ1fjEq5OTPDv3eN3+6glJnRm4XHS+PKPJDqQ=; b=UW4wk2DOhjMy83FFRzdnNiWiqexCgDZS52WHPtVpuLEoI4MUEg0qxst5PR6fsjKKu1 PgdjVAFbXCnOiEbGN8mPVDbsQhkNzm9zDfla1syTohrgZIhV4TMms+KB8UCEGukNQrwD afHu6gMpsrafV2GYEd/z4lgDU0JznqYiNm/BpIcHex9+8pGrgvh6F0wGePtoKVe9dtkY BFla1iKcm0CkRmWE8hFWrfBHeyddIbkaSNxNe9nGWbcfNQGatHXAwgRshnxVrGgxA24r WKcoEIbCfqkKwWz1IEad0Ud8KSxFodhd9kW1RZm0giubU/6SiRhHit3cESw4U+bIcfLj FJ/Q== X-Gm-Message-State: AOAM531G10RFqn1MeEZLhdTtFbNfZyKJ8VDpMUiLC36ehcKIvwOZHqmn 3J7+ivDCX25NQ0FXoz48vo4Z6rWnhrH/lA== X-Google-Smtp-Source: ABdhPJy9tq8jPJY+ebhUXAl3EcvJ1PKeKQVZ9aWvrBWOFDSB3qbryOjP9jS6yOfytiqDVbXjWXm6HbciSaRB5A== X-Received: from spirogrip.svl.corp.google.com ([2620:15c:2cb:201:7a7f:ce22:a6af:49e5]) (user=davidgow job=sendgmr) by 2002:a25:cacd:: with SMTP id a196mr11407255ybg.296.1620364159507; Thu, 06 May 2021 22:09:19 -0700 (PDT) Date: Thu, 6 May 2021 22:09:07 -0700 Message-Id: <20210507050908.1008686-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog Subject: [PATCH 1/2] kunit: Do not typecheck binary assertions From: David Gow To: Brendan Higgins , Daniel Latypov , Shuah Khan Cc: David Gow , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The use of typecheck() in KUNIT_EXPECT_EQ() and friends is causing more problems than I think it's worth. Things like enums need to have their values explicitly cast, and literals all need to be very precisely typed for the code to compile. While typechecking does have its uses, the additional overhead of having lots of needless casts -- combined with the awkward error messages which don't mention which types are involved -- makes tests less readable and more difficult to write. By removing the typecheck() call, the two arguments still need to be of compatible types, but don't need to be of exactly the same time, which seems a less confusing and more useful compromise. Signed-off-by: David Gow Reviewed-by: Daniel Latypov Reviewed-by: Brendan Higgins --- I appreciate that this is probably a bit controversial (and, indeed, I was a bit hesitant about sending it out myself), but after sitting on it for a few days, I still think this is probably an improvement overall. The second patch does fix what I think is an actual bug, though, so even if this isn't determined to be a good idea, it (or some equivalent) should probably go through. Cheers, -- David include/kunit/test.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 49601c4b98b8..4c56ffcb7403 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -775,7 +775,6 @@ void kunit_do_assertion(struct kunit *test, do { \ typeof(left) __left = (left); \ typeof(right) __right = (right); \ - ((void)__typecheck(__left, __right)); \ \ KUNIT_ASSERTION(test, \ __left op __right, \ From patchwork Fri May 7 05:09:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12243957 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7790C433B4 for ; Fri, 7 May 2021 05:09:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CCAE613E3 for ; Fri, 7 May 2021 05:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233253AbhEGFKc (ORCPT ); Fri, 7 May 2021 01:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232410AbhEGFKb (ORCPT ); Fri, 7 May 2021 01:10:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57988C061574 for ; Thu, 6 May 2021 22:09:32 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a7-20020a5b00070000b02904ed415d9d84so8754560ybp.0 for ; Thu, 06 May 2021 22:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HRBAR21u7PRZM/8/eMSlewl7NCMmiIJxdjUH7mvZekY=; b=DhGNJidwdrI3KXAJXGCmwGs1p7rL6egOFnrxLtNMmdergPEvrfY5NzHibtJacZfh8c VdjMv+Gx6FvB0wDZfPIidP3RVhGOJgz87g/tHu4bf0CSo6lr9cuey2az4gb0JHDkIKTU Wuz5yC9bRlYmf4g+9ZReAKGIR6hIMyw7rD76FXyy8BuWJsz3Sk56KbXQtPdWruz+D2c1 GbWPtcXtLzA5+iPIx5fu508twhW3F0oxlcXJDaMd2CDs68G9Db+u+XFFME6dK9rMhsQS v31gn4PQLWvAg7ecWh4KXdeWVDA4dTn4TJtd5IkFEs0WqTbhAdh5i3pDlqT9gnCItcwA 7ohQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HRBAR21u7PRZM/8/eMSlewl7NCMmiIJxdjUH7mvZekY=; b=ID5obnqdoFXAv0IJbM+twWVXJs5lGt4R05dKhPMr4hmAfRzA1Ooly/TzTcfm0/Nvhu Jna5Dn3iMgcqeN7THHz0FmuNnL18nNy2IH94/Hq9iXGTfAJXXn88uDqnx8SVdM3V90j6 5JFLWs7vnXpWGkyq+I+wFr5c5iHenGI5cSahEkk2FZ38aswuPjgUbt1ccCtjfJDuTXUi FTqi//U2+5lHU/rCp1ka6utDSlhXVN6+A6+bXuVcNP2f3JA5GQSmQvTzyoElHGXUpntT h/5n+qMPR2ABmX3BuiRpGxlgi+eHWoZbbVhRjR7XqiznIgjmSlqM8JOF4mbHgF/lJXEU ygmQ== X-Gm-Message-State: AOAM531yIWKrdHmqYayw3RSuJMmaOCYSkPim4oxbW/6ff8u00lukMTBS gvAS1bIamqcePm8zxI5FR9sj8W7aSO1pzw== X-Google-Smtp-Source: ABdhPJw+CbtEFdF9Vkfc06hXM/f6APOThaXd1KaFsU9TTsm45ExcEMGJ2t9r92IcHQyFQdvPpXwXO4kIrKKuhw== X-Received: from spirogrip.svl.corp.google.com ([2620:15c:2cb:201:7a7f:ce22:a6af:49e5]) (user=davidgow job=sendgmr) by 2002:a25:bd50:: with SMTP id p16mr11249160ybm.290.1620364171642; Thu, 06 May 2021 22:09:31 -0700 (PDT) Date: Thu, 6 May 2021 22:09:08 -0700 In-Reply-To: <20210507050908.1008686-1-davidgow@google.com> Message-Id: <20210507050908.1008686-2-davidgow@google.com> Mime-Version: 1.0 References: <20210507050908.1008686-1-davidgow@google.com> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog Subject: [PATCH 2/2] kunit: Assign strings to 'const char*' in STREQ assertions From: David Gow To: Brendan Higgins , Daniel Latypov , Shuah Khan Cc: David Gow , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently, the KUNIT_EXPECT_STREQ() and related macros assign both string arguments to variables of their own type (via typeof()). This seems to be to prevent the macro argument from being evaluated multiple times. However, yhis doesn't work if one of these is a fixed-length character array, rather than a character pointer, as (for example) char[16] will always allocate a new string. By always using 'const char*' (the type strcmp expects), we're always just taking a pointer to the string, which works even with character arrays. Signed-off-by: David Gow Reviewed-by: Daniel Latypov Reviewed-by: Brendan Higgins --- include/kunit/test.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 4c56ffcb7403..b68c61348121 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1128,8 +1128,8 @@ do { \ fmt, \ ...) \ do { \ - typeof(left) __left = (left); \ - typeof(right) __right = (right); \ + const char *__left = (left); \ + const char *__right = (right); \ \ KUNIT_ASSERTION(test, \ strcmp(__left, __right) op 0, \