From 0c8bc35dab09939d07d9f9eeaa042fb0dac05fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marczewski?= Date: Tue, 20 Oct 2020 12:04:53 +0200 Subject: [PATCH] [LibOS] test/ltp: Use multiple configuration files This is to make ltp-sgx.cfg an override for ltp.cfg, instead of duplicating the content. I'm also adding config/conf_subtract.py, a quick-and-dirty script for reducing the ltp-sgx.cfg file (result committed separately). --- LibOS/shim/test/ltp/Makefile | 9 +-- LibOS/shim/test/ltp/README.rst | 7 +++ LibOS/shim/test/ltp/contrib/conf_lint.py | 31 +++++----- LibOS/shim/test/ltp/contrib/conf_subtract.py | 64 ++++++++++++++++++++ 4 files changed, 92 insertions(+), 19 deletions(-) create mode 100755 LibOS/shim/test/ltp/contrib/conf_subtract.py diff --git a/LibOS/shim/test/ltp/Makefile b/LibOS/shim/test/ltp/Makefile index 418a2f2f..6191b28d 100644 --- a/LibOS/shim/test/ltp/Makefile +++ b/LibOS/shim/test/ltp/Makefile @@ -56,11 +56,12 @@ else $(MAKE) ltp.xml endif -%.xml: %.cfg ltp-bug-1075.cfg $(LTPSCENARIO) $(target) - ./contrib/conf_lint.py $< --scenario $(LTPSCENARIO) - ./runltp_xml.py $(RUNLTPOPTS) -c $< $(LTPSCENARIO) -O $@ +ltp.xml: CFG = ltp.cfg +ltp-sgx.xml: CFG = ltp.cfg ltp-sgx.cfg ltp-bug-1075.cfg -ltp-sgx.xml: RUNLTPOPTS += -c ltp-bug-1075.cfg +%.xml: $(CFG) $(LTPSCENARIO) $(target) + ./contrib/conf_lint.py $(CFG) --scenario $(LTPSCENARIO) + ./runltp_xml.py $(RUNLTPOPTS) $(foreach cfg,$(CFG),-c $(cfg)) $(LTPSCENARIO) -O $@ .PHONY: clean-build clean-build: diff --git a/LibOS/shim/test/ltp/README.rst b/LibOS/shim/test/ltp/README.rst index 0c07ac16..7a4b8d94 100644 --- a/LibOS/shim/test/ltp/README.rst +++ b/LibOS/shim/test/ltp/README.rst @@ -49,3 +49,10 @@ See ``--help``. A lot of LTP tests cause problems in Graphene. The ones we've already analyzed should have an appropriate comment in the ``ltp.cfg`` file. + +SGX mode +-------- + +In SGX mode, we use additional files: ``ltp-sgx.cfg``, and (temporarily) +``ltp-bug-1075.cfg``. These function as an override for ``ltp.cfg``, so that +configuration is not duplicated. diff --git a/LibOS/shim/test/ltp/contrib/conf_lint.py b/LibOS/shim/test/ltp/contrib/conf_lint.py index 91edabf1..511a52be 100755 --- a/LibOS/shim/test/ltp/contrib/conf_lint.py +++ b/LibOS/shim/test/ltp/contrib/conf_lint.py @@ -13,7 +13,7 @@ import shlex argparser = argparse.ArgumentParser() argparser.add_argument('config', metavar='FILENAME', - type=argparse.FileType('r'), nargs='?', default='-', + type=argparse.FileType('r'), nargs='+', default='-', help='ltp.cfg file (default: stdin)') argparser.add_argument('--scenario', metavar='FILENAME', @@ -38,44 +38,45 @@ def read_tags(file): yield shlex.split(line)[0] -def validate_section_order(sections): +def validate_section_order(name, sections): mistakes = 0 prev = '' for lineno, section in sections: if section < prev: - print('line {lineno}: bad order: [{section}] (after [{prev}])'.format( - lineno=lineno, section=section, prev=prev)) + print('{name}:{lineno}: bad order: [{section}] (after [{prev}])'.format( + name=name, lineno=lineno, section=section, prev=prev)) mistakes += 1 prev = section return mistakes -def validate_section_names(sections, tags): +def validate_section_names(name, sections, tags): mistakes = 0 for lineno, section in sections: if set(section) & set('*?[]!'): # fnmatch pattern if not any(tag for tag in tags if fnmatch.fnmatch(tag, section)): - print("line {lineno}: pattern doesn't match any test: [{section}]".format( - lineno=lineno, section=section)) + print("{name}:{lineno}: pattern doesn't match any test: [{section}]".format( + name=name, lineno=lineno, section=section)) mistakes += 1 elif section != 'DEFAULT': if section not in tags: - print("line {lineno}: test doesn't exist: [{section}]".format( - lineno=lineno, section=section)) + print("{name}:{lineno}: test doesn't exist: [{section}]".format( + name=name, lineno=lineno, section=section)) mistakes += 1 return mistakes def main(args=None): args = argparser.parse_args(args) - sections = list(read_sections(args.config)) + tags = set(read_tags(args.scenario)) if args.scenario else None + for config in args.config: + sections = list(read_sections(config)) - mistakes = 0 - mistakes += validate_section_order(sections) - if args.scenario: - tags = set(read_tags(args.scenario)) - mistakes += validate_section_names(sections, tags) + mistakes = 0 + mistakes += validate_section_order(config.name, sections) + if args.scenario: + mistakes += validate_section_names(config.name, sections, tags) return min(mistakes, 255) diff --git a/LibOS/shim/test/ltp/contrib/conf_subtract.py b/LibOS/shim/test/ltp/contrib/conf_subtract.py new file mode 100755 index 00000000..5bb4e761 --- /dev/null +++ b/LibOS/shim/test/ltp/contrib/conf_subtract.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (C) 2020 Intel Corporation +# Paweł Marczewski + +import argparse + +DEFAULT = 'DEFAULT' + +# Compute a difference between two files. + +# textual config representation to preserve comments + +argparser = argparse.ArgumentParser() +argparser.add_argument('file_a', metavar='FILE_A', + type=argparse.FileType('r'), + help='first file') + +argparser.add_argument('file_b', metavar='FILE_B', + type=argparse.FileType('r'), + help='second file') + +def read_file(file): + sections = {} + + section = '' + section_name = None + for line in file: + if line.startswith('['): + if section_name is None: + # We're in a new section already, this is its name. + section_name = line.strip(' \n[]') + section += line + else: + # We start a new section. + sections[section_name] = section + section_name = line.strip(' \n[]') + section = line + elif line.startswith('#') and section_name is not None: + # Treat comments as a start of a new section. + sections[section_name] = section + + section = line + section_name = None + else: + section += line + + assert section_name is not None + sections[section_name] = section + return sections + + +def main(args=None): + args = argparser.parse_args(args) + + sections_a = read_file(args.file_a) + sections_b = read_file(args.file_b) + + for name, section in sections_b.items(): + if name not in sections_a or sections_a[name] != sections_b[name]: + print(section, end='') + +if __name__ == '__main__': + main()