resolv: fix rotate option
[glibc.git] / benchtests / scripts / validate_benchout.py
blobd1cd719794c5634cf1ff1c32a7d5d8f13dcd226e
1 #!/usr/bin/python
2 # Copyright (C) 2014-2015 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 # <http://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.
22 """
24 from __future__ import print_function
25 import json
26 import sys
27 import os
29 try:
30 import jsonschema
31 except ImportError:
32 print('Could not find jsonschema module. Output not validated.')
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)
38 def validate_bench(benchfile, schemafile):
39 """Validate benchmark file
41 Validate a benchmark output file against a JSON schema.
43 Args:
44 benchfile: The file name of the bench.out file.
45 schemafile: The file name of the JSON schema file to validate
46 bench.out against.
48 Exceptions:
49 jsonschema.ValidationError: When bench.out is not valid
50 jsonschema.SchemaError: When the JSON schema is not valid
51 IOError: If any of the files are not found.
52 """
53 with open(benchfile, 'r') as bfile:
54 with open(schemafile, 'r') as sfile:
55 bench = json.load(bfile)
56 schema = json.load(sfile)
57 jsonschema.validate(bench, schema)
59 # If we reach here, we're all good.
60 print("Benchmark output in %s is valid." % benchfile)
63 def main(args):
64 """Main entry point
66 Args:
67 args: The command line arguments to the program
69 Returns:
70 0 on success or a non-zero failure code
72 Exceptions:
73 Exceptions thrown by validate_bench
74 """
75 if len(args) != 2:
76 print("Usage: %s <bench.out file> <bench.out schema>" % sys.argv[0],
77 file=sys.stderr)
78 return os.EX_USAGE
80 validate_bench(args[0], args[1])
81 return os.EX_OK
84 if __name__ == '__main__':
85 sys.exit(main(sys.argv[1:]))