Commit 07e4c76d authored by Sven Zheng's avatar Sven Zheng Committed by Commit Bot

Adds dryrun mode for Gold pixel diff

For local development, test owner don't need to actually upload anything.

Bug: 1145334
Change-Id: I2b7f2808d6bc10c7e6dbcfb99805ea52d2b3f152
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522611Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Commit-Queue: Sven Zheng <svenzheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824720}
parent 37e0b5b5
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
...@@ -55,6 +56,7 @@ const char* kCodeReviewSystemKey = "code-review-system"; ...@@ -55,6 +56,7 @@ const char* kCodeReviewSystemKey = "code-review-system";
const char* kNoLuciAuth = "no-luci-auth"; const char* kNoLuciAuth = "no-luci-auth";
const char* kBypassSkiaGoldFunctionality = "bypass-skia-gold-functionality"; const char* kBypassSkiaGoldFunctionality = "bypass-skia-gold-functionality";
const char* kDryRun = "dryrun";
namespace { namespace {
...@@ -145,6 +147,12 @@ bool FillInTestEnvironment(const base::FilePath& keys_file) { ...@@ -145,6 +147,12 @@ bool FillInTestEnvironment(const base::FilePath& keys_file) {
return true; return true;
} }
bool BotModeEnabled(const base::CommandLine* command_line) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
return command_line->HasSwitch(switches::kTestLauncherBotMode) ||
env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE");
}
} // namespace } // namespace
SkiaGoldPixelDiff::SkiaGoldPixelDiff() = default; SkiaGoldPixelDiff::SkiaGoldPixelDiff() = default;
...@@ -245,8 +253,7 @@ void SkiaGoldPixelDiff::Init(const std::string& screenshot_prefix, ...@@ -245,8 +253,7 @@ void SkiaGoldPixelDiff::Init(const std::string& screenshot_prefix,
code_review_system_ = "gerrit"; code_review_system_ = "gerrit";
} }
} }
if (cmd_line->HasSwitch(kNoLuciAuth) || if (cmd_line->HasSwitch(kNoLuciAuth) || !BotModeEnabled(cmd_line)) {
!cmd_line->HasSwitch(switches::kTestLauncherBotMode)) {
luci_auth_ = false; luci_auth_ = false;
} }
initialized_ = true; initialized_ = true;
...@@ -277,6 +284,10 @@ bool SkiaGoldPixelDiff::UploadToSkiaGoldServer( ...@@ -277,6 +284,10 @@ bool SkiaGoldPixelDiff::UploadToSkiaGoldServer(
cmd.AppendSwitchPath("png-file", local_file_path); cmd.AppendSwitchPath("png-file", local_file_path);
cmd.AppendSwitchPath("work-dir", working_dir_); cmd.AppendSwitchPath("work-dir", working_dir_);
if (!BotModeEnabled(base::CommandLine::ForCurrentProcess())) {
cmd.AppendSwitch(kDryRun);
}
std::map<std::string, std::string> optional_keys; std::map<std::string, std::string> optional_keys;
if (!ShouldMakeGerritCommentsOnFailures()) { if (!ShouldMakeGerritCommentsOnFailures()) {
optional_keys["ignore"] = "1"; optional_keys["ignore"] = "1";
......
...@@ -346,5 +346,36 @@ TEST_F(SkiaGoldPixelDiffTest, MakeGerritCommentInvalidFlag) { ...@@ -346,5 +346,36 @@ TEST_F(SkiaGoldPixelDiffTest, MakeGerritCommentInvalidFlag) {
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
} }
TEST_F(SkiaGoldPixelDiffTest, DryRunLocally) {
auto* cmd_line = base::CommandLine::ForCurrentProcess();
cmd_line->RemoveSwitch(switches::kTestLauncherBotMode);
MockSkiaGoldPixelDiff mock_pixel;
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(AnyNumber());
EXPECT_CALL(
mock_pixel,
LaunchProcess(AllOf(Property(&base::CommandLine::GetCommandLineString,
HasSubstr(FILE_PATH_LITERAL("--dryrun"))))))
.Times(1);
mock_pixel.Init("Prefix");
bool ret = mock_pixel.CompareScreenshot("test", GetTestBitmap());
EXPECT_TRUE(ret);
}
TEST_F(SkiaGoldPixelDiffTest, NotDryRunOnBots) {
auto* cmd_line = base::CommandLine::ForCurrentProcess();
cmd_line->AppendSwitch(switches::kTestLauncherBotMode);
MockSkiaGoldPixelDiff mock_pixel;
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(AnyNumber());
EXPECT_CALL(mock_pixel, LaunchProcess(AllOf(Property(
&base::CommandLine::GetCommandLineString,
Not(HasSubstr(FILE_PATH_LITERAL("--dryrun")))))))
.Times(3);
mock_pixel.Init("Prefix");
bool ret = mock_pixel.CompareScreenshot("test", GetTestBitmap());
EXPECT_TRUE(ret);
}
} // namespace test } // namespace test
} // namespace ui } // namespace ui
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