#ifndef gm_expectations_DEFINED
#define gm_expectations_DEFINED
+#include <stdarg.h>
#include "gm.h"
#include "SkBitmap.h"
#include "SkBitmapChecksummer.h"
return jsonValue.asUInt64();
}
+ static void gm_fprintf(FILE *stream, const char format[], ...) {
+ va_list args;
+ va_start(args, format);
+ fprintf(stream, "GM: ");
+ vfprintf(stream, format, args);
+ va_end(args);
+ }
+
static SkString make_filename(const char path[],
const char renderModeDescriptor[],
const char *name,
if (ignoreFailure.isNull()) {
fIgnoreFailure = kDefaultIgnoreFailure;
} else if (!ignoreFailure.isBool()) {
- fprintf(stderr, "found non-boolean json value for key '%s' in element '%s'\n",
- kJsonKey_ExpectedResults_IgnoreFailure,
- jsonElement.toStyledString().c_str());
+ gm_fprintf(stderr, "found non-boolean json value"
+ " for key '%s' in element '%s'\n",
+ kJsonKey_ExpectedResults_IgnoreFailure,
+ jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
fIgnoreFailure = kDefaultIgnoreFailure;
} else {
if (allowedChecksums.isNull()) {
// ok, we'll just assume there aren't any expected checksums to compare against
} else if (!allowedChecksums.isArray()) {
- fprintf(stderr, "found non-array json value for key '%s' in element '%s'\n",
- kJsonKey_ExpectedResults_Checksums,
- jsonElement.toStyledString().c_str());
+ gm_fprintf(stderr, "found non-array json value"
+ " for key '%s' in element '%s'\n",
+ kJsonKey_ExpectedResults_Checksums,
+ jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) {
Json::Value checksumElement = allowedChecksums[i];
if (!checksumElement.isIntegral()) {
- fprintf(stderr, "found non-integer checksum in json element '%s'\n",
- jsonElement.toStyledString().c_str());
+ gm_fprintf(stderr, "found non-integer checksum"
+ " in json element '%s'\n",
+ jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
fAllowedChecksums.push_back() = asChecksum(checksumElement);
return Expectations(referenceBitmap);
} else {
if (fNotifyOfMissingFiles) {
- fprintf(stderr, "FAILED to read %s\n", path.c_str());
+ gm_fprintf(stderr, "FAILED to read %s\n", path.c_str());
}
return Expectations();
}
static bool parse(const char *jsonPath, Json::Value *jsonRoot) {
SkFILEStream inFile(jsonPath);
if (!inFile.isValid()) {
- fprintf(stderr, "unable to read JSON file %s\n", jsonPath);
+ gm_fprintf(stderr, "unable to read JSON file %s\n", jsonPath);
DEBUGFAIL_SEE_STDERR;
return false;
}
SkAutoDataUnref dataRef(readFileIntoSkData(inFile));
if (NULL == dataRef.get()) {
- fprintf(stderr, "error reading JSON file %s\n", jsonPath);
+ gm_fprintf(stderr, "error reading JSON file %s\n", jsonPath);
DEBUGFAIL_SEE_STDERR;
return false;
}
size_t size = dataRef.get()->size();
Json::Reader reader;
if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
- fprintf(stderr, "error parsing JSON file %s\n", jsonPath);
+ gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath);
DEBUGFAIL_SEE_STDERR;
return false;
}
// nothing to do here; 565 bitmaps are inherently opaque
break;
default:
- fprintf(stderr, "unsupported bitmap config %d\n", config);
- SkDEBUGFAIL("unsupported bitmap config");
+ gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
+ DEBUGFAIL_SEE_STDERR;
}
}
void ListErrors() {
for (int i = 0; i < fFailedTests.count(); ++i) {
if (fFailedTests[i].fIsPixelError) {
- SkDebugf("\t\t%s pixel_error\n", fFailedTests[i].fName.c_str());
+ gm_fprintf(stderr, "\t\t%s pixel_error\n", fFailedTests[i].fName.c_str());
} else {
- SkDebugf("\t\t%s\n", fFailedTests[i].fName.c_str());
+ gm_fprintf(stderr, "\t\t%s\n", fFailedTests[i].fName.c_str());
}
}
}
if (success) {
return kEmptyErrorBitfield;
} else {
- fprintf(stderr, "FAILED to write %s\n", path.c_str());
+ gm_fprintf(stderr, "FAILED to write %s\n", path.c_str());
RecordError(kWritingReferenceImage_ErrorBitmask, name,
renderModeDescriptor);
return kWritingReferenceImage_ErrorBitmask;
const int width = actualBitmap.width();
const int height = actualBitmap.height();
if ((expectedWidth != width) || (expectedHeight != height)) {
- SkDebugf("---- %s: dimension mismatch -- expected [%d %d], actual [%d %d]\n",
- testName, expectedWidth, expectedHeight, width, height);
+ gm_fprintf(stderr, "---- %s: dimension mismatch --"
+ " expected [%d %d], actual [%d %d]\n",
+ testName, expectedWidth, expectedHeight, width, height);
return;
}
if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
(SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
- SkDebugf("---- %s: not computing max per-channel pixel mismatch because non-8888\n",
- testName);
+ gm_fprintf(stderr, "---- %s: not computing max per-channel"
+ " pixel mismatch because non-8888\n", testName);
return;
}
}
}
}
- SkDebugf("---- %s: %d (of %d) differing pixels, max per-channel mismatch"
- " R=%d G=%d B=%d A=%d\n",
- testName, differingPixels, width*height, errR, errG, errB, errA);
+ gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
+ " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
+ testName, differingPixels, width*height, errR, errG, errB, errA);
}
/**
};
static void usage(const char * argv0) {
- SkDebugf("%s\n", argv0);
- SkDebugf(" [--config ");
+ fprintf(stderr, "%s\n", argv0);
+ fprintf(stderr, " [--config ");
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
if (i > 0) {
- SkDebugf("|");
+ fprintf(stderr, "|");
}
- SkDebugf(gRec[i].fName);
+ fprintf(stderr, "%s", gRec[i].fName);
}
- SkDebugf("]:\n run these configurations\n");
- SkDebugf(
+ fprintf(stderr, "]:\n run these configurations\n");
+ fprintf(stderr,
// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
// It would probably be better if we allowed both yes-and-no settings for each
// one, e.g.:
appendUnique<size_t>(&configs, index);
userConfig = true;
} else {
- SkString str;
- str.printf("unrecognized config %s\n", *argv);
- SkDebugf(str.c_str());
+ gm_fprintf(stderr, "unrecognized config %s\n", *argv);
usage(commandName);
return -1;
}
} else {
- SkDebugf("missing arg for --config\n");
+ gm_fprintf(stderr, "missing arg for --config\n");
usage(commandName);
return -1;
}
if (index >= 0) {
*excludeConfigs.append() = index;
} else {
- SkString str;
- str.printf("unrecognized exclude-config %s\n", *argv);
- SkDebugf(str.c_str());
+ gm_fprintf(stderr, "unrecognized exclude-config %s\n", *argv);
usage(commandName);
return -1;
}
} else {
- SkDebugf("missing arg for --exclude-config\n");
+ gm_fprintf(stderr, "missing arg for --exclude-config\n");
usage(commandName);
return -1;
}
gpuCacheSize.fBytes = atoi(*++argv);
gpuCacheSize.fCount = atoi(*++argv);
} else {
- SkDebugf("missing arg for --gpuCacheSize\n");
+ gm_fprintf(stderr, "missing arg for --gpuCacheSize\n");
usage(commandName);
return -1;
}
}
moduloDivisor = atoi(*argv);
if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) {
- SkDebugf("invalid modulo values.");
+ gm_fprintf(stderr, "invalid modulo values.");
return -1;
}
} else if (strcmp(*argv, "--nopdf") == 0) {
if (doVerbose) {
SkString str;
- str.printf("gm: %d configs:", configs.count());
+ str.printf("%d configs:", configs.count());
for (int i = 0; i < configs.count(); ++i) {
str.appendf(" %s", gRec[configs[i]].fName);
}
- SkDebugf("%s\n", str.c_str());
+ gm_fprintf(stderr, "%s\n", str.c_str());
}
GM::SetResourcePath(resourcePath);
if (readPath) {
if (!sk_exists(readPath)) {
- fprintf(stderr, "readPath %s does not exist!\n", readPath);
+ gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
return -1;
}
if (sk_isdir(readPath)) {
- fprintf(stderr, "reading from %s\n", readPath);
+ gm_fprintf(stdout, "reading from %s\n", readPath);
gmmain.fExpectationsSource.reset(SkNEW_ARGS(
IndividualImageExpectationsSource,
(readPath, notifyMissingReadReference)));
} else {
- fprintf(stderr, "reading expectations from JSON summary file %s\n",
- readPath);
+ gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
gmmain.fExpectationsSource.reset(SkNEW_ARGS(
JsonExpectationsSource, (readPath)));
}
}
if (writePath) {
- fprintf(stderr, "writing to %s\n", writePath);
+ gm_fprintf(stdout, "writing to %s\n", writePath);
}
if (writePicturePath) {
- fprintf(stderr, "writing pictures to %s\n", writePicturePath);
+ gm_fprintf(stdout, "writing pictures to %s\n", writePicturePath);
}
if (resourcePath) {
- fprintf(stderr, "reading resources from %s\n", resourcePath);
+ gm_fprintf(stdout, "reading resources from %s\n", resourcePath);
}
if (moduloDivisor <= 0) {
}
SkISize size = gm->getISize();
- SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
- size.width(), size.height());
+ gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
+ size.width(), size.height());
ErrorBitfield testErrors = kEmptyErrorBitfield;
uint32_t gmFlags = gm->getFlags();
SkDELETE(gm);
}
- SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
- testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
+ gm_fprintf(stdout, "Ran %d tests: %d passed, %d failed, %d missing reference images\n",
+ testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
gmmain.ListErrors();
if (NULL != writeJsonSummaryPath) {
if (kGPU_Backend == config.fBackend) {
GrContext* gr = grFactory->get(config.fGLContextType);
- SkDebugf("config: %s %x\n", config.fName, gr);
+ gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
gr->printCacheStats();
}
}