From patchwork Fri Oct 18 15:17:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhargava Shastry X-Patchwork-Id: 1179449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="E2rV5j6m"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46vqRK0MxVz9sNw for ; Sat, 19 Oct 2019 02:18:04 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1DCA4BB3; Fri, 18 Oct 2019 15:18:02 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 4078AAB5 for ; Fri, 18 Oct 2019 15:18:00 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 92C50608 for ; Fri, 18 Oct 2019 15:17:59 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id f22so6480055wmc.2 for ; Fri, 18 Oct 2019 08:17:59 -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=F6UC7FlaFfI249fsS8wr6KT2buCYgnGECWZjYQvMZ24=; b=E2rV5j6m5gwSZqMykwGeOANpFxn2c1qCcEx34x89F6Usxm8jD20qkpcSSkhqkrarJv C10c6UdAs1wkppZ8Si8OXIeYWcfLngjfNQUE7nlZUDKeVWmGN0SlxHj8MqB5OZS7KeYN HwJdaJ5GYMG7MRLdC2ZwSznsxn1n3+l8DBVWgZwHgRLdJ6uSuaZXQWrgaohDmNqcK8Dj eh1R52HWNy5l1ZhpUKSLkN9AF4PegxTKe6xVCf/GZZSAvieUYTNQg871xhwA0FRvvufK Bf8+FDEXlnbSjBQ2kklb3r6I0eMW1w8FoKr+O+9N6lJ71PZf2wlZLiJp4EkCF57dyxZy Lmmw== 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=F6UC7FlaFfI249fsS8wr6KT2buCYgnGECWZjYQvMZ24=; b=hS0TgTEm1eyGR1faatYZinRB+5F7WuA2TSpRaRPzIdGE87mHm+pKM9Bg4l9sMxOYvK SfqBjjT+TORS+KNE/HtoghUdhZn/yKLMNkNl07F6gJARjoOKj8Q6/7VGimmSeADPAjm3 fT+skhQf+BTFnjdd8vHlhuNqjs8cPGS1TrlgV23qrZE2vm+3NqTyNREZg/dOK4oL2DsZ icQm9167Css68tFw+vhYZjsod7C22vWe0oDPDa0wBUo3t493+Z4+NwKvDw3nCkp6yUfI AisNcxLKdwI2s0TlPMNUWo84tjReYoLrYH+0nYELRJYwiMbQXXXT/sN7UubNZk2xw/ls lVJQ== X-Gm-Message-State: APjAAAXhbvua4ZSu/N1Fq7kO+ze5g7pb7xkxM5sGh4ywizK8NfvqbU67 UH3HGO6Gm6OhqPU6h7oZhVSt7zWk X-Google-Smtp-Source: APXvYqyHqTQnzUaFIFxcfzstRv5B6lCIDkmRxf7jHVmhBAK/0Ois5xKQ7J0hhI1xOpzC7YpQ0niSbg== X-Received: by 2002:a1c:8189:: with SMTP id c131mr8065982wmd.151.1571411877772; Fri, 18 Oct 2019 08:17:57 -0700 (PDT) Received: from x270.Speedport_W_724V_09011603_06_003 ([2003:c0:df1a:f67c:28fe:f2d0:8379:f09]) by smtp.gmail.com with ESMTPSA id t6sm7965075wmf.8.2019.10.18.08.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 08:17:56 -0700 (PDT) From: bshas3@gmail.com To: dev@openvswitch.org Date: Fri, 18 Oct 2019 17:17:34 +0200 Message-Id: <20191018151734.2898-1-bshas3@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Bhargava Shastry Subject: [ovs-dev] [PATCH] ossfuzz: Simplify miniflow fuzzer harness. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Bhargava Shastry Google's oss-fuzz builder bots were complaining that miniflow_target is too slow to fuzz in that some tests take longer than a second to complete. This patch fixes this by replacing the random flow generation within the harness to a more simpler scenario. Signed-off-by: Bhargava Shastry --- tests/oss-fuzz/miniflow_target.c | 139 +++---------------------------- 1 file changed, 10 insertions(+), 129 deletions(-) diff --git a/tests/oss-fuzz/miniflow_target.c b/tests/oss-fuzz/miniflow_target.c index 800375d63..d747ff9ae 100644 --- a/tests/oss-fuzz/miniflow_target.c +++ b/tests/oss-fuzz/miniflow_target.c @@ -9,17 +9,6 @@ #include "classifier-private.h" #include "util.h" -static void -shuffle_u32s(uint32_t *p, size_t n) -{ - for (; n > 1; n--, p++) { - uint32_t *q = &p[random_range(n)]; - uint32_t tmp = *p; - *p = *q; - *q = tmp; - } -} - /* Returns a copy of 'src'. The caller must eventually free the returned * miniflow with free(). */ static struct miniflow * @@ -59,119 +48,8 @@ miniflow_hash__(const struct miniflow *flow, uint32_t basis) return hash_finish(hash, n_values); } -static uint32_t -random_value(void) -{ - static const uint32_t values_[] = - { 0xffffffff, 0xaaaaaaaa, 0x55555555, 0x80000000, - 0x00000001, 0xface0000, 0x00d00d1e, 0xdeadbeef }; - - return values_[random_range(ARRAY_SIZE(values_))]; -} - -static bool -choose(unsigned int n, unsigned int *idxp) -{ - if (*idxp < n) { - return true; - } else { - *idxp -= n; - return false; - } -} - #define FLOW_U32S (FLOW_U64S * 2) -static bool -init_consecutive_values(int n_consecutive, struct flow *flow, - unsigned int *idxp) -{ - uint32_t *flow_u32 = (uint32_t *) flow; - - if (choose(FLOW_U32S - n_consecutive + 1, idxp)) { - int i; - - for (i = 0; i < n_consecutive; i++) { - flow_u32[i + *idxp] = random_value(); - } - return true; - } else { - return false; - } -} - -static bool -next_random_flow(struct flow *flow, unsigned int idx) -{ - uint32_t *flow_u32 = (uint32_t *) flow; - - memset(flow, 0, sizeof *flow); - - /* Empty flow. */ - if (choose(1, &idx)) { - return true; - } - - /* All flows with a small number of consecutive nonzero values. */ - for (int i = 1; i <= 4; i++) { - if (init_consecutive_values(i, flow, &idx)) { - return true; - } - } - - /* All flows with a large number of consecutive nonzero values. */ - for (int i = FLOW_U32S - 4; i <= FLOW_U32S; i++) { - if (init_consecutive_values(i, flow, &idx)) { - return true; - } - } - - /* All flows with exactly two nonconsecutive nonzero values. */ - if (choose((FLOW_U32S - 1) * (FLOW_U32S - 2) / 2, &idx)) { - int ofs1; - - for (ofs1 = 0; ofs1 < FLOW_U32S - 2; ofs1++) { - int ofs2; - - for (ofs2 = ofs1 + 2; ofs2 < FLOW_U32S; ofs2++) { - if (choose(1, &idx)) { - flow_u32[ofs1] = random_value(); - flow_u32[ofs2] = random_value(); - return true; - } - } - } - OVS_NOT_REACHED(); - } - - /* 16 randomly chosen flows with N >= 3 nonzero values. */ - if (choose(16 * (FLOW_U32S - 4), &idx)) { - int n = idx / 16 + 3; - - for (int i = 0; i < n; i++) { - flow_u32[i] = random_value(); - } - shuffle_u32s(flow_u32, FLOW_U32S); - - return true; - } - - return false; -} - -static void -any_random_flow(struct flow *flow) -{ - static unsigned int max; - if (!max) { - while (next_random_flow(flow, max)) { - max++; - } - } - - next_random_flow(flow, random_range(max)); -} - static void toggle_masked_flow_bits(struct flow *flow, const struct flow_wildcards *mask) { @@ -251,12 +129,15 @@ test_miniflow(struct flow *flow) /* Check that masked matches work as expected for identical flows and * miniflows. */ - do { - next_random_flow(&mask.masks, 1); - } while (flow_wildcards_is_catchall(&mask)); + flow_wildcards_init_for_packet(&mask, flow); + /* Ensure that mask is not catchall just in case + * flow_wildcards_init_for_packet returns a catchall mask + */ + uint64_t *mask_u64 = (uint64_t *) &mask.masks; + mask_u64[0] = 1; + ovs_assert(!flow_wildcards_is_catchall(&mask)); minimask = minimask_create(&mask); - ovs_assert(minimask_is_catchall(minimask) - == flow_wildcards_is_catchall(&mask)); + ovs_assert(!minimask_is_catchall(minimask)); ovs_assert(miniflow_equal_in_minimask(miniflow, miniflow2, minimask)); ovs_assert(miniflow_equal_flow_in_minimask(miniflow, &flow2, minimask)); ovs_assert(miniflow_hash_in_minimask(miniflow, minimask, 0x12345678) == @@ -325,7 +206,7 @@ test_minimask_combine(struct flow *flow) struct minimask minicombined; uint64_t storage[FLOW_U64S]; } m; - struct flow flow2; + struct flow flow2 = {0}; mask.masks = *flow; minimask = minimask_create(&mask); @@ -333,7 +214,7 @@ test_minimask_combine(struct flow *flow) minimask_combine(&m.minicombined, minimask, minicatchall, m.storage); ovs_assert(minimask_is_catchall(&m.minicombined)); - any_random_flow(&flow2); + /* Create mask based on zero flow */ mask2.masks = flow2; minimask2 = minimask_create(&mask2);