From patchwork Mon May 11 08:41:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahesh J Salgaonkar X-Patchwork-Id: 1288185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Lmzv1Mjlz9sRR for ; Tue, 12 May 2020 15:47:55 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49Lmzt34M1zDqg5 for ; Tue, 12 May 2020 15:47:54 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=mahesh@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49LDtm0b14zDqZp for ; Mon, 11 May 2020 18:41:34 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04B8WoFB012975; Mon, 11 May 2020 04:41:30 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 30wsc2vn0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 04:41:30 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04B8XFvU014386; Mon, 11 May 2020 04:41:30 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 30wsc2vn00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 04:41:30 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04B8Yxkp030234; Mon, 11 May 2020 08:41:28 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 30wm569kqp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 08:41:28 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04B8fQwL50987114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 May 2020 08:41:26 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B3A35204F; Mon, 11 May 2020 08:41:26 +0000 (GMT) Received: from [192.168.0.24] (unknown [9.199.58.67]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 747F452050; Mon, 11 May 2020 08:41:25 +0000 (GMT) From: Mahesh Salgaonkar To: pdbg Date: Mon, 11 May 2020 14:11:24 +0530 Message-ID: <158918648405.16822.8656222589108716359.stgit@jupiter> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-11_02:2020-05-11, 2020-05-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 spamscore=0 bulkscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005110066 X-Mailman-Approved-At: Tue, 12 May 2020 15:47:51 +1000 Subject: [Pdbg] [PATCH RFC 1/4] pdbg: Add support for error injection framework. X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Add new command called "inject" to allow users to inject errors using pdbg. Signed-off-by: Mahesh Salgaonkar --- 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 +#include +#include +#include +#include +#include + +#include + +#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", " |0", "Execute istep on SBE" }, + { "inject", "|? |?", "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 #include #include +#include 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