]>
git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/scripts/validate_benchout.py
2 # Copyright (C) 2014-2019 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
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.
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.
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 # <https://www.gnu.org/licenses/>.
18 """Benchmark output validator
20 Given a benchmark output file in json format and a benchmark schema file,
21 validate the output against the schema.
24 from __future__
import print_function
30 import import_bench
as bench
32 print('Import Error: Output will not be validated.')
33 # Return success because we don't want the bench target to fail just
34 # because the jsonschema module was not found.
38 def print_and_exit(message
, exitcode
):
39 """Prints message to stderr and returns the exit code.
42 message: The message to print
43 exitcode: The exit code to return
48 print(message
, file=sys
.stderr
)
56 args: The command line arguments to the program
59 0 on success or a non-zero failure code
62 Exceptions thrown by validate_bench
65 return print_and_exit("Usage: %s <bench.out file> <bench.out schema>"
66 % sys
.argv
[0], os
.EX_USAGE
)
69 bench
.parse_bench(args
[0], args
[1])
71 return print_and_exit("IOError(%d): %s" % (e
.errno
, e
.strerror
),
74 except bench
.validator
.ValidationError
as e
:
75 return print_and_exit("Invalid benchmark output: %s" % e
.message
,
78 except bench
.validator
.SchemaError
as e
:
79 return print_and_exit("Invalid schema: %s" % e
.message
, os
.EX_DATAERR
)
81 print("Benchmark output in %s is valid." % args
[0])
85 if __name__
== '__main__':
86 sys
.exit(main(sys
.argv
[1:]))