| // Copyright 2016 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include <benchmark/benchmark.h> |
| #include <fstream> |
| #include <libgen.h> |
| #include <spec_fixture.h> |
| #include <spec_utils.h> |
| #include <sys/stat.h> |
| #include <unistd.h> |
| #include <glog/logging.h> |
| |
| namespace { |
| |
| class MesaFixture : public SpecFixture { |
| protected: |
| MesaFixture() : SpecFixture("177.mesa") {} |
| }; |
| |
| class GzipFixture : public SpecFixture { |
| protected: |
| GzipFixture() : SpecFixture("164.gzip"){}; |
| }; |
| |
| } // namespace |
| |
| std::string executableDir; |
| |
| // Where we will run benchmarks |
| std::string tmpDir; |
| |
| BENCHMARK_F(MesaFixture, 177_Mesa)(benchmark::State& st) { |
| while (st.KeepRunning()) { |
| if (RunSpec(NULL, 0) != 0) { |
| st.SkipWithError( |
| (std::string("Error while running benchmark: ") + strerror(errno)) |
| .c_str()); |
| } |
| } |
| } |
| |
| BENCHMARK_F(GzipFixture, 164_Gzip)(benchmark::State& st) { |
| while (st.KeepRunning()) { |
| std::vector<std::string> inputs = {"input.source", "input.log", |
| "input.graphic", "input.random", |
| "input.program"}; |
| |
| for (auto& it : inputs) { |
| const char* args[] = {it.c_str(), "60"}; |
| if (RunSpec(args, 2) != 0) { |
| st.SkipWithError( |
| (std::string("Error while running benchmark: ") + strerror(errno)) |
| .c_str()); |
| } |
| } |
| } |
| } |
| |
| int main(int argc, char* argv[]) { |
| ::benchmark::Initialize(&argc, argv); |
| google::InitGoogleLogging(argv[0]); |
| char* cwd; |
| CHECK_NOTNULL((cwd = get_current_dir_name())); |
| executableDir = std::string(cwd) + "/" + dirname(argv[0]); |
| |
| char* c = tempnam(NULL, "speccpu2000"); |
| CHECK_NOTNULL(c); |
| tmpDir = c; |
| |
| CHECK_EQ(mkdir(tmpDir.c_str(), 0600), 0) |
| << "Error while creating tmp dir: " << tmpDir.c_str() |
| << ", error:" << strerror(errno); |
| |
| ::benchmark::RunSpecifiedBenchmarks(); |
| |
| // try deleting temp directory |
| CHECK_EQ(DeleteDir(tmpDir), 0) << "Error while deleting tmp dir: " << tmpDir |
| << ", error:" << strerror(errno); |
| return 0; |
| } |