skia2/tests/MemsetTest.cpp
Kevin Lubick 65a726bb49 Move GR_MAKE_BITFIELD_OPS and GrAlignTo to non-GPU files
These have been renamed SK_MAKE_BITFIELD_OPS and SkAlignTo
because nothing seemed particularly GPU/Ganesh specific to them.

I moved the latter to SkTypes.h because we have other align
code there and former to src/SkUtils.h because I didn't know
where else it should go.

The primary motivation was removing the GrTypesPriv.h
include from src/core/SkBlockAllocator.h. I had attempted
some amount of #if SK_SUPPORT_GPU, but that's not as clean
here because both our CPU and GPU backends use the
SkBlockAllocator (as far as I could tell).

This also moves sk_memset* from SkUtils.h to SkOpts.h, because
SkOpts.h requires bringing in RasterPipeline, which seemed
like overkill.

Change-Id: I5163ef5064ad3840a15b7e873930d60e2620bf9d
Bug: skia:12584
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/464876
Reviewed-by: Brian Osman <brianosman@google.com>
2021-10-28 18:18:47 +00:00

90 lines
2.6 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/utils/SkRandom.h"
#include "src/core/SkOpts.h"
#include "tests/Test.h"
static void set_zero(void* dst, size_t bytes) {
char* ptr = (char*)dst;
for (size_t i = 0; i < bytes; ++i) {
ptr[i] = 0;
}
}
#define MAX_ALIGNMENT 64
#define MAX_COUNT ((MAX_ALIGNMENT) * 32)
#define PAD 32
#define TOTAL (PAD + MAX_ALIGNMENT + MAX_COUNT + PAD)
#define VALUE16 0x1234
#define VALUE32 0x12345678
static void compare16(skiatest::Reporter* r, const uint16_t base[],
uint16_t value, int count) {
for (int i = 0; i < count; ++i) {
if (base[i] != value) {
ERRORF(r, "[%d] expected %x found %x\n", i, value, base[i]);
return;
}
}
}
static void compare32(skiatest::Reporter* r, const uint32_t base[],
uint32_t value, int count) {
for (int i = 0; i < count; ++i) {
if (base[i] != value) {
ERRORF(r, "[%d] expected %x found %x\n", i, value, base[i]);
return;
}
}
}
static void test_16(skiatest::Reporter* reporter) {
uint16_t buffer[TOTAL];
for (int count = 0; count < MAX_COUNT; ++count) {
for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) {
set_zero(buffer, sizeof(buffer));
uint16_t* base = &buffer[PAD + alignment];
sk_memset16(base, VALUE16, count);
compare16(reporter, buffer, 0, PAD + alignment);
compare16(reporter, base, VALUE16, count);
compare16(reporter, base + count, 0, TOTAL - count - PAD - alignment);
}
}
}
static void test_32(skiatest::Reporter* reporter) {
uint32_t buffer[TOTAL];
for (int count = 0; count < MAX_COUNT; ++count) {
for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) {
set_zero(buffer, sizeof(buffer));
uint32_t* base = &buffer[PAD + alignment];
sk_memset32(base, VALUE32, count);
compare32(reporter, buffer, 0, PAD + alignment);
compare32(reporter, base, VALUE32, count);
compare32(reporter, base + count, 0, TOTAL - count - PAD - alignment);
}
}
}
/**
* Test sk_memset16 and sk_memset32.
* For performance considerations, implementations may take different paths
* depending on the alignment of the dst, and/or the size of the count.
*/
DEF_TEST(Memset, reporter) {
test_16(reporter);
test_32(reporter);
}