Make zircon benchmarks runnable from FIDL service
Change-Id: Iac79d74759034c7595ddb800d69e354b1de79a77
diff --git a/system/ulib/perftest/include/perftest/perftest.h b/system/ulib/perftest/include/perftest/perftest.h
index a94c635..3f18c98 100644
--- a/system/ulib/perftest/include/perftest/perftest.h
+++ b/system/ulib/perftest/include/perftest/perftest.h
@@ -8,6 +8,7 @@
#include <fbl/function.h>
#include <fbl/string.h>
+#include <fbl/vector.h>
#include <perftest/results.h>
// This is a library for writing performance tests. It supports
@@ -181,6 +182,9 @@
// details.)
int PerfTestMain(int argc, char** argv);
+// Experimental. Just returns the test results so they may be written to a FIDL service.
+fbl::Vector<TestCaseResults> RunPerfTests();
+
// Run a single test |run_count| times, and add the results to
// |results_set| using the given name, |test_name|. On error, this returns
// false and sets |*error_out| to an error string.
diff --git a/system/ulib/perftest/include/perftest/results.h b/system/ulib/perftest/include/perftest/results.h
index c152419..9bd50e0 100644
--- a/system/ulib/perftest/include/perftest/results.h
+++ b/system/ulib/perftest/include/perftest/results.h
@@ -69,7 +69,7 @@
class ResultsSet {
public:
fbl::Vector<TestCaseResults>* results() { return &results_; }
-
+ fbl::Vector<TestCaseResults> take_results() { return fbl::move(results_); }
TestCaseResults* AddTestCase(const fbl::String& label,
const fbl::String& unit);
diff --git a/system/ulib/perftest/include/perftest/runner.h b/system/ulib/perftest/include/perftest/runner.h
index 41a62df..a70ce5a 100644
--- a/system/ulib/perftest/include/perftest/runner.h
+++ b/system/ulib/perftest/include/perftest/runner.h
@@ -8,6 +8,7 @@
#include <perftest/perftest.h>
namespace perftest {
+
namespace internal {
// Definitions used by the perf test runner. These are in a header file so
@@ -23,6 +24,8 @@
bool RunTests(TestList* test_list, uint32_t run_count, const char* regex_string,
FILE* log_stream, ResultsSet* results_set);
+fbl::Vector<TestCaseResults> RunPerfTests();
+
struct CommandArgs {
const char* output_filename = nullptr;
// Note that this default matches any string.
diff --git a/system/ulib/perftest/runner.cpp b/system/ulib/perftest/runner.cpp
index 3d910ca..e1228ec 100644
--- a/system/ulib/perftest/runner.cpp
+++ b/system/ulib/perftest/runner.cpp
@@ -22,7 +22,14 @@
#include <zircon/assert.h>
#include <zircon/syscalls.h>
+
namespace perftest {
+
+// Experimental. Just returns the test results so they may be written to a FIDL service.
+fbl::Vector<TestCaseResults> RunPerfTests() {
+ return internal::RunPerfTests();
+}
+
namespace {
// g_tests needs to be POD because this list is populated by constructors.
@@ -273,6 +280,20 @@
namespace internal {
+// Experimental. Just returns the test results so they may be written to a FIDL service.
+fbl::Vector<TestCaseResults> RunPerfTests() {
+ internal::CommandArgs args;
+
+ zx_duration_t duration =
+ static_cast<zx_duration_t>(ZX_SEC(1) * args.startup_delay_seconds);
+ zx_nanosleep(zx_deadline_after(duration));
+
+ ResultsSet results;
+ // Just run each test 10 times to make the output easy to understand.
+ RunTests(g_tests, 10, args.filter_regex, stdout, &results);
+ return results.take_results();
+}
+
bool RunTests(TestList* test_list, uint32_t run_count, const char* regex_string,
FILE* log_stream, ResultsSet* results_set) {
// Compile the regular expression.