[Pdbg] [PATCH RFC 1/4] pdbg: Add support for error injection framework.

Mahesh Salgaonkar mahesh at linux.ibm.com
Mon May 11 18:41:24 AEST 2020


Add new command called "inject" to allow users to inject errors using pdbg.

Signed-off-by: Mahesh Salgaonkar <mahesh at linux.ibm.com>
---
 Makefile.am      |    3 ++-
 src/err_inject.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/main.c       |    5 +++-
 src/parsers.c    |   14 ++++++++++++
 src/parsers.h    |    3 +++
 5 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 src/err_inject.c

diff --git a/Makefile.am b/Makefile.am
index fdcbb09..1e444ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -120,7 +120,8 @@ pdbg_SOURCES = \
 	src/scom.c \
 	src/thread.c \
 	src/util.c \
-	src/util.h
+	src/util.h \
+	src/err_inject.c
 
 pdbg_CFLAGS = -I$(top_srcdir)/libpdbg -Wall -Werror -DGIT_SHA1=\"${GIT_SHA1}\" \
 	      $(ARCH_FLAGS)
diff --git a/src/err_inject.c b/src/err_inject.c
new file mode 100644
index 0000000..23463e7
--- /dev/null
+++ b/src/err_inject.c
@@ -0,0 +1,64 @@
+/* Copyright 2020 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <libpdbg.h>
+
+#include "main.h"
+#include "optcmd.h"
+#include "path.h"
+
+static void list_error_components(void)
+{
+	/* TODO: List error components */
+}
+
+static void list_err_type(char *component)
+{
+	/* TODO: List error type for a give component */
+}
+
+static void inject_errors(char *component, char *error)
+{
+	/* TODO: Inject errors */
+}
+
+
+static void error_inject_init(void)
+{
+	/* Call error inject init routines. */
+}
+
+static int inject(char *component, char *error)
+{
+	error_inject_init();
+
+	if (!strcmp(component, "?"))
+		list_error_components();
+	else if (!strcmp(error, "?"))
+		list_err_type(component);
+	else
+		inject_errors(component, error);
+
+	return 0;
+}
+OPTCMD_DEFINE_CMD_WITH_ARGS(inject, inject,
+			(DEFAULT_STRING("?"), DEFAULT_STRING("?")));
diff --git a/src/main.c b/src/main.c
index 5a5616d..7fd26f9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,7 +74,7 @@ extern struct optcmd_cmd
 	optcmd_getmem, optcmd_putmem, optcmd_getmemio, optcmd_putmemio,
 	optcmd_getmempba, optcmd_putmempba,
 	optcmd_getxer, optcmd_putxer, optcmd_getcr, optcmd_putcr,
-	optcmd_gdbserver, optcmd_istep;
+	optcmd_gdbserver, optcmd_istep, optcmd_inject;
 
 static struct optcmd_cmd *cmds[] = {
 	&optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam,
@@ -85,7 +85,7 @@ static struct optcmd_cmd *cmds[] = {
 	&optcmd_getmem, &optcmd_putmem, &optcmd_getmemio, &optcmd_putmemio,
 	&optcmd_getmempba, &optcmd_putmempba,
 	&optcmd_getxer, &optcmd_putxer, &optcmd_getcr, &optcmd_putcr,
-	&optcmd_gdbserver, &optcmd_istep,
+	&optcmd_gdbserver, &optcmd_istep, &optcmd_inject,
 };
 
 /* Purely for printing usage text. We could integrate printing argument and flag
@@ -130,6 +130,7 @@ static struct action actions[] = {
 	{ "regs",  "[--backtrace]", "State (optionally display backtrace)" },
 	{ "gdbserver", "", "Start a gdb server" },
 	{ "istep", "<major> <minor>|0", "Execute istep on SBE" },
+	{ "inject",  "<component>|? <error>|?", "Inject an error in specified component" },
 };
 
 static void print_usage(void)
diff --git a/src/parsers.c b/src/parsers.c
index 8575784..ef71a0f 100644
--- a/src/parsers.c
+++ b/src/parsers.c
@@ -3,6 +3,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <errno.h>
+#include <string.h>
 
 uint64_t *parse_number64(const char *argv)
 {
@@ -127,3 +128,16 @@ bool *parse_flag_noarg(const char *argv)
 	*result = true;
 	return result;
 }
+
+/* Just read the string and return */
+char **parse_string(const char *argv)
+{
+	char **str = malloc(sizeof(char *));
+
+	if (!argv)
+		return NULL;
+
+	*str = malloc(strlen(argv) + 1);
+	strcpy(*str, argv);
+	return str;
+}
diff --git a/src/parsers.h b/src/parsers.h
index be13ce9..ca8d74f 100644
--- a/src/parsers.h
+++ b/src/parsers.h
@@ -13,6 +13,8 @@
 #define DEFAULT_DATA32(default) (parse_number32, default)
 #define GPR (parse_gpr, NULL)
 #define SPR (parse_spr, NULL)
+#define STRING (parse_string, NULL)
+#define DEFAULT_STRING(default) (parse_string, default)
 
 uint64_t *parse_number64(const char *argv);
 uint32_t *parse_number32(const char *argv);
@@ -21,5 +23,6 @@ uint8_t *parse_number8_pow2(const char *argv);
 int *parse_gpr(const char *argv);
 int *parse_spr(const char *argv);
 bool *parse_flag_noarg(const char *argv);
+char **parse_string(const char *argv);
 
 #endif



More information about the Pdbg mailing list