Commit f4f7a6ef authored by zmo@google.com's avatar zmo@google.com

Add key pixel check option in GpuPixelBrowserTest.

BUG=122861
TEST=gpu bots
Review URL: https://chromiumcodereview.appspot.com/10829432

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152378 0039d316-1c4b-4281-b951-d872f2087c98
parent 7c6e1fa2
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
...@@ -35,6 +36,17 @@ ...@@ -35,6 +36,17 @@
namespace { namespace {
enum ReferenceImageOption {
kReferenceImageLocal,
kReferenceImageCheckedIn,
kReferenceImageNone // Only check a few key pixels.
};
struct ReferencePixel {
int x, y;
unsigned char r, g, b;
};
// Command line flag for overriding the default location for putting generated // Command line flag for overriding the default location for putting generated
// test images that do not match references. // test images that do not match references.
const char kGeneratedDir[] = "generated-dir"; const char kGeneratedDir[] = "generated-dir";
...@@ -92,7 +104,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -92,7 +104,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
GpuPixelBrowserTest() GpuPixelBrowserTest()
: ref_img_revision_(0), : ref_img_revision_(0),
ref_img_revision_no_older_than_(0), ref_img_revision_no_older_than_(0),
use_checked_in_ref_imgs_(false) { ref_img_option_(kReferenceImageNone) {
} }
virtual void SetUpCommandLine(CommandLine* command_line) { virtual void SetUpCommandLine(CommandLine* command_line) {
...@@ -103,25 +115,31 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -103,25 +115,31 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
virtual void SetUpInProcessBrowserTestFixture() { virtual void SetUpInProcessBrowserTestFixture() {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kUseGpuInTests))
ref_img_option_ = kReferenceImageLocal;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
test_data_dir_ = test_data_dir_.AppendASCII("gpu"); test_data_dir_ = test_data_dir_.AppendASCII("gpu");
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(kGeneratedDir)) if (command_line->HasSwitch(kGeneratedDir))
generated_img_dir_ = command_line->GetSwitchValuePath(kGeneratedDir); generated_img_dir_ = command_line->GetSwitchValuePath(kGeneratedDir);
else else
generated_img_dir_ = test_data_dir_.AppendASCII("generated"); generated_img_dir_ = test_data_dir_.AppendASCII("generated");
if (command_line->HasSwitch(kReferenceDir))
ref_img_dir_ = command_line->GetSwitchValuePath(kReferenceDir);
else if (!command_line->HasSwitch(switches::kUseGpuInTests))
ref_img_dir_ = test_data_dir_.AppendASCII("llvmpipe_reference");
else
ref_img_dir_ = test_data_dir_.AppendASCII("gpu_reference");
// Only use checked in ref images when using a software rasterizer as switch (ref_img_option_) {
// all machines should generate the same output with a software rasterizer. case kReferenceImageLocal:
use_checked_in_ref_imgs_ = !command_line->HasSwitch( if (command_line->HasSwitch(kReferenceDir))
switches::kUseGpuInTests); ref_img_dir_ = command_line->GetSwitchValuePath(kReferenceDir);
else
ref_img_dir_ = test_data_dir_.AppendASCII("gpu_reference");
break;
case kReferenceImageCheckedIn:
ref_img_dir_ = test_data_dir_.AppendASCII("llvmpipe_reference");
break;
default:
break;
}
test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name(); test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name();
const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"}; const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"};
...@@ -137,8 +155,10 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -137,8 +155,10 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
// ref_img_update_revision, refresh the ref image. // ref_img_update_revision, refresh the ref image.
void RunPixelTest(const gfx::Size& tab_container_size, void RunPixelTest(const gfx::Size& tab_container_size,
const FilePath& url, const FilePath& url,
int64 ref_img_update_revision) { int64 ref_img_update_revision,
if (!use_checked_in_ref_imgs_) { const ReferencePixel* ref_pixels,
size_t ref_pixel_count) {
if (ref_img_option_ == kReferenceImageLocal) {
ref_img_revision_no_older_than_ = ref_img_update_revision; ref_img_revision_no_older_than_ = ref_img_update_revision;
ObtainLocalRefImageRevision(); ObtainLocalRefImageRevision();
} }
...@@ -186,15 +206,19 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -186,15 +206,19 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
SkBitmap bitmap; SkBitmap bitmap;
ASSERT_TRUE(TabSnapShotToImage(&bitmap)); ASSERT_TRUE(TabSnapShotToImage(&bitmap));
bool is_image_same = CompareImages(bitmap, ignore_bottom_corners); bool same_pixels = true;
EXPECT_TRUE(is_image_same); if (ref_img_option_ == kReferenceImageNone && ref_pixels && ref_pixel_count)
same_pixels = ComparePixels(bitmap, ref_pixels, ref_pixel_count);
else
same_pixels = CompareImages(bitmap, ignore_bottom_corners);
EXPECT_TRUE(same_pixels);
#if defined(OS_WIN) #if defined(OS_WIN)
// For debugging the flaky test, this prints out a trace of what happened on // For debugging the flaky test, this prints out a trace of what happened on
// failure. // failure.
std::string trace_events; std::string trace_events;
ASSERT_TRUE(tracing::EndTracing(&trace_events)); ASSERT_TRUE(tracing::EndTracing(&trace_events));
if (!is_image_same) if (!same_pixels)
fprintf(stderr, "\n\nTRACE JSON:\n\n%s\n\n", trace_events.c_str()); fprintf(stderr, "\n\nTRACE JSON:\n\n%s\n\n", trace_events.c_str());
#endif #endif
} }
...@@ -214,8 +238,9 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -214,8 +238,9 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
// Any local ref image generated from older revision is ignored. // Any local ref image generated from older revision is ignored.
int64 ref_img_revision_no_older_than_; int64 ref_img_revision_no_older_than_;
// If true, the test will use checked in reference images. // Whether use locally generated ref images, or checked in ref images, or
bool use_checked_in_ref_imgs_; // simply check a few key pixels.
ReferenceImageOption ref_img_option_;
// Compares the generated bitmap with the appropriate reference image on disk. // Compares the generated bitmap with the appropriate reference image on disk.
// Returns true iff the images were the same. // Returns true iff the images were the same.
...@@ -238,7 +263,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -238,7 +263,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
FilePath img_path = ref_img_dir_.AppendASCII(test_name_ + ".png"); FilePath img_path = ref_img_dir_.AppendASCII(test_name_ + ".png");
bool found_ref_img = ReadPNGFile(img_path, &ref_bmp_on_disk); bool found_ref_img = ReadPNGFile(img_path, &ref_bmp_on_disk);
if (!found_ref_img && use_checked_in_ref_imgs_) { if (!found_ref_img && ref_img_option_ == kReferenceImageCheckedIn) {
LOG(ERROR) << "Couldn't find reference image: " LOG(ERROR) << "Couldn't find reference image: "
<< img_path.value(); << img_path.value();
// No image to compare to, exit early. // No image to compare to, exit early.
...@@ -250,7 +275,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -250,7 +275,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
bool save_diff = true; bool save_diff = true;
bool rt = true; bool rt = true;
if ((ref_img_revision_ <= 0 && !use_checked_in_ref_imgs_) || if ((ref_img_revision_ <= 0 && ref_img_option_ == kReferenceImageLocal) ||
!found_ref_img) { !found_ref_img) {
chrome::VersionInfo chrome_version_info; chrome::VersionInfo chrome_version_info;
FilePath rev_path = ref_img_dir_.AppendASCII( FilePath rev_path = ref_img_dir_.AppendASCII(
...@@ -298,7 +323,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -298,7 +323,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
<< "(" << ref_bmp->width() << "x" << ref_bmp->height() << "(" << ref_bmp->width() << "x" << ref_bmp->height()
<< ") vs. " << ") vs. "
<< "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")"; << "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")";
if (!use_checked_in_ref_imgs_) if (ref_img_option_ == kReferenceImageLocal)
save_gen = true; save_gen = true;
rt = false; rt = false;
} else { } else {
...@@ -333,7 +358,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -333,7 +358,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
if (diff_pixels_count > 0) { if (diff_pixels_count > 0) {
LOG(ERROR) << diff_pixels_count LOG(ERROR) << diff_pixels_count
<< " pixels do not match."; << " pixels do not match.";
if (!use_checked_in_ref_imgs_) { if (ref_img_option_ == kReferenceImageLocal) {
save_gen = true; save_gen = true;
save_diff = true; save_diff = true;
} }
...@@ -367,6 +392,34 @@ class GpuPixelBrowserTest : public InProcessBrowserTest { ...@@ -367,6 +392,34 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
return rt; return rt;
} }
bool ComparePixels(const SkBitmap& gen_bmp,
const ReferencePixel* ref_pixels,
size_t ref_pixel_count) {
SkAutoLockPixels lock_bmp(gen_bmp);
for (size_t i = 0; i < ref_pixel_count; ++i) {
int x = ref_pixels[i].x;
int y = ref_pixels[i].y;
unsigned char r = ref_pixels[i].r;
unsigned char g = ref_pixels[i].g;
unsigned char b = ref_pixels[i].b;
DCHECK(x >= 0 && x < gen_bmp.width() && y >= 0 && y < gen_bmp.height());
unsigned char* rgba = reinterpret_cast<unsigned char*>(
gen_bmp.getAddr32(x, y));
DCHECK(rgba);
if (rgba[0] != b || rgba[1] != g || rgba[2] != r) {
std::string error_message = base::StringPrintf(
"pixel(%d,%d) expects [%u,%u,%u], but gets [%u,%u,%u] instead",
x, y, r, g, b, rgba[0], rgba[1], rgba[2]);
LOG(ERROR) << error_message.c_str();
return false;
}
}
return true;
}
// Returns a gfx::Rect representing the bounds that the browser window should // Returns a gfx::Rect representing the bounds that the browser window should
// have if the tab contents have the desired size. // have if the tab contents have the desired size.
gfx::Rect GetNewTabContainerBounds(const gfx::Size& desired_size) { gfx::Rect GetNewTabContainerBounds(const gfx::Size& desired_size) {
...@@ -469,10 +522,22 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_WebGLGreenTriangle) { ...@@ -469,10 +522,22 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_WebGLGreenTriangle) {
// following number. If no revision requirement, then 0. // following number. If no revision requirement, then 0.
const int64 ref_img_revision_update = 123489; const int64 ref_img_revision_update = 123489;
const ReferencePixel ref_pixels[] = {
// x, y, r, g, b
{50, 100, 0, 0, 0},
{100, 100, 0, 255, 0},
{150, 100, 0, 0, 0},
{50, 150, 0, 255, 0},
{100, 150, 0, 255, 0},
{150, 150, 0, 255, 0}
};
const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel);
gfx::Size container_size(400, 300); gfx::Size container_size(400, 300);
FilePath url = FilePath url =
test_data_dir().AppendASCII("pixel_webgl.html"); test_data_dir().AppendASCII("pixel_webgl.html");
RunPixelTest(container_size, url, ref_img_revision_update); RunPixelTest(container_size, url, ref_img_revision_update,
ref_pixels, ref_pixel_count);
} }
IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_CSS3DBlueBox) { IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_CSS3DBlueBox) {
...@@ -480,10 +545,22 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_CSS3DBlueBox) { ...@@ -480,10 +545,22 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_CSS3DBlueBox) {
// following number. If no revision requirement, then 0. // following number. If no revision requirement, then 0.
const int64 ref_img_revision_update = 123489; const int64 ref_img_revision_update = 123489;
const ReferencePixel ref_pixels[] = {
// x, y, r, g, b
{70, 50, 0, 0, 255},
{150, 50, 0, 0, 0},
{70, 90, 0, 0, 255},
{150, 90, 0, 0, 255},
{70, 125, 0, 0, 255},
{150, 125, 0, 0, 0}
};
const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel);
gfx::Size container_size(400, 300); gfx::Size container_size(400, 300);
FilePath url = FilePath url =
test_data_dir().AppendASCII("pixel_css3d.html"); test_data_dir().AppendASCII("pixel_css3d.html");
RunPixelTest(container_size, url, ref_img_revision_update); RunPixelTest(container_size, url, ref_img_revision_update,
ref_pixels, ref_pixel_count);
} }
IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, Canvas2DRedBoxHD) { IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, Canvas2DRedBoxHD) {
...@@ -491,10 +568,20 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, Canvas2DRedBoxHD) { ...@@ -491,10 +568,20 @@ IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, Canvas2DRedBoxHD) {
// following number. If no revision requirement, then 0. // following number. If no revision requirement, then 0.
const int64 ref_img_revision_update = 123489; const int64 ref_img_revision_update = 123489;
const ReferencePixel ref_pixels[] = {
// x, y, r, g, b
{40, 100, 0, 0, 0},
{60, 100, 127, 0, 0},
{140, 100, 127, 0, 0},
{160, 100, 0, 0, 0}
};
const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel);
gfx::Size container_size(400, 300); gfx::Size container_size(400, 300);
FilePath url = FilePath url =
test_data_dir().AppendASCII("pixel_canvas2d.html"); test_data_dir().AppendASCII("pixel_canvas2d.html");
RunPixelTest(container_size, url, ref_img_revision_update); RunPixelTest(container_size, url, ref_img_revision_update,
ref_pixels, ref_pixel_count);
} }
class Canvas2DPixelTestSD : public GpuPixelBrowserTest { class Canvas2DPixelTestSD : public GpuPixelBrowserTest {
...@@ -510,8 +597,18 @@ IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, Canvas2DRedBoxSD) { ...@@ -510,8 +597,18 @@ IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, Canvas2DRedBoxSD) {
// following number. If no revision requirement, then 0. // following number. If no revision requirement, then 0.
const int64 ref_img_revision_update = 123489; const int64 ref_img_revision_update = 123489;
const ReferencePixel ref_pixels[] = {
// x, y, r, g, b
{40, 100, 0, 0, 0},
{60, 100, 127, 0, 0},
{140, 100, 127, 0, 0},
{160, 100, 0, 0, 0}
};
const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel);
gfx::Size container_size(400, 300); gfx::Size container_size(400, 300);
FilePath url = FilePath url =
test_data_dir().AppendASCII("pixel_canvas2d.html"); test_data_dir().AppendASCII("pixel_canvas2d.html");
RunPixelTest(container_size, url, ref_img_revision_update); RunPixelTest(container_size, url, ref_img_revision_update,
ref_pixels, ref_pixel_count);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment