blob: 7ae82311e52e4921b11867d4d5445e1ef49a7353 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina880914c2014-06-09 12:05:34 -07007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tests/Test.h"
reed@android.comed673312009-02-27 16:24:51 +00009
Hal Canary925e31e2017-12-11 14:42:58 -050010#include <stdlib.h>
11
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkString.h"
13#include "include/core/SkTime.h"
14#include "tools/flags/CommandLineFlags.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000015
Mike Klein84836b72019-03-21 11:31:36 -050016static DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use.");
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000017
halcanary87f3ba42015-01-20 09:30:20 -080018void skiatest::Reporter::bumpTestCount() {}
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000019
halcanary87f3ba42015-01-20 09:30:20 -080020bool skiatest::Reporter::allowExtendedTest() const { return false; }
reed@android.comed673312009-02-27 16:24:51 +000021
halcanary87f3ba42015-01-20 09:30:20 -080022bool skiatest::Reporter::verbose() const { return false; }
reed@android.comed673312009-02-27 16:24:51 +000023
Mike Klein4d907da2019-02-07 09:54:30 -050024
25void skiatest::Reporter::reportFailedWithContext(const skiatest::Failure& f) {
26 SkString fullMessage = f.message;
27 if (!fContextStack.empty()) {
28 fullMessage.append(" [");
29 for (int i = 0; i < fContextStack.count(); ++i) {
30 if (i > 0) {
31 fullMessage.append(", ");
32 }
33 fullMessage.append(fContextStack[i]);
34 }
35 fullMessage.append("]");
36 }
37 this->reportFailed(skiatest::Failure(f.fileName, f.lineNo, f.condition, fullMessage));
38}
39
halcanary87f3ba42015-01-20 09:30:20 -080040SkString skiatest::Failure::toString() const {
41 SkString result = SkStringPrintf("%s:%d\t", this->fileName, this->lineNo);
42 if (!this->message.isEmpty()) {
43 result.append(this->message);
44 if (strlen(this->condition) > 0) {
45 result.append(": ");
46 }
reed@android.comed673312009-02-27 16:24:51 +000047 }
halcanary87f3ba42015-01-20 09:30:20 -080048 result.append(this->condition);
49 return result;
reed@android.comed673312009-02-27 16:24:51 +000050}
51
halcanary87f3ba42015-01-20 09:30:20 -080052SkString skiatest::GetTmpDir() {
Hal Canary925e31e2017-12-11 14:42:58 -050053 if (!FLAGS_tmpDir.isEmpty()) {
54 return SkString(FLAGS_tmpDir[0]);
55 }
56#ifdef SK_BUILD_FOR_ANDROID
57 const char* environmentVariable = "TMPDIR";
58 const char* defaultValue = "/data/local/tmp";
59#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
60 const char* environmentVariable = "TMPDIR";
61 const char* defaultValue = "/tmp";
Mike Klein8f11d4d2018-01-24 12:42:55 -050062#elif defined(SK_BUILD_FOR_WIN)
Hal Canary925e31e2017-12-11 14:42:58 -050063 const char* environmentVariable = "TEMP";
64 const char* defaultValue = nullptr;
65#else
66 const char* environmentVariable = nullptr;
67 const char* defaultValue = nullptr;
68#endif
69 const char* tmpdir = environmentVariable ? getenv(environmentVariable) : nullptr;
70 return SkString(tmpdir ? tmpdir : defaultValue);
djsollen@google.com0945bde2012-11-29 15:28:45 +000071}
benjaminwagnerec4d4d72016-03-25 12:59:53 -070072
73skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {}
74
75double skiatest::Timer::elapsedNs() const {
76 return SkTime::GetNSecs() - fStartNanos;
77}
78
79double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; }
80
81SkMSec skiatest::Timer::elapsedMsInt() const {
82 const double elapsedMs = this->elapsedMs();
83 SkASSERT(SK_MSecMax >= elapsedMs);
84 return static_cast<SkMSec>(elapsedMs);
85}