Commit aac524df authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

media/gpu/test: remove s'more LOG_ASSERTs

This CL continues crrev.com/c/1897358 by substituting LOG_ASSERT()s in
test code with ASSERT_TRUE()s, avoiding crashing the test binary.

m/g/t/video_frame_validator.cc is an easy one-to-one substitution,
whereas video_frame_helpers.cc need to add a macro to return an
invalid value when the predicate doesn't hold up.

Bug: 1020776
Change-Id: I8e0671dce792b479c91c722c652bd387f4cd5faa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900559Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713268}
parent 94cf7edb
......@@ -16,6 +16,7 @@
#include "media/base/video_frame.h"
#include "media/gpu/buildflags.h"
#include "media/gpu/test/image.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libyuv/include/libyuv.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/gpu_memory_buffer.h"
......@@ -31,10 +32,19 @@ namespace test {
namespace {
#define ASSERT_TRUE_AND_RETURN(predicate, return_value) \
do { \
if (!(predicate)) { \
ADD_FAILURE(); \
return (return_value); \
} \
} while (0)
bool ConvertVideoFrameToI420(const VideoFrame* src_frame,
VideoFrame* dst_frame) {
LOG_ASSERT(src_frame->visible_rect() == dst_frame->visible_rect());
LOG_ASSERT(dst_frame->format() == PIXEL_FORMAT_I420);
ASSERT_TRUE_AND_RETURN(src_frame->visible_rect() == dst_frame->visible_rect(),
false);
ASSERT_TRUE_AND_RETURN(dst_frame->format() == PIXEL_FORMAT_I420, false);
const auto& visible_rect = src_frame->visible_rect();
const int width = visible_rect.width();
......@@ -81,8 +91,9 @@ bool ConvertVideoFrameToI420(const VideoFrame* src_frame,
bool ConvertVideoFrameToARGB(const VideoFrame* src_frame,
VideoFrame* dst_frame) {
LOG_ASSERT(src_frame->visible_rect() == dst_frame->visible_rect());
LOG_ASSERT(dst_frame->format() == PIXEL_FORMAT_ARGB);
ASSERT_TRUE_AND_RETURN(src_frame->visible_rect() == dst_frame->visible_rect(),
false);
ASSERT_TRUE_AND_RETURN(dst_frame->format() == PIXEL_FORMAT_ARGB, false);
const auto& visible_rect = src_frame->visible_rect();
const int width = visible_rect.width();
......@@ -126,7 +137,7 @@ bool ConvertVideoFrameToARGB(const VideoFrame* src_frame,
// Copy memory based |src_frame| buffer to |dst_frame| buffer.
bool CopyVideoFrame(const VideoFrame* src_frame,
scoped_refptr<VideoFrame> dst_frame) {
LOG_ASSERT(src_frame->IsMappable());
ASSERT_TRUE_AND_RETURN(src_frame->IsMappable(), false);
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
// If |dst_frame| is a Dmabuf-backed VideoFrame, we need to map its underlying
// buffer into memory. We use a VideoFrameMapper to create a memory-based
......@@ -134,7 +145,7 @@ bool CopyVideoFrame(const VideoFrame* src_frame,
if (dst_frame->storage_type() == VideoFrame::STORAGE_DMABUFS) {
auto video_frame_mapper = VideoFrameMapperFactory::CreateMapper(
dst_frame->format(), VideoFrame::STORAGE_DMABUFS, true);
LOG_ASSERT(video_frame_mapper);
ASSERT_TRUE_AND_RETURN(video_frame_mapper, false);
dst_frame = video_frame_mapper->Map(std::move(dst_frame));
if (!dst_frame) {
LOG(ERROR) << "Failed to map DMABuf video frame.";
......@@ -142,13 +153,15 @@ bool CopyVideoFrame(const VideoFrame* src_frame,
}
}
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
LOG_ASSERT(dst_frame->IsMappable());
LOG_ASSERT(src_frame->format() == dst_frame->format());
ASSERT_TRUE_AND_RETURN(dst_frame->IsMappable(), false);
ASSERT_TRUE_AND_RETURN(src_frame->format() == dst_frame->format(), false);
// Copy every plane's content from |src_frame| to |dst_frame|.
const size_t num_planes = VideoFrame::NumPlanes(dst_frame->format());
LOG_ASSERT(dst_frame->layout().planes().size() == num_planes);
LOG_ASSERT(src_frame->layout().planes().size() == num_planes);
ASSERT_TRUE_AND_RETURN(dst_frame->layout().planes().size() == num_planes,
false);
ASSERT_TRUE_AND_RETURN(src_frame->layout().planes().size() == num_planes,
false);
for (size_t i = 0; i < num_planes; ++i) {
// |width| in libyuv::CopyPlane() is in bytes, not pixels.
gfx::Size plane_size = VideoFrame::PlaneSize(dst_frame->format(), i,
......@@ -164,8 +177,10 @@ bool CopyVideoFrame(const VideoFrame* src_frame,
} // namespace
bool ConvertVideoFrame(const VideoFrame* src_frame, VideoFrame* dst_frame) {
LOG_ASSERT(src_frame->visible_rect() == dst_frame->visible_rect());
LOG_ASSERT(src_frame->IsMappable() && dst_frame->IsMappable());
ASSERT_TRUE_AND_RETURN(src_frame->visible_rect() == dst_frame->visible_rect(),
false);
ASSERT_TRUE_AND_RETURN(src_frame->IsMappable() && dst_frame->IsMappable(),
false);
// Writing into non-owned memory might produce some unexpected side effects.
if (dst_frame->storage_type() != VideoFrame::STORAGE_OWNED_MEMORY)
......@@ -347,11 +362,14 @@ base::Optional<VideoFrameLayout> CreateVideoFrameLayout(VideoPixelFormat format,
size_t CompareFramesWithErrorDiff(const VideoFrame& frame1,
const VideoFrame& frame2,
uint8_t tolerance) {
LOG_ASSERT(frame1.format() == frame2.format());
LOG_ASSERT(frame1.visible_rect() == frame2.visible_rect());
LOG_ASSERT(frame1.visible_rect().origin() == gfx::Point(0, 0));
LOG_ASSERT(frame1.IsMappable() && frame2.IsMappable());
ASSERT_TRUE_AND_RETURN(frame1.format() == frame2.format(),
std::numeric_limits<std::size_t>::max());
ASSERT_TRUE_AND_RETURN(frame1.visible_rect() == frame2.visible_rect(),
std::numeric_limits<std::size_t>::max());
ASSERT_TRUE_AND_RETURN(frame1.visible_rect().origin() == gfx::Point(0, 0),
std::numeric_limits<std::size_t>::max());
ASSERT_TRUE_AND_RETURN(frame1.IsMappable() && frame2.IsMappable(),
std::numeric_limits<std::size_t>::max());
size_t diff_cnt = 0;
const VideoPixelFormat format = frame1.format();
......
......@@ -176,7 +176,7 @@ void VideoFrameValidator::ProcessVideoFrameTask(
if (!video_frame_mapper_) {
video_frame_mapper_ = VideoFrameMapperFactory::CreateMapper(
video_frame->format(), video_frame->storage_type());
LOG_ASSERT(video_frame_mapper_) << "Failed to create VideoFrameMapper";
ASSERT_TRUE(video_frame_mapper_) << "Failed to create VideoFrameMapper";
}
validated_frame = video_frame_mapper_->Map(std::move(validated_frame));
......@@ -187,7 +187,7 @@ void VideoFrameValidator::ProcessVideoFrameTask(
}
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
LOG_ASSERT(validated_frame->IsMappable());
ASSERT_TRUE(validated_frame->IsMappable());
base::Optional<MismatchedFrameInfo> mismatched_info;
switch (validate_mode_) {
......
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