diff mbox series

[08/11] telemetry: add vdev kvargs for selftest

Message ID 1535026093-101872-9-git-send-email-ciara.power@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series introduce telemetry library | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Power, Ciara Aug. 23, 2018, 12:08 p.m. UTC
This patch adds functionality to run the selftest by passing
in an argument to vdev, "selftest".

To run the tests that were added in the previous patch, the
argument "selftest=1" must be added to the vdev arguments.
This will enable the user to run telemetry with or without tests,
as required.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Signed-off-by: Brian Archbold <brian.archbold@intel.com>
---
 drivers/telemetry/telemetry/telemetry_driver.c | 50 ++++++++++++++++++++++----
 lib/librte_telemetry/rte_telemetry.c           | 35 +++++++++---------
 lib/librte_telemetry/rte_telemetry.h           |  8 ++++-
 lib/librte_telemetry/rte_telemetry_internal.h  |  1 +
 4 files changed, 70 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/drivers/telemetry/telemetry/telemetry_driver.c b/drivers/telemetry/telemetry/telemetry_driver.c
index 125a89c..a97c199 100644
--- a/drivers/telemetry/telemetry/telemetry_driver.c
+++ b/drivers/telemetry/telemetry/telemetry_driver.c
@@ -8,21 +8,57 @@ 
 #include <rte_malloc.h>
 #include <rte_bus_vdev.h>
 #include <rte_lcore.h>
+#include <rte_kvargs.h>
+
+#define SELFTEST_ARG "selftest"
+
+static int
+assign_selftest(const char *key __rte_unused, const char *value, void *opaque)
+{
+	int *selftest = opaque;
+	*selftest = atoi(value);
+	return 0;
+}
 
 static int
 telemetry_probe(struct rte_vdev_device *vdev)
 {
+	static const char *const args[] = {
+		SELFTEST_ARG
+	};
+
+	const char *params;
 	int ret;
+	struct telemetry_args telemetry_args;
+	telemetry_args.selftest = 0;
 
-	RTE_SET_USED(vdev);
-	ret = rte_telemetry_selftest();
-	if (ret < 0) {
-		printf("Error - Selftest failed\n");
-		return -1;
+	params = rte_vdev_device_args(vdev);
+	if (params != NULL && params[0] != '\0') {
+		struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
+
+		if (!kvlist) {
+			printf("Error - Could not create kvlist\n");
+		} else {
+			ret = rte_kvargs_process(kvlist, SELFTEST_ARG,
+			assign_selftest, &telemetry_args.selftest);
+			if (ret != 0) {
+				printf("Error - Processing the arguments\n");
+				rte_kvargs_free(kvlist);
+				return ret;
+			}
+		}
+		rte_kvargs_free(kvlist);
+	}
+	if (telemetry_args.selftest) {
+		ret = rte_telemetry_selftest();
+		if (ret < 0) {
+			printf("Error - Selftest failed\n");
+			return -1;
+		}
+		printf("Success - Selftest passed\n");
 	}
-	printf("Success - Selftest passed\n");
 
-	ret = rte_telemetry_init(rte_socket_id());
+	ret = rte_telemetry_init(rte_socket_id(), &telemetry_args);
 	if (ret < 0) {
 		printf("Error - Telemetry initialisation failed\n");
 		return -1;
diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c
index ecf644b..1f7528d 100644
--- a/lib/librte_telemetry/rte_telemetry.c
+++ b/lib/librte_telemetry/rte_telemetry.c
@@ -666,18 +666,21 @@  rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 		return -1;
 	}
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (telemetry->selftest) {
+		ret =
+		rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+			telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Error - Parser Tests Failed\n");
-		return -1;
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Error - Parser Tests Failed\n");
+			return -1;
+		}
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed\n");
+		telemetry->selftest = 0;
 	}
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed\n");
-
 	return 0;
 }
 
@@ -856,7 +859,7 @@  rte_telemetry_create_socket(struct telemetry_impl *telemetry)
 }
 
 int32_t
-rte_telemetry_init(uint32_t socket_id)
+rte_telemetry_init(uint32_t socket_id, struct telemetry_args *args)
 {
 	int ret;
 	pthread_attr_t attr;
@@ -873,7 +876,7 @@  rte_telemetry_init(uint32_t socket_id)
 		TELEMETRY_LOG_ERR("Error - Memory could not be allocated\n");
 		return -ENOMEM;
 	}
-
+	static_telemetry->selftest = args->selftest;
 	static_telemetry->socket_id = socket_id;
 	rte_metrics_init(static_telemetry->socket_id);
 	ret = rte_telemetry_create_socket(static_telemetry);
@@ -1167,10 +1170,10 @@  rte_telemetry_selftest(void)
 	const char *invalid_client_path = SELFTEST_INVALID_CLIENT;
 	const char *valid_client_path = SELFTEST_VALID_CLIENT;
 	int ret, sockfd;
+	struct telemetry_args args;
+	args.selftest = 0;
 
-	TELEMETRY_LOG_INFO("Selftest\n");
-
-	ret = rte_telemetry_init(rte_socket_id());
+	ret = rte_telemetry_init(rte_socket_id(), &args);
 	if (ret < 0) {
 		TELEMETRY_LOG_ERR("Error - Valid initialisation test"
 			" failed\n");
@@ -1178,7 +1181,7 @@  rte_telemetry_selftest(void)
 	}
 	TELEMETRY_LOG_INFO("Success - Valid initialisation test passed\n");
 
-	ret = rte_telemetry_init(rte_socket_id());
+	ret = rte_telemetry_init(rte_socket_id(), &args);
 	if (ret != -EALREADY) {
 		TELEMETRY_LOG_ERR("Error - Invalid initialisation test "
 			"failed\n");
diff --git a/lib/librte_telemetry/rte_telemetry.h b/lib/librte_telemetry/rte_telemetry.h
index 4f187b7..ac66595 100644
--- a/lib/librte_telemetry/rte_telemetry.h
+++ b/lib/librte_telemetry/rte_telemetry.h
@@ -7,12 +7,18 @@ 
 #ifndef _RTE_TELEMETRY_H_
 #define _RTE_TELEMETRY_H_
 
+typedef struct telemetry_args {
+	int selftest;
+} telemetry_args;
+
 /**
  * Get the telemetry_impl structure device pointer initialised.
  *
  * @param socket_id
  *  Unsigned integer representing the socket id to be used
  *  for the telemetry structure.
+ * @param args
+ *  Struct containing arguments from telemetry_args
  *
  * @return
  *  0 on successful initialisation.
@@ -24,7 +30,7 @@ 
  *  -EALREADY if Telemetry is already initialised.
  */
 int32_t
-rte_telemetry_init(uint32_t socket_id);
+rte_telemetry_init(uint32_t socket_id, struct telemetry_args *args);
 
 /**
  * Clean up and free memory.
diff --git a/lib/librte_telemetry/rte_telemetry_internal.h b/lib/librte_telemetry/rte_telemetry_internal.h
index 3e21b79..3270711 100644
--- a/lib/librte_telemetry/rte_telemetry_internal.h
+++ b/lib/librte_telemetry/rte_telemetry_internal.h
@@ -41,6 +41,7 @@  typedef struct telemetry_impl {
 	TAILQ_HEAD(, telemetry_client) client_list_head;
 	struct telemetry_client *request_client;
 	int register_fail_count;
+	int selftest;
 } telemetry_impl;
 
 int32_t