Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp144258pxj; Thu, 13 May 2021 23:51:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjNOLFCJoTYkGtSEOCeZEfUgjDWAOqnAgaO8gccc/GtItovNovErA0pH+/Th19sn4U+1AI X-Received: by 2002:a02:a30e:: with SMTP id q14mr41508888jai.4.1620975109455; Thu, 13 May 2021 23:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620975109; cv=none; d=google.com; s=arc-20160816; b=AQfh21E3kk3WqfZ7t6a4LTM/j4WHjCbrsA5HaIHx1WTiGcQZs2o3ROsbBJsiLmefcg SZPwr/VOoGBnFClS6XV389kUiLhv6HizWsM+UZDD/gpZLME9fnBdyRvEgbirxTFDREQO zY6K7MbnO2DPQbHJS45n/ltNfpCaNUBxhOe8XHGcGttf68iQi9MA32bUSckiJgpI4qn1 1RKjgIuYMAHPBXKwkipnrUCl1Hi8YRbIbaKZGQgjqgWFzAMdlXPpVTc1Jyc2IWSWazRz C6nRtn3Uxi4raKIk+OLeWt9dYPG5DbMX1B9Umraw5fQ9sHqi46mhOli5AYIzOpMoHDIK cUQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=UG4DRgps52OAiZfNV/lZ0BYy7DJApRr1J3Fdn5d6SOI=; b=idxMWCWhDYzEXfRiySzhuq3o+XiQeAy2c1XkdLf4NSRrQVyOzSIlDmUd8rDBUmMtzf MqwO6qMhVwD1J1WiSmy+d7fNoxcwckKp4tPZ4qQXmTSw6iQuA/b/S1mzf4Q2Tfjz/Nlh yR/J1yQDJdu/6HndlP+JEQ4EaPsPZVnXSzIrqZfx8afG1ls1oi0D0STsZUtAiuzVRtHk NH76LTGLK9BCYVsXCuG+/qD9q08ou4SVE7A/S6BsBrzCS47G40g09RsHajPMw2nzaVid b8cxnpA3yadqzIhYcMCS/gEU7BZ/h1S6uaH1f3oL0h8rOFUZrUyYZpxtu3LANfdwkEPs +CHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KANv2qwD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si6042063iol.93.2021.05.13.23.50.59; Thu, 13 May 2021 23:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KANv2qwD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230199AbhEMTdh (ORCPT + 99 others); Thu, 13 May 2021 15:33:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbhEMTda (ORCPT ); Thu, 13 May 2021 15:33:30 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FD1FC06174A for ; Thu, 13 May 2021 12:32:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a7-20020a5b00070000b02904ed415d9d84so33159438ybp.0 for ; Thu, 13 May 2021 12:32:20 -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=UG4DRgps52OAiZfNV/lZ0BYy7DJApRr1J3Fdn5d6SOI=; b=KANv2qwDOqKW0FC+g0njej0NjGjlVChYKPW+DOiX8ImpyDmo766P3ods4/mfOwqaeJ vbHDPPbMvoDYgPtvU0yATr6ch9bkAJRJBTGUs4igfyUqf5gqzTBr/cH/YAlkY74ba/Y0 v/GhIXmawVuEqtVKXwR0aCbzf+aKZUZhm4uq8GMykVh5J7UnUx2rNkR4Ao5adLYj26ib TWUJl5qiBiysxUuo7H3ic1mKteW1ZnLVo35yYFJvALSI1xnkGO3xt+e3tWdG9jg0+iaf M0mZGEpPAdkr2geDb+Y1TyfloZhrANyQCPriODVViZZvEBawEosodTwMzOJpKtH2tB9+ HJkQ== 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=UG4DRgps52OAiZfNV/lZ0BYy7DJApRr1J3Fdn5d6SOI=; b=JiZiyRIFwHhdXANLv2ir7Uah++OsiCGGYbXI3RoJpM+BovDcoao2K2skkDYZkx/s8H bL9mKk4+FnS9QjvrWNA+5i1Pkno7Oyeq7rpNSxu6BrFMYbc2PexVYgT24h+E3gPygAXR NGSFZ16+fUvhOntAVaeX+cZi6TGBB1Ti9k0TNbJDpfAiayodN4FHQwbp+2sxH3RyfsR3 9LWzM6HrVnY/n86oSYpVtJwlSAZvcAZAXteskIoO46JSyNnVaPjrynjVDTzZc+yLks7o X+6ZNUjINSn0x9jA0DMPGJ13OUBaxp0KZOEclGfCmkhZvc5eE/JkEG11vju/m4hlzMxj 25eQ== X-Gm-Message-State: AOAM53235jtNBrWwcioF90dcEp3dWn5NMbJI1tiWMeQ4VPlrKWlvgE+4 qJByBniRRv3V80u978N+1vrHXQXf2HwfLQ== X-Received: from spirogrip.svl.corp.google.com ([2620:15c:2cb:201:5f61:8ca4:879b:809e]) (user=davidgow job=sendgmr) by 2002:a25:74d3:: with SMTP id p202mr37721158ybc.38.1620934339592; Thu, 13 May 2021 12:32:19 -0700 (PDT) Date: Thu, 13 May 2021 12:31:56 -0700 In-Reply-To: <20210513193204.816681-1-davidgow@google.com> Message-Id: <20210513193204.816681-2-davidgow@google.com> Mime-Version: 1.0 References: <20210513193204.816681-1-davidgow@google.com> X-Mailer: git-send-email 2.31.1.751.gd2f1c929bd-goog Subject: [PATCH v2 02/10] 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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, this 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(-) Changes since v1: https://lore.kernel.org/linux-kselftest/20210507050908.1008686-2-davidgow@google.com/ - Fix a typo in the description ('yhis' -> 'this'). 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, \ -- 2.31.1.751.gd2f1c929bd-goog