2014-12-18 18:50:47 +00:00
|
|
|
/*
|
2016-02-11 19:48:58 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2014-12-18 18:50:47 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
2015-04-27 09:12:58 +00:00
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
2014-12-18 18:50:47 +00:00
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-08-30 07:15:31 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2014-12-03 23:14:02 +00:00
|
|
|
#include <osquery/core.h>
|
|
|
|
#include <osquery/filesystem.h>
|
|
|
|
#include <osquery/flags.h>
|
2015-01-21 21:36:55 +00:00
|
|
|
#include <osquery/logger.h>
|
2014-12-03 23:14:02 +00:00
|
|
|
|
2016-06-09 17:49:26 +00:00
|
|
|
#include "osquery/tests/test_util.h"
|
2014-08-30 07:15:31 +00:00
|
|
|
|
|
|
|
namespace pt = boost::property_tree;
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
|
|
|
// run this benchmark with --iterations=9001 to parse over 9000 property lists
|
2015-02-17 08:36:20 +00:00
|
|
|
FLAG(int32, plist_iterations, 100, "Iterations to execute plist benchmark");
|
2014-08-30 07:15:31 +00:00
|
|
|
|
|
|
|
class PlistBenchmark : public testing::Test {};
|
|
|
|
|
|
|
|
TEST_F(PlistBenchmark, bench_parse_plist_content) {
|
|
|
|
// using LOG(ERROR) as a quick hack so that gtest displays the log line even
|
|
|
|
// when the test passes
|
|
|
|
LOG(ERROR) << "Starting: " << getAsciiTime();
|
2015-02-05 00:54:44 +00:00
|
|
|
LOG(ERROR) << "Performing " << FLAGS_plist_iterations << " iterations";
|
2014-08-30 07:15:31 +00:00
|
|
|
int time = getUnixTime();
|
2015-02-05 00:54:44 +00:00
|
|
|
for (int i = 0; i < FLAGS_plist_iterations; ++i) {
|
2014-12-17 05:35:26 +00:00
|
|
|
std::string content;
|
|
|
|
readFile(kTestDataPath + "test.plist", content);
|
|
|
|
|
2014-08-30 07:15:31 +00:00
|
|
|
pt::ptree tree;
|
|
|
|
auto s = parsePlistContent(content, tree);
|
|
|
|
EXPECT_TRUE(s.ok());
|
2014-12-17 05:35:26 +00:00
|
|
|
|
2014-08-30 07:15:31 +00:00
|
|
|
EXPECT_EQ(s.toString(), "OK");
|
|
|
|
EXPECT_EQ(tree.get<bool>("Disabled"), true);
|
|
|
|
EXPECT_THROW(tree.get<bool>("foobar"), pt::ptree_bad_path);
|
|
|
|
EXPECT_EQ(tree.get<std::string>("Label"), "com.apple.FileSyncAgent.sshd");
|
|
|
|
std::vector<std::string> program_arguments = {
|
|
|
|
"/System/Library/CoreServices/FileSyncAgent.app/Contents/Resources/"
|
|
|
|
"FileSyncAgent_sshd-keygen-wrapper",
|
2014-10-28 00:37:36 +00:00
|
|
|
"-i",
|
|
|
|
"-f",
|
2014-08-30 07:15:31 +00:00
|
|
|
"/System/Library/CoreServices/FileSyncAgent.app/Contents/Resources/"
|
2014-10-28 00:37:36 +00:00
|
|
|
"FileSyncAgent_sshd_config",
|
|
|
|
};
|
2014-08-30 07:15:31 +00:00
|
|
|
pt::ptree program_arguments_tree = tree.get_child("ProgramArguments");
|
|
|
|
std::vector<std::string> program_arguments_parsed;
|
|
|
|
for (const auto& argument : program_arguments_tree) {
|
|
|
|
program_arguments_parsed.push_back(argument.second.get<std::string>(""));
|
|
|
|
}
|
|
|
|
EXPECT_EQ(program_arguments_parsed, program_arguments);
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "Ending: " << getAsciiTime();
|
2014-08-30 11:06:21 +00:00
|
|
|
LOG(ERROR) << "Benchmark executed in " << (getUnixTime() - time)
|
|
|
|
<< " seconds";
|
2014-08-30 07:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|