Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp987614ybm; Fri, 29 May 2020 17:46:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz75vQMkobyb6JMfqFY0l9yohZZHkkw1JhdaZUcyod69u67eN1Qdus0Hf7zxa1+cxMnw8+j X-Received: by 2002:a50:d490:: with SMTP id s16mr10599659edi.242.1590799585133; Fri, 29 May 2020 17:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590799585; cv=none; d=google.com; s=arc-20160816; b=kwrT8fc1GwFVkYunGz9o3nNPEMcQNA7bVp4wBBaoV44SnG43zh3vbUmMl+3N9MZ+rj h8jF6nNijg6xY6//jK1WEIPAOfsSGuZZ3kL4klBDdsK8yf8WoElep3E2tUYTncglmG35 CazySyzyvrNYSX4a7AQjj5GixnYJ5ucx7CTyX2PnTIOKscsyHZ6semXfw/jNKnq6EcMW eIl9ywVaMFTTJ03URb5d3OVLbqEFs67BZ0y/C4y+9gYPGDdMmwhtX79fDSV6H0jiHY8K PblKEl0oG7tgBrK9UYeo8pOKpNnVODs0BChCgQRRRIZ3cbAebRGUw75HdIJBKl0Vw7Zq MaMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=IVM+2iuYQX6ocMaE9S2ysvmWTQDm/L7TAb7CL71ga/Y=; b=PiEWw8E+HdoDnJW6j5kPanpmYYplwEn+a/g8oNKMTklplObpWbYbDXgsuN2br70RFj U7QPd4+KDxOAAvmB9ZUDA+yxkvnAFlExYy7iF3CLRdIY9hqJEU4TITsBcjcJFHlLAJxt np19iKvfcQgUXMctnlIS+VqpGEYM4BW35etpi6GtXN0H8QHb3ThiQtr/WGjfCE5QcQlf TXH7Iq1FtZ3vdhEil9DuFJpnBly6qvIAe0ng4ls9Mm0TNaLSY4KisfIO7F4W17DAZRhZ Qj5nAnjktHxk+gdpjpXvcqTZZF1edqta3joHG6coW3msD7163YJkXlesOB/b2/5ss85W QKsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rK2wTZV2; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o23si6205829eds.570.2020.05.29.17.46.01; Fri, 29 May 2020 17:46:25 -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=@gmail.com header.s=20161025 header.b=rK2wTZV2; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728594AbgE3AoM (ORCPT + 99 others); Fri, 29 May 2020 20:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728525AbgE3AoM (ORCPT ); Fri, 29 May 2020 20:44:12 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC888C03E969 for ; Fri, 29 May 2020 17:44:10 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id k8so3073808edq.4 for ; Fri, 29 May 2020 17:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=IVM+2iuYQX6ocMaE9S2ysvmWTQDm/L7TAb7CL71ga/Y=; b=rK2wTZV2IVOck/1x+EU1Bbo0tHbJ/xDluHD+3lLr98k9UxJAYOYvipDjpz8G1+TCkI 5l8azXrMuGsob51dJPCUD/PMXHYXy5/2rnjfwjEdgS+Jz0GGkqO/ePfhgoVeIsYn43GG T9tJjjUg7xrFhtKVRLyr8HrQRIsv3SiCS5Bj3Zr52N4+Rzk3k7kmRLdyjZhAgzv/fbLn R7kW+9MG+sI1zm4aBeBGeh4Hc4v8o3qi2Qj9DJcbhVOmEouAFBQJpxTCFtYCcA71tgQI e9EuhvnOn4knf9BBuO5qblAeXQLkzZlK2cYy2y0HrWcQKzNVWYS0jG3Ifnr98FSZ/7cN F9mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=IVM+2iuYQX6ocMaE9S2ysvmWTQDm/L7TAb7CL71ga/Y=; b=A78PdSiUezqOhHpuUM4A6oTPC7eKHJ/7cQKiws7a0pBXgnPu4AnnUqos29uetjg4LC n3PMved5lLIEmQ1tEjLbdf9TiChEDImRZH+jeIEDiGBwnVgOsQOnc0oVOggsFxOGb+gk aF8MnF3+gPp8JiRxCj+D7+KpUFAFYDQQx57EYD1oCzmP/SIdOvJryEoXRXERMcu+iOyi 8W6t7kwdQvPfvI7HB0Z+zY4pW6kuS+4exMuWlMEDjKB1oVIWNcELlw0zEl1fr04F+sNX lTpKZA/Oau/6IDeN3xTYlJnplFb3RD+natsprvLQKagjvTF5nMa27QCkuJg4/U4bgatG UUtQ== X-Gm-Message-State: AOAM5310SOlQkzt0iq8FIYrUFBLUYz6nEuABVQH7SfYvNXYiCVtq5/NV m9cfG1SGpTKvVjstVubmNT0= X-Received: by 2002:aa7:c143:: with SMTP id r3mr11210651edp.203.1590799449452; Fri, 29 May 2020 17:44:09 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id e8sm8655662edk.42.2020.05.29.17.44.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 17:44:08 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, christian.brauner@ubuntu.com Cc: linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] lib: make a test module with get_count_order/long Date: Sat, 30 May 2020 00:43:28 +0000 Message-Id: <20200530004328.30530-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A test module to make sure get_count_order/long returns the correct result. Signed-off-by: Wei Yang --- lib/Kconfig.debug | 13 ++++++ lib/Makefile | 2 + lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++ tools/testing/selftests/lib/config | 1 + 4 files changed, 80 insertions(+) create mode 100644 lib/test_getorder.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c0ef216bb803..01e671151f42 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1999,6 +1999,19 @@ config TEST_BITOPS If unsure, say N. +config TEST_GETORDER + tristate "Test module for compilation of get_count_order operations" + depends on m + help + This builds the "test_getorder" module that is much like the + TEST_LKM module except that it does a basic exercise of the + get_count_order and get_count_order_long to make sure there are no + compiler warnings from C=1 sparse checker or -Wextra compilations. + It has no dependencies and doesn't run or load unless explicitly + requested by name. For example: modprobe test_getorder. + + If unsure, say N. + config TEST_VMALLOC tristate "Test module for stress/performance analysis of vmalloc allocator" default n diff --git a/lib/Makefile b/lib/Makefile index 0d942f7c7478..806d4df8f7c7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -81,6 +81,8 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o obj-$(CONFIG_TEST_BITOPS) += test_bitops.o CFLAGS_test_bitops.o += -Werror +obj-$(CONFIG_TEST_GETORDER) += test_getorder.o +CFLAGS_test_getorder.o += -Werror obj-$(CONFIG_TEST_PRINTF) += test_printf.o obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o diff --git a/lib/test_getorder.c b/lib/test_getorder.c new file mode 100644 index 000000000000..6492abc793af --- /dev/null +++ b/lib/test_getorder.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Author: Wei Yang + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include + +/* a tiny module only meant to test get_count_order/long */ +unsigned int order_comb[][2] = { + {0x00000003, 2}, + {0x00000004, 2}, + {0x00001fff, 13}, + {0x00002000, 13}, + {0x50000000, 31}, + {0x80000000, 31}, + {0x80003000, 32}, +}; + +unsigned long order_comb_long[][2] = { + {0x0000000300000000, 34}, + {0x0000000400000000, 34}, + {0x00001fff00000000, 45}, + {0x0000200000000000, 45}, + {0x5000000000000000, 63}, + {0x8000000000000000, 63}, + {0x8000300000000000, 64}, +}; + +static int __init test_getorder_startup(void) +{ + int i; + + pr_warn("Loaded test module\n"); + for (i = 0; i < ARRAY_SIZE(order_comb); i++) { + if (order_comb[i][1] != get_count_order(order_comb[i][0])) + pr_warn("get_count_order wrong for %x\n", + order_comb[i][0]); + } + + for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) { + if (order_comb_long[i][1] != + get_count_order_long(order_comb_long[i][0])) + pr_warn("get_count_order_long wrong for %lx\n", + order_comb_long[i][0]); + } + + return 0; +} + +static void __exit test_getorder_unstartup(void) +{ + pr_warn("Unloaded test module\n"); +} + +module_init(test_getorder_startup); +module_exit(test_getorder_unstartup); + +MODULE_AUTHOR("Wei Yang "); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("get_count_order/long testing module"); diff --git a/tools/testing/selftests/lib/config b/tools/testing/selftests/lib/config index b80ee3f6e265..2ad467d34648 100644 --- a/tools/testing/selftests/lib/config +++ b/tools/testing/selftests/lib/config @@ -3,3 +3,4 @@ CONFIG_TEST_BITMAP=m CONFIG_PRIME_NUMBERS=m CONFIG_TEST_STRSCPY=m CONFIG_TEST_BITOPS=m +CONFIG_TEST_GETORDER=m -- 2.23.0