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
This commit is contained in:
Stephan Aßmus 2009-04-05 15:41:41 +00:00
parent 561b5d977b
commit 418ce29089
11 changed files with 121 additions and 22 deletions

View File

@ -1,8 +1,9 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include <memory>
#include <stdio.h>
#include <Application.h>
@ -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 <test name>\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;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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();
}

View File

@ -1,9 +1,9 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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 <Rect.h>
@ -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

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* 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;