From 418ce29089b861fc323914f3a76b54b1191f4ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 5 Apr 2009 15:41:41 +0000 Subject: [PATCH] Make Benchmark pick up the test you want to run from the command line args. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29941 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/servers/app/benchmark/Benchmark.cpp | 71 ++++++++++++++++--- .../servers/app/benchmark/ClippedLineTest.cpp | 9 ++- .../servers/app/benchmark/ClippedLineTest.h | 4 +- .../app/benchmark/HorizontalLineTest.cpp | 9 ++- .../app/benchmark/HorizontalLineTest.h | 4 +- .../servers/app/benchmark/RandomLineTest.cpp | 10 ++- .../servers/app/benchmark/RandomLineTest.h | 10 +-- .../servers/app/benchmark/StringTest.cpp | 9 ++- src/tests/servers/app/benchmark/StringTest.h | 4 +- .../app/benchmark/VerticalLineTest.cpp | 9 ++- .../servers/app/benchmark/VerticalLineTest.h | 4 +- 11 files changed, 121 insertions(+), 22 deletions(-) diff --git a/src/tests/servers/app/benchmark/Benchmark.cpp b/src/tests/servers/app/benchmark/Benchmark.cpp index 0727fbeafb..d974c506ff 100644 --- a/src/tests/servers/app/benchmark/Benchmark.cpp +++ b/src/tests/servers/app/benchmark/Benchmark.cpp @@ -1,8 +1,9 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ +#include #include #include @@ -17,15 +18,27 @@ #include "StringTest.h" #include "VerticalLineTest.h" + +struct test_info { + const char* name; + Test* (*create)(); +}; + +const test_info kTestInfos[] = { + { "ClippedLines", ClippedLineTest::CreateTest }, + { "HorizontalLines", HorizontalLineTest::CreateTest }, + { "RandomLines", RandomLineTest::CreateTest }, + { "Strings", StringTest::CreateTest }, + { "VerticalLines", VerticalLineTest::CreateTest }, + { NULL, NULL } +}; + + class Benchmark : public BApplication { public: - Benchmark() + Benchmark(Test* test) : BApplication("application/x-vnd.haiku-benchmark"), - fTest(new ClippedLineTest), -// fTest(new HorizontalLineTest), -// fTest(new RandomLineTest), -// fTest(new StringTest), -// fTest(new VerticalLineTest), + fTest(test), fTestWindow(NULL) { } @@ -79,11 +92,51 @@ private: }; -// main +static void +print_test_list(bool error) +{ + FILE* out = (error ? stderr : stdout); + + fprintf(out, "available tests:\n"); + + for (int32 i = 0; kTestInfos[i].name; i++) + fprintf(out, " %s\n", kTestInfos[i].name); +} + + int main(int argc, char** argv) { - Benchmark app; + // get test name + const char* testName; + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + print_test_list(true); + exit(1); + } + testName = argv[1]; + + // find and create the test + Test* test = NULL; + try { + for (int32 i = 0; kTestInfos[i].name; i++) { + if (strcmp(testName, kTestInfos[i].name) == 0) { + test = (kTestInfos[i].create)(); + break; + } + } + } catch (std::bad_alloc) { + fprintf(stderr, "Insufficient memory to create the test. Sorry.\n"); + exit(1); + } + + if (test == NULL) { + fprintf(stderr, "Error: Invalid test name: \"%s\"\n", testName); + print_test_list(true); + exit(1); + } + + Benchmark app(test); app.Run(); return 0; } diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.cpp b/src/tests/servers/app/benchmark/ClippedLineTest.cpp index 431699a19c..39462679ea 100644 --- a/src/tests/servers/app/benchmark/ClippedLineTest.cpp +++ b/src/tests/servers/app/benchmark/ClippedLineTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -95,3 +95,10 @@ ClippedLineTest::PrintResults() (float)timeLeak / fIterations / 1000000); } + +Test* +ClippedLineTest::CreateTest() +{ + return new ClippedLineTest(); +} + diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.h b/src/tests/servers/app/benchmark/ClippedLineTest.h index 878120efe5..dc48fc1609 100644 --- a/src/tests/servers/app/benchmark/ClippedLineTest.h +++ b/src/tests/servers/app/benchmark/ClippedLineTest.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ #ifndef CLIPPED_LINE_TEST_H @@ -18,6 +18,8 @@ public: virtual bool RunIteration(BView* view); virtual void PrintResults(); + static Test* CreateTest(); + private: bigtime_t fTestDuration; bigtime_t fTestStart; diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.cpp b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp index 24c8d45243..89f4922429 100644 --- a/src/tests/servers/app/benchmark/HorizontalLineTest.cpp +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -87,3 +87,10 @@ HorizontalLineTest::PrintResults() (float)timeLeak / fIterations / 1000000); } + +Test* +HorizontalLineTest::CreateTest() +{ + return new HorizontalLineTest(); +} + diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.h b/src/tests/servers/app/benchmark/HorizontalLineTest.h index 04c600d5ff..99c1d56d30 100644 --- a/src/tests/servers/app/benchmark/HorizontalLineTest.h +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ #ifndef HORIZONTAL_LINE_TEST_H @@ -18,6 +18,8 @@ public: virtual bool RunIteration(BView* view); virtual void PrintResults(); + static Test* CreateTest(); + private: bigtime_t fTestDuration; bigtime_t fTestStart; diff --git a/src/tests/servers/app/benchmark/RandomLineTest.cpp b/src/tests/servers/app/benchmark/RandomLineTest.cpp index b49352b47a..c2844774ee 100644 --- a/src/tests/servers/app/benchmark/RandomLineTest.cpp +++ b/src/tests/servers/app/benchmark/RandomLineTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -90,3 +90,11 @@ RandomLineTest::PrintResults() (float)timeLeak / fIterations / 1000000); } + +Test* +RandomLineTest::CreateTest() +{ + return new RandomLineTest(); +} + + diff --git a/src/tests/servers/app/benchmark/RandomLineTest.h b/src/tests/servers/app/benchmark/RandomLineTest.h index 74c52d485b..e2a5e67975 100644 --- a/src/tests/servers/app/benchmark/RandomLineTest.h +++ b/src/tests/servers/app/benchmark/RandomLineTest.h @@ -1,9 +1,9 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ -#ifndef VERTICAL_LINE_TEST_H -#define VERTICAL_LINE_TEST_H +#ifndef RANDOM_LINE_TEST_H +#define RANDOM_LINE_TEST_H #include @@ -18,6 +18,8 @@ public: virtual bool RunIteration(BView* view); virtual void PrintResults(); + static Test* CreateTest(); + private: bigtime_t fTestDuration; bigtime_t fTestStart; @@ -30,4 +32,4 @@ private: BRect fViewBounds; }; -#endif // VERTICAL_LINE_TEST_H +#endif // RANDOM_LINE_TEST_H diff --git a/src/tests/servers/app/benchmark/StringTest.cpp b/src/tests/servers/app/benchmark/StringTest.cpp index 4896d9fbad..2b09b4419e 100644 --- a/src/tests/servers/app/benchmark/StringTest.cpp +++ b/src/tests/servers/app/benchmark/StringTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -111,3 +111,10 @@ StringTest::PrintResults() (float)timeLeak / fIterations / 1000000); } + +Test* +StringTest::CreateTest() +{ + return new StringTest(); +} + diff --git a/src/tests/servers/app/benchmark/StringTest.h b/src/tests/servers/app/benchmark/StringTest.h index 062a7d5ada..dec6bcf708 100644 --- a/src/tests/servers/app/benchmark/StringTest.h +++ b/src/tests/servers/app/benchmark/StringTest.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ #ifndef STRING_TEST_H @@ -18,6 +18,8 @@ public: virtual bool RunIteration(BView* view); virtual void PrintResults(); + static Test* CreateTest(); + private: bigtime_t fTestDuration; bigtime_t fTestStart; diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.cpp b/src/tests/servers/app/benchmark/VerticalLineTest.cpp index 90d81a2f7f..cdaa1fa9e2 100644 --- a/src/tests/servers/app/benchmark/VerticalLineTest.cpp +++ b/src/tests/servers/app/benchmark/VerticalLineTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -87,3 +87,10 @@ VerticalLineTest::PrintResults() (float)timeLeak / fIterations / 1000000); } + +Test* +VerticalLineTest::CreateTest() +{ + return new VerticalLineTest(); +} + diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.h b/src/tests/servers/app/benchmark/VerticalLineTest.h index d2a936d22a..7f5229392c 100644 --- a/src/tests/servers/app/benchmark/VerticalLineTest.h +++ b/src/tests/servers/app/benchmark/VerticalLineTest.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stephan Aßmus + * Copyright (C) 2008-2009 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ #ifndef VERTICAL_LINE_TEST_H @@ -18,6 +18,8 @@ public: virtual bool RunIteration(BView* view); virtual void PrintResults(); + static Test* CreateTest(); + private: bigtime_t fTestDuration; bigtime_t fTestStart;