From patchwork Tue May 29 17:17:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leonardo.sandoval.gonzalez@linux.intel.com X-Patchwork-Id: 27543 Received: (qmail 3313 invoked by alias); 29 May 2018 17:17:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3183 invoked by uid 89); 29 May 2018 17:17:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=plot, Plot X-HELO: mga14.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: leonardo.sandoval.gonzalez@linux.intel.com To: libc-alpha@sourceware.org Cc: Leonardo Sandoval Subject: [PATCH 2/2 v2] benchtests: Catch exceptions in input arguments Date: Tue, 29 May 2018 12:17:47 -0500 Message-Id: <20180529171747.3667-2-leonardo.sandoval.gonzalez@linux.intel.com> In-Reply-To: <20180529171747.3667-1-leonardo.sandoval.gonzalez@linux.intel.com> References: <20180529171747.3667-1-leonardo.sandoval.gonzalez@linux.intel.com> From: Leonardo Sandoval Catch runtime exceptions in case the user provided: wrong base function, attribute(s) or input file. In any of the latter, quit immediately with non-zero return code. * benchtests/scripts/compare_string.py: (process_results) Catch exception in non-existent base_func. (process_results) Catch exception in non-existent attribute. (parse_file) Catch exception in non-existent input file. --- ChangeLog | 7 ++++++ benchtests/scripts/compare_strings.py | 34 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index d55a49765b3..41633079e5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-05-28 Leonardo Sandoval + + * benchtests/scripts/compare_string.py: (process_results) Catch + exception in non-existent base_func. + (process_results) Catch exception in non-existent attribute. + (parse_file) Catch exception if input file does not exist. + 2018-05-28 Leonardo Sandoval * benchtests/scripts/compare_string.py: Add --no-diff and --no-header diff --git a/benchtests/scripts/compare_strings.py b/benchtests/scripts/compare_strings.py index 850c455f3aa..ddce84a3ac3 100755 --- a/benchtests/scripts/compare_strings.py +++ b/benchtests/scripts/compare_strings.py @@ -38,13 +38,16 @@ except ImportError: def parse_file(filename, schema_filename): - with open(schema_filename, 'r') as schemafile: - schema = json.load(schemafile) - with open(filename, 'r') as benchfile: - bench = json.load(benchfile) - validator.validate(bench, schema) - return bench - + try: + with open(schema_filename, 'r') as schemafile: + schema = json.load(schemafile) + with open(filename, 'r') as benchfile: + bench = json.load(benchfile) + validator.validate(bench, schema) + return bench + except FileNotFoundError: + sys.stderr.write('Invalid input file %s.\n' % filename) + sys.exit(os.EX_NOINPUT) def draw_graph(f, v, ifuncs, results): """Plot graphs for functions @@ -93,7 +96,12 @@ def process_results(results, attrs, base_func, graph, no_diff, no_header): base_index = 0 if base_func: - base_index = results['functions'][f]['ifuncs'].index(base_func) + try: + base_index = results['functions'][f]['ifuncs'].index(base_func) + except ValueError: + sys.stderr.write('Invalid -b "%s" parameter. Options: %s.\n' % + (base_func, ', '.join(results['functions'][f]['ifuncs']))) + sys.exit(os.EX_DATAERR) if not no_header: print('Function: %s' % f) @@ -103,7 +111,12 @@ def process_results(results, attrs, base_func, graph, no_diff, no_header): graph_res = {} for res in results['functions'][f]['results']: - attr_list = ['%s=%s' % (a, res[a]) for a in attrs] + try: + attr_list = ['%s=%s' % (a, res[a]) for a in attrs] + except KeyError as ke: + sys.stderr.write('Invalid -a %s parameter. Options: %s.\n' + % (ke, ', '.join([a for a in res.keys() if a != 'timings']))) + sys.exit(os.EX_DATAERR) i = 0 key = ', '.join(attr_list) sys.stdout.write('%36s: ' % key) @@ -137,6 +150,7 @@ def main(args): results = parse_file(args.input, args.schema) process_results(results, attrs, base_func, args.graph, args.no_diff, args.no_header) + return os.EX_OK if __name__ == '__main__': @@ -162,4 +176,4 @@ if __name__ == '__main__': help='Do not print the header.') args = parser.parse_args() - main(args) + sys.exit(main(args))