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.
24 from __future__
import print_function
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.
38 def validate_bench(benchfile
, schemafile
):
39 """Validate benchmark file
41 Validate a benchmark output file against a JSON schema.
44 benchfile: The file name of the bench.out file.
45 schemafile: The file name of the JSON schema file to validate
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.
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
)
67 args: The command line arguments to the program
70 0 on success or a non-zero failure code
73 Exceptions thrown by validate_bench
76 print("Usage: %s <bench.out file> <bench.out schema>" % sys
.argv
[0],
80 validate_bench(args
[0], args
[1])
84 if __name__
== '__main__':
85 sys
.exit(main(sys
.argv
[1:]))