From 7b99f783525afe9380392e2e8cef692a0fadbfbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 5 Jul 2019 11:41:03 +0200 Subject: [PATCH] [post_and_hardware_tests] Bad pixels limit of 2, not 0 --- apps/shared/post_and_hardware_tests.cpp | 10 ++++++++-- apps/shared/post_and_hardware_tests.h | 1 + kandinsky/include/kandinsky/context.h | 4 ++-- kandinsky/src/context_text.cpp | 15 +++++++-------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/shared/post_and_hardware_tests.cpp b/apps/shared/post_and_hardware_tests.cpp index 414898af0..b0ac06ca0 100644 --- a/apps/shared/post_and_hardware_tests.cpp +++ b/apps/shared/post_and_hardware_tests.cpp @@ -29,8 +29,10 @@ bool POSTAndHardwareTests::TextLCDTestOK() { KDIonContext::sharedContext()->drawString(text, KDPoint(0, i * glyphHeight), font); } // Check the drawing + int numberOfFailures = 0; for (int i = 0; i < Ion::Display::Height / glyphHeight; i++) { - if (!KDIonContext::sharedContext()->checkDrawnString(text, KDPoint(0, i * glyphHeight), font)) { + numberOfFailures += KDIonContext::sharedContext()->checkDrawnString(text, KDPoint(0, i * glyphHeight), font); + if (numberOfFailures > k_acceptableNumberOfFailures) { return false; } } @@ -49,6 +51,7 @@ bool POSTAndHardwareTests::LCDDataOK() { bool POSTAndHardwareTests::TilingLCDTestOK() { Ion::Display::POSTPushMulticolor(k_stampSize); KDColor stamp[k_stampSize*k_stampSize]; + int numberOfFailures = 0; for (int i = 0; i < Ion::Display::Width / k_stampSize; i++) { for (int j = 0; j < Ion::Display::Height / k_stampSize; j++) { Ion::Display::pullRect(KDRect(i * k_stampSize, j * k_stampSize, k_stampSize, k_stampSize), stamp); @@ -56,7 +59,10 @@ bool POSTAndHardwareTests::TilingLCDTestOK() { uint16_t color = (uint16_t)(1 << shift); for (int k = 0; k < k_stampSize*k_stampSize; k++) { if (stamp[k] != color) { - return false; + numberOfFailures++; + if (numberOfFailures > k_acceptableNumberOfFailures) { + return false; + } } color ^= 0xFFFF; } diff --git a/apps/shared/post_and_hardware_tests.h b/apps/shared/post_and_hardware_tests.h index af01f0341..87fe04af0 100644 --- a/apps/shared/post_and_hardware_tests.h +++ b/apps/shared/post_and_hardware_tests.h @@ -23,6 +23,7 @@ public: private: constexpr static int k_stampSize = 8; constexpr static int k_numberOfLCDIterations = 20; + constexpr static int k_acceptableNumberOfFailures = 2; static bool TilingLCDTestOK(); static_assert(Ion::Display::Width % k_stampSize == 0, "Stamps must tesselate the display"); static_assert(Ion::Display::Height % k_stampSize == 0, "Stamps must tesselate the display"); diff --git a/kandinsky/include/kandinsky/context.h b/kandinsky/include/kandinsky/context.h index b18a19e75..684be6cf3 100644 --- a/kandinsky/include/kandinsky/context.h +++ b/kandinsky/include/kandinsky/context.h @@ -18,7 +18,7 @@ public: // Text KDPoint drawString(const char * text, KDPoint p, const KDFont * font = KDFont::LargeFont, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite, int maxLength = -1); // Check that a string is drawn. - bool checkDrawnString(const char * text, KDPoint p, const KDFont * font = KDFont::LargeFont, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite, int maxLength = -1); + int checkDrawnString(const char * text, KDPoint p, const KDFont * font = KDFont::LargeFont, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite, int maxLength = -1); // Line. Not anti-aliased. void drawLine(KDPoint p1, KDPoint p2, KDColor c); @@ -35,7 +35,7 @@ protected: virtual void pullRect(KDRect rect, KDColor * pixels) = 0; private: KDRect absoluteFillRect(KDRect rect); - KDPoint pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, bool * result = nullptr); + KDPoint pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, int * result = nullptr); KDPoint m_origin; KDRect m_clippingRect; }; diff --git a/kandinsky/src/context_text.cpp b/kandinsky/src/context_text.cpp index 22050b3a6..5420db940 100644 --- a/kandinsky/src/context_text.cpp +++ b/kandinsky/src/context_text.cpp @@ -10,13 +10,13 @@ KDPoint KDContext::drawString(const char * text, KDPoint p, const KDFont * font, return pushOrPullString(text, p, font, textColor, backgroundColor, maxByteLength, true); } -bool KDContext::checkDrawnString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxLength) { - bool result = true; - pushOrPullString(text, p, font, textColor, backgroundColor, maxLength, false, &result); - return result; +int KDContext::checkDrawnString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxLength) { + int numberOfFailedPixels = 0; + pushOrPullString(text, p, font, textColor, backgroundColor, maxLength, false, &numberOfFailedPixels); + return numberOfFailedPixels; } -KDPoint KDContext::pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, bool * result) { +KDPoint KDContext::pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, int * result) { KDPoint position = p; KDSize glyphSize = font->glyphSize(); KDFont::RenderPalette palette = font->renderPalette(textColor, backgroundColor); @@ -53,7 +53,7 @@ KDPoint KDContext::pushOrPullString(const char * text, KDPoint p, const KDFont * } else { // Pull and compare the character from the screen assert(result != nullptr); - *result = true; + *result = 0; KDFont::GlyphBuffer workingGlyphBuffer; KDColor * workingColorBuffer = workingGlyphBuffer.colorBuffer(); KDColor * colorBuffer = glyphBuffer.colorBuffer(); @@ -65,8 +65,7 @@ KDPoint KDContext::pushOrPullString(const char * text, KDPoint p, const KDFont * Ion::Display::pullRect(KDRect(position, glyphSize), workingColorBuffer); for (int k = 0; k < glyphSize.height() * glyphSize.width(); k++) { if (colorBuffer[k] != workingColorBuffer[k]) { - *result = false; - return position; + *result = (*result)+1; } } }