epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame] | 7 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | |
Hal Canary | 925e31e | 2017-12-11 14:42:58 -0500 | [diff] [blame] | 10 | #include <stdlib.h> |
| 11 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 12 | #include "SkCommandLineFlags.h" |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 14 | #include "SkTime.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 15 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 16 | DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use."); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 17 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 18 | void skiatest::Reporter::bumpTestCount() {} |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 19 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 20 | bool skiatest::Reporter::allowExtendedTest() const { return false; } |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 21 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 22 | bool skiatest::Reporter::verbose() const { return false; } |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 23 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 24 | SkString 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.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 31 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 32 | result.append(this->condition); |
| 33 | return result; |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 34 | } |
| 35 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 36 | SkString skiatest::GetTmpDir() { |
Hal Canary | 925e31e | 2017-12-11 14:42:58 -0500 | [diff] [blame] | 37 | 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 Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 46 | #elif defined(SK_BUILD_FOR_WIN) |
Hal Canary | 925e31e | 2017-12-11 14:42:58 -0500 | [diff] [blame] | 47 | 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.com | 0945bde | 2012-11-29 15:28:45 +0000 | [diff] [blame] | 55 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 56 | |
| 57 | skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {} |
| 58 | |
| 59 | double skiatest::Timer::elapsedNs() const { |
| 60 | return SkTime::GetNSecs() - fStartNanos; |
| 61 | } |
| 62 | |
| 63 | double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; } |
| 64 | |
| 65 | SkMSec skiatest::Timer::elapsedMsInt() const { |
| 66 | const double elapsedMs = this->elapsedMs(); |
| 67 | SkASSERT(SK_MSecMax >= elapsedMs); |
| 68 | return static_cast<SkMSec>(elapsedMs); |
| 69 | } |