blob: da260a0ee6214bad65ea23605296e2e3f7d736ec [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
Hal Canary925e31e2017-12-11 14:42:58 -050010#include <stdlib.h>
11
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000012#include "SkCommandLineFlags.h"
commit-bot@chromium.org197845a2013-04-19 13:24:28 +000013#include "SkString.h"
commit-bot@chromium.org0506b9d2013-04-22 16:43:07 +000014#include "SkTime.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000015
halcanary96fcdcc2015-08-27 07:41:13 -070016DEFINE_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
halcanary87f3ba42015-01-20 09:30:20 -080024SkString skiatest::Failure::toString() const {
25 SkString result = SkStringPrintf("%s:%d\t", this->fileName, this->lineNo);
26 if (!this->message.isEmpty()) {
27 result.append(this->message);
28 if (strlen(this->condition) > 0) {
29 result.append(": ");
30 }
reed@android.comed673312009-02-27 16:24:51 +000031 }
halcanary87f3ba42015-01-20 09:30:20 -080032 result.append(this->condition);
33 return result;
reed@android.comed673312009-02-27 16:24:51 +000034}
35
halcanary87f3ba42015-01-20 09:30:20 -080036SkString skiatest::GetTmpDir() {
Hal Canary925e31e2017-12-11 14:42:58 -050037 if (!FLAGS_tmpDir.isEmpty()) {
38 return SkString(FLAGS_tmpDir[0]);
39 }
40#ifdef SK_BUILD_FOR_ANDROID
41 const char* environmentVariable = "TMPDIR";
42 const char* defaultValue = "/data/local/tmp";
43#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
44 const char* environmentVariable = "TMPDIR";
45 const char* defaultValue = "/tmp";
Mike Klein8f11d4d2018-01-24 12:42:55 -050046#elif defined(SK_BUILD_FOR_WIN)
Hal Canary925e31e2017-12-11 14:42:58 -050047 const char* environmentVariable = "TEMP";
48 const char* defaultValue = nullptr;
49#else
50 const char* environmentVariable = nullptr;
51 const char* defaultValue = nullptr;
52#endif
53 const char* tmpdir = environmentVariable ? getenv(environmentVariable) : nullptr;
54 return SkString(tmpdir ? tmpdir : defaultValue);
djsollen@google.com0945bde2012-11-29 15:28:45 +000055}
benjaminwagnerec4d4d72016-03-25 12:59:53 -070056
57skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {}
58
59double skiatest::Timer::elapsedNs() const {
60 return SkTime::GetNSecs() - fStartNanos;
61}
62
63double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; }
64
65SkMSec skiatest::Timer::elapsedMsInt() const {
66 const double elapsedMs = this->elapsedMs();
67 SkASSERT(SK_MSecMax >= elapsedMs);
68 return static_cast<SkMSec>(elapsedMs);
69}