From 6a0f2a6afdee636310f4093774d2deef617f15d3 Mon Sep 17 00:00:00 2001 From: zuzy Date: Wed, 25 Dec 2019 16:46:34 +0800 Subject: [PATCH 1/4] Fixed extra return in client.cpp, when generages callbacks with return value. Enriched test_callbacks demo with some new callbacks. --- .../src/templates/c_client_source.template | 2 -- test/test_callbacks/test_callbacks.erpc | 9 ++++++ .../test_callbacks_client_impl.cpp | 15 ++++++++++ .../test_callbacks_server_impl.cpp | 28 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/erpcgen/src/templates/c_client_source.template b/erpcgen/src/templates/c_client_source.template index 050cedd1b..10711d7c9 100644 --- a/erpcgen/src/templates/c_client_source.template +++ b/erpcgen/src/templates/c_client_source.template @@ -164,8 +164,6 @@ static {$callbackType.prototype} { {% if fn.isCallback %} {% if fn.returnValue.type.isNotVoid %}return {% endif %}{$fn.callbackFName}(k{$iface.name}_service_id, k{$iface.name}_{$fn.name}_id{% for param in fn.parameters %}, {$param.name}{% endfor %}); -{% if fn.returnValue.type.isNotVoid %}return; -{% endif %} {% else -- fn.isCallback >%} {$ clientShimCode(fn, "k"& iface.name & "_service_id", "k" & iface.name & "_" & fn.name & "_id") >} {% endif -- fn.isCallback >%} diff --git a/test/test_callbacks/test_callbacks.erpc b/test/test_callbacks/test_callbacks.erpc index 031cdf9ce..3c3aff2ec 100644 --- a/test/test_callbacks/test_callbacks.erpc +++ b/test/test_callbacks/test_callbacks.erpc @@ -12,6 +12,7 @@ import "../common/unit_test_common.erpc" oneway callback1_t(int32 a, int32 b) oneway callback2_t(int32, int32) +callback3_t(int32 arg1, int32 arg2) -> int32 @include("test_core1.h") @group("core0") @@ -21,9 +22,17 @@ interface ClientCore0Services myFun2(callback2_t pCallback2_in, out callback2_t pCallback2_out) -> void + myFun3(callback3_t callback, in int32 arg1, in int32 arg2) -> int32 + + callback3_t my_add; + callback3_t my_sub; + callback3_t my_mul; + callback3_t my_div; + @include("callbacks1.h") callback1_t callback1a; + @include("callbacks1.h") callback1_t callback1b(param1, param2); } diff --git a/test/test_callbacks/test_callbacks_client_impl.cpp b/test/test_callbacks/test_callbacks_client_impl.cpp index 4d812e6ca..7b21043df 100644 --- a/test/test_callbacks/test_callbacks_client_impl.cpp +++ b/test/test_callbacks/test_callbacks_client_impl.cpp @@ -38,3 +38,18 @@ TEST(test_callbacks, In_Out_withoutTable) EXPECT_TRUE(callback2 == *pCallback2_out); } + +TEST(test_callbacks, Common_Callback) +{ + callback3_t callback = my_add; + EXPECT_TRUE(12 == myFun3(callback, 9, 3)); + + callback = my_sub; + EXPECT_TRUE(6 == myFun3(callback, 9, 3)); + + callback = my_mul; + EXPECT_TRUE(27 == myFun3(callback, 9, 3)); + + callback = my_div; + EXPECT_TRUE(3 == myFun3(callback, 9, 3)); +} \ No newline at end of file diff --git a/test/test_callbacks/test_callbacks_server_impl.cpp b/test/test_callbacks/test_callbacks_server_impl.cpp index 1d76d7ee7..c96c0c07c 100644 --- a/test/test_callbacks/test_callbacks_server_impl.cpp +++ b/test/test_callbacks/test_callbacks_server_impl.cpp @@ -49,6 +49,34 @@ void callback2(int32_t param1, int32_t param2) cb2 = (callback2_t *)callback2; } +int32_t myFun3(const callback3_t callback, int32_t arg1, int32_t arg2) +{ + return callback(arg1, arg2); +} + +int32_t my_add(int32_t arg1, int32_t arg2) +{ + return arg1 + arg2; +} + +int32_t my_sub(int32_t arg1, int32_t arg2) +{ + return arg1 - arg2; +} + +int32_t my_mul(int32_t arg1, int32_t arg2) +{ + return arg1 * arg2; +} + +int32_t my_div(int32_t arg1, int32_t arg2) +{ + if(arg2) { + return arg1 / arg2; + } + return 0; +} + //////////////////////////////////////////////////////////////////////////////// // Add service to server code //////////////////////////////////////////////////////////////////////////////// From 439affde13546f200fcb935cf0aeaf2b3d772d61 Mon Sep 17 00:00:00 2001 From: zuzy Date: Wed, 3 Jun 2020 10:14:54 +0800 Subject: [PATCH 2/4] : Fix erpcgen python client inout argument bug : Insert a judge of parameter.direction Issue #98 --- erpcgen/src/templates/py_client.template | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpcgen/src/templates/py_client.template b/erpcgen/src/templates/py_client.template index a9bdfd5ee..e9f629e16 100644 --- a/erpcgen/src/templates/py_client.template +++ b/erpcgen/src/templates/py_client.template @@ -61,7 +61,11 @@ class {$iface.name}Client(interface.I{$iface.name}): {% if p.type.type == 'union' %} {$p.name}._write(codec, {$p.discriminator}) {% else%} +{% if p.direction == "inout" %} + {$encodeValue(p.type, p.name & ".value", "codec", " ", 0)} +{% else %} {$encodeValue(p.type, p.name, "codec", " ", 0)} +{% endif -- p.direction %} {% endif -- isUnion %} {% endif -- isNullable %} {% endfor -- inParams %} From 840488ea4a973b4dddf63b3e17a2f2e03c4bfa44 Mon Sep 17 00:00:00 2001 From: zuzy Date: Fri, 5 Jun 2020 15:29:57 +0800 Subject: [PATCH 3/4] : Generate python union & type bug : 1. Move aliases into group. Incase of type struct/union when import other IDL file. 2. Delete spare Union definition. 3. Fix discriminator bug: when the discriminator is named by other parameter. 4. Value the union data in __init__, delete the data argument 5. Match test_length/name/union.yml --- erpcgen/src/PythonGenerator.cpp | 32 +++++++++++++++++++++++- erpcgen/src/templates/py_client.template | 2 +- erpcgen/src/templates/py_coders.template | 2 +- erpcgen/src/templates/py_common.template | 14 +++++++---- erpcgen/test/test_length_py.yml | 9 +++++-- erpcgen/test/test_name_py.yml | 1 - erpcgen/test/test_union_py.yml | 2 +- 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/erpcgen/src/PythonGenerator.cpp b/erpcgen/src/PythonGenerator.cpp index 755195c76..26ded4169 100644 --- a/erpcgen/src/PythonGenerator.cpp +++ b/erpcgen/src/PythonGenerator.cpp @@ -136,7 +136,7 @@ void PythonGenerator::generate() makeIncludesTemplateData(); - makeAliasesTemplateData(); + //makeAliasesTemplateData(); makeConstTemplateData(); @@ -407,6 +407,7 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) data_list structs; data_list unions; + data_list aliases; Log::info("Group symbols:\n"); @@ -453,6 +454,10 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) Log::info("%s\n", unionType->getDescription().c_str()); string name = filterName(getOutputName(unionType)); + if(name.find('$') != string::npos) { + Log::debug("%s is inside struct!\n", name.c_str()); + break; + } // check if template for this structure has not already been generated if (names.find(name) == names.end()) @@ -468,6 +473,30 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) } break; } + case DataType::kAliasTypeSymbol: + { + AliasType *aliasType = dynamic_cast(symbol); + if (aliasType == nullptr) + break; + + DataType *elementDataType = aliasType->getElementType(); + DataType *trueDataType = elementDataType->getTrueDataType(); + // Only generate aliases for enums, unions and structs in Python. + if (!(trueDataType->isEnum() || trueDataType->isUnion() || trueDataType->isStruct())) + break; + + string realType = getOutputName(aliasType); + Log::debug("%s\n", realType.c_str()); + + info["name"] = filterName(realType); + info["elementType"] = getTypeInfo(elementDataType); + info["trueType"] = getTypeInfo(trueDataType); + + setTemplateComments(aliasType, info); + + aliases.push_back(info); + break; + } default: break; } @@ -475,6 +504,7 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) symbolsTemplate["structs"] = structs; symbolsTemplate["unions"] = unions; + symbolsTemplate["aliases"] = aliases; return symbolsTemplate; } diff --git a/erpcgen/src/templates/py_client.template b/erpcgen/src/templates/py_client.template index e9f629e16..1c9824419 100644 --- a/erpcgen/src/templates/py_client.template +++ b/erpcgen/src/templates/py_client.template @@ -62,7 +62,7 @@ class {$iface.name}Client(interface.I{$iface.name}): {$p.name}._write(codec, {$p.discriminator}) {% else%} {% if p.direction == "inout" %} - {$encodeValue(p.type, p.name & ".value", "codec", " ", 0)} + {$encodeValue(p.type, p.name & ".value", "codec", " ", 0)} {% else %} {$encodeValue(p.type, p.name, "codec", " ", 0)} {% endif -- p.direction %} diff --git a/erpcgen/src/templates/py_coders.template b/erpcgen/src/templates/py_coders.template index 60b5760fe..73d2d998a 100644 --- a/erpcgen/src/templates/py_coders.template +++ b/erpcgen/src/templates/py_coders.template @@ -11,7 +11,7 @@ {% else %} {% set self = "self." %} {% endif %} -codec.start_write_union({$self}discriminator) +codec.start_write_union({$self}{$info.discriminatorName}) {# unions are always within structs, so we have self available #} {% set isFirst = true %} {% set hasNonVoidCase = false %} diff --git a/erpcgen/src/templates/py_common.template b/erpcgen/src/templates/py_common.template index e4fcc8289..8583e3da2 100644 --- a/erpcgen/src/templates/py_common.template +++ b/erpcgen/src/templates/py_common.template @@ -58,9 +58,13 @@ class {$s.name}(object): {% endfor -- union cases %} {% endfor -- members %} - def __init__(self{% for m in s.members if not m.lengthForMember %}, {$m.name}=None{% endfor %}): + def __init__(self{% for m in s.members if ((not m.lengthForMember) && m.type.type != 'union') %}, {$m.name}=None{% endfor %}): {% for m in s.members if not m.lengthForMember %} +{% if (m.type.type == 'union' && m.type.isNonEncapsulatedUnion == false) %} + self.{$m.name} = self.{$m.name}_union # {$prettyTypeName(m.name, m.type)} +{% else %} self.{$m.name} = {$m.name} # {$prettyTypeName(m.name, m.type)} +{% endif -- union type %} {% endfor -- members %} {# create read-only properties for @length counts #} @@ -146,10 +150,10 @@ class {$u.name}(object): {% endfor -- group.symbolsMap.unions %} {% endif -- not empty(group.symbolsMap.unions) %} +{% if not empty(group.symbolsMap.aliases) %} -{% if aliases %} # Type aliases -{% for a in aliases %} +{% for a in group.symbolsMap.aliases %} {$a.name} = {$a.elementType.name} -{% endfor -- aliases %} -{% endif -- aliases %} +{% endfor -- group.symbolsMap.aliases %} +{% endif -- not empty(group.symbolsMap.aliases) %} \ No newline at end of file diff --git a/erpcgen/test/test_length_py.yml b/erpcgen/test/test_length_py.yml index 85db39ec0..1ac4a1b06 100644 --- a/erpcgen/test/test_length_py.yml +++ b/erpcgen/test/test_length_py.yml @@ -48,7 +48,7 @@ test/interface.py: - def bar(self, l) test/client.py: - def bar(self, l) - - start_write_list(len(l)) + - start_write_list(len(l.value)) - perform_request - start_read_list - not: codec.read_int32() @@ -78,9 +78,14 @@ idl: | lang: py test/client.py: - def bar(self, v) + - if: dir in ('in', ) + then: + - write_{type}(v) + - if: dir in ('inout', ) + then: + - write_{type}(v.value) - if: dir in ('in', 'inout') then: - - write_{type}(v) - not: write_int32(len(v)) - perform_request - if: dir in ('inout',) diff --git a/erpcgen/test/test_name_py.yml b/erpcgen/test/test_name_py.yml index ad57ec695..6fd3de6d3 100644 --- a/erpcgen/test/test_name_py.yml +++ b/erpcgen/test/test_name_py.yml @@ -41,7 +41,6 @@ test/common.py: - if self.d is None - codec.write_int32(self.d) - self.d - - type = StructName test/client.py: - def function(self, m) diff --git a/erpcgen/test/test_union_py.yml b/erpcgen/test/test_union_py.yml index a2cf6b137..9c210920f 100644 --- a/erpcgen/test/test_union_py.yml +++ b/erpcgen/test/test_union_py.yml @@ -168,7 +168,7 @@ lang: py test/common.py: - not: class unionVariable_union(object) - "class structType(object):" - - def __init__(self, discriminator=None, unionVariable=None) + - def __init__(self, discriminator=None) - self.discriminator = discriminator # fruitType - self.unionVariable = unionVariable # unionType - self.unionVariable, self.discriminator = common.unionType()._read(codec) From 2499b13b7835426d90f3e14b09c1a429801f0d91 Mon Sep 17 00:00:00 2001 From: zuzy Date: Mon, 31 Aug 2020 16:18:08 +0800 Subject: [PATCH 4/4] : Some error in erpcgen/test/readme.md : - Because of path problem, py.test in `./erpcgen` folder cannot pass the `test/test_redundant_definitions.yml` case. And the case gets passed while in `./erpcgen/test`. --- erpcgen/test/readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpcgen/test/readme.md b/erpcgen/test/readme.md index baf8e6efb..c0730d2b9 100644 --- a/erpcgen/test/readme.md +++ b/erpcgen/test/readme.md @@ -4,9 +4,8 @@ erpcgen test system This file documents the parser and output test system for erpcgen. This test system is built on py.test using its extensive plugin hooks. To run the tests, just run -py.test in either the `erpc/erpgen/` or `erpc/erpcgen/test/` directory. -Because of py.test are trying run all tests in all subfolders, is safer to run py.test with parameter -source directory (from erpcgen directory run: "pytest test"). This prevent on windows to execute +py.test in `erpc/erpcgen/test/` directory. It's safer to run py.test with parameter source +directory (from erpcgen directory run: "pytest test"). This prevent on windows to execute boost test in boost folder.