Message ID | 20180226061854.20061-1-rhyskidd@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hey Rhys, Pushed! Change-ID tag was dropped. Rob. On 02/26/2018 07:18 AM, Rhys Kidd wrote: > 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 <rhyskidd@gmail.com> > --- > 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<Rect<int>> &in, > } > > } // namespace separate_rects > - > -#ifdef RECTS_TEST > - > -using namespace separate_rects; > - > -int main(int argc, char **argv) { > -#define RectSet RectSet<TId, TNum> > -#define Rect Rect<TNum> > -#define IdSet IdSet<TId> > - typedef uint64_t TId; > - typedef float TNum; > - > - std::vector<Rect> in; > - std::vector<RectSet> out; > - std::vector<RectSet> 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 <gtest/gtest.h> > +#include <hardware/hardware.h> > + > +#include "separate_rects.h" > + > +using namespace separate_rects; > + > +#define RectSet RectSet<TId, TNum> > +#define Rect Rect<TNum> > +#define IdSet IdSet<TId> > +typedef uint64_t TId; > +typedef float TNum; > + > +struct SeparateRectTest : public testing::Test { > + bool IsEquality(std::vector<RectSet> &out, > + std::vector<RectSet> &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<Rect> in; > + std::vector<RectSet> out; > + std::vector<RectSet> 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)); > +} >
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<Rect<int>> &in, } } // namespace separate_rects - -#ifdef RECTS_TEST - -using namespace separate_rects; - -int main(int argc, char **argv) { -#define RectSet RectSet<TId, TNum> -#define Rect Rect<TNum> -#define IdSet IdSet<TId> - typedef uint64_t TId; - typedef float TNum; - - std::vector<Rect> in; - std::vector<RectSet> out; - std::vector<RectSet> 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 <gtest/gtest.h> +#include <hardware/hardware.h> + +#include "separate_rects.h" + +using namespace separate_rects; + +#define RectSet RectSet<TId, TNum> +#define Rect Rect<TNum> +#define IdSet IdSet<TId> +typedef uint64_t TId; +typedef float TNum; + +struct SeparateRectTest : public testing::Test { + bool IsEquality(std::vector<RectSet> &out, + std::vector<RectSet> &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<Rect> in; + std::vector<RectSet> out; + std::vector<RectSet> 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)); +}
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 <rhyskidd@gmail.com> --- 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