[Test/UnittestPlugins/Transform] Add a macro to test typecast
authorWook Song <wook16.song@samsung.com>
Tue, 12 Mar 2019 02:01:21 +0000 (11:01 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 13 Mar 2019 01:06:30 +0000 (10:06 +0900)
This patch adds a macro to test typecast mode of the tensor_transform
element for convenience.

Signed-off-by: Wook Song <wook16.song@samsung.com>
tests/nnstreamer_plugins/unittest_plugins.cpp

index f2f3ff9..04d4b77 100644 (file)
  */
 #define _print_log(...) if (DBG) g_message (__VA_ARGS__)
 
+#define str(s) #s
+#define TEST_TRANSFORM_TYPECAST(name, num_bufs, size, from_t, from_nns_t, to_t, str_to_t, to_nns_t, accel) \
+    TEST (test_tensor_transform, name)  \
+    { \
+      const guint num_buffers = num_bufs; \
+      const guint array_size = size; \
+      \
+      GstHarness *h;  \
+      GstBuffer *in_buf, *out_buf;  \
+      GstTensorConfig config; \
+      GstMemory *mem; \
+      GstMapInfo info;  \
+      guint i, b; \
+      gsize data_in_size, data_out_size;  \
+      \
+      h = gst_harness_new ("tensor_transform"); \
+      \
+      g_object_set (h->element, "mode", GTT_TYPECAST, "option", str_to_t, NULL);  \
+      g_object_set (h->element, "acceleration", (gboolean) accel, NULL);  \
+      /** input tensor info */ \
+      config.info.type = from_nns_t; \
+      gst_tensor_parse_dimension (str(size), config.info.dimension); \
+      config.rate_n = 0; \
+      config.rate_d = 1; \
+      \
+      gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));  \
+      data_in_size = gst_tensor_info_get_size (&config.info); \
+      \
+      config.info.type = to_nns_t; \
+      data_out_size = gst_tensor_info_get_size (&config.info); \
+      \
+      /** push buffers */  \
+      for (b = 0; b < num_buffers; b++) { \
+        /** set input buffer */ \
+        in_buf = gst_harness_create_buffer (h, data_in_size); \
+        \
+        mem = gst_buffer_peek_memory (in_buf, 0); \
+        ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE)); \
+        \
+        for (i = 0; i < array_size; i++) {  \
+          from_t value = (i + 1) * (b + 1);  \
+          ((from_t *) info.data)[i] = value; \
+        } \
+        \
+        gst_memory_unmap (mem, &info);  \
+        \
+        EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);  \
+        \
+        /** get output buffer */ \
+        out_buf = gst_harness_pull (h); \
+        \
+        ASSERT_TRUE (out_buf != NULL);  \
+        ASSERT_EQ (gst_buffer_n_memory (out_buf), 1); \
+        ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size); \
+        \
+        mem = gst_buffer_peek_memory (out_buf, 0);  \
+        ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));  \
+        \
+        for (i = 0; i < array_size; i++) {  \
+          to_t expected = (i + 1) * (b + 1);  \
+          EXPECT_EQ (((to_t *) info.data)[i], expected);  \
+        } \
+        \
+        gst_memory_unmap (mem, &info);  \
+        gst_buffer_unref (out_buf); \
+      } \
+      EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);  \
+      gst_harness_teardown (h); \
+    }
+
 /**
  * @brief Test for tensor_transform typecast (uint8 > uint32)
  */