Exemplo n.º 1
0
ThermalManager::ThermalManager(int32_t threshold, uint32_t sleepIntervalMs, uint32_t timeoutMs)
    : fSleepIntervalMs(sleepIntervalMs)
    , fTimeoutMs(timeoutMs) {
    static const char* kThermalZonePath = "/sys/class/thermal/";
    SkOSFile::Iter it(kThermalZonePath);
    SkString path;
    while (it.next(&path, true)) {
        if (!path.contains("thermal_zone")) {
            continue;
        }

        SkString fullPath(kThermalZonePath);
        fullPath.append(path);
        SkOSFile::Iter thermalZoneIt(fullPath.c_str());

        SkString filename;
        while (thermalZoneIt.next(&filename)) {
            if (!(filename.contains("trip_point") && filename.contains("temp"))) {
                continue;
            }

            fTripPoints.push_back(TripPoint(fullPath, filename, threshold));
        }
    }
}
Exemplo n.º 2
0
/// Returns true if string contains any of these substrings.
static bool string_contains_any_of(const SkString& string,
                                   const StringArray& substrings) {
    for (int i = 0; i < substrings.count(); i++) {
        if (string.contains(substrings[i]->c_str())) {
            return true;
        }
    }
    return false;
}
Exemplo n.º 3
0
/**
 *  Test SkOSPath::Join, SkOSPath::Basename, and SkOSPath::Dirname.
 *  Will use SkOSPath::Join to append filename to dir, test that it works correctly,
 *  and tests using SkOSPath::Basename on the result.
 *  @param reporter Reporter for test conditions.
 *  @param dir String representing the path to a folder. May or may not
 *      end with SkOSPath::SEPARATOR.
 *  @param filename String representing the basename of a file. Must NOT
 *      contain SkOSPath::SEPARATOR.
 */
static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir,
                               SkString filename) {
    // If filename contains SkOSPath::SEPARATOR, the tests will fail.
    SkASSERT(!filename.contains(SkOSPath::SEPARATOR));

    // Tests for SkOSPath::Join and SkOSPath::Basename

    // fullName should be "dir<SkOSPath::SEPARATOR>file"
    SkString fullName = SkOSPath::Join(dir.c_str(), filename.c_str());

    // fullName should be the combined size of dir and file, plus one if
    // dir did not include the final path separator.
    size_t expectedSize = dir.size() + filename.size();
    if (!dir.endsWith(SkOSPath::SEPARATOR) && !dir.isEmpty()) {
        expectedSize++;
    }
    REPORTER_ASSERT(reporter, fullName.size() == expectedSize);

    SkString basename = SkOSPath::Basename(fullName.c_str());
    SkString dirname = SkOSPath::Dirname(fullName.c_str());

    // basename should be the same as filename
    REPORTER_ASSERT(reporter, basename.equals(filename));

    // dirname should be the same as dir with any trailing seperators removed.
    // Except when the the string is just "/".
    SkString strippedDir = dir;
    while (strippedDir.size() > 2 && strippedDir[strippedDir.size() - 1] == SkOSPath::SEPARATOR) {
        strippedDir.remove(strippedDir.size() - 1, 1);
    }
    if (!dirname.equals(strippedDir)) {
        SkDebugf("OOUCH %s %s %s\n", dir.c_str(), strippedDir.c_str(), dirname.c_str());
    }
    REPORTER_ASSERT(reporter, dirname.equals(strippedDir));

    // basename will not contain a path separator
    REPORTER_ASSERT(reporter, !basename.contains(SkOSPath::SEPARATOR));

    // Now take the basename of filename, which should be the same as filename.
    basename = SkOSPath::Basename(filename.c_str());
    REPORTER_ASSERT(reporter, basename.equals(filename));
}
Exemplo n.º 4
0
void SkAppendScalar(SkString* str, SkScalar value, SkScalarAsStringType asType) {
    switch (asType) {
        case kHex_SkScalarAsStringType:
            str->appendf("SkBits2Float(0x%08x)", SkFloat2Bits(value));
            break;
        case kDec_SkScalarAsStringType: {
            SkString tmp;
            tmp.printf("%g", value);
            if (tmp.contains('.')) {
                tmp.appendUnichar('f');
            }
            str->append(tmp);
            break;
        }
    }
}