• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "tests/Test.h"
9 
10 #include "include/core/SkString.h"
11 #include "include/core/SkTime.h"
12 #include "tools/flags/CommandLineFlags.h"
13 
14 #include <cstdlib>
15 #include <string>
16 
17 static DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use.");
18 
bumpTestCount()19 void skiatest::Reporter::bumpTestCount() {}
20 
allowExtendedTest() const21 bool skiatest::Reporter::allowExtendedTest() const { return false; }
22 
verbose() const23 bool skiatest::Reporter::verbose() const { return false; }
24 
25 
reportFailedWithContext(const skiatest::Failure & f)26 void skiatest::Reporter::reportFailedWithContext(const skiatest::Failure& f) {
27     SkString fullMessage = f.message;
28     if (!fContextStack.empty()) {
29         fullMessage.append(" [");
30         for (int i = 0; i < fContextStack.size(); ++i) {
31             if (i > 0) {
32                 fullMessage.append(", ");
33             }
34             fullMessage.append(fContextStack[i]);
35         }
36         fullMessage.append("]");
37     }
38     this->reportFailed(skiatest::Failure(f.fileName, f.lineNo, f.condition, fullMessage));
39 }
40 
toString() const41 SkString skiatest::Failure::toString() const {
42     SkString result = SkStringPrintf("%s:%d\t", this->fileName, this->lineNo);
43     if (!this->message.isEmpty()) {
44         result.append(this->message);
45         if (strlen(this->condition) > 0) {
46             result.append(": ");
47         }
48     }
49     result.append(this->condition);
50     return result;
51 }
52 
GetTmpDir()53 SkString skiatest::GetTmpDir() {
54     if (!FLAGS_tmpDir.isEmpty()) {
55         return SkString(FLAGS_tmpDir[0]);
56     }
57 #ifdef SK_BUILD_FOR_ANDROID
58     const char* environmentVariable = "TMPDIR";
59     const char* defaultValue = "/data/local/tmp";
60 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
61     const char* environmentVariable = "TMPDIR";
62     const char* defaultValue = "/tmp";
63 #elif defined(SK_BUILD_FOR_WIN)
64     const char* environmentVariable = "TEMP";
65     const char* defaultValue = nullptr;
66 #else
67     const char* environmentVariable = nullptr;
68     const char* defaultValue = nullptr;
69 #endif
70     const char* tmpdir = environmentVariable ? getenv(environmentVariable) : nullptr;
71     return SkString(tmpdir ? tmpdir : defaultValue);
72 }
73 
Timer()74 skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {}
75 
elapsedNs() const76 double skiatest::Timer::elapsedNs() const {
77     return SkTime::GetNSecs() - fStartNanos;
78 }
79 
elapsedMs() const80 double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; }
81 
elapsedMsInt() const82 SkMSec skiatest::Timer::elapsedMsInt() const {
83     const double elapsedMs = this->elapsedMs();
84     SkASSERT(SK_MSecMax >= elapsedMs);
85     return static_cast<SkMSec>(elapsedMs);
86 }
87