Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1350591ybh; Thu, 16 Jul 2020 09:43:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSxqSiJ5soE52/Zj5Z4fkjPOEGBpRRdhCOFzFISlPURAPooFTCxHnlJ0npM80gKdV6h/ws X-Received: by 2002:a05:6402:1805:: with SMTP id g5mr5060067edy.357.1594917781239; Thu, 16 Jul 2020 09:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594917781; cv=none; d=google.com; s=arc-20160816; b=ysGF1PxixET8QDhr7OM1vptcS3UrldYEtIWS1I4jJ9wzLb3gMIQaJvu4Le3OSh8HB8 GZICGmEu3KvGYMxv1LdJ2yVDHGCRj9FTiQ19vXXu6xIT97CTuBLh3oEV+19k942G/Gbq abQszscrL1gwv6KMiLDxwjYK9P8vGu/NMKkS+X88wAOti5CuVBHNVmVeeWtYQO0hqkE+ lbdY8xeMAyOcMmFvm37gcrUoLfNRD2EtArwl2mpFQAYNnaTLBu7ah5WQDGREk3OCMvni U36DjNAOCXGez60pZhXjs5oQrpwkgjauh4erXpNJeE+oKdaeGeiURpxGOniQdkAC5Sd6 OTsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=LMlqxALUY61jlVk3BUiDy9VLg6DTugrK02O4xaMAXeE=; b=DfNL3nd/Qa8/L5inIlqlB5ePogq5BptGbn01UNzl9Tbe+YnIocuWdtyY5H4CW+u6bD 07AYl/I6C0eetQw2Ljt6KAN/ewwlrpZENVftswOkd/p7LZMo99zfnfEYsJ5AJxc5Suby 0zZKhBrzJ2vo13SYj5ddnj2S5ndtChDKMir8/FCB5flLzJuNJC/nxLt6O8LC+dr86pdo QUb0nZmue3wd6llMqHrKdTZBHk2hqJeQLJ2xgHq6jmSKPVSBnSp/8SEIQqUY3UcYcA26 uXToqhJccFuW3Mkhq4tG88VgUFj8IpKyW+eOMGL4Uko4sah4zVAaTf72h35Ap8GZ7a57 Ufqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b=l4b5Hqho; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id uz6si3494198ejb.50.2020.07.16.09.42.37; Thu, 16 Jul 2020 09:43:01 -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=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b=l4b5Hqho; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728909AbgGPQm0 (ORCPT + 99 others); Thu, 16 Jul 2020 12:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728385AbgGPQmZ (ORCPT ); Thu, 16 Jul 2020 12:42:25 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF744C061755 for ; Thu, 16 Jul 2020 09:42:24 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id m9so2998601qvx.5 for ; Thu, 16 Jul 2020 09:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=massaru-org.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=LMlqxALUY61jlVk3BUiDy9VLg6DTugrK02O4xaMAXeE=; b=l4b5Hqho974uh2PmbRJzJutQgFImeAJVlHlLkooGLhdZe1nS7mvf+x6gt/QOZw/qL9 A84pVZc5FD32JGLt4LlnzFB06rz+hmPXLaI8hDe2fLxz/921s2jVMy4thipSXuNctzI7 HkMqqpSinh/agWeAyLOt/K2QJIn1uTWJuHTPMTVpaO76a66+rxTTbLjEM8mQcObpOs2+ 8BUxyfhfHcFtYnPUbTfLKKZrZtVMp7BOCDW5a6netEOHL7Wv1pCOt9WjfJdZ1HyHyp9F K/0MQrVQdEzKi3vmuBUuhAa8yjbOADZqvUk0N5rSn5dQnSeMoHx9kweWpQy1527gH79c KhnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=LMlqxALUY61jlVk3BUiDy9VLg6DTugrK02O4xaMAXeE=; b=WPllS2yGwyE2+CpeiOWnQqxPVTC6o3oBXv5W4Dh+BtAA51GRhuz8s7PT4JbdjwO7hM MDDh2IAhvCFLE14k1NDP4+v8zjze+Ckd5Wc4BOuMu3duHRWXHgPIy6sRBiGQoDFuibno a0Ug6aCcW7aDnhxTctpkhuw7/lsmV93NHEq0ScLIt33nfheyWAvy8jaamRLsnp6B1/+E irlOn74b9LU4RHamIkn4jcj7tVjSWLwAjEBYoQam51BFZSZpMRSP4n9gti1s891ejTyt OutzMzjrJKAIIBTmjMtTmQIUVxa/yyeArObDQEkpWh9xa0zfKGuSboDDk1YUM84hdv04 OKUQ== X-Gm-Message-State: AOAM531JowvKd9IbBCkFAIsHEsBnFvZB5pGYA4UJMA+OL/cUdiVltQjF w8eOHgXuYGG7lhui5IMJt7rcJA== X-Received: by 2002:a0c:dc07:: with SMTP id s7mr5275693qvk.122.1594917744190; Thu, 16 Jul 2020 09:42:24 -0700 (PDT) Received: from bbking.lan ([2804:14c:4a5:36c::cd2]) by smtp.gmail.com with ESMTPSA id u68sm8060659qkd.59.2020.07.16.09.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 09:42:23 -0700 (PDT) Message-ID: Subject: Re: [RFC 3/3] lib: Convert test_user_copy to KUnit test From: Vitor Massaru Iha To: Kees Cook Cc: kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, brendanhiggins@google.com, davidgow@google.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org Date: Thu, 16 Jul 2020 13:42:20 -0300 In-Reply-To: <202007151929.7A4E04E@keescook> References: <20200715031120.1002016-1-vitor@massaru.org> <20200715031120.1002016-4-vitor@massaru.org> <202007151929.7A4E04E@keescook> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.3 (3.36.3-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-07-15 at 19:34 -0700, Kees Cook wrote: > On Wed, Jul 15, 2020 at 12:11:20AM -0300, Vitor Massaru Iha wrote: > > This adds the conversion of the runtime tests of test_user_copy > > fuctions, > > from `lib/test_user_copy.c`to KUnit tests. > > > > Signed-off-by: Vitor Massaru Iha > > [...] > > @@ -16,6 +16,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * Several 32-bit architectures support 64-bit {get,put}_user() > > calls. > > @@ -31,26 +32,16 @@ > > # define TEST_U64 > > #endif > > > > -#define test(condition, msg, ...) > > \ > > -({ > > \ > > - int cond = (condition); > > \ > > - if (cond) \ > > - pr_warn("[%d] " msg "\n", __LINE__, ##__VA_ARGS__); \ > > - cond; > > \ > > -}) > > - > > static bool is_zeroed(void *from, size_t size) > > { > > return memchr_inv(from, 0x0, size) == NULL; > > } > > > > -static int test_check_nonzero_user(char *kmem, char __user *umem, > > size_t size) > > +static void test_check_nonzero_user(struct kunit *test, char > > *kmem, char __user *umem, size_t size) > > { > > - int ret = 0; > > size_t start, end, i, zero_start, zero_end; > > > > - if (test(size < 2 * PAGE_SIZE, "buffer too small")) > > - return -EINVAL; > > + KUNIT_EXPECT_FALSE_MSG(test, size < 2 * PAGE_SIZE, "buffer too > > small"); > > I think this could be a much smaller diff if you just replaced the > "test" macro: > > #define test(condition, msg, ...) > \ > ({ > \ > int cond = !!(condition); \ > KUNIT_EXPECT_FALSE_MSG(kunit_context, cond, msg, > ##__VA_ARGS__);\ > cond; > \ > }) > Sure, I'll do it. Thanks.