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 */ 7 8 #include "Test.h" 9 10 #include <stdlib.h> 11 12 #include "SkCommandLineFlags.h" 13 #include "SkString.h" 14 #include "SkTime.h" 15 16 DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use."); 17 bumpTestCount()18void skiatest::Reporter::bumpTestCount() {} 19 allowExtendedTest() const20bool skiatest::Reporter::allowExtendedTest() const { return false; } 21 verbose() const22bool skiatest::Reporter::verbose() const { return false; } 23 toString() const24SkString 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 } 31 } 32 result.append(this->condition); 33 return result; 34 } 35 GetTmpDir()36SkString skiatest::GetTmpDir() { 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"; 46 #elif defined(SK_BUILD_FOR_WIN) 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); 55 } 56 Timer()57skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {} 58 elapsedNs() const59double skiatest::Timer::elapsedNs() const { 60 return SkTime::GetNSecs() - fStartNanos; 61 } 62 elapsedMs() const63double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; } 64 elapsedMsInt() const65SkMSec skiatest::Timer::elapsedMsInt() const { 66 const double elapsedMs = this->elapsedMs(); 67 SkASSERT(SK_MSecMax >= elapsedMs); 68 return static_cast<SkMSec>(elapsedMs); 69 } 70