mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 13:51:28 +00:00
[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).
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# Paweł Marczewski <pawel@invisiblethingslab.com>
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user