DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] rawdev autotest fixes
@ 2019-06-19 17:08 Bruce Richardson
  2019-06-19 17:08 ` [dpdk-dev] [PATCH 1/2] raw/skeleton: fix failing test case Bruce Richardson
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-19 17:08 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

The rawdev_autotest command was failing due to memory issues, and was
not present at all in meson builds. These two patches fix these
problems.

Bruce Richardson (2):
  raw/skeleton: fix failing test case
  app/test: add missing rawdev autotest to meson build

 app/test/meson.build                               | 3 +++
 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 8 ++------
 2 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH 1/2] raw/skeleton: fix failing test case
  2019-06-19 17:08 [dpdk-dev] [PATCH 0/2] rawdev autotest fixes Bruce Richardson
@ 2019-06-19 17:08 ` Bruce Richardson
  2019-06-19 17:08 ` [dpdk-dev] [PATCH 2/2] app/test: add missing rawdev autotest to meson build Bruce Richardson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-19 17:08 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain, stable

The freeing of the malloced memory is difficult when using asserts to
cause early abort of the test cases, since that can leak memory. The
original placement of the free call caused a memory leak if the test
finished early, while a fix for that leak caused the test to fail at
times due to the memory variable being referenced after free. For a case
like this, using stack rather than heap memory is just easier and avoids
all issues.

Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Fixes: 88d0e47880ec ("raw/skeleton: fix memory leak on test failure")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index 359c9e296..a0961c77b 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -274,17 +274,14 @@ static int
 test_rawdev_attr_set_get(void)
 {
 	int ret;
-	int *dummy_value;
+	int dummy_value_store;
+	int *dummy_value = &dummy_value_store;
 	uint64_t ret_value;
 
 	/* Set an attribute and fetch it */
 	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100);
 	RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
 
-	dummy_value = malloc(sizeof(int));
-	if (!dummy_value)
-		RTE_TEST_ASSERT(1, "Unable to allocate memory (dummy_value)");
-
 	*dummy_value = 200;
 	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uintptr_t)dummy_value);
 
@@ -294,7 +291,6 @@ test_rawdev_attr_set_get(void)
 			      "Attribute (Test1) not set correctly (%" PRIu64 ")",
 			      ret_value);
 
-	free(dummy_value);
 
 	ret_value = 0;
 	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH 2/2] app/test: add missing rawdev autotest to meson build
  2019-06-19 17:08 [dpdk-dev] [PATCH 0/2] rawdev autotest fixes Bruce Richardson
  2019-06-19 17:08 ` [dpdk-dev] [PATCH 1/2] raw/skeleton: fix failing test case Bruce Richardson
@ 2019-06-19 17:08 ` Bruce Richardson
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-19 17:08 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain, stable

the test_rawdev.c file was missing from the meson.build file, and the test
case from the list of test commands.

Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/meson.build | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test/meson.build b/app/test/meson.build
index 4de856f93..9b52ec9d7 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -89,6 +89,7 @@ test_sources = files('commands.c',
 	'test_power_acpi_cpufreq.c',
 	'test_power_kvm_vm.c',
 	'test_prefetch.c',
+	'test_rawdev.c',
 	'test_rcu_qsbr.c',
 	'test_rcu_qsbr_perf.c',
 	'test_reciprocal_division.c',
@@ -140,6 +141,7 @@ test_deps = ['acl',
 	'metrics',
 	'pipeline',
 	'port',
+	'rawdev',
 	'rcu',
 	'reorder',
 	'ring',
@@ -179,6 +181,7 @@ fast_parallel_test_names = [
         'multiprocess_autotest',
         'per_lcore_autotest',
         'prefetch_autotest',
+        'rawdev_autotest',
         'rcu_qsbr_autotest',
         'red_autotest',
         'ring_autotest',
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev
  2019-06-19 17:08 [dpdk-dev] [PATCH 0/2] rawdev autotest fixes Bruce Richardson
  2019-06-19 17:08 ` [dpdk-dev] [PATCH 1/2] raw/skeleton: fix failing test case Bruce Richardson
  2019-06-19 17:08 ` [dpdk-dev] [PATCH 2/2] app/test: add missing rawdev autotest to meson build Bruce Richardson
@ 2019-06-21 15:56 ` Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
                     ` (3 more replies)
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
  3 siblings, 4 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-21 15:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

This set includes some general fixes and improvements for rawdev, the
rawdev autotests and the rawdev skeleton example implementation.
Specifically:

* the unit test were failing for me due to bad memory management
* the unit tests were not present in the meson builds due to missing
  file in file list
* the self-test function for a rawdev driver did not take the actual
  device id as a parameter:
  - because of this the skeleton driver always assumed device 0 was to
    be tested, an unsafe assumption

V2:
	extended the set with additional fixes to allow selftests to know
	what instance the tests are to be run on.

Bruce Richardson (4):
  raw/skeleton: fix failing test case
  app/test: add missing rawdev autotest to meson build
  raw/skeleton: remove compile-time constant for device id
  rawdev: pass the device id as parameter to selftest

 app/test/meson.build                          |  3 +
 drivers/raw/skeleton_rawdev/skeleton_rawdev.c |  8 ++-
 drivers/raw/skeleton_rawdev/skeleton_rawdev.h |  2 +-
 .../skeleton_rawdev/skeleton_rawdev_test.c    | 66 +++++++++----------
 lib/librte_rawdev/rte_rawdev.c                |  2 +-
 lib/librte_rawdev/rte_rawdev_pmd.h            |  2 +-
 6 files changed, 43 insertions(+), 40 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
@ 2019-06-21 15:56   ` Bruce Richardson
  2019-06-27 11:50     ` Hemant Agrawal
  2019-07-01 18:03     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 2/4] app/test: add missing rawdev test to meson build Bruce Richardson
                     ` (2 subsequent siblings)
  3 siblings, 2 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-21 15:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain, stable

Rawdev unit test for setting and getting parameters is failing because
of a pointer value being dereferenced after the memory it pointed to is
freed.

The freeing of the malloced memory is difficult when using asserts to
cause early abort of the test cases, since that can leak memory. The
original placement of the free call caused a memory leak if the test
finished early, while a fix for that leak caused the test to fail at
times due to the memory variable being referenced after free. For a case
like this, using stack rather than heap memory is just easier and avoids
all issues.

Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Fixes: 88d0e47880ec ("raw/skeleton: fix memory leak on test failure")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index 359c9e296..a0961c77b 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -274,17 +274,14 @@ static int
 test_rawdev_attr_set_get(void)
 {
 	int ret;
-	int *dummy_value;
+	int dummy_value_store;
+	int *dummy_value = &dummy_value_store;
 	uint64_t ret_value;
 
 	/* Set an attribute and fetch it */
 	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100);
 	RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
 
-	dummy_value = malloc(sizeof(int));
-	if (!dummy_value)
-		RTE_TEST_ASSERT(1, "Unable to allocate memory (dummy_value)");
-
 	*dummy_value = 200;
 	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uintptr_t)dummy_value);
 
@@ -294,7 +291,6 @@ test_rawdev_attr_set_get(void)
 			      "Attribute (Test1) not set correctly (%" PRIu64 ")",
 			      ret_value);
 
-	free(dummy_value);
 
 	ret_value = 0;
 	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] app/test: add missing rawdev test to meson build
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
@ 2019-06-21 15:56   ` Bruce Richardson
  2019-07-01 18:10     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 3/4] raw/skeleton: remove compile-time constant for device id Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest Bruce Richardson
  3 siblings, 1 reply; 17+ messages in thread
From: Bruce Richardson @ 2019-06-21 15:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain, stable

the test_rawdev.c file was missing from the meson.build file, and the test
case from the list of test commands.

Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/meson.build | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test/meson.build b/app/test/meson.build
index 4de856f93..9b52ec9d7 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -89,6 +89,7 @@ test_sources = files('commands.c',
 	'test_power_acpi_cpufreq.c',
 	'test_power_kvm_vm.c',
 	'test_prefetch.c',
+	'test_rawdev.c',
 	'test_rcu_qsbr.c',
 	'test_rcu_qsbr_perf.c',
 	'test_reciprocal_division.c',
@@ -140,6 +141,7 @@ test_deps = ['acl',
 	'metrics',
 	'pipeline',
 	'port',
+	'rawdev',
 	'rcu',
 	'reorder',
 	'ring',
@@ -179,6 +181,7 @@ fast_parallel_test_names = [
         'multiprocess_autotest',
         'per_lcore_autotest',
         'prefetch_autotest',
+        'rawdev_autotest',
         'rcu_qsbr_autotest',
         'red_autotest',
         'ring_autotest',
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] raw/skeleton: remove compile-time constant for device id
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 2/4] app/test: add missing rawdev test to meson build Bruce Richardson
@ 2019-06-21 15:56   ` Bruce Richardson
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest Bruce Richardson
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-06-21 15:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain

Use a variable value rather than compile-time constant zero as the
device id for the skeleton rawdev tests. This ensures we can make the
tests work even if other rawdevs are present.

Cc: shreyansh.jain@nxp.com
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 .../skeleton_rawdev/skeleton_rawdev_test.c    | 55 ++++++++++---------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index a0961c77b..d7177ea75 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -14,7 +14,6 @@
 /* Using relative path as skeleton_rawdev is not part of exported headers */
 #include "skeleton_rawdev.h"
 
-#define TEST_DEV_ID   0
 #define TEST_DEV_NAME "rawdev_skeleton"
 
 #define SKELDEV_LOGS(level, fmt, args...) \
@@ -37,6 +36,8 @@ static int passed;
 static int failed;
 static int unsupported;
 
+static uint16_t test_dev_id;
+
 static int
 testsuite_setup(void)
 {
@@ -88,7 +89,7 @@ static int
 test_rawdev_socket_id(void)
 {
 	int socket_id;
-	socket_id = rte_rawdev_socket_id(TEST_DEV_ID);
+	socket_id = rte_rawdev_socket_id(test_dev_id);
 	RTE_TEST_ASSERT(socket_id != -EINVAL,
 			"Failed to get socket_id %d", socket_id);
 	socket_id = rte_rawdev_socket_id(RTE_RAWDEV_MAX_DEVS);
@@ -105,12 +106,12 @@ test_rawdev_info_get(void)
 	struct rte_rawdev_info rdev_info = {0};
 	struct skeleton_rawdev_conf skel_conf = {0};
 
-	ret = rte_rawdev_info_get(TEST_DEV_ID, NULL);
+	ret = rte_rawdev_info_get(test_dev_id, NULL);
 	RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
 
 	rdev_info.dev_private = &skel_conf;
 
-	ret = rte_rawdev_info_get(TEST_DEV_ID, &rdev_info);
+	ret = rte_rawdev_info_get(test_dev_id, &rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get raw dev info");
 
 	return TEST_SUCCESS;
@@ -125,7 +126,7 @@ test_rawdev_configure(void)
 	struct skeleton_rawdev_conf rdev_conf_get = {0};
 
 	/* Check invalid configuration */
-	ret = rte_rawdev_configure(TEST_DEV_ID, NULL);
+	ret = rte_rawdev_configure(test_dev_id, NULL);
 	RTE_TEST_ASSERT(ret == -EINVAL,
 			"Null configure; Expected -EINVAL, got %d", ret);
 
@@ -135,12 +136,12 @@ test_rawdev_configure(void)
 				     SKELETON_CAPA_FW_RESET;
 
 	rdev_info.dev_private = &rdev_conf_set;
-	ret = rte_rawdev_configure(TEST_DEV_ID,
+	ret = rte_rawdev_configure(test_dev_id,
 				   (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure rawdev (%d)", ret);
 
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
@@ -168,7 +169,7 @@ test_rawdev_queue_default_conf_get(void)
 
 	/* Get the current configuration */
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -181,7 +182,7 @@ test_rawdev_queue_default_conf_get(void)
 	 * depth = DEF_DEPTH
 	 */
 	for (i = 0; i < rdev_conf_get.num_queues; i++) {
-		rte_rawdev_queue_conf_get(TEST_DEV_ID, i, &q);
+		rte_rawdev_queue_conf_get(test_dev_id, i, &q);
 		RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH,
 				      "Invalid default depth of queue (%d)",
 				      q.depth);
@@ -199,7 +200,7 @@ test_rawdev_queue_count(void)
 	unsigned int q_count;
 
 	/* Get the current configuration */
-	q_count = rte_rawdev_queue_count(TEST_DEV_ID);
+	q_count = rte_rawdev_queue_count(test_dev_id);
 	RTE_TEST_ASSERT_EQUAL(q_count, 1, "Invalid queue count (%d)", q_count);
 
 	return TEST_SUCCESS;
@@ -216,7 +217,7 @@ test_rawdev_queue_setup(void)
 
 	/* Get the current configuration */
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
@@ -230,11 +231,11 @@ test_rawdev_queue_setup(void)
 	/* Modify the queue depth for Queue 0 and attach it */
 	qset.depth = 15;
 	qset.state = SKELETON_QUEUE_ATTACH;
-	ret = rte_rawdev_queue_setup(TEST_DEV_ID, 0, &qset);
+	ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret);
 
 	/* Now, fetching the queue 0 should show depth as 15 */
-	ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget);
+	ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
 
 	RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth,
@@ -254,11 +255,11 @@ test_rawdev_queue_release(void)
 	struct skeleton_rawdev_queue qget = {0};
 
 	/* Now, fetching the queue 0 should show depth as 100 */
-	ret = rte_rawdev_queue_release(TEST_DEV_ID, 0);
+	ret = rte_rawdev_queue_release(test_dev_id, 0);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret);
 
 	/* Now, fetching the queue 0 should show depth as default */
-	ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget);
+	ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
 
 	RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH,
@@ -279,21 +280,21 @@ test_rawdev_attr_set_get(void)
 	uint64_t ret_value;
 
 	/* Set an attribute and fetch it */
-	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100);
+	ret = rte_rawdev_set_attr(test_dev_id, "Test1", 100);
 	RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
 
 	*dummy_value = 200;
-	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uintptr_t)dummy_value);
+	ret = rte_rawdev_set_attr(test_dev_id, "Test2", (uintptr_t)dummy_value);
 
 	/* Check if attributes have been set */
-	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test1", &ret_value);
+	ret = rte_rawdev_get_attr(test_dev_id, "Test1", &ret_value);
 	RTE_TEST_ASSERT_EQUAL(ret_value, 100,
 			      "Attribute (Test1) not set correctly (%" PRIu64 ")",
 			      ret_value);
 
 
 	ret_value = 0;
-	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value);
+	ret = rte_rawdev_get_attr(test_dev_id, "Test2", &ret_value);
 	RTE_TEST_ASSERT_EQUAL(*((int *)(uintptr_t)ret_value), 200,
 			      "Attribute (Test2) not set correctly (%" PRIu64 ")",
 			      ret_value);
@@ -317,7 +318,7 @@ test_rawdev_start_stop(void)
 	RTE_TEST_ASSERT(dummy_firmware != NULL,
 			"Failed to create firmware memory backing");
 
-	ret = rte_rawdev_firmware_load(TEST_DEV_ID, dummy_firmware);
+	ret = rte_rawdev_firmware_load(test_dev_id, dummy_firmware);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Firmware loading failed (%d)", ret);
 
 	/* Skeleton doesn't do anything with the firmware area - that is dummy
@@ -326,8 +327,8 @@ test_rawdev_start_stop(void)
 	rte_free(dummy_firmware);
 	dummy_firmware = NULL;
 
-	rte_rawdev_start(TEST_DEV_ID);
-	ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info);
+	rte_rawdev_start(test_dev_id);
+	ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -335,8 +336,8 @@ test_rawdev_start_stop(void)
 			      "Device start failed. State is (%d)",
 			      rdev_conf_get.device_state);
 
-	rte_rawdev_stop(TEST_DEV_ID);
-	ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info);
+	rte_rawdev_stop(test_dev_id);
+	ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -345,7 +346,7 @@ test_rawdev_start_stop(void)
 			      rdev_conf_get.device_state);
 
 	/* Unloading the firmware once device is stopped */
-	ret = rte_rawdev_firmware_unload(TEST_DEV_ID);
+	ret = rte_rawdev_firmware_unload(test_dev_id);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to unload firmware (%d)", ret);
 
 	return TEST_SUCCESS;
@@ -366,7 +367,7 @@ test_rawdev_enqdeq(void)
 	snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d",
 		 TEST_DEV_NAME, 0);
 
-	ret = rte_rawdev_enqueue_buffers(TEST_DEV_ID,
+	ret = rte_rawdev_enqueue_buffers(test_dev_id,
 					 (struct rte_rawdev_buf **)&buffers,
 					 count, &queue_id);
 	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
@@ -376,7 +377,7 @@ test_rawdev_enqdeq(void)
 	if (!deq_buffers)
 		goto cleanup;
 
-	ret = rte_rawdev_dequeue_buffers(TEST_DEV_ID,
+	ret = rte_rawdev_dequeue_buffers(test_dev_id,
 					(struct rte_rawdev_buf **)&deq_buffers,
 					count, &queue_id);
 	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
                     ` (2 preceding siblings ...)
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 3/4] raw/skeleton: remove compile-time constant for device id Bruce Richardson
@ 2019-06-21 15:56   ` Bruce Richardson
  2019-07-04  9:33     ` Shreyansh Jain
  3 siblings, 1 reply; 17+ messages in thread
From: Bruce Richardson @ 2019-06-21 15:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain

When running self-tests, the driver needs to know the device on which to
run the tests, so we need to take the device ID as parameter. Only the
skeleton driver is providing this selftest capability right now, so we can
easily update it for this change.

Cc: shreyansh.jain@nxp.com
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---

Since this change only affects the internals of the drivers, it's not an
ABI or API change

---

 drivers/raw/skeleton_rawdev/skeleton_rawdev.c      | 8 +++++---
 drivers/raw/skeleton_rawdev/skeleton_rawdev.h      | 2 +-
 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 3 ++-
 lib/librte_rawdev/rte_rawdev.c                     | 2 +-
 lib/librte_rawdev/rte_rawdev_pmd.h                 | 2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
index 709be7691..42471fbd1 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
@@ -583,6 +583,8 @@ skeleton_rawdev_create(const char *name,
 		goto cleanup;
 	}
 
+	ret = rawdev->dev_id; /* return the rawdev id of new device */
+
 	rawdev->dev_ops = &skeleton_rawdev_ops;
 	rawdev->device = &vdev->device;
 
@@ -720,19 +722,19 @@ skeleton_rawdev_probe(struct rte_vdev_device *vdev)
 	/* In case of invalid argument, selftest != 1; ignore other values */
 
 	ret = skeleton_rawdev_create(name, vdev, rte_socket_id());
-	if (!ret) {
+	if (ret >= 0) {
 		/* In case command line argument for 'selftest' was passed;
 		 * if invalid arguments were passed, execution continues but
 		 * without selftest.
 		 */
 		if (selftest == 1)
-			test_rawdev_skeldev();
+			test_rawdev_skeldev(ret);
 	}
 
 	/* Device instance created; Second instance not possible */
 	skeldev_init_once = 1;
 
-	return ret;
+	return ret < 0 ? ret : 0;
 }
 
 static int
diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev.h b/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
index 5045b5922..c3f92e72a 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
@@ -131,6 +131,6 @@ skeleton_rawdev_get_priv(const struct rte_rawdev *rawdev)
 	return rawdev->dev_private;
 }
 
-int test_rawdev_skeldev(void);
+int test_rawdev_skeldev(uint16_t dev_id);
 
 #endif /* __SKELETON_RAWDEV_H__ */
diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index d7177ea75..ad700e21c 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -427,8 +427,9 @@ static void skeldev_test_run(int (*setup)(void),
 }
 
 int
-test_rawdev_skeldev(void)
+test_rawdev_skeldev(uint16_t dev_id)
 {
+	test_dev_id = dev_id;
 	testsuite_setup();
 
 	SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_count);
diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 2b2f45d7c..15de2d413 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -378,7 +378,7 @@ rte_rawdev_selftest(uint16_t dev_id)
 	struct rte_rawdev *dev = &rte_rawdevs[dev_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_selftest, -ENOTSUP);
-	return (*dev->dev_ops->dev_selftest)();
+	return (*dev->dev_ops->dev_selftest)(dev_id);
 }
 
 int
diff --git a/lib/librte_rawdev/rte_rawdev_pmd.h b/lib/librte_rawdev/rte_rawdev_pmd.h
index 5e6cf1d16..aa6af4a37 100644
--- a/lib/librte_rawdev/rte_rawdev_pmd.h
+++ b/lib/librte_rawdev/rte_rawdev_pmd.h
@@ -499,7 +499,7 @@ typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
  * @return
  *   Return 0 on success
  */
-typedef int (*rawdev_selftest_t)(void);
+typedef int (*rawdev_selftest_t)(uint16_t dev_id);
 
 /** Rawdevice operations function pointer table */
 struct rte_rawdev_ops {
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
@ 2019-06-27 11:50     ` Hemant Agrawal
  2019-07-01 18:03     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
  1 sibling, 0 replies; 17+ messages in thread
From: Hemant Agrawal @ 2019-06-27 11:50 UTC (permalink / raw)
  To: Bruce Richardson, dev; +Cc: Shreyansh Jain, stable

Series-Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

On 21-Jun-19 9:26 PM, Bruce Richardson wrote:
> Rawdev unit test for setting and getting parameters is failing because
> of a pointer value being dereferenced after the memory it pointed to is
> freed.
>
> The freeing of the malloced memory is difficult when using asserts to
> cause early abort of the test cases, since that can leak memory. The
> original placement of the free call caused a memory leak if the test
> finished early, while a fix for that leak caused the test to fail at
> times due to the memory variable being referenced after free. For a case
> like this, using stack rather than heap memory is just easier and avoids
> all issues.
>
> Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
> Fixes: 88d0e47880ec ("raw/skeleton: fix memory leak on test failure")
> Cc: shreyansh.jain@nxp.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>   drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
> index 359c9e296..a0961c77b 100644
> --- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
> +++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
> @@ -274,17 +274,14 @@ static int
>   test_rawdev_attr_set_get(void)
>   {
>   	int ret;
> -	int *dummy_value;
> +	int dummy_value_store;
> +	int *dummy_value = &dummy_value_store;
>   	uint64_t ret_value;
>   
>   	/* Set an attribute and fetch it */
>   	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100);
>   	RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
>   
> -	dummy_value = malloc(sizeof(int));
> -	if (!dummy_value)
> -		RTE_TEST_ASSERT(1, "Unable to allocate memory (dummy_value)");
> -
>   	*dummy_value = 200;
>   	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uintptr_t)dummy_value);
>   
> @@ -294,7 +291,6 @@ test_rawdev_attr_set_get(void)
>   			      "Attribute (Test1) not set correctly (%" PRIu64 ")",
>   			      ret_value);
>   
> -	free(dummy_value);
>   
>   	ret_value = 0;
>   	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value);

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-dev] [dpdk-stable] [PATCH v2 1/4] raw/skeleton: fix failing test case
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
  2019-06-27 11:50     ` Hemant Agrawal
@ 2019-07-01 18:03     ` Thomas Monjalon
  1 sibling, 0 replies; 17+ messages in thread
From: Thomas Monjalon @ 2019-07-01 18:03 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: stable, dev, shreyansh.jain

21/06/2019 17:56, Bruce Richardson:
> Rawdev unit test for setting and getting parameters is failing because
> of a pointer value being dereferenced after the memory it pointed to is
> freed.
> 
> The freeing of the malloced memory is difficult when using asserts to
> cause early abort of the test cases, since that can leak memory. The
> original placement of the free call caused a memory leak if the test
> finished early, while a fix for that leak caused the test to fail at
> times due to the memory variable being referenced after free. For a case
> like this, using stack rather than heap memory is just easier and avoids
> all issues.
> 
> Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
> Fixes: 88d0e47880ec ("raw/skeleton: fix memory leak on test failure")
> Cc: shreyansh.jain@nxp.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

This test is already fixed by another patch:
http://git.dpdk.org/dpdk/commit/?id=dcb1595956




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-dev] [dpdk-stable] [PATCH v2 2/4] app/test: add missing rawdev test to meson build
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 2/4] app/test: add missing rawdev test to meson build Bruce Richardson
@ 2019-07-01 18:10     ` Thomas Monjalon
  0 siblings, 0 replies; 17+ messages in thread
From: Thomas Monjalon @ 2019-07-01 18:10 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: stable, dev, shreyansh.jain

21/06/2019 17:56, Bruce Richardson:
> the test_rawdev.c file was missing from the meson.build file, and the test
> case from the list of test commands.
> 
> Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
> Cc: shreyansh.jain@nxp.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> @@ -179,6 +181,7 @@ fast_parallel_test_names = [
>          'multiprocess_autotest',
>          'per_lcore_autotest',
>          'prefetch_autotest',
> +        'rawdev_autotest',
>          'rcu_qsbr_autotest',
>          'red_autotest',
>          'ring_autotest',

For consistency, I think rawdev_autotest should go in driver_test_names,
as it is testing the skeleton driver.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev
  2019-06-19 17:08 [dpdk-dev] [PATCH 0/2] rawdev autotest fixes Bruce Richardson
                   ` (2 preceding siblings ...)
  2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
@ 2019-07-02  9:56 ` Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 1/3] app/test: add missing rawdev autotest to meson build Bruce Richardson
                     ` (3 more replies)
  3 siblings, 4 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-07-02  9:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

This set includes some general fixes and improvements for rawdev, the
rawdev autotests and the rawdev skeleton example implementation.
Specifically:

* the unit test were failing for me due to bad memory management
* the unit tests were not present in the meson builds due to missing
  file in file list
* the self-test function for a rawdev driver did not take the actual
  device id as a parameter:
  - because of this the skeleton driver always assumed device 0 was to
    be tested, an unsafe assumption

V3:
	* dropped patch 1 which has been independently fixed
	* added autotest to the drivers set rather than fast tests one

V2:
	extended the set with additional fixes to allow selftests to know
	what instance the tests are to be run on.

*** SUBJECT HERE ***

*** BLURB HERE ***

Bruce Richardson (3):
  app/test: add missing rawdev autotest to meson build
  raw/skeleton: remove compile-time constant for device id
  rawdev: pass the device id as parameter to selftest

 app/test/meson.build                          |  3 +
 drivers/raw/skeleton_rawdev/skeleton_rawdev.c |  8 ++-
 drivers/raw/skeleton_rawdev/skeleton_rawdev.h |  2 +-
 .../skeleton_rawdev/skeleton_rawdev_test.c    | 58 ++++++++++---------
 lib/librte_rawdev/rte_rawdev.c                |  2 +-
 lib/librte_rawdev/rte_rawdev_pmd.h            |  2 +-
 6 files changed, 41 insertions(+), 34 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v3 1/3] app/test: add missing rawdev autotest to meson build
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
@ 2019-07-02  9:56   ` Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 2/3] raw/skeleton: remove compile-time constant for device id Bruce Richardson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-07-02  9:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, shreyansh.jain, stable, Hemant Agrawal

the test_rawdev.c file was missing from the meson.build file, and the test
case from the list of test commands.

Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 app/test/meson.build | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test/meson.build b/app/test/meson.build
index 562b93efb..466fd56da 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -91,6 +91,7 @@ test_sources = files('commands.c',
 	'test_power_kvm_vm.c',
 	'test_prefetch.c',
 	'test_rand_perf.c',
+	'test_rawdev.c',
 	'test_rcu_qsbr.c',
 	'test_rcu_qsbr_perf.c',
 	'test_reciprocal_division.c',
@@ -142,6 +143,7 @@ test_deps = ['acl',
 	'metrics',
 	'pipeline',
 	'port',
+	'rawdev',
 	'rcu',
 	'reorder',
 	'ring',
@@ -279,6 +281,7 @@ driver_test_names = [
         'link_bonding_autotest',
         'link_bonding_mode4_autotest',
         'link_bonding_rssconf_autotest',
+        'rawdev_autotest',
 ]
 
 dump_test_names = [
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v3 2/3] raw/skeleton: remove compile-time constant for device id
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 1/3] app/test: add missing rawdev autotest to meson build Bruce Richardson
@ 2019-07-02  9:56   ` Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 3/3] rawdev: pass the device id as parameter to selftest Bruce Richardson
  2019-07-02 15:05   ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Thomas Monjalon
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-07-02  9:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, Hemant Agrawal

Use a variable value rather than compile-time constant zero as the
device id for the skeleton rawdev tests. This ensures we can make the
tests work even if other rawdevs are present.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 .../skeleton_rawdev/skeleton_rawdev_test.c    | 55 ++++++++++---------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index 3250c2296..a6be99aee 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -14,7 +14,6 @@
 /* Using relative path as skeleton_rawdev is not part of exported headers */
 #include "skeleton_rawdev.h"
 
-#define TEST_DEV_ID   0
 #define TEST_DEV_NAME "rawdev_skeleton"
 
 #define SKELDEV_LOGS(level, fmt, args...) \
@@ -37,6 +36,8 @@ static int passed;
 static int failed;
 static int unsupported;
 
+static uint16_t test_dev_id;
+
 static int
 testsuite_setup(void)
 {
@@ -88,7 +89,7 @@ static int
 test_rawdev_socket_id(void)
 {
 	int socket_id;
-	socket_id = rte_rawdev_socket_id(TEST_DEV_ID);
+	socket_id = rte_rawdev_socket_id(test_dev_id);
 	RTE_TEST_ASSERT(socket_id != -EINVAL,
 			"Failed to get socket_id %d", socket_id);
 	socket_id = rte_rawdev_socket_id(RTE_RAWDEV_MAX_DEVS);
@@ -105,12 +106,12 @@ test_rawdev_info_get(void)
 	struct rte_rawdev_info rdev_info = {0};
 	struct skeleton_rawdev_conf skel_conf = {0};
 
-	ret = rte_rawdev_info_get(TEST_DEV_ID, NULL);
+	ret = rte_rawdev_info_get(test_dev_id, NULL);
 	RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
 
 	rdev_info.dev_private = &skel_conf;
 
-	ret = rte_rawdev_info_get(TEST_DEV_ID, &rdev_info);
+	ret = rte_rawdev_info_get(test_dev_id, &rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get raw dev info");
 
 	return TEST_SUCCESS;
@@ -125,7 +126,7 @@ test_rawdev_configure(void)
 	struct skeleton_rawdev_conf rdev_conf_get = {0};
 
 	/* Check invalid configuration */
-	ret = rte_rawdev_configure(TEST_DEV_ID, NULL);
+	ret = rte_rawdev_configure(test_dev_id, NULL);
 	RTE_TEST_ASSERT(ret == -EINVAL,
 			"Null configure; Expected -EINVAL, got %d", ret);
 
@@ -135,12 +136,12 @@ test_rawdev_configure(void)
 				     SKELETON_CAPA_FW_RESET;
 
 	rdev_info.dev_private = &rdev_conf_set;
-	ret = rte_rawdev_configure(TEST_DEV_ID,
+	ret = rte_rawdev_configure(test_dev_id,
 				   (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure rawdev (%d)", ret);
 
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
@@ -168,7 +169,7 @@ test_rawdev_queue_default_conf_get(void)
 
 	/* Get the current configuration */
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -181,7 +182,7 @@ test_rawdev_queue_default_conf_get(void)
 	 * depth = DEF_DEPTH
 	 */
 	for (i = 0; i < rdev_conf_get.num_queues; i++) {
-		rte_rawdev_queue_conf_get(TEST_DEV_ID, i, &q);
+		rte_rawdev_queue_conf_get(test_dev_id, i, &q);
 		RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH,
 				      "Invalid default depth of queue (%d)",
 				      q.depth);
@@ -199,7 +200,7 @@ test_rawdev_queue_count(void)
 	unsigned int q_count;
 
 	/* Get the current configuration */
-	q_count = rte_rawdev_queue_count(TEST_DEV_ID);
+	q_count = rte_rawdev_queue_count(test_dev_id);
 	RTE_TEST_ASSERT_EQUAL(q_count, 1, "Invalid queue count (%d)", q_count);
 
 	return TEST_SUCCESS;
@@ -216,7 +217,7 @@ test_rawdev_queue_setup(void)
 
 	/* Get the current configuration */
 	rdev_info.dev_private = &rdev_conf_get;
-	ret = rte_rawdev_info_get(TEST_DEV_ID,
+	ret = rte_rawdev_info_get(test_dev_id,
 				  (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
@@ -230,11 +231,11 @@ test_rawdev_queue_setup(void)
 	/* Modify the queue depth for Queue 0 and attach it */
 	qset.depth = 15;
 	qset.state = SKELETON_QUEUE_ATTACH;
-	ret = rte_rawdev_queue_setup(TEST_DEV_ID, 0, &qset);
+	ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret);
 
 	/* Now, fetching the queue 0 should show depth as 15 */
-	ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget);
+	ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
 
 	RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth,
@@ -254,11 +255,11 @@ test_rawdev_queue_release(void)
 	struct skeleton_rawdev_queue qget = {0};
 
 	/* Now, fetching the queue 0 should show depth as 100 */
-	ret = rte_rawdev_queue_release(TEST_DEV_ID, 0);
+	ret = rte_rawdev_queue_release(test_dev_id, 0);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret);
 
 	/* Now, fetching the queue 0 should show depth as default */
-	ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget);
+	ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
 
 	RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH,
@@ -278,21 +279,21 @@ test_rawdev_attr_set_get(void)
 	uint64_t ret_value;
 
 	/* Set an attribute and fetch it */
-	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100);
+	ret = rte_rawdev_set_attr(test_dev_id, "Test1", 100);
 	RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
 
 	dummy_value = &set_value;
 	*dummy_value = 200;
-	ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uintptr_t)dummy_value);
+	ret = rte_rawdev_set_attr(test_dev_id, "Test2", (uintptr_t)dummy_value);
 
 	/* Check if attributes have been set */
-	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test1", &ret_value);
+	ret = rte_rawdev_get_attr(test_dev_id, "Test1", &ret_value);
 	RTE_TEST_ASSERT_EQUAL(ret_value, 100,
 			      "Attribute (Test1) not set correctly (%" PRIu64 ")",
 			      ret_value);
 
 	ret_value = 0;
-	ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value);
+	ret = rte_rawdev_get_attr(test_dev_id, "Test2", &ret_value);
 	RTE_TEST_ASSERT_EQUAL(*((int *)(uintptr_t)ret_value), set_value,
 			      "Attribute (Test2) not set correctly (%" PRIu64 ")",
 			      ret_value);
@@ -316,7 +317,7 @@ test_rawdev_start_stop(void)
 	RTE_TEST_ASSERT(dummy_firmware != NULL,
 			"Failed to create firmware memory backing");
 
-	ret = rte_rawdev_firmware_load(TEST_DEV_ID, dummy_firmware);
+	ret = rte_rawdev_firmware_load(test_dev_id, dummy_firmware);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Firmware loading failed (%d)", ret);
 
 	/* Skeleton doesn't do anything with the firmware area - that is dummy
@@ -325,8 +326,8 @@ test_rawdev_start_stop(void)
 	rte_free(dummy_firmware);
 	dummy_firmware = NULL;
 
-	rte_rawdev_start(TEST_DEV_ID);
-	ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info);
+	rte_rawdev_start(test_dev_id);
+	ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -334,8 +335,8 @@ test_rawdev_start_stop(void)
 			      "Device start failed. State is (%d)",
 			      rdev_conf_get.device_state);
 
-	rte_rawdev_stop(TEST_DEV_ID);
-	ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info);
+	rte_rawdev_stop(test_dev_id);
+	ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info);
 	RTE_TEST_ASSERT_SUCCESS(ret,
 				"Failed to obtain rawdev configuration (%d)",
 				ret);
@@ -344,7 +345,7 @@ test_rawdev_start_stop(void)
 			      rdev_conf_get.device_state);
 
 	/* Unloading the firmware once device is stopped */
-	ret = rte_rawdev_firmware_unload(TEST_DEV_ID);
+	ret = rte_rawdev_firmware_unload(test_dev_id);
 	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to unload firmware (%d)", ret);
 
 	return TEST_SUCCESS;
@@ -365,7 +366,7 @@ test_rawdev_enqdeq(void)
 	snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d",
 		 TEST_DEV_NAME, 0);
 
-	ret = rte_rawdev_enqueue_buffers(TEST_DEV_ID,
+	ret = rte_rawdev_enqueue_buffers(test_dev_id,
 					 (struct rte_rawdev_buf **)&buffers,
 					 count, &queue_id);
 	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
@@ -375,7 +376,7 @@ test_rawdev_enqdeq(void)
 	if (!deq_buffers)
 		goto cleanup;
 
-	ret = rte_rawdev_dequeue_buffers(TEST_DEV_ID,
+	ret = rte_rawdev_dequeue_buffers(test_dev_id,
 					(struct rte_rawdev_buf **)&deq_buffers,
 					count, &queue_id);
 	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-dev] [PATCH v3 3/3] rawdev: pass the device id as parameter to selftest
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 1/3] app/test: add missing rawdev autotest to meson build Bruce Richardson
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 2/3] raw/skeleton: remove compile-time constant for device id Bruce Richardson
@ 2019-07-02  9:56   ` Bruce Richardson
  2019-07-02 15:05   ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Thomas Monjalon
  3 siblings, 0 replies; 17+ messages in thread
From: Bruce Richardson @ 2019-07-02  9:56 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, Hemant Agrawal

When running self-tests, the driver needs to know the device on which to
run the tests, so we need to take the device ID as parameter. Only the
skeleton driver is providing this selftest capability right now, so we can
easily update it for this change.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 drivers/raw/skeleton_rawdev/skeleton_rawdev.c      | 8 +++++---
 drivers/raw/skeleton_rawdev/skeleton_rawdev.h      | 2 +-
 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 3 ++-
 lib/librte_rawdev/rte_rawdev.c                     | 2 +-
 lib/librte_rawdev/rte_rawdev_pmd.h                 | 2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
index 709be7691..42471fbd1 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c
@@ -583,6 +583,8 @@ skeleton_rawdev_create(const char *name,
 		goto cleanup;
 	}
 
+	ret = rawdev->dev_id; /* return the rawdev id of new device */
+
 	rawdev->dev_ops = &skeleton_rawdev_ops;
 	rawdev->device = &vdev->device;
 
@@ -720,19 +722,19 @@ skeleton_rawdev_probe(struct rte_vdev_device *vdev)
 	/* In case of invalid argument, selftest != 1; ignore other values */
 
 	ret = skeleton_rawdev_create(name, vdev, rte_socket_id());
-	if (!ret) {
+	if (ret >= 0) {
 		/* In case command line argument for 'selftest' was passed;
 		 * if invalid arguments were passed, execution continues but
 		 * without selftest.
 		 */
 		if (selftest == 1)
-			test_rawdev_skeldev();
+			test_rawdev_skeldev(ret);
 	}
 
 	/* Device instance created; Second instance not possible */
 	skeldev_init_once = 1;
 
-	return ret;
+	return ret < 0 ? ret : 0;
 }
 
 static int
diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev.h b/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
index 5045b5922..c3f92e72a 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev.h
@@ -131,6 +131,6 @@ skeleton_rawdev_get_priv(const struct rte_rawdev *rawdev)
 	return rawdev->dev_private;
 }
 
-int test_rawdev_skeldev(void);
+int test_rawdev_skeldev(uint16_t dev_id);
 
 #endif /* __SKELETON_RAWDEV_H__ */
diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
index a6be99aee..9ecfdee81 100644
--- a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c
@@ -426,8 +426,9 @@ static void skeldev_test_run(int (*setup)(void),
 }
 
 int
-test_rawdev_skeldev(void)
+test_rawdev_skeldev(uint16_t dev_id)
 {
+	test_dev_id = dev_id;
 	testsuite_setup();
 
 	SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_count);
diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 2b2f45d7c..15de2d413 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -378,7 +378,7 @@ rte_rawdev_selftest(uint16_t dev_id)
 	struct rte_rawdev *dev = &rte_rawdevs[dev_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_selftest, -ENOTSUP);
-	return (*dev->dev_ops->dev_selftest)();
+	return (*dev->dev_ops->dev_selftest)(dev_id);
 }
 
 int
diff --git a/lib/librte_rawdev/rte_rawdev_pmd.h b/lib/librte_rawdev/rte_rawdev_pmd.h
index 5e6cf1d16..aa6af4a37 100644
--- a/lib/librte_rawdev/rte_rawdev_pmd.h
+++ b/lib/librte_rawdev/rte_rawdev_pmd.h
@@ -499,7 +499,7 @@ typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
  * @return
  *   Return 0 on success
  */
-typedef int (*rawdev_selftest_t)(void);
+typedef int (*rawdev_selftest_t)(uint16_t dev_id);
 
 /** Rawdevice operations function pointer table */
 struct rte_rawdev_ops {
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev
  2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
                     ` (2 preceding siblings ...)
  2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 3/3] rawdev: pass the device id as parameter to selftest Bruce Richardson
@ 2019-07-02 15:05   ` Thomas Monjalon
  3 siblings, 0 replies; 17+ messages in thread
From: Thomas Monjalon @ 2019-07-02 15:05 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

> Bruce Richardson (3):
>   app/test: add missing rawdev autotest to meson build
>   raw/skeleton: remove compile-time constant for device id
>   rawdev: pass the device id as parameter to selftest

Applied, thanks



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest
  2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest Bruce Richardson
@ 2019-07-04  9:33     ` Shreyansh Jain
  0 siblings, 0 replies; 17+ messages in thread
From: Shreyansh Jain @ 2019-07-04  9:33 UTC (permalink / raw)
  To: Bruce Richardson, dev

> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Friday, June 21, 2019 9:27 PM
> To: dev@dpdk.org
> Cc: Bruce Richardson <bruce.richardson@intel.com>; Shreyansh Jain
> <shreyansh.jain@nxp.com>
> Subject: [PATCH v2 4/4] rawdev: pass device id as parameter to selftest
> 
> When running self-tests, the driver needs to know the device on which to
> run the tests, so we need to take the device ID as parameter. Only the
> skeleton driver is providing this selftest capability right now, so we
> can
> easily update it for this change.
> 
> Cc: shreyansh.jain@nxp.com
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> 
> Since this change only affects the internals of the drivers, it's not an
> ABI or API change
> 
> ---

Sorry for delay in responding to this. If not already merged:

Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-07-04  9:33 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19 17:08 [dpdk-dev] [PATCH 0/2] rawdev autotest fixes Bruce Richardson
2019-06-19 17:08 ` [dpdk-dev] [PATCH 1/2] raw/skeleton: fix failing test case Bruce Richardson
2019-06-19 17:08 ` [dpdk-dev] [PATCH 2/2] app/test: add missing rawdev autotest to meson build Bruce Richardson
2019-06-21 15:56 ` [dpdk-dev] [PATCH v2 0/4] fixes and improvements for rawdev Bruce Richardson
2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 1/4] raw/skeleton: fix failing test case Bruce Richardson
2019-06-27 11:50     ` Hemant Agrawal
2019-07-01 18:03     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 2/4] app/test: add missing rawdev test to meson build Bruce Richardson
2019-07-01 18:10     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 3/4] raw/skeleton: remove compile-time constant for device id Bruce Richardson
2019-06-21 15:56   ` [dpdk-dev] [PATCH v2 4/4] rawdev: pass device id as parameter to selftest Bruce Richardson
2019-07-04  9:33     ` Shreyansh Jain
2019-07-02  9:56 ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Bruce Richardson
2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 1/3] app/test: add missing rawdev autotest to meson build Bruce Richardson
2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 2/3] raw/skeleton: remove compile-time constant for device id Bruce Richardson
2019-07-02  9:56   ` [dpdk-dev] [PATCH v3 3/3] rawdev: pass the device id as parameter to selftest Bruce Richardson
2019-07-02 15:05   ` [dpdk-dev] [PATCH v3 0/3] fixes and improvements for rawdev Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).