Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2809134rwi; Fri, 21 Oct 2022 08:10:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4M+MlmGHQ9RTYXF1eZMaqwWVasX1ge8iKsh3/BA840vR6yLiUfiU81rF+rTGaat/lMTA5e X-Received: by 2002:a17:902:ce88:b0:186:7e98:86d6 with SMTP id f8-20020a170902ce8800b001867e9886d6mr2642804plg.123.1666365003705; Fri, 21 Oct 2022 08:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666365003; cv=none; d=google.com; s=arc-20160816; b=fH6GbP5KZtIaQPn3HyXnTq3cpjvsvcOejIuv+HM4MVwHtKEfjFqHcvQL9VdS0dR21T ApzDOJEbM72+6+hXzefcwKkN2V5XTF1G1L2jW51TqB2C1Y8yBBlyZfNPWHTR8Z7SpzYh aqr8lRwobVGfqNN/6LsnrIL3mtixOYME3dz+D1Hwaw3Vdxoy39lkJl/a/OfEn0a1Vkmg htPru3Orc1lC4aWvFMxtwHZ+HLzoZFOYvBvI2yl2Mt2/Kt9fo3TLFzCnqe6JXjtYdjhM t8LvL83I3CdZuX/gbGCtqKDunhb3mLjjAQ6JllNICnaM/wotiRONO+utSZqxwzXuwIRW nndw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=S9sAGs3Wo0lHK9Sj2L9VmmxgTJ6QghJrVOpEZXeJji8=; b=lt50eRZ8jgXbl5QjaZCi3HnYLBpfD8v78StWXPUBwoZKycsY4zUxfWObM05jkxyY9J IY/ucMwekiJCg0m/s9bK8RG4o+923KEVdi0TAmcakH9S2VrYbU8qJ0csK7wkcgMf2H+U ks+Nt4pYX6hfyTrB1z8Z2/yeKXulCVheWVyZLLeRj28BW0GCojOK/jeNsOBMnuUWY/nI DMm3jS6wRlfGp7S0n7N16Oe9eesASRCmmr3mVKKYHyzY2bp8W4xwwGBp6hsW51puz/8c epBN4BrQnCsBSvTptqGYV369xBJFeKCF3ipPwcXe/ME+H5Z6UO8HWGrlUJ6At8TFVFXm sVlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a17090ab90c00b001fdcb564d7fsi5729398pjr.158.2022.10.21.08.09.50; Fri, 21 Oct 2022 08:10:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231190AbiJUNpi (ORCPT + 99 others); Fri, 21 Oct 2022 09:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbiJUNpe (ORCPT ); Fri, 21 Oct 2022 09:45:34 -0400 Received: from mail.sf-mail.de (mail.sf-mail.de [IPv6:2a01:4f8:1c17:6fae:616d:6c69:616d:6c69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B8F9A2A0 for ; Fri, 21 Oct 2022 06:45:28 -0700 (PDT) Received: (qmail 18684 invoked from network); 21 Oct 2022 13:44:36 -0000 Received: from p200300cf07087500581cdcfffecf391f.dip0.t-ipconnect.de ([2003:cf:708:7500:581c:dcff:fecf:391f]:60600 HELO eto.sf-tec.de) (auth=eike@sf-mail.de) by mail.sf-mail.de (Qsmtpd 0.38dev) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPSA for ; Fri, 21 Oct 2022 15:44:36 +0200 From: Rolf Eike Beer To: Thomas Graf , Herbert Xu , Florian Westphal Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Jason A. Donenfeld" Subject: [PATCH] rhashtable: make test actually random Date: Fri, 21 Oct 2022 15:45:23 +0200 Message-ID: <12102372.O9o76ZdvQC@eto.sf-tec.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "random rhlist add/delete operations" actually wasn't very random, as all cases tested the same bit. Since the later parts of this loop depend on the first case execute this unconditionally, and then test on different bits for the remaining tests. While at it only request as much random bits as are actually used. Signed-off-by: Rolf Eike Beer --- lib/test_rhashtable.c | 58 ++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c index b358a74ed7ed..f2ba5787055a 100644 --- a/lib/test_rhashtable.c +++ b/lib/test_rhashtable.c @@ -369,18 +369,10 @@ static int __init test_rhltable(unsigned int entries) pr_info("test %d random rhlist add/delete operations\n", entries); for (j = 0; j < entries; j++) { u32 i = prandom_u32_max(entries); - u32 prand = get_random_u32(); + u32 prand = prandom_u32_max(4); cond_resched(); - if (prand == 0) - prand = get_random_u32(); - - if (prand & 1) { - prand >>= 1; - continue; - } - err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); if (test_bit(i, obj_in_table)) { clear_bit(i, obj_in_table); @@ -393,35 +385,29 @@ static int __init test_rhltable(unsigned int entries) } if (prand & 1) { - prand >>= 1; - continue; - } - - err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - if (err == 0) { - if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i)) - continue; - } else { - if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i)) - continue; - } - - if (prand & 1) { - prand >>= 1; - continue; + err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + if (err == 0) { + if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i)) + continue; + } else { + if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i)) + continue; + } } - i = prandom_u32_max(entries); - if (test_bit(i, obj_in_table)) { - err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - WARN(err, "cannot remove element at slot %d", i); - if (err == 0) - clear_bit(i, obj_in_table); - } else { - err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); - WARN(err, "failed to insert object %d", i); - if (err == 0) - set_bit(i, obj_in_table); + if (prand & 2) { + i = prandom_u32_max(entries); + if (test_bit(i, obj_in_table)) { + err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + WARN(err, "cannot remove element at slot %d", i); + if (err == 0) + clear_bit(i, obj_in_table); + } else { + err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params); + WARN(err, "failed to insert object %d", i); + if (err == 0) + set_bit(i, obj_in_table); + } } } -- 2.35.3