Commit 05fd879e authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add Serialize() function to traffic annotation auditor.

Serialize function for text output of annotations is added to
traffic_annotation_auditor for debugging purposes.
Also two small updates in output and documentation are done.

Bug: 690323
Change-Id: I35ab3381a116dde685f283982b378c6549ce8a90
Reviewed-on: https://chromium-review.googlesource.com/916196
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536677}
parent a913aa86
......@@ -98,5 +98,5 @@ disable this test by setting the `TEST_IS_ENABLED` flag to False in
and cc the people listed in OWNERS; they'll be on the hook to rebuild and
re-enable the test.
CLANG_REVISION = '321529'
LASTCHANGE=0e610ff740a0875d44277eda30348c6009c73761-refs/heads/master@{#535445}
CLANG_REVISION = '324578'
LASTCHANGE=cd6e9ca2e9c5cda30fac77c70d35d2eb699e5f88-refs/heads/master@{#536659}
......@@ -18,12 +18,5 @@ The binaries of this file and the clang tool are checked out into
`tools/traffic_annotation/bin/[platform]`. This is only done for Linux platform
now and will be extended to other platforms later.
## Running on Linux
## Running
Before running, you need to build the COMPLETE chromium.
## Running on Windows
Before running, you need to build the COMPLETE chromium using clang with keeprsp
switch as follows:
1. `gn args [build_dir, e.g. out\Debug]`
2. add `is_clang=true` to the opened text file and save and close it.
3. `ninja -C [build_dir] -d keeprsp`
......@@ -615,6 +615,42 @@ AnnotationInstance AnnotationInstance::LoadFromArchive(
return annotation;
}
std::string AnnotationInstance::Serialize() const {
std::string text;
std::set<int> fields;
text = base::StringPrintf(
"{\tType: %i\n"
"\tID: %s\n"
"\tHashcode 1: %i\n"
"\tHashcode 2: %i\n"
"\tFrom Archive: %i\n"
"\tSource File: %s\n",
static_cast<int>(type), proto.unique_id().c_str(), unique_id_hash_code,
second_id_hash_code, is_loaded_from_archive,
proto.source().file().c_str());
GetSemanticsFieldNumbers(&fields);
text += "\tSemantics: ";
for (int i : fields)
text += base::StringPrintf("%s,", kSemanticsFields[i].c_str());
GetPolicyFieldNumbers(&fields);
text += "\n\tPolicies: ";
for (int i : fields) {
text += base::StringPrintf("%s%s,", i < 0 ? "-" : "",
kPolicyFields[abs(i)].c_str());
}
text += "\n}";
return text;
}
std::ostream& operator<<(std::ostream& out,
const AnnotationInstance& instance) {
return out << instance.Serialize();
}
CallInstance::CallInstance() : line_number(0), is_annotated(false) {}
CallInstance::CallInstance(const CallInstance& other)
......
......@@ -105,6 +105,9 @@ class AnnotationInstance : public InstanceBase {
AnnotationInstance& completing_annotation,
AnnotationInstance* combination) const;
// Serializes to text for debugging and visualization.
std::string Serialize() const;
// Protobuf of the annotation.
traffic_annotation::NetworkTrafficAnnotation proto;
......@@ -129,6 +132,8 @@ class AnnotationInstance : public InstanceBase {
bool is_merged;
};
std::ostream& operator<<(std::ostream& out, const AnnotationInstance& instance);
// Holds an instance of calling a function that might have a network traffic
// annotation argument.
class CallInstance : public InstanceBase {
......
......@@ -464,7 +464,7 @@ int main(int argc, char* argv[]) {
break;
}
} else {
printf("/Completed.");
printf("Traffic annotations are all OK.\n");
}
return static_cast<int>(errors.size());
......
946afc69eb6314243010adb7bdd9bd952909fc4e
\ No newline at end of file
5fcf7e1a6e38b432a7246b791398115f388011e3
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment