A few small fix ups.
- Add a default xml file to run if nothing is specified on the command-line.
- Add a way to specify a xml file in suites without having to specify the
full path name.
- Move all of the test xml files into their own directory.
- Add the suites directory for to glibc benchmarks.
- Add a new test for help data.
- Modify the full suite test to verify the default xml is chosen and use
the real full.xml instead of the test one. Delete the test_full.xml.
- Move the property tests to the end of the suite.
- Add skipping of xml comments.
Test: Ran the unit tests and ran the bionic benchmarks.
Change-Id: Ie99965f86fe915af0175de46c7780ab79e2b0843
diff --git a/benchmarks/bionic_benchmarks.cpp b/benchmarks/bionic_benchmarks.cpp
index e5a23ad..e61233c 100644
--- a/benchmarks/bionic_benchmarks.cpp
+++ b/benchmarks/bionic_benchmarks.cpp
@@ -25,11 +25,18 @@
#include <string>
#include <vector>
-#include "android-base/strings.h"
+#include <android-base/file.h>
+#include <android-base/strings.h>
#include <benchmark/benchmark.h>
#include <tinyxml2.h>
#include "util.h"
+#if defined(__ANDROID__)
+static constexpr const char* kDefaultSuite="full.xml";
+#else
+static constexpr const char* kDefaultSuite="host.xml";
+#endif
+
std::map<std::string, benchmark_func_t> g_str_to_func;
std::mutex g_map_lock;
@@ -48,9 +55,10 @@
void Usage() {
printf("Usage:\n");
- printf("bionic_benchmarks [--bionic_cpu=<cpu_to_isolate>] [--bionic_xml=<path_to_xml>]\n");
+ printf("bionic_benchmarks [--bionic_cpu=<cpu_to_isolate>]\n");
+ printf(" [--bionic_xml=<path_to_xml>]\n");
printf(" [--bionic_iterations=<num_iter>]\n");
- printf(" [--bionic_extra=\"<fn_name> <arg1> <arg 2> ... ]\n");
+ printf(" [--bionic_extra=\"<fn_name> <arg1> <arg 2> ...\"]\n");
printf(" [<Google benchmark flags>]\n");
printf("Google benchmark flags:\n");
@@ -255,9 +263,13 @@
// Read and register the functions.
tinyxml2::XMLNode* fn = doc.FirstChildElement("fn");
- args_vector_t arg_vector;
- args_vector_t* run_args = &arg_vector;
while (fn) {
+ if (fn == fn->ToComment()) {
+ // Skip comments.
+ fn = fn->NextSibling();
+ continue;
+ }
+
auto fn_elem = fn->FirstChildElement("name");
if (!fn_elem) {
errx(1, "ERROR: Malformed XML entry: missing name element.");
@@ -267,8 +279,10 @@
errx(1, "ERROR: Malformed XML entry: error parsing name text.");
}
auto* xml_args = fn->FirstChildElement("args");
- run_args = ResolveArgs(run_args, xml_args ? android::base::Trim(xml_args->GetText()) : "",
- args_shorthand);
+ args_vector_t arg_vector;
+ args_vector_t* run_args = ResolveArgs(&arg_vector,
+ xml_args ? android::base::Trim(xml_args->GetText()) : "",
+ args_shorthand);
// XML values for CPU and iterations take precedence over those passed in via CLI.
bench_opts_t xml_opts{};
@@ -292,8 +306,6 @@
RegisterGoogleBenchmarks(xml_opts, cmdline_opts, fn_name, run_args);
fn = fn->NextSibling();
- run_args = &arg_vector;
- arg_vector.clear();
}
return 0;
}
@@ -355,6 +367,10 @@
return args_shorthand;
}
+static bool FileExists(const std::string& file) {
+ struct stat st;
+ return stat(file.c_str(), &st) != -1 && S_ISREG(st.st_mode);
+}
int main(int argc, char** argv) {
std::map<std::string, args_vector_t> args_shorthand = GetShorthand();
@@ -362,6 +378,26 @@
std::vector<char*> new_argv(argc);
SanitizeOpts(argc, argv, &new_argv);
+ if (opts.xmlpath.empty()) {
+ // Don't add the default xml file if a user is specifying the tests to run.
+ if (opts.extra_benchmarks.empty()) {
+ // Try and use the default.
+ opts.xmlpath = android::base::GetExecutableDirectory() + "/suites/" + kDefaultSuite;
+ if (!FileExists(opts.xmlpath)) {
+ printf("Cannot find default xml file %s\n", kDefaultSuite);
+ return 1;
+ }
+ }
+ } else if (!FileExists(opts.xmlpath)) {
+ // See if this is a file in the suites directory.
+ std::string file(android::base::GetExecutableDirectory() + "/suites/" + opts.xmlpath);
+ if (opts.xmlpath[0] == '/' || !FileExists(file)) {
+ printf("Cannot find xml file %s: does not exist or is not a file.\n", opts.xmlpath.c_str());
+ return 1;
+ }
+ opts.xmlpath = file;
+ }
+
if (!opts.xmlpath.empty()) {
if (int err = RegisterXmlBenchmarks(opts, args_shorthand)) {
return err;