]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/scripts/validate_benchout.py
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / benchtests / scripts / validate_benchout.py
CommitLineData
42b1161e 1#!/usr/bin/python
f7a9f785 2# Copyright (C) 2014-2016 Free Software Foundation, Inc.
42b1161e
SP
3# This file is part of the GNU C Library.
4#
5# The GNU C Library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# The GNU C Library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public
16# License along with the GNU C Library; if not, see
17# <http://www.gnu.org/licenses/>.
18"""Benchmark output validator
19
20Given a benchmark output file in json format and a benchmark schema file,
21validate the output against the schema.
22"""
23
24from __future__ import print_function
25import json
26import sys
27import os
28
29try:
0994b9b6 30 import import_bench as bench
42b1161e 31except ImportError:
0994b9b6 32 print('Import Error: Output will not be validated.')
42b1161e
SP
33 # Return success because we don't want the bench target to fail just
34 # because the jsonschema module was not found.
35 sys.exit(os.EX_OK)
36
37
0994b9b6
SP
38def print_and_exit(message, exitcode):
39 """Prints message to stderr and returns the exit code.
42b1161e
SP
40
41 Args:
0994b9b6
SP
42 message: The message to print
43 exitcode: The exit code to return
42b1161e 44
0994b9b6
SP
45 Returns:
46 The passed exit code
42b1161e 47 """
0994b9b6
SP
48 print(message, file=sys.stderr)
49 return exitcode
42b1161e
SP
50
51
52def main(args):
53 """Main entry point
54
55 Args:
56 args: The command line arguments to the program
57
58 Returns:
59 0 on success or a non-zero failure code
60
61 Exceptions:
62 Exceptions thrown by validate_bench
63 """
64 if len(args) != 2:
0994b9b6
SP
65 return print_and_exit("Usage: %s <bench.out file> <bench.out schema>"
66 % sys.argv[0], os.EX_USAGE)
67
68 try:
69 bench.parse_bench(args[0], args[1])
70 except IOError as e:
71 return print_and_exit("IOError(%d): %s" % (e.errno, e.strerror),
72 os.EX_OSFILE)
73
74 except bench.validator.ValidationError as e:
75 return print_and_exit("Invalid benchmark output: %s" % e.message,
76 os.EX_DATAERR)
77
78 except bench.validator.SchemaError as e:
79 return print_and_exit("Invalid schema: %s" % e.message, os.EX_DATAERR)
42b1161e 80
0994b9b6 81 print("Benchmark output in %s is valid." % args[0])
42b1161e
SP
82 return os.EX_OK
83
84
85if __name__ == '__main__':
86 sys.exit(main(sys.argv[1:]))