From 741109a727fdd6548e9fc106c3b6e3034f857f86 Mon Sep 17 00:00:00 2001 From: Pawel Wasowski Date: Fri, 12 Mar 2021 15:32:18 +0100 Subject: [PATCH] [ML][Pipeline] Fix issues reported by TCT team Fixed problems: - Pipeline::{getNodeInfo, getSwitch, getValve}: throw TypeMismatchError when no argument is passed - NodeInfo::setProperty: throw TypeMismatchError, instead of AbortError when value type is other than expected - Pipeline::unregisterSinkListener: throw InvalidValuesError when sink has not been registered [Verification] Code was tested with the snippets below and worked fine ///// checking problems with getNodeInfo, getSwitch, getValve, ///// and unregisterSinkListener var pipelineDefinition = "videotestsrc name=vsrc is-live=true " + "! videoconvert " + "! videoscale name=vscale " + "! video/x-raw,format=RGBx,width=224,height=224,framerate=60/1 " + "! tensor_converter " + "! valve name=valvex " + "! input-selector name=is01 " + "! tensor_sink name=sinkx"; var pipeline = tizen.ml.pipeline.createPipeline(pipelineDefinition); pipeline.getNodeInfo(); // TypeMismatchError pipeline.getSwitch(); // TypeMismatchError pipeline.getValve(); // TypeMismatchError pipeline.unregisterSinkListener('test') // InvalidValuesError ///// checking problem with setProperty pipelineDefinition = "videotestsrc name=vsrc is-live=true " + "! videoconvert " + "! videoscale name=vscale " + "! video/x-raw,format=RGBx,width=224,height=224,framerate=60/1 " + "! tensor_converter " + "! valve name=valvex " + "! input-selector name=is01 " + "! tensor_sink name=sinkx"; pipeline = tizen.ml.pipeline.createPipeline(pipelineDefinition); nodeInfo = pipeline.getNodeInfo("vsrc"); nodeInfo.setProperty("is-live", "DOUBLE", NaN); // TypeMismatchError Change-Id: I25438b037e0a2dd2f91f8d9b398cffcaf457386b Signed-off-by: Pawel Wasowski --- src/ml/js/ml_pipeline.js | 21 +++++++++++++++++++++ src/ml/ml_instance.cc | 7 ++++--- src/ml/ml_pipeline.cc | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/ml/js/ml_pipeline.js b/src/ml/js/ml_pipeline.js index fe986efe..b7204bf4 100755 --- a/src/ml/js/ml_pipeline.js +++ b/src/ml/js/ml_pipeline.js @@ -191,6 +191,13 @@ Pipeline.prototype.getNodeInfo = function() { } ]); + if (!args.has.name) { + throw new WebAPIException( + WebAPIException.TYPE_MISMATCH_ERR, + 'Invalid parameter: node name is mandatory' + ); + } + var nativeArgs = { id: this._id, name: args.name @@ -313,6 +320,13 @@ Pipeline.prototype.getSwitch = function() { } ]); + if (!args.has.name) { + throw new WebAPIException( + WebAPIException.TYPE_MISMATCH_ERR, + 'Invalid parameter: switch name is mandatory' + ); + } + var nativeArgs = { name: args.name, id: this._id @@ -382,6 +396,13 @@ Pipeline.prototype.getValve = function() { } ]); + if (!args.has.name) { + throw new WebAPIException( + WebAPIException.TYPE_MISMATCH_ERR, + 'Invalid parameter: valve name is mandatory' + ); + } + var nativeArgs = { name: args.name, id: this._id diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 37e574c0..37e70e81 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -1385,12 +1385,13 @@ void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, pico const auto& node_name = args.get(kNodeName).get(); const auto& type = args.get(kType).get(); + CHECK_EXIST(args, kProperty, out); if (kBOOLEAN == type) { - CHECK_ARGS(args, kProperty, bool, out); + CHECK_TYPE(args, kProperty, bool, out, ErrorCode::TYPE_MISMATCH_ERR); } else if (kSTRING == type) { - CHECK_ARGS(args, kProperty, std::string, out); + CHECK_TYPE(args, kProperty, std::string, out, ErrorCode::TYPE_MISMATCH_ERR); } else { - CHECK_ARGS(args, kProperty, double, out); + CHECK_TYPE(args, kProperty, double, out, ErrorCode::TYPE_MISMATCH_ERR); } const picojson::value& property = args.get(kProperty); diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc index 66b77564..0719a2d9 100644 --- a/src/ml/ml_pipeline.cc +++ b/src/ml/ml_pipeline.cc @@ -331,7 +331,7 @@ PlatformResult Pipeline::UnregisterSinkListener(const std::string& sink_name) { auto sink_it = sinks_.find(sink_name); if (sinks_.end() == sink_it) { LoggerD("sink [%s] not found", sink_name.c_str()); - return PlatformResult{ErrorCode::ABORT_ERR, "An unknown error occurred"}; + return PlatformResult{ErrorCode::INVALID_VALUES_ERR, "The sink has not been registered"}; } auto ret = sink_it->second->Unregister(); -- 2.34.1