Commit 55e0048a authored by David Staessens's avatar David Staessens Committed by Commit Bot

media/gpu: Add parameter to JPEG decode test to overwrite default test data dir.

When the HW JPEG decode tests are run by the Tast test framework, the location
of the test file directory will vary. This CL adds the '--test_data_path'
parameter to the test binary, so Tast can overwrite the default test file path.

TEST=ran JPEG decode tests on eve

BUG=899604

Change-Id: I7f242eb4356445a3bc3bb44a9d40221009343c7e
Reviewed-on: https://chromium-review.googlesource.com/c/1328063
Commit-Queue: David Staessens <dstaessens@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607142}
parent 38242dea
......@@ -151,15 +151,20 @@ class JpegDecodeAcceleratorTestEnvironment : public ::testing::Environment {
public:
JpegDecodeAcceleratorTestEnvironment(
const base::FilePath::CharType* jpeg_filenames,
const base::FilePath::CharType* test_data_path,
int perf_decode_times)
: perf_decode_times_(perf_decode_times ? perf_decode_times
: kDefaultPerfDecodeTimes),
user_jpeg_filenames_(jpeg_filenames ? jpeg_filenames
: kDefaultJpegFilename) {}
: kDefaultJpegFilename),
test_data_path_(test_data_path) {}
void SetUp() override;
// Creates and returns a FilePath for the pathless |name|. The current folder
// is used if |name| exists in it, otherwise //media/test/data is used.
// is used if |name| exists in it. If not the file will be treated as relative
// to the test data path. This is either a custom test data path provided by
// --test_data_path, or the default test data path (//media/test/data).
base::FilePath GetOriginalOrTestDataFilePath(const std::string& name) {
LOG_ASSERT(std::find_if(name.begin(), name.end(),
base::FilePath::IsSeparator) == name.end())
......@@ -167,6 +172,8 @@ class JpegDecodeAcceleratorTestEnvironment : public ::testing::Environment {
const base::FilePath original_file_path = base::FilePath(name);
if (base::PathExists(original_file_path))
return original_file_path;
if (test_data_path_)
return base::FilePath(test_data_path_).Append(original_file_path);
return GetTestDataFilePath(name);
}
......@@ -193,6 +200,7 @@ class JpegDecodeAcceleratorTestEnvironment : public ::testing::Environment {
private:
const base::FilePath::CharType* user_jpeg_filenames_;
const base::FilePath::CharType* test_data_path_;
};
void JpegDecodeAcceleratorTestEnvironment::SetUp() {
......@@ -853,6 +861,7 @@ int main(int argc, char** argv) {
DCHECK(cmd_line);
const base::FilePath::CharType* jpeg_filenames = nullptr;
const base::FilePath::CharType* test_data_path = nullptr;
int perf_decode_times = 0;
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
......@@ -862,6 +871,10 @@ int main(int argc, char** argv) {
jpeg_filenames = it->second.c_str();
continue;
}
if (it->first == "test_data_path") {
test_data_path = it->second.c_str();
continue;
}
if (it->first == "perf_decode_times") {
perf_decode_times = std::stoi(it->second);
continue;
......@@ -883,8 +896,8 @@ int main(int argc, char** argv) {
media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>(
testing::AddGlobalTestEnvironment(
new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames,
perf_decode_times)));
new media::JpegDecodeAcceleratorTestEnvironment(
jpeg_filenames, test_data_path, perf_decode_times)));
return RUN_ALL_TESTS();
}
......@@ -13,6 +13,7 @@
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/md5.h"
......@@ -44,14 +45,6 @@ void LogOnError() {
LOG(FATAL) << "Oh noes! Decoder failed";
}
// Find the location of the specified test file. If a file with specified path
// is not found, treat the path as being relative to the standard test file
// directory.
base::FilePath FindTestDataFilePath(const std::string& file_name) {
base::FilePath file_path = base::FilePath(file_name);
return PathExists(file_path) ? file_path : GetTestDataFilePath(file_name);
}
uint32_t GetVASurfaceFormat() {
if (VaapiWrapper::IsImageFormatSupported(kImageFormatI420))
return VA_RT_FORMAT_YUV420;
......@@ -76,7 +69,12 @@ VAImageFormat GetVAImageFormat() {
class VaapiJpegDecodeAcceleratorTest : public ::testing::Test {
protected:
VaapiJpegDecodeAcceleratorTest() {}
VaapiJpegDecodeAcceleratorTest() {
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (cmd_line && cmd_line->HasSwitch("test_data_path")) {
test_data_path_ = cmd_line->GetSwitchValueASCII("test_data_path");
}
}
void SetUp() override {
base::RepeatingClosure report_error_cb = base::BindRepeating(&LogOnError);
......@@ -84,14 +82,18 @@ class VaapiJpegDecodeAcceleratorTest : public ::testing::Test {
VAProfileJPEGBaseline, report_error_cb);
ASSERT_TRUE(wrapper_);
base::FilePath input_file = FindTestDataFilePath(kTestFilename);
ASSERT_TRUE(base::ReadFileToString(input_file, &jpeg_data_))
<< "failed to read input data from " << input_file.value();
// Load the test data, if not loaded yet.
if (jpeg_data_.size() == 0) {
base::FilePath input_file = FindTestDataFilePath(kTestFilename);
ASSERT_TRUE(base::ReadFileToString(input_file, &jpeg_data_))
<< "failed to read input data from " << input_file.value();
}
}
void TearDown() override { wrapper_ = nullptr; }
base::FilePath FindTestDataFilePath(const std::string& file_name);
bool VerifyDecode(const JpegParseResult& parse_result) const;
bool Decode(VaapiWrapper* vaapi_wrapper,
const JpegParseResult& parse_result,
......@@ -103,8 +105,23 @@ class VaapiJpegDecodeAcceleratorTest : public ::testing::Test {
protected:
scoped_refptr<VaapiWrapper> wrapper_;
std::string jpeg_data_;
std::string test_data_path_;
};
// Find the location of the specified test file. If a file with specified path
// is not found, treat the file as being relative to the test file directory.
// This is either a custom test data path provided by --test_data_path, or the
// default test data path (//media/test/data).
base::FilePath VaapiJpegDecodeAcceleratorTest::FindTestDataFilePath(
const std::string& file_name) {
const base::FilePath file_path = base::FilePath(file_name);
if (base::PathExists(file_path))
return file_path;
if (!test_data_path_.empty())
return base::FilePath(test_data_path_).Append(file_path);
return GetTestDataFilePath(file_name);
}
bool VaapiJpegDecodeAcceleratorTest::VerifyDecode(
const JpegParseResult& parse_result) const {
gfx::Size size(parse_result.frame_header.coded_width,
......
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