blob: dcb08e6badc6bf513740657f01e733c46794f559 [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
reed@android.comed673312009-02-27 16:24:51 +00008#include "Test.h"
9
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000010#include "SkCommandLineFlags.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000011#include "SkError.h"
commit-bot@chromium.org197845a2013-04-19 13:24:28 +000012#include "SkString.h"
commit-bot@chromium.org0506b9d2013-04-22 16:43:07 +000013#include "SkTime.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000014
halcanary96fcdcc2015-08-27 07:41:13 -070015DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use.");
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000016
halcanary87f3ba42015-01-20 09:30:20 -080017void skiatest::Reporter::bumpTestCount() {}
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000018
halcanary87f3ba42015-01-20 09:30:20 -080019bool skiatest::Reporter::allowExtendedTest() const { return false; }
reed@android.comed673312009-02-27 16:24:51 +000020
halcanary87f3ba42015-01-20 09:30:20 -080021bool skiatest::Reporter::verbose() const { return false; }
reed@android.comed673312009-02-27 16:24:51 +000022
halcanary87f3ba42015-01-20 09:30:20 -080023SkString skiatest::Failure::toString() const {
24 SkString result = SkStringPrintf("%s:%d\t", this->fileName, this->lineNo);
25 if (!this->message.isEmpty()) {
26 result.append(this->message);
27 if (strlen(this->condition) > 0) {
28 result.append(": ");
29 }
reed@android.comed673312009-02-27 16:24:51 +000030 }
halcanary87f3ba42015-01-20 09:30:20 -080031 result.append(this->condition);
32 return result;
reed@android.comed673312009-02-27 16:24:51 +000033}
34
halcanary87f3ba42015-01-20 09:30:20 -080035SkString skiatest::GetTmpDir() {
halcanary96fcdcc2015-08-27 07:41:13 -070036 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? nullptr : FLAGS_tmpDir[0];
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000037 return SkString(tmpDir);
djsollen@google.com0945bde2012-11-29 15:28:45 +000038}
benjaminwagnerec4d4d72016-03-25 12:59:53 -070039
40skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {}
41
42double skiatest::Timer::elapsedNs() const {
43 return SkTime::GetNSecs() - fStartNanos;
44}
45
46double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; }
47
48SkMSec skiatest::Timer::elapsedMsInt() const {
49 const double elapsedMs = this->elapsedMs();
50 SkASSERT(SK_MSecMax >= elapsedMs);
51 return static_cast<SkMSec>(elapsedMs);
52}