|
Packit Bot |
4e18ad |
#!/usr/bin/python3
|
|
Packit |
6c4009 |
# Copyright (C) 2014-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
# This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
# Lesser General Public License for more details.
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
# <http://www.gnu.org/licenses/>.
|
|
Packit |
6c4009 |
"""Benchmark output validator
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Given a benchmark output file in json format and a benchmark schema file,
|
|
Packit |
6c4009 |
validate the output against the schema.
|
|
Packit |
6c4009 |
"""
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
from __future__ import print_function
|
|
Packit |
6c4009 |
import json
|
|
Packit |
6c4009 |
import sys
|
|
Packit |
6c4009 |
import os
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
try:
|
|
Packit |
6c4009 |
import import_bench as bench
|
|
Packit |
6c4009 |
except ImportError:
|
|
Packit |
6c4009 |
print('Import Error: Output will not be validated.')
|
|
Packit |
6c4009 |
# Return success because we don't want the bench target to fail just
|
|
Packit |
6c4009 |
# because the jsonschema module was not found.
|
|
Packit |
6c4009 |
sys.exit(os.EX_OK)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
def print_and_exit(message, exitcode):
|
|
Packit |
6c4009 |
"""Prints message to stderr and returns the exit code.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Args:
|
|
Packit |
6c4009 |
message: The message to print
|
|
Packit |
6c4009 |
exitcode: The exit code to return
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Returns:
|
|
Packit |
6c4009 |
The passed exit code
|
|
Packit |
6c4009 |
"""
|
|
Packit |
6c4009 |
print(message, file=sys.stderr)
|
|
Packit |
6c4009 |
return exitcode
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
def main(args):
|
|
Packit |
6c4009 |
"""Main entry point
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Args:
|
|
Packit |
6c4009 |
args: The command line arguments to the program
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Returns:
|
|
Packit |
6c4009 |
0 on success or a non-zero failure code
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Exceptions:
|
|
Packit |
6c4009 |
Exceptions thrown by validate_bench
|
|
Packit |
6c4009 |
"""
|
|
Packit |
6c4009 |
if len(args) != 2:
|
|
Packit |
6c4009 |
return print_and_exit("Usage: %s <bench.out file> <bench.out schema>"
|
|
Packit |
6c4009 |
% sys.argv[0], os.EX_USAGE)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
try:
|
|
Packit |
6c4009 |
bench.parse_bench(args[0], args[1])
|
|
Packit |
6c4009 |
except IOError as e:
|
|
Packit |
6c4009 |
return print_and_exit("IOError(%d): %s" % (e.errno, e.strerror),
|
|
Packit |
6c4009 |
os.EX_OSFILE)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
except bench.validator.ValidationError as e:
|
|
Packit |
6c4009 |
return print_and_exit("Invalid benchmark output: %s" % e.message,
|
|
Packit |
6c4009 |
os.EX_DATAERR)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
except bench.validator.SchemaError as e:
|
|
Packit |
6c4009 |
return print_and_exit("Invalid schema: %s" % e.message, os.EX_DATAERR)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
print("Benchmark output in %s is valid." % args[0])
|
|
Packit |
6c4009 |
return os.EX_OK
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if __name__ == '__main__':
|
|
Packit |
6c4009 |
sys.exit(main(sys.argv[1:]))
|