[ML][Pipeline] Fix issues reported by TCT team 47/255147/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Fri, 12 Mar 2021 14:32:18 +0000 (15:32 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Fri, 12 Mar 2021 14:32:18 +0000 (15:32 +0100)
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 <p.wasowski2@samsung.com>
src/ml/js/ml_pipeline.js
src/ml/ml_instance.cc
src/ml/ml_pipeline.cc

index fe986ef..b7204bf 100755 (executable)
@@ -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
index 37e574c..37e70e8 100644 (file)
@@ -1385,12 +1385,13 @@ void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, pico
   const auto& node_name = args.get(kNodeName).get<std::string>();
   const auto& type = args.get(kType).get<std::string>();
 
+  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);
 
index 66b7756..0719a2d 100644 (file)
@@ -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();