Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6536157rdb; Tue, 2 Jan 2024 05:23:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMoJo5pr7awtuhFMwINxy9d0Gb8c1QOazvB2+mXi1kar/wgE3GrnkiqeHXQp6f8RfykkVB X-Received: by 2002:a05:622a:1a8a:b0:423:6e9c:2de9 with SMTP id s10-20020a05622a1a8a00b004236e9c2de9mr21694654qtc.17.1704201827969; Tue, 02 Jan 2024 05:23:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704201827; cv=none; d=google.com; s=arc-20160816; b=doLSCOW1/JcqOwnP3LBNu4O2ZU0/pKffN6Hwj/nhE45PDrAEfjk1aFSeeValKshfoZ 8j3XsKzT8bHcQ4Av8wuo+c/TytEuEfLoQs3UPZ+FpP6WigiJG53MA0Zr5VXOsCGLx7Ni jqV9ViFR25XEvWQRKDEgSXYjG/s1VFxCxb3XkF+DGKt8oxSML1HbThvatx+aPQkzXvwO U7QcxNKPQtauGNtow/vo9UBP8VOQOskP5HiweBRO/L/4y7KbQQVfWmEa/iyx+v2V1xVi 68yQlbth0hZyEDZshl10rtsGn9bwtZmQjn25Sk9u5YADWE7aHj5Ux1EKTDpa2s0ElEQ5 ICtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=zySj094qMEb17HPJF6gPpK0IiBjG+tOCD5/2Q7OgQ6I=; fh=AJH/zDsl/jOWSj5xG4fXgEud5gdyvJKN4hCME92Zz/c=; b=05ryMCbVbzo9MAuNeNXDvK3WIoPbREIlb7A1lQa/sD/104l/Qm4GIlgIqXC4afdip3 h03m9P4j8VLjhEiUS4PR/3Lc/t/4rspIErqIWqP0jCpfE1vm83Hluw9w3EPVu8NC+LTu 1BTc3I+LSIju1ZLwJJ0F9KNbXtYaNO1EsqTRQJQDNWMn6+Mzi8I9FKXQ4VWTvWSxAUIu koZc/F3bnmyMJVh5EGJCnvXqLalFDXMIMyT5i68bZ5yel0Hw/IcUYIYYZHCyE4+HhTta 7uPS0v0ZuFbccVmFquTnPDoJwH/+hzZFUqj46jtUKOKVYCWASn7Te9+fp/2dcESPrFnY eTZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14397-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f6-20020ac87f06000000b0042812d90622si6729730qtk.156.2024.01.02.05.23.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:23:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14397-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B10851C21F0D for ; Tue, 2 Jan 2024 13:23:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BECC1FBF5; Tue, 2 Jan 2024 13:23:37 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE747FBE4; Tue, 2 Jan 2024 13:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-5e89ba9810aso72523867b3.2; Tue, 02 Jan 2024 05:23:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704201814; x=1704806614; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zySj094qMEb17HPJF6gPpK0IiBjG+tOCD5/2Q7OgQ6I=; b=pLFaXGHlqruqG2I2+eFUU58prrsDpZDvns9i9Vo4JyfFm6LgN6uIN+ANg92275iJp2 Lt7pWs+Kl0TvYMm926OLKy6fcgmex2LVMESuR21pssVE6Lf4UFd2KRU6ImHw0mB2el0O hzMWvLN1WxUxwjyasNLC99Il1QBJegKgf4qd8rPRmBMF6BxT55H7L9x3N2h9Vr3lh/rx J95fM0m4VSrmYEfeJhROUDniHkUs7/PbVBM1IReajFRmtHRlHnRoXSLQcmqmbKJi+Cg0 djVXWBmX4K2X4lfUQlB4Hy6cCvG9soi1vQrA32TTwC4r5FbpD5UeetRimmpJKDDX3CMz YFIw== X-Gm-Message-State: AOJu0YxDnyUCbHnr3fWb2SEm6mr7Wvu8wR+c94zycVhAzNyYvVU+xJys TN8fK6+qukc6WzkbbbD/xxXMptl/ioveBw== X-Received: by 2002:a25:6802:0:b0:dbd:a9b6:b01e with SMTP id d2-20020a256802000000b00dbda9b6b01emr9727796ybc.36.1704201813717; Tue, 02 Jan 2024 05:23:33 -0800 (PST) Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com. [209.85.128.172]) by smtp.gmail.com with ESMTPSA id a19-20020a25ae13000000b00d974c72068fsm10171381ybj.4.2024.01.02.05.23.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jan 2024 05:23:32 -0800 (PST) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-5e74b4d5445so72477457b3.1; Tue, 02 Jan 2024 05:23:32 -0800 (PST) X-Received: by 2002:a0d:dd8e:0:b0:5e2:ecfe:48e5 with SMTP id g136-20020a0ddd8e000000b005e2ecfe48e5mr11185191ywe.45.1704201812539; Tue, 02 Jan 2024 05:23:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Geert Uytterhoeven Date: Tue, 2 Jan 2024 14:23:20 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/4] kstrtox: add unit tests for memparse_safe() To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, christophe.jaillet@wanadoo.fr, andriy.shevchenko@linux.intel.com, David.Laight@aculab.com, ddiss@suse.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Qu, On Tue, Jan 2, 2024 at 5:13=E2=80=AFAM Qu Wenruo wrote: > The new tests cases for memparse_safe() include: > > - The existing test cases for kstrtoull() > Including all the 3 bases (8, 10, 16), and all the ok and failure > cases. > Although there are something we need to verify specific for > memparse_safe(): > > * @retptr and @value are not modified for failure cases > > * return value are correct for failure cases > > * @retptr is correct for the good cases > > - New test cases > Not only testing the result value, but also the @retptr, including: > > * good cases with extra tailing chars, but without valid prefix > The @retptr should point to the first char after a valid string. > 3 cases for all the 3 bases. > > * good cases with extra tailing chars, with valid prefix > 5 cases for all the suffixes. > > * bad cases without any number but stray suffix > Should be rejected with -EINVAL > > Signed-off-by: Qu Wenruo Thanks for your patch! > --- a/lib/test-kstrtox.c > +++ b/lib/test-kstrtox.c > @@ -268,6 +268,237 @@ static void __init test_kstrtoll_ok(void) > TEST_OK(kstrtoll, long long, "%lld", test_ll_ok); > } > > +/* > + * The special pattern to make sure the result is not modified for error= cases. > + */ > +#define ULL_PATTERN (0xefefefef7a7a7a7aULL) > +#if BITS_PER_LONG =3D=3D 32 > +#define POINTER_PATTERN (0xefef7a7a7aUL) This pattern needs 40 bits to fit, so it doesn't fit in a 32-bit unsigned long or pointer. Probably you wanted to use 0xef7a7a7aUL instead? > +#else > +#define POINTER_PATTERN (ULL_PATTERN) > +#endif Shouldn't a simple cast to uintptr_t work fine for both 32-bit and 64-bit systems: #define POINTER_PATTERN ((uintptr_t)ULL_PATTERN) Or even better, incorporate the cast to a pointer: #define POINTER_PATTERN ((void *)(uintptr_t)ULL_PATTERN) so you can drop the extra cast when assigning/comparing retptr below. > + > +/* Want to include "E" suffix for full coverage. */ > +#define MEMPARSE_TEST_SUFFIX (MEMPARSE_SUFFIX_K | MEMPARSE_SUFFIX_M |\ > + MEMPARSE_SUFFIX_G | MEMPARSE_SUFFIX_T |\ > + MEMPARSE_SUFFIX_P | MEMPARSE_SUFFIX_E) > + > +static void __init test_memparse_safe_fail(void) > +{ [...] > + for_each_test(i, tests) { > + const struct memparse_test_fail *t =3D &tests[i]; > + unsigned long long tmp =3D ULL_PATTERN; > + char *retptr =3D (char *)POINTER_PATTERN; > + int ret; [...] + if (retptr !=3D (char *)POINTER_PATTERN) Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds