dynamically generate host-side data object generator from the spec
Change-Id: I0eac7ec273c0e30ada47ce171e1bb9a5b58e9be3
diff --git a/sysfuzzer/vtscompiler/VtsCompilerUtils.cpp b/sysfuzzer/vtscompiler/VtsCompilerUtils.cpp
index 02cc4e5..fc6142b 100644
--- a/sysfuzzer/vtscompiler/VtsCompilerUtils.cpp
+++ b/sysfuzzer/vtscompiler/VtsCompilerUtils.cpp
@@ -104,10 +104,15 @@
string GetCppVariableType(ArgumentSpecificationMessage arg) {
- if (arg.has_aggregate_type()) {
- return arg.aggregate_type();
- } else if (arg.has_primitive_type()) {
- return GetCppVariableType(arg.primitive_type());
+ if (arg.aggregate_type().size() == 1) {
+ return arg.aggregate_type(0);
+ } else if (arg.primitive_type().size() == 1) {
+ return GetCppVariableType(arg.primitive_type(0));
+ } else if (arg.primitive_type().size() > 1
+ || arg.aggregate_type().size() > 1) {
+ cerr << __FUNCTION__
+ << ": aggregate type with multiple attributes; not supported" << endl;
+ exit(-1);
}
cerr << __FUNCTION__ << ": neither instance nor data type is set" << endl;
exit(-1);
@@ -115,46 +120,54 @@
string GetCppInstanceType(ArgumentSpecificationMessage arg, string msg) {
- if (arg.has_aggregate_type()) {
- if (!strcmp(arg.aggregate_type().c_str(), "struct light_state_t*")) {
+ if (arg.aggregate_type().size() == 1) {
+ if (!strcmp(arg.aggregate_type(0).c_str(), "struct light_state_t*")) {
if (msg.length() == 0) {
return "GenerateLightState()";
} else {
return "GenerateLightStateUsingMessage(" + msg + ")";
}
- } else if (!strcmp(arg.aggregate_type().c_str(), "GpsCallbacks*")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "GpsCallbacks*")) {
return "GenerateGpsCallbacks()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "GpsUtcTime")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "GpsUtcTime")) {
return "GenerateGpsUtcTime()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "vts_gps_latitude")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "vts_gps_latitude")) {
return "GenerateLatitude()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "vts_gps_longitude")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "vts_gps_longitude")) {
return "GenerateLongitude()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "vts_gps_accuracy")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "vts_gps_accuracy")) {
return "GenerateGpsAccuracy()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "vts_gps_flags_uint16")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "vts_gps_flags_uint16")) {
return "GenerateGpsFlagsUint16()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "GpsPositionMode")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "GpsPositionMode")) {
return "GenerateGpsPositionMode()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "GpsPositionRecurrence")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "GpsPositionRecurrence")) {
return "GenerateGpsPositionRecurrence()";
- } else if (!strcmp(arg.aggregate_type().c_str(), "wifi_handle*")) {
+ } else if (!strcmp(arg.aggregate_type(0).c_str(), "wifi_handle*")) {
return "(wifi_handle*) malloc(sizeof(wifi_handle))";
} else {
cerr << __FILE__ << ":" << __LINE__ << " "
- << "unknown instance type " << arg.aggregate_type() << endl;
+ << "unknown instance type " << arg.aggregate_type(0) << endl;
}
+ } else if (arg.aggregate_type().size() > 1) {
+ cerr << __FUNCTION__
+ << ": aggregate type with multiple attributes; not supported" << endl;
+ exit(-1);
}
- if (arg.has_primitive_type()) {
- if (!strcmp(arg.primitive_type().c_str(), "uint32_t")) {
+ if (arg.primitive_type().size() > 1) {
+ cerr << __FUNCTION__
+ << ": a structure with multiple attributes; not supported" << endl;
+ exit(-1);
+ } else if (arg.primitive_type().size() == 1) {
+ if (!strcmp(arg.primitive_type(0).c_str(), "uint32_t")) {
return "RandomUint32()";
- } else if (!strcmp(arg.primitive_type().c_str(), "int32_t")) {
+ } else if (!strcmp(arg.primitive_type(0).c_str(), "int32_t")) {
return "RandomInt32()";
- } else if (!strcmp(arg.primitive_type().c_str(), "char_pointer")) {
+ } else if (!strcmp(arg.primitive_type(0).c_str(), "char_pointer")) {
return "RandomCharPointer()";
}
cerr << __FILE__ << ":" << __LINE__ << " "
- << "unknown data type " << arg.primitive_type() << endl;
+ << "unknown data type " << arg.primitive_type(0) << endl;
exit(-1);
}
cerr << __FUNCTION__ << ": neither instance nor data type is set" << endl;
diff --git a/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp b/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
index 955fc55..d351304 100644
--- a/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
+++ b/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
@@ -53,8 +53,8 @@
cpp_ss << " " << GetCppVariableType(arg) << " ";
cpp_ss << "arg" << arg_count << " = ";
if (arg_count == 0
- && arg.has_aggregate_type()
- && !strncmp(arg.aggregate_type().c_str(),
+ && arg.aggregate_type().size() == 1
+ && !strncmp(arg.aggregate_type(0).c_str(),
message.original_data_structure_name().c_str(),
message.original_data_structure_name().length())) {
cpp_ss << "reinterpret_cast<" << GetCppVariableType(arg) << ">("
@@ -78,8 +78,8 @@
// actual function call
GenerateCodeToStartMeasurement(cpp_ss);
cpp_ss << " ";
- if (api.return_type().has_primitive_type()
- && !strcmp(api.return_type().primitive_type().c_str(), "void")) {
+ if (api.return_type().primitive_type().size() == 1
+ && !strcmp(api.return_type().primitive_type(0).c_str(), "void")) {
cpp_ss << "*result = NULL;" << endl;
} else {
cpp_ss << "*result = const_cast<void*>(reinterpret_cast<const void*>(";
@@ -94,8 +94,9 @@
cpp_ss << "," << endl;
}
}
- if (!api.return_type().has_primitive_type()
- || strcmp(api.return_type().primitive_type().c_str(), "void")) {
+ if (api.return_type().primitive_type().size() == 0
+ || (api.return_type().primitive_type().size() == 1
+ && strcmp(api.return_type().primitive_type(0).c_str(), "void"))) {
cpp_ss << "))";
}
cpp_ss << ");" << endl;
diff --git a/sysfuzzer/vtscompiler/code_gen/LegacyHalCodeGen.cpp b/sysfuzzer/vtscompiler/code_gen/LegacyHalCodeGen.cpp
index 72310f2..146d4de 100644
--- a/sysfuzzer/vtscompiler/code_gen/LegacyHalCodeGen.cpp
+++ b/sysfuzzer/vtscompiler/code_gen/LegacyHalCodeGen.cpp
@@ -55,8 +55,8 @@
cpp_ss << " " << GetCppVariableType(arg) << " ";
cpp_ss << "arg" << arg_count << " = ";
if (arg_count == 0
- && arg.has_aggregate_type()
- && !strncmp(arg.aggregate_type().c_str(),
+ && arg.aggregate_type().size() == 1
+ && !strncmp(arg.aggregate_type(0).c_str(),
message.original_data_structure_name().c_str(),
message.original_data_structure_name().length())
&& message.original_data_structure_name().length() > 0) {
@@ -77,8 +77,8 @@
cpp_ss << ");" << endl;
// actual function call
- if (api.return_type().has_primitive_type()
- && !strcmp(api.return_type().primitive_type().c_str(), "void")) {
+ if (api.return_type().primitive_type().size() == 1
+ && !strcmp(api.return_type().primitive_type(0).c_str(), "void")) {
cpp_ss << "*result = NULL;" << endl;
} else {
cpp_ss << "*result = const_cast<void*>(reinterpret_cast<const void*>(";
@@ -97,8 +97,9 @@
cpp_ss << "," << endl;
}
}
- if (!api.return_type().has_primitive_type()
- || strcmp(api.return_type().primitive_type().c_str(), "void")) {
+ if (api.return_type().primitive_type().size() == 0
+ || (api.return_type().primitive_type().size() == 1
+ && strcmp(api.return_type().primitive_type(0).c_str(), "void"))) {
cpp_ss << "))";
}
cpp_ss << ");" << endl;