From patchwork Mon Feb 26 06:18:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rhys Kidd X-Patchwork-Id: 10241643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D67BB60211 for ; Mon, 26 Feb 2018 08:44:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C90DF29D0E for ; Mon, 26 Feb 2018 08:44:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD68229D29; Mon, 26 Feb 2018 08:44:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 00F0929D0E for ; Mon, 26 Feb 2018 08:44:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D4CD6E3F6; Mon, 26 Feb 2018 08:43:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C74C6E1DC for ; Mon, 26 Feb 2018 06:19:05 +0000 (UTC) Received: by mail-qt0-x241.google.com with SMTP id m13so12821906qtg.13 for ; Sun, 25 Feb 2018 22:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=auENE0x6eIwivrR1H3zB46ftp3+1F+Y7UZvu2E6uXmY=; b=Q2q3TyoAJnnq8KwuSPb9Ji2ImBoGLaYhaN5xObliwtm+ydYSwNRTy7lm4IcjWBmU99 p633bdL8IfHO9QASYlj75ytG0QaO/0dHXLek5T2D9awQlo3+VXXUzUDbHR1ylZZyX5MY 3U4A6OE89kmCJdmg26zP+HXmNtZ5sSDhWOFsDNzWJdAhgqCvKa5w9pxEi4c/WTrBvAxH WChASRWqxmh9QqYUYFeJTvKPxhSJ2Odp6VBn/aEpPyogsK81i4denkQ2jBC9CO+ywK7j hji9MKv0QRpdN68vxZO9bhjne+FcvCtYExKRDtcsrTZRKnrmuoGeQZTwaOQNTaY4CyUi K5WA== 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=auENE0x6eIwivrR1H3zB46ftp3+1F+Y7UZvu2E6uXmY=; b=MIaNwjsRSibJomnESGjxGKumORtcKalkK85N7NEKpceDchQC5x2us0MHjHcLC6ET5B 2KmR+KyxkGABJo1VaaFnI5xq9ofdpVdjWSj7DwJ1SvuwoAif5KfdpxQedY57JkkVHy3l 2dBnJwp5mNXYOvbdy7KnnbrhcSl7DmMXSYzRSDrIH6GzbMwwZOMsq2ZfVTkRF9XIfRYn tr91f7Zd7jx8GPBkmNFKpEdakMr5i5FTIowDM5/capYSlZ8FM4gQl5E34UcEpTNVNCyx RtBQHD99CYbZ295074XChAaSWl3nmXQIFu5tyxRInbNEUg607t47WgWbSMNiFm/SLKsI XFKQ== X-Gm-Message-State: APf1xPAzCPCEzuq1dXFJq518z8UWT44pzRT66cAMvqQmAic5tAisNuiE 5NHv80T3yxVr0ZGaczXXURG5ilSv X-Google-Smtp-Source: AG47ELvN3Wur3H8V/htqlNWT6EPJWc7ReMKGyM2wwFBfSegJJVgo8beNegsee1MKh5SVMMNaTSiqHw== X-Received: by 10.237.33.75 with SMTP id 69mr15201371qtc.21.1519625944448; Sun, 25 Feb 2018 22:19:04 -0800 (PST) Received: from xps9560.fios-router.home (pool-108-30-59-81.nycmny.fios.verizon.net. [108.30.59.81]) by smtp.gmail.com with ESMTPSA id x10sm4131514qkl.83.2018.02.25.22.19.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Feb 2018 22:19:04 -0800 (PST) From: Rhys Kidd To: dri-devel@lists.freedesktop.org Subject: [PATCH hwc RFC] drm_hwcomposer: Enable and refactor Separate Rects test Date: Mon, 26 Feb 2018 01:18:54 -0500 Message-Id: <20180226061854.20061-1-rhyskidd@gmail.com> X-Mailer: git-send-email 2.14.1 X-Mailman-Approved-At: Mon, 26 Feb 2018 08:43:04 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zachr@chromium.org, Robert Foss , marissaw@google.com, marcheu@chromium.org, Rhys Kidd MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Plumb through the existing test based on known sample data for the Separate Rect algorithm via Android's NATIVE_TEST harness. Change-Id: I82b5ab8ed97e338fd20b7e38b4b35ac8c53f4d2d Signed-off-by: Rhys Kidd --- separate_rects.cpp | 99 ----------------------------------------- tests/Android.mk | 2 + tests/separate_rects_test.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 99 deletions(-) create mode 100644 tests/separate_rects_test.cpp diff --git a/separate_rects.cpp b/separate_rects.cpp index 9fd1ae4..0e74cfc 100644 --- a/separate_rects.cpp +++ b/separate_rects.cpp @@ -315,102 +315,3 @@ void separate_rects_64(const std::vector> &in, } } // namespace separate_rects - -#ifdef RECTS_TEST - -using namespace separate_rects; - -int main(int argc, char **argv) { -#define RectSet RectSet -#define Rect Rect -#define IdSet IdSet - typedef uint64_t TId; - typedef float TNum; - - std::vector in; - std::vector out; - std::vector expected_out; - - in.push_back({0, 0, 4, 5}); - in.push_back({2, 0, 6, 6}); - in.push_back({4, 0, 8, 5}); - in.push_back({0, 7, 8, 9}); - - in.push_back({10, 0, 18, 5}); - in.push_back({12, 0, 16, 5}); - - in.push_back({20, 11, 24, 17}); - in.push_back({22, 13, 26, 21}); - in.push_back({32, 33, 36, 37}); - in.push_back({30, 31, 38, 39}); - - in.push_back({40, 43, 48, 45}); - in.push_back({44, 41, 46, 47}); - - in.push_back({50, 51, 52, 53}); - in.push_back({50, 51, 52, 53}); - in.push_back({50, 51, 52, 53}); - - in.push_back({0, 0, 0, 10}); - in.push_back({0, 0, 10, 0}); - in.push_back({10, 0, 0, 10}); - in.push_back({0, 10, 10, 0}); - - for (int i = 0; i < 100000; i++) { - out.clear(); - separate_rects(in, &out); - } - - for (int i = 0; i < out.size(); i++) { - std::cout << out[i].id_set << "(" << out[i].rect << ")" << std::endl; - } - - std::cout << "# of rects: " << out.size() << std::endl; - - expected_out.push_back(RectSet(IdSet(0), Rect(0, 0, 2, 5))); - expected_out.push_back(RectSet(IdSet(1), Rect(2, 5, 6, 6))); - expected_out.push_back(RectSet(IdSet(1) | 0, Rect(2, 0, 4, 5))); - expected_out.push_back(RectSet(IdSet(1) | 2, Rect(4, 0, 6, 5))); - expected_out.push_back(RectSet(IdSet(2), Rect(6, 0, 8, 5))); - expected_out.push_back(RectSet(IdSet(3), Rect(0, 7, 8, 9))); - expected_out.push_back(RectSet(IdSet(4), Rect(10, 0, 12, 5))); - expected_out.push_back(RectSet(IdSet(5) | 4, Rect(12, 0, 16, 5))); - expected_out.push_back(RectSet(IdSet(4), Rect(16, 0, 18, 5))); - expected_out.push_back(RectSet(IdSet(6), Rect(20, 11, 22, 17))); - expected_out.push_back(RectSet(IdSet(6) | 7, Rect(22, 13, 24, 17))); - expected_out.push_back(RectSet(IdSet(6), Rect(22, 11, 24, 13))); - expected_out.push_back(RectSet(IdSet(7), Rect(22, 17, 24, 21))); - expected_out.push_back(RectSet(IdSet(7), Rect(24, 13, 26, 21))); - expected_out.push_back(RectSet(IdSet(9), Rect(30, 31, 32, 39))); - expected_out.push_back(RectSet(IdSet(8) | 9, Rect(32, 33, 36, 37))); - expected_out.push_back(RectSet(IdSet(9), Rect(32, 37, 36, 39))); - expected_out.push_back(RectSet(IdSet(9), Rect(32, 31, 36, 33))); - expected_out.push_back(RectSet(IdSet(9), Rect(36, 31, 38, 39))); - expected_out.push_back(RectSet(IdSet(10), Rect(40, 43, 44, 45))); - expected_out.push_back(RectSet(IdSet(10) | 11, Rect(44, 43, 46, 45))); - expected_out.push_back(RectSet(IdSet(11), Rect(44, 41, 46, 43))); - expected_out.push_back(RectSet(IdSet(11), Rect(44, 45, 46, 47))); - expected_out.push_back(RectSet(IdSet(10), Rect(46, 43, 48, 45))); - expected_out.push_back(RectSet(IdSet(12) | 13 | 14, Rect(50, 51, 52, 53))); - - for (int i = 0; i < expected_out.size(); i++) { - RectSet &ex_out = expected_out[i]; - if (std::find(out.begin(), out.end(), ex_out) == out.end()) { - std::cout << "Missing Rect: " << ex_out.id_set << "(" << ex_out.rect - << ")" << std::endl; - } - } - - for (int i = 0; i < out.size(); i++) { - RectSet &actual_out = out[i]; - if (std::find(expected_out.begin(), expected_out.end(), actual_out) == - expected_out.end()) { - std::cout << "Extra Rect: " << actual_out.id_set << "(" << actual_out.rect - << ")" << std::endl; - } - } - - return 0; -} - -#endif diff --git a/tests/Android.mk b/tests/Android.mk index 5bbda93..3b9e0a2 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -3,10 +3,12 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := \ + separate_rects_test.cpp \ worker_test.cpp LOCAL_MODULE := hwc-drm-tests LOCAL_STATIC_LIBRARIES := libdrmhwc_utils +LOCAL_SHARED_LIBRARIES := hwcomposer.drm LOCAL_C_INCLUDES := external/drm_hwcomposer include $(BUILD_NATIVE_TEST) diff --git a/tests/separate_rects_test.cpp b/tests/separate_rects_test.cpp new file mode 100644 index 0000000..d9595dd --- /dev/null +++ b/tests/separate_rects_test.cpp @@ -0,0 +1,100 @@ +#include +#include + +#include "separate_rects.h" + +using namespace separate_rects; + +#define RectSet RectSet +#define Rect Rect +#define IdSet IdSet +typedef uint64_t TId; +typedef float TNum; + +struct SeparateRectTest : public testing::Test { + bool IsEquality(std::vector &out, + std::vector &expected_out) { + // Test for rects missing from out + for (size_t i = 0; i < expected_out.size(); i++) { + RectSet &ex_out = expected_out[i]; + if (std::find(out.begin(), out.end(), ex_out) == out.end()) { + return false; + } + } + + // Test for presence of unexpected rects in out + for (size_t i = 0; i < out.size(); i++) { + RectSet &actual_out = out[i]; + if (std::find(expected_out.begin(), expected_out.end(), actual_out) == + expected_out.end()) { + return false; + } + } + + return true; + } +}; + +TEST_F(SeparateRectTest, test_separate_rect) { + std::vector in; + std::vector out; + std::vector expected_out; + + in.push_back({0, 0, 4, 5}); + in.push_back({2, 0, 6, 6}); + in.push_back({4, 0, 8, 5}); + in.push_back({0, 7, 8, 9}); + + in.push_back({10, 0, 18, 5}); + in.push_back({12, 0, 16, 5}); + + in.push_back({20, 11, 24, 17}); + in.push_back({22, 13, 26, 21}); + in.push_back({32, 33, 36, 37}); + in.push_back({30, 31, 38, 39}); + + in.push_back({40, 43, 48, 45}); + in.push_back({44, 41, 46, 47}); + + in.push_back({50, 51, 52, 53}); + in.push_back({50, 51, 52, 53}); + in.push_back({50, 51, 52, 53}); + + in.push_back({0, 0, 0, 10}); + in.push_back({0, 0, 10, 0}); + in.push_back({10, 0, 0, 10}); + in.push_back({0, 10, 10, 0}); + + for (int i = 0; i < 100000; i++) { + out.clear(); + separate_frects_64(in, &out); + } + + expected_out.push_back(RectSet(IdSet(0), Rect(0, 0, 2, 5))); + expected_out.push_back(RectSet(IdSet(1), Rect(2, 5, 6, 6))); + expected_out.push_back(RectSet(IdSet(1) | 0, Rect(2, 0, 4, 5))); + expected_out.push_back(RectSet(IdSet(1) | 2, Rect(4, 0, 6, 5))); + expected_out.push_back(RectSet(IdSet(2), Rect(6, 0, 8, 5))); + expected_out.push_back(RectSet(IdSet(3), Rect(0, 7, 8, 9))); + expected_out.push_back(RectSet(IdSet(4), Rect(10, 0, 12, 5))); + expected_out.push_back(RectSet(IdSet(5) | 4, Rect(12, 0, 16, 5))); + expected_out.push_back(RectSet(IdSet(4), Rect(16, 0, 18, 5))); + expected_out.push_back(RectSet(IdSet(6), Rect(20, 11, 22, 17))); + expected_out.push_back(RectSet(IdSet(6) | 7, Rect(22, 13, 24, 17))); + expected_out.push_back(RectSet(IdSet(6), Rect(22, 11, 24, 13))); + expected_out.push_back(RectSet(IdSet(7), Rect(22, 17, 24, 21))); + expected_out.push_back(RectSet(IdSet(7), Rect(24, 13, 26, 21))); + expected_out.push_back(RectSet(IdSet(9), Rect(30, 31, 32, 39))); + expected_out.push_back(RectSet(IdSet(8) | 9, Rect(32, 33, 36, 37))); + expected_out.push_back(RectSet(IdSet(9), Rect(32, 37, 36, 39))); + expected_out.push_back(RectSet(IdSet(9), Rect(32, 31, 36, 33))); + expected_out.push_back(RectSet(IdSet(9), Rect(36, 31, 38, 39))); + expected_out.push_back(RectSet(IdSet(10), Rect(40, 43, 44, 45))); + expected_out.push_back(RectSet(IdSet(10) | 11, Rect(44, 43, 46, 45))); + expected_out.push_back(RectSet(IdSet(11), Rect(44, 41, 46, 43))); + expected_out.push_back(RectSet(IdSet(11), Rect(44, 45, 46, 47))); + expected_out.push_back(RectSet(IdSet(10), Rect(46, 43, 48, 45))); + expected_out.push_back(RectSet(IdSet(12) | 13 | 14, Rect(50, 51, 52, 53))); + + ASSERT_TRUE(IsEquality(out, expected_out)); +}