summaryrefslogtreecommitdiff
path: root/tools/stats_log_api_gen/test_collation.cpp
diff options
context:
space:
mode:
authorTej Singh <singhtejinder@google.com>2019-03-07 19:08:52 -0800
committerTej Singh <singhtejinder@google.com>2019-03-15 18:54:02 -0700
commit810eeb3eed455812f2240040858a4d4882df7a4e (patch)
tree8318c290ea7710c7b5bef236a2430a7aa7d891bf /tools/stats_log_api_gen/test_collation.cpp
parenta3e9de112196e86bbafd36d70983fa7981f39295 (diff)
Mainline logging to statsd: native static libs
Creates an annotation to specify if an atom needs to be logged from a specific mainline module. Creates options in stats-log-api-gen so that if the same module name is passed in, cpp/h files will be generated with only those atoms that are specified. These files can be used to create a static library per mainline module to log to statsd. Test: builds Test: atest stats-log-api-gen-test Test: does not affect existing shared libstatslog Test: manually created a static lib for netd and used it to log to statsd. Used testdrive to validate the data was properly flowing. Bug: 126134616 Change-Id: I78064f81fb4971eede8e97dacce5424e3eefd8bb
Diffstat (limited to 'tools/stats_log_api_gen/test_collation.cpp')
-rw-r--r--tools/stats_log_api_gen/test_collation.cpp54
1 files changed, 47 insertions, 7 deletions
diff --git a/tools/stats_log_api_gen/test_collation.cpp b/tools/stats_log_api_gen/test_collation.cpp
index dc585c1c5dd1..bcf18ae8bf19 100644
--- a/tools/stats_log_api_gen/test_collation.cpp
+++ b/tools/stats_log_api_gen/test_collation.cpp
@@ -32,7 +32,7 @@ using std::vector;
* Return whether the set contains a vector of the elements provided.
*/
static bool
-set_contains_vector(const set<vector<java_type_t>>& s, int count, ...)
+set_contains_vector(const map<vector<java_type_t>, set<string>>& s, int count, ...)
{
va_list args;
vector<java_type_t> v;
@@ -86,17 +86,17 @@ TEST(CollationTest, CollateStats) {
int errorCount = collate_atoms(Event::descriptor(), &atoms);
EXPECT_EQ(0, errorCount);
- EXPECT_EQ(3ul, atoms.signatures.size());
+ EXPECT_EQ(3ul, atoms.signatures_to_modules.size());
// IntAtom, AnotherIntAtom
- EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures, JAVA_TYPE_INT);
+ EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures_to_modules, JAVA_TYPE_INT);
// OutOfOrderAtom
- EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures, JAVA_TYPE_INT, JAVA_TYPE_INT);
+ EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures_to_modules, JAVA_TYPE_INT, JAVA_TYPE_INT);
// AllTypesAtom
EXPECT_SET_CONTAINS_SIGNATURE(
- atoms.signatures,
+ atoms.signatures_to_modules,
JAVA_TYPE_ATTRIBUTION_CHAIN, // AttributionChain
JAVA_TYPE_DOUBLE, // double
JAVA_TYPE_FLOAT, // float
@@ -228,8 +228,7 @@ TEST(CollationTest, FailOnBadBinaryFieldAtom) {
TEST(CollationTest, PassOnWhitelistedAtom) {
Atoms atoms;
- int errorCount =
- collate_atoms(ListedAtoms::descriptor(), &atoms);
+ int errorCount = collate_atoms(ListedAtoms::descriptor(), &atoms);
EXPECT_EQ(errorCount, 0);
EXPECT_EQ(atoms.decls.size(), 2ul);
}
@@ -246,5 +245,46 @@ TEST(CollationTest, RecogniseWhitelistedAtom) {
}
}
+TEST(CollationTest, PassOnLogFromModuleAtom) {
+ Atoms atoms;
+ int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
+ EXPECT_EQ(errorCount, 0);
+ EXPECT_EQ(atoms.decls.size(), 3ul);
+}
+
+TEST(CollationTest, RecognizeModuleAtom) {
+ Atoms atoms;
+ int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
+ EXPECT_EQ(errorCount, 0);
+ EXPECT_EQ(atoms.decls.size(), 3ul);
+ for (const auto& atomDecl: atoms.decls) {
+ if (atomDecl.code == 1) {
+ EXPECT_TRUE(atomDecl.hasModule);
+ EXPECT_EQ(atomDecl.moduleName, "module1");
+ } else if (atomDecl.code == 2) {
+ EXPECT_TRUE(atomDecl.hasModule);
+ EXPECT_EQ(atomDecl.moduleName, "module2");
+ } else {
+ EXPECT_FALSE(atomDecl.hasModule);
+ }
+ }
+
+ EXPECT_EQ(atoms.signatures_to_modules.size(), 2u);
+ EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures_to_modules, JAVA_TYPE_INT);
+ EXPECT_SET_CONTAINS_SIGNATURE(atoms.signatures_to_modules, JAVA_TYPE_STRING);
+ for (auto signature_to_modules_it : atoms.signatures_to_modules) {
+ vector<java_type_t> signature = signature_to_modules_it.first;
+ if (signature[0] == JAVA_TYPE_STRING) {
+ EXPECT_EQ(signature_to_modules_it.second.size(), 0u);
+ } else if (signature[0] == JAVA_TYPE_INT) {
+ set<string> modules = signature_to_modules_it.second;
+ EXPECT_EQ(modules.size(), 2u);
+ // Assert that the set contains "module1" and "module2".
+ EXPECT_NE(modules.find("module1"), modules.end());
+ EXPECT_NE(modules.find("module2"), modules.end());
+ }
+ }
+}
+
} // namespace stats_log_api_gen
} // namespace android \ No newline at end of file