From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1499742C50; Mon, 12 Jun 2023 19:59:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 06AA141138; Mon, 12 Jun 2023 19:59:06 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 42B9341138 for ; Mon, 12 Jun 2023 19:59:04 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35CH2wZa000514 for ; Mon, 12 Jun 2023 10:59:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=pfpt0220; bh=WCOKpmLljYC4gxeoQOfoQ4nq+4AJ5CxZgiFyl3ISBqc=; b=FL/YcOT7jvJT5/6fP2k3aiqFra+a8a4rGY9PHIjooUwGpaQ6UURwZVgpP2V/vYJZJzLZ RtmwN8+L93rRELB9L/CpZ5TxuLD+cFwh/7mD8Adkptm9JrvY7fUwtqZdlTxxdiioJEzm U6SKSTtnHa+SIOxLXetbNKmLJSnmELy66ihVZy+Mb5h+q1EmTzIWZ1oEzPMcrEu0yvkG YrNXouzXqAR0+Vxyh5xyETnZ4U7UwDeQB/rA94dVUZfYT9U1Z1GBHmui9OO+DprFnW2f gPwxJnVmizWM0HQiD4NUe8GWORPjQPy/SJGcEwY78fdXLkXjfuyWeJ+VKnH6L3vecczv cg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r4rpkddaj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 12 Jun 2023 10:59:03 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 12 Jun 2023 10:59:01 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Mon, 12 Jun 2023 10:59:01 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 73F1E3F7057; Mon, 12 Jun 2023 10:59:01 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , Subject: [PATCH v1] app/mldev: improve checks for invalid options Date: Mon, 12 Jun 2023 10:58:57 -0700 Message-ID: <20230612175857.30086-1-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: lD2Ew4TeaUnodz3Y84Z67C67bMXGPvCT X-Proofpoint-GUID: lD2Ew4TeaUnodz3Y84Z67C67bMXGPvCT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-12_13,2023-06-12_02,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Improve checks for ML application options. Check for negative, non-integral and hexadecimal values. Check for number of entries in filelist option. Improve error reporting for invalid options. Signed-off-by: Srikanth Yalavarthi --- app/test-mldev/ml_options.c | 55 +++++++++++++++++++++----- app/test-mldev/parser.c | 8 ++-- app/test-mldev/test_common.c | 6 +-- app/test-mldev/test_inference_common.c | 10 ++--- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index a63506cf7d..bed06d1bf7 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -43,6 +43,7 @@ static int ml_parse_test_name(struct ml_options *opt, const char *arg) { strlcpy(opt->test_name, arg, ML_TEST_NAME_MAX_LEN); + return 0; } @@ -52,9 +53,8 @@ ml_parse_dev_id(struct ml_options *opt, const char *arg) int ret; ret = parser_read_int16(&opt->dev_id, arg); - if (ret < 0) - return -EINVAL; + ml_err("Invalid option: dev_id = %s\n", arg); return ret; } @@ -62,9 +62,13 @@ ml_parse_dev_id(struct ml_options *opt, const char *arg) static int ml_parse_socket_id(struct ml_options *opt, const char *arg) { - opt->socket_id = atoi(arg); + int ret; - return 0; + ret = parser_read_int32(&opt->socket_id, arg); + if (ret < 0) + ml_err("Invalid option: socket_id = %s\n", arg); + + return ret; } static int @@ -143,10 +147,17 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) else memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX); + /* check for extra tokens */ + token = strtok(NULL, delim); + if (token != NULL) { + ml_err("Invalid filelist. Entries > 4\n."); + return -EINVAL; + } + opt->nb_filelist++; if (opt->nb_filelist == 0) { - ml_err("Empty filelist. Need at least one filelist entry for the test."); + ml_err("Empty filelist. Need at least one filelist entry for the test.\n"); return -EINVAL; } @@ -156,13 +167,25 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) static int ml_parse_repetitions(struct ml_options *opt, const char *arg) { - return parser_read_uint64(&opt->repetitions, arg); + int ret; + + ret = parser_read_uint64(&opt->repetitions, arg); + if (ret != 0) + ml_err("Invalid option, repetitions = %s\n", arg); + + return ret; } static int ml_parse_burst_size(struct ml_options *opt, const char *arg) { - return parser_read_uint16(&opt->burst_size, arg); + int ret; + + ret = parser_read_uint16(&opt->burst_size, arg); + if (ret != 0) + ml_err("Invalid option, burst_size = %s\n", arg); + + return ret; } static int @@ -171,6 +194,8 @@ ml_parse_queue_pairs(struct ml_options *opt, const char *arg) int ret; ret = parser_read_uint16(&opt->queue_pairs, arg); + if (ret != 0) + ml_err("Invalid option, queue_pairs = %s\n", arg); return ret; } @@ -178,13 +203,25 @@ ml_parse_queue_pairs(struct ml_options *opt, const char *arg) static int ml_parse_queue_size(struct ml_options *opt, const char *arg) { - return parser_read_uint16(&opt->queue_size, arg); + int ret; + + ret = parser_read_uint16(&opt->queue_size, arg); + if (ret != 0) + ml_err("Invalid option, queue_size = %s\n", arg); + + return ret; } static int ml_parse_batches(struct ml_options *opt, const char *arg) { - return parser_read_uint16(&opt->batches, arg); + int ret; + + ret = parser_read_uint16(&opt->batches, arg); + if (ret != 0) + ml_err("Invalid option, batches = %s\n", arg); + + return ret; } static int diff --git a/app/test-mldev/parser.c b/app/test-mldev/parser.c index 0b7fb63fe5..277dcaedb2 100644 --- a/app/test-mldev/parser.c +++ b/app/test-mldev/parser.c @@ -132,11 +132,11 @@ parser_read_int32(int32_t *value, const char *p) int32_t val; p = skip_white_spaces(p); - if (!isdigit(*p)) + if ((*p != '-') && (!isdigit(*p))) return -EINVAL; val = strtol(p, &next, 10); - if (p == next) + if ((*next != '\0') || (p == next)) return -EINVAL; *value = val; @@ -150,11 +150,11 @@ parser_read_int16(int16_t *value, const char *p) int16_t val; p = skip_white_spaces(p); - if (!isdigit(*p)) + if ((*p != '-') && (!isdigit(*p))) return -EINVAL; val = strtol(p, &next, 10); - if (p == next) + if ((*next != '\0') || (p == next)) return -EINVAL; *value = val; diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c index 891e8d0ca8..3cf1362285 100644 --- a/app/test-mldev/test_common.c +++ b/app/test-mldev/test_common.c @@ -95,13 +95,13 @@ ml_test_opt_check(struct ml_options *opt) return -ENODEV; } - if (opt->dev_id >= dev_count) { - ml_err("Invalid option dev_id = %d", opt->dev_id); + if ((opt->dev_id >= dev_count) || (opt->dev_id < 0)) { + ml_err("Invalid option, dev_id = %d", opt->dev_id); return -EINVAL; } socket_id = rte_ml_dev_socket_id(opt->dev_id); - if (!((opt->socket_id != SOCKET_ID_ANY) || (opt->socket_id != socket_id))) { + if ((opt->socket_id != SOCKET_ID_ANY) && (opt->socket_id != socket_id)) { ml_err("Invalid option, socket_id = %d\n", opt->socket_id); return -EINVAL; } diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index 231ef2defa..7c62726761 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -302,19 +302,19 @@ test_inference_cap_check(struct ml_options *opt) rte_ml_dev_info_get(opt->dev_id, &dev_info); if (opt->queue_pairs > dev_info.max_queue_pairs) { - ml_err("Insufficient capabilities: queue_pairs = %u, max_queue_pairs = %u", + ml_err("Insufficient capabilities: queue_pairs = %u > (max_queue_pairs = %u)", opt->queue_pairs, dev_info.max_queue_pairs); return false; } if (opt->queue_size > dev_info.max_desc) { - ml_err("Insufficient capabilities: queue_size = %u, max_desc = %u", opt->queue_size, - dev_info.max_desc); + ml_err("Insufficient capabilities: queue_size = %u > (max_desc = %u)", + opt->queue_size, dev_info.max_desc); return false; } if (opt->nb_filelist > dev_info.max_models) { - ml_err("Insufficient capabilities: Filelist count exceeded device limit, count = %u (max limit = %u)", + ml_err("Insufficient capabilities: Filelist count exceeded device limit, count = %u > (max limit = %u)", opt->nb_filelist, dev_info.max_models); return false; } @@ -408,7 +408,7 @@ test_inference_opt_dump(struct ml_options *opt) ml_dump("stats", "%s", (opt->stats ? "true" : "false")); if (opt->batches == 0) - ml_dump("batches", "%u (default)", opt->batches); + ml_dump("batches", "%u (default batch size)", opt->batches); else ml_dump("batches", "%u", opt->batches); -- 2.17.1