2014-10-15 20:43:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "tests/Test.h"
|
2014-10-15 20:43:48 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrTRecorder.h"
|
2015-04-16 17:42:49 +00:00
|
|
|
|
2014-10-15 20:43:48 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
static int gActiveRecorderItems = 0;
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
class IntWrapper {
|
|
|
|
public:
|
|
|
|
IntWrapper() {}
|
|
|
|
IntWrapper(int value) : fValue(value) {}
|
|
|
|
operator int() { return fValue; }
|
|
|
|
private:
|
|
|
|
int fValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ExtraData {
|
2019-04-23 19:24:31 +00:00
|
|
|
typedef GrTRecorder<ExtraData> Recorder;
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
ExtraData(int i) : fData(i) {
|
|
|
|
int* extraData = this->extraData();
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
extraData[j] = i;
|
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
++gActiveRecorderItems;
|
2014-10-15 20:43:48 +00:00
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
~ExtraData() { --gActiveRecorderItems; }
|
|
|
|
int* extraData() { return reinterpret_cast<int*>(this + 1); }
|
2014-10-15 20:43:48 +00:00
|
|
|
int fData;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_extra_data(skiatest::Reporter* reporter) {
|
|
|
|
ExtraData::Recorder recorder(0);
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, recorder.empty());
|
2014-10-15 20:43:48 +00:00
|
|
|
for (int i = 0; i < 100; ++i) {
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplaceWithData<ExtraData>(i * sizeof(int), i);
|
|
|
|
REPORTER_ASSERT(reporter, !recorder.empty());
|
2014-10-15 20:43:48 +00:00
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, 100 == gActiveRecorderItems);
|
2014-10-15 20:43:48 +00:00
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
auto iter = recorder.begin();
|
|
|
|
for (int i = 0; i < 100; ++i, ++iter) {
|
2014-10-15 20:43:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, i == iter->fData);
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
REPORTER_ASSERT(reporter, i == iter->extraData()[j]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, iter == recorder.end());
|
2015-04-16 17:42:49 +00:00
|
|
|
|
2014-10-15 20:43:48 +00:00
|
|
|
recorder.reset();
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == gActiveRecorderItems);
|
|
|
|
REPORTER_ASSERT(reporter, recorder.begin() == recorder.end());
|
|
|
|
REPORTER_ASSERT(reporter, recorder.empty());
|
2014-10-15 20:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ClassType {
|
|
|
|
kBase_ClassType,
|
|
|
|
kSubclass_ClassType,
|
|
|
|
kSubSubclass_ClassType,
|
|
|
|
kSubclassExtraData_ClassType,
|
|
|
|
kSubclassEmpty_ClassType,
|
|
|
|
|
|
|
|
kNumClassTypes
|
|
|
|
};
|
|
|
|
|
|
|
|
class Base {
|
|
|
|
public:
|
2019-04-23 19:24:31 +00:00
|
|
|
typedef GrTRecorder<Base> Recorder;
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
Base() {
|
|
|
|
fMatrix.reset();
|
2019-04-23 19:24:31 +00:00
|
|
|
++gActiveRecorderItems;
|
2014-10-15 20:43:48 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
virtual ~Base() { --gActiveRecorderItems; }
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
virtual ClassType getType() { return kBase_ClassType; }
|
|
|
|
|
|
|
|
virtual void validate(skiatest::Reporter* reporter) const {
|
|
|
|
REPORTER_ASSERT(reporter, fMatrix.isIdentity());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Subclass : public Base {
|
|
|
|
public:
|
|
|
|
Subclass() : fString("Lorem ipsum dolor sit amet") {}
|
|
|
|
|
|
|
|
virtual ClassType getType() { return kSubclass_ClassType; }
|
|
|
|
|
|
|
|
virtual void validate(skiatest::Reporter* reporter) const {
|
|
|
|
Base::validate(reporter);
|
|
|
|
REPORTER_ASSERT(reporter, !strcmp("Lorem ipsum dolor sit amet", fString.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fString;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SubSubclass : public Subclass {
|
|
|
|
public:
|
|
|
|
SubSubclass() : fInt(1234), fFloat(1.234f) {}
|
|
|
|
|
|
|
|
virtual ClassType getType() { return kSubSubclass_ClassType; }
|
|
|
|
|
|
|
|
virtual void validate(skiatest::Reporter* reporter) const {
|
|
|
|
Subclass::validate(reporter);
|
|
|
|
REPORTER_ASSERT(reporter, 1234 == fInt);
|
|
|
|
REPORTER_ASSERT(reporter, 1.234f == fFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int fInt;
|
|
|
|
float fFloat;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SubclassExtraData : public Base {
|
|
|
|
public:
|
|
|
|
SubclassExtraData(int length) : fLength(length) {
|
2019-04-23 19:24:31 +00:00
|
|
|
int* data = reinterpret_cast<int*>(this + 1);
|
2014-10-15 20:43:48 +00:00
|
|
|
for (int i = 0; i < fLength; ++i) {
|
|
|
|
data[i] = ValueAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ClassType getType() { return kSubclassExtraData_ClassType; }
|
|
|
|
|
|
|
|
virtual void validate(skiatest::Reporter* reporter) const {
|
|
|
|
Base::validate(reporter);
|
2019-04-23 19:24:31 +00:00
|
|
|
const int* data = reinterpret_cast<const int*>(this + 1);
|
2014-10-15 20:43:48 +00:00
|
|
|
for (int i = 0; i < fLength; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, ValueAt(i) == data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-02-04 15:01:53 +00:00
|
|
|
static int ValueAt(uint64_t i) {
|
|
|
|
return static_cast<int>((123456789 + 987654321 * i) & 0xFFFFFFFF);
|
|
|
|
}
|
2014-10-15 20:43:48 +00:00
|
|
|
int fLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SubclassEmpty : public Base {
|
|
|
|
public:
|
|
|
|
virtual ClassType getType() { return kSubclassEmpty_ClassType; }
|
|
|
|
};
|
|
|
|
|
2015-04-16 17:42:49 +00:00
|
|
|
class Order {
|
|
|
|
public:
|
|
|
|
Order() { this->reset(); }
|
|
|
|
void reset() { fCurrent = 0; }
|
|
|
|
ClassType next() {
|
|
|
|
fCurrent = 1664525 * fCurrent + 1013904223;
|
|
|
|
return static_cast<ClassType>(fCurrent % kNumClassTypes);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
uint32_t fCurrent;
|
|
|
|
};
|
2019-04-23 19:24:31 +00:00
|
|
|
|
|
|
|
static void test_subclasses_iter(skiatest::Reporter*, Order&, Base::Recorder::iterator&, int = 0);
|
|
|
|
|
2014-10-15 20:43:48 +00:00
|
|
|
static void test_subclasses(skiatest::Reporter* reporter) {
|
|
|
|
Base::Recorder recorder(1024);
|
|
|
|
|
|
|
|
Order order;
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
switch (order.next()) {
|
|
|
|
case kBase_ClassType:
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplace<Base>();
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kSubclass_ClassType:
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplace<Subclass>();
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kSubSubclass_ClassType:
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplace<SubSubclass>();
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kSubclassExtraData_ClassType:
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplaceWithData<SubclassExtraData>(sizeof(int) * i, i);
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kSubclassEmpty_ClassType:
|
2019-04-23 19:24:31 +00:00
|
|
|
recorder.emplace<SubclassEmpty>();
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
When running DM, write test failures to json.
Add skiatest::Failure to keep track of data about a test failure.
Reporter::reportFailed and ::onReportFailed now take Failure as a
parameter. This allows the implementation to treat the failure as it
wishes. Provide a helper to format the failure the same as prior to
the change.
Update the macros for calling reportFailed (REPORTER_ASSERT etc) to
create a Failure object.
Convert a direct call to reportFailed to the macro ERRORF.
Write Failures to Json.
Sample output when running dm on the dummy test crrev.com/705723004:
{
"test_results" : {
"failures" : [
{
"condition" : "0 > 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 10,
"message" : ""
},
{
"condition" : "false",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 4,
"message" : ""
},
{
"condition" : "1 == 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 5,
"message" : "I can too count!"
},
{
"condition" : "",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 6,
"message" : "seven is 7"
},
{
"condition" : "1 == 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 14,
"message" : "I can too count!"
}
]
}
}
Report all of the failures from one test.
Previously, if one test had multiple failures, only one was reportered.
e.g:
Failures:
test Dummy: ../../tests/DummyTest.cpp:6 seven is 7
test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3
test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3
3 failures.
Now, we get all the messages:
Failures:
test Dummy: ../../tests/DummyTest.cpp:4 false
../../tests/DummyTest.cpp:5 I can too count!: 1 == 3
../../tests/DummyTest.cpp:6 seven is 7
test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3
test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3
3 failures.
(Note that we still state "3 failures" because 3 DM::Tasks failed.)
BUG=skia:3082
BUG=skia:2454
Review URL: https://codereview.chromium.org/694703005
2014-11-07 14:07:32 +00:00
|
|
|
ERRORF(reporter, "Invalid class type");
|
2014-10-15 20:43:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1000 == gActiveRecorderItems);
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
order.reset();
|
2019-04-23 19:24:31 +00:00
|
|
|
auto iter = recorder.begin();
|
2015-04-16 17:42:49 +00:00
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
test_subclasses_iter(reporter, order, iter);
|
2014-10-15 20:43:48 +00:00
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, iter == recorder.end());
|
2014-10-15 20:43:48 +00:00
|
|
|
// Don't reset the recorder. It should automatically destruct all its items.
|
|
|
|
}
|
2019-04-23 19:24:31 +00:00
|
|
|
static void test_subclasses_iter(skiatest::Reporter* reporter, Order& order,
|
|
|
|
Base::Recorder::iterator& iter, int i) {
|
2015-04-16 17:42:49 +00:00
|
|
|
if (i >= 1000) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassType classType = order.next();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, classType == iter->getType());
|
|
|
|
iter->validate(reporter);
|
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
++iter;
|
|
|
|
test_subclasses_iter(reporter, order, iter, i + 1);
|
|
|
|
}
|
2015-04-16 17:42:49 +00:00
|
|
|
|
2019-04-23 19:24:31 +00:00
|
|
|
struct AlignBase {
|
|
|
|
AlignBase() { ++gActiveRecorderItems; }
|
|
|
|
~AlignBase() { --gActiveRecorderItems; }
|
|
|
|
char fValue;
|
|
|
|
};
|
|
|
|
struct alignas(16) Align16 : public AlignBase {};
|
|
|
|
struct alignas(32) Align32 : public AlignBase {};
|
|
|
|
struct alignas(64) Align64 : public AlignBase {};
|
|
|
|
struct alignas(128) Align128 : public AlignBase {};
|
|
|
|
|
|
|
|
static void test_alignment(skiatest::Reporter* reporter) {
|
|
|
|
GrTRecorder<AlignBase> recorder(0);
|
|
|
|
SkTArray<size_t> expectedAlignments;
|
|
|
|
SkRandom random;
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
size_t dataSize = random.nextULessThan(20);
|
|
|
|
switch (random.nextULessThan(5)) {
|
|
|
|
case 0:
|
|
|
|
recorder.emplaceWithData<AlignBase>(dataSize);
|
|
|
|
expectedAlignments.push_back(alignof(AlignBase));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
recorder.emplaceWithData<Align16>(dataSize);
|
|
|
|
expectedAlignments.push_back(16);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
recorder.emplaceWithData<Align32>(dataSize);
|
|
|
|
expectedAlignments.push_back(32);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
recorder.emplaceWithData<Align64>(dataSize);
|
|
|
|
expectedAlignments.push_back(64);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
recorder.emplaceWithData<Align128>(dataSize);
|
|
|
|
expectedAlignments.push_back(128);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
recorder.back().fValue = i;
|
|
|
|
}
|
|
|
|
int i = 0;
|
|
|
|
for (const auto& x : recorder) {
|
|
|
|
REPORTER_ASSERT(reporter, x.fValue == i);
|
|
|
|
auto pointer = reinterpret_cast<uintptr_t>(&x);
|
|
|
|
auto mask = static_cast<uintptr_t>(expectedAlignments[i]) - 1;
|
|
|
|
REPORTER_ASSERT(reporter, !(pointer & mask));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, i == 100);
|
2015-04-16 17:42:49 +00:00
|
|
|
}
|
2014-10-15 20:43:48 +00:00
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(GrTRecorder, reporter, /* options */) {
|
2014-10-15 20:43:48 +00:00
|
|
|
test_extra_data(reporter);
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == gActiveRecorderItems); // test_extra_data should call reset().
|
2014-10-15 20:43:48 +00:00
|
|
|
|
|
|
|
test_subclasses(reporter);
|
2019-04-23 19:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == gActiveRecorderItems); // Ensure ~GrTRecorder invokes dtors.
|
|
|
|
|
|
|
|
test_alignment(reporter);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == gActiveRecorderItems); // Ensure ~GrTRecorder invokes dtors.
|
2014-10-15 20:43:48 +00:00
|
|
|
}
|