2017-06-16 17:22:35 -04:00
#!/usr/bin/env python3
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 15:07:57 +01:00
# SPDX-License-Identifier: GPL-2.0
2017-06-16 17:22:35 -04:00
"""
tdc . py - Linux tc ( Traffic Control ) unit test driver
Copyright ( C ) 2017 Lucas Bates < lucasb @mojatatu.com >
"""
import re
import os
import sys
import argparse
2018-02-14 14:09:21 -05:00
import importlib
2017-06-16 17:22:35 -04:00
import json
import subprocess
2018-02-14 14:09:21 -05:00
import time
2018-02-23 12:16:38 -05:00
import traceback
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
import random
2023-09-19 10:54:03 -03:00
from multiprocessing import Pool
2017-06-16 17:22:35 -04:00
from collections import OrderedDict
from string import Template
from tdc_config import *
from tdc_helper import *
2018-02-14 14:09:21 -05:00
import TdcPlugin
2018-12-06 17:42:26 -05:00
from TdcResults import *
2017-06-16 17:22:35 -04:00
2019-06-24 21:00:27 -04:00
class PluginDependencyException ( Exception ) :
def __init__ ( self , missing_pg ) :
self . missing_pg = missing_pg
2018-02-23 12:16:38 -05:00
class PluginMgrTestFail ( Exception ) :
def __init__ ( self , stage , output , message ) :
self . stage = stage
self . output = output
self . message = message
2018-02-14 14:09:21 -05:00
class PluginMgr :
def __init__ ( self , argparser ) :
super ( ) . __init__ ( )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
self . plugins = set ( )
2018-02-14 14:09:21 -05:00
self . plugin_instances = [ ]
2019-06-24 21:00:27 -04:00
self . failed_plugins = { }
2018-02-14 14:09:21 -05:00
self . argparser = argparser
plugindir = os . getenv ( ' TDC_PLUGIN_DIR ' , ' ./plugins ' )
for dirpath , dirnames , filenames in os . walk ( plugindir ) :
for fn in filenames :
if ( fn . endswith ( ' .py ' ) and
not fn == ' __init__.py ' and
not fn . startswith ( ' # ' ) and
not fn . startswith ( ' .# ' ) ) :
mn = fn [ 0 : - 3 ]
foo = importlib . import_module ( ' plugins. ' + mn )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
self . plugins . add ( mn )
self . plugin_instances [ mn ] = foo . SubPlugin ( )
2018-02-14 14:09:21 -05:00
2019-06-24 21:00:27 -04:00
def load_plugin ( self , pgdir , pgname ) :
pgname = pgname [ 0 : - 3 ]
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
self . plugins . add ( pgname )
2019-06-24 21:00:27 -04:00
foo = importlib . import_module ( ' {} . {} ' . format ( pgdir , pgname ) )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
# nsPlugin must always be the first one
if pgname == " nsPlugin " :
self . plugin_instances . insert ( 0 , ( pgname , foo . SubPlugin ( ) ) )
self . plugin_instances [ 0 ] [ 1 ] . check_args ( self . args , None )
else :
self . plugin_instances . append ( ( pgname , foo . SubPlugin ( ) ) )
self . plugin_instances [ - 1 ] [ 1 ] . check_args ( self . args , None )
2019-06-24 21:00:27 -04:00
def get_required_plugins ( self , testlist ) :
'''
Get all required plugins from the list of test cases and return
all unique items .
'''
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
reqs = set ( )
2019-06-24 21:00:27 -04:00
for t in testlist :
try :
if ' requires ' in t [ ' plugins ' ] :
if isinstance ( t [ ' plugins ' ] [ ' requires ' ] , list ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
reqs . update ( set ( t [ ' plugins ' ] [ ' requires ' ] ) )
2019-06-24 21:00:27 -04:00
else :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
reqs . add ( t [ ' plugins ' ] [ ' requires ' ] )
t [ ' plugins ' ] = t [ ' plugins ' ] [ ' requires ' ]
else :
t [ ' plugins ' ] = [ ]
2019-06-24 21:00:27 -04:00
except KeyError :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
t [ ' plugins ' ] = [ ]
2019-06-24 21:00:27 -04:00
continue
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
2019-06-24 21:00:27 -04:00
return reqs
def load_required_plugins ( self , reqs , parser , args , remaining ) :
'''
Get all required plugins from the list of test cases and load any plugin
that is not already enabled .
'''
pgd = [ ' plugin-lib ' , ' plugin-lib-custom ' ]
pnf = [ ]
for r in reqs :
if r not in self . plugins :
fname = ' {} .py ' . format ( r )
source_path = [ ]
for d in pgd :
pgpath = ' {} / {} ' . format ( d , fname )
if os . path . isfile ( pgpath ) :
source_path . append ( pgpath )
if len ( source_path ) == 0 :
print ( ' ERROR: unable to find required plugin {} ' . format ( r ) )
pnf . append ( fname )
continue
elif len ( source_path ) > 1 :
print ( ' WARNING: multiple copies of plugin {} found, using version found ' )
print ( ' at {} ' . format ( source_path [ 0 ] ) )
pgdir = source_path [ 0 ]
pgdir = pgdir . split ( ' / ' ) [ 0 ]
self . load_plugin ( pgdir , fname )
if len ( pnf ) > 0 :
raise PluginDependencyException ( pnf )
parser = self . call_add_args ( parser )
( args , remaining ) = parser . parse_known_args ( args = remaining , namespace = args )
return args
2018-02-14 14:09:21 -05:00
def call_pre_suite ( self , testcount , testidlist ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
for ( _ , pgn_inst ) in self . plugin_instances :
2018-02-14 14:09:21 -05:00
pgn_inst . pre_suite ( testcount , testidlist )
def call_post_suite ( self , index ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
for ( _ , pgn_inst ) in reversed ( self . plugin_instances ) :
2018-02-14 14:09:21 -05:00
pgn_inst . post_suite ( index )
2019-07-08 21:34:26 -04:00
def call_pre_case ( self , caseinfo , * , test_skip = False ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
for ( pgn , pgn_inst ) in self . plugin_instances :
if pgn not in caseinfo [ ' plugins ' ] :
continue
2018-02-14 14:09:21 -05:00
try :
2019-07-08 21:34:26 -04:00
pgn_inst . pre_case ( caseinfo , test_skip )
2018-02-14 14:09:21 -05:00
except Exception as ee :
print ( ' exception {} in call to pre_case for {} plugin ' .
format ( ee , pgn_inst . __class__ ) )
print ( ' test_ordinal is {} ' . format ( test_ordinal ) )
2019-07-08 21:34:26 -04:00
print ( ' testid is {} ' . format ( caseinfo [ ' id ' ] ) )
2018-02-14 14:09:21 -05:00
raise
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def call_post_case ( self , caseinfo ) :
for ( pgn , pgn_inst ) in reversed ( self . plugin_instances ) :
if pgn not in caseinfo [ ' plugins ' ] :
continue
2018-02-14 14:09:21 -05:00
pgn_inst . post_case ( )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def call_pre_execute ( self , caseinfo ) :
for ( pgn , pgn_inst ) in self . plugin_instances :
if pgn not in caseinfo [ ' plugins ' ] :
continue
2018-02-14 14:09:21 -05:00
pgn_inst . pre_execute ( )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def call_post_execute ( self , caseinfo ) :
for ( pgn , pgn_inst ) in reversed ( self . plugin_instances ) :
if pgn not in caseinfo [ ' plugins ' ] :
continue
2018-02-14 14:09:21 -05:00
pgn_inst . post_execute ( )
def call_add_args ( self , parser ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
for ( pgn , pgn_inst ) in self . plugin_instances :
2018-02-14 14:09:21 -05:00
parser = pgn_inst . add_args ( parser )
return parser
def call_check_args ( self , args , remaining ) :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
for ( pgn , pgn_inst ) in self . plugin_instances :
2018-02-14 14:09:21 -05:00
pgn_inst . check_args ( args , remaining )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def call_adjust_command ( self , caseinfo , stage , command ) :
for ( pgn , pgn_inst ) in self . plugin_instances :
if pgn not in caseinfo [ ' plugins ' ] :
continue
2018-02-14 14:09:21 -05:00
command = pgn_inst . adjust_command ( stage , command )
return command
2019-06-24 21:00:27 -04:00
def set_args ( self , args ) :
self . args = args
2018-02-14 14:09:21 -05:00
@staticmethod
def _make_argparser ( args ) :
self . argparser = argparse . ArgumentParser (
description = ' Linux TC unit tests ' )
2017-06-16 17:22:35 -04:00
def replace_keywords ( cmd ) :
"""
For a given executable command , substitute any known
variables contained within NAMES with the correct values
"""
tcmd = Template ( cmd )
subcmd = tcmd . safe_substitute ( NAMES )
return subcmd
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def exec_cmd ( caseinfo , args , pm , stage , command ) :
2017-06-16 17:22:35 -04:00
"""
Perform any required modifications on an executable command , then run
it in a subprocess and return the results .
"""
2018-02-14 14:09:21 -05:00
if len ( command . strip ( ) ) == 0 :
return None , None
2017-06-16 17:22:35 -04:00
if ' $ ' in command :
command = replace_keywords ( command )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
command = pm . call_adjust_command ( caseinfo , stage , command )
2018-02-14 14:09:21 -05:00
if args . verbose > 0 :
print ( ' command " {} " ' . format ( command ) )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
2017-06-16 17:22:35 -04:00
proc = subprocess . Popen ( command ,
shell = True ,
stdout = subprocess . PIPE ,
2018-02-14 14:09:21 -05:00
stderr = subprocess . PIPE ,
env = ENVIR )
2017-06-16 17:22:35 -04:00
2018-12-06 17:42:24 -05:00
try :
( rawout , serr ) = proc . communicate ( timeout = NAMES [ ' TIMEOUT ' ] )
if proc . returncode != 0 and len ( serr ) > 0 :
foutput = serr . decode ( " utf-8 " , errors = " ignore " )
else :
foutput = rawout . decode ( " utf-8 " , errors = " ignore " )
except subprocess . TimeoutExpired :
foutput = " Command \" {} \" timed out \n " . format ( command )
proc . returncode = 255
2017-06-16 17:22:35 -04:00
proc . stdout . close ( )
proc . stderr . close ( )
return proc , foutput
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def prepare_env ( caseinfo , args , pm , stage , prefix , cmdlist , output = None ) :
2017-06-16 17:22:35 -04:00
"""
2018-02-14 14:09:21 -05:00
Execute the setup / teardown commands for a test case .
Optionally terminate test execution if the command fails .
2017-06-16 17:22:35 -04:00
"""
2018-02-14 14:09:21 -05:00
if args . verbose > 0 :
print ( ' {} ' . format ( prefix ) )
2017-06-16 17:22:35 -04:00
for cmdinfo in cmdlist :
2018-02-14 14:09:21 -05:00
if isinstance ( cmdinfo , list ) :
2017-06-16 17:22:35 -04:00
exit_codes = cmdinfo [ 1 : ]
cmd = cmdinfo [ 0 ]
else :
exit_codes = [ 0 ]
cmd = cmdinfo
2018-02-14 14:09:21 -05:00
if not cmd :
2017-06-16 17:22:35 -04:00
continue
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
( proc , foutput ) = exec_cmd ( caseinfo , args , pm , stage , cmd )
2017-06-16 17:22:35 -04:00
2018-02-14 14:09:21 -05:00
if proc and ( proc . returncode not in exit_codes ) :
print ( ' ' , file = sys . stderr )
print ( " {} *** Could not execute: \" {} \" " . format ( prefix , cmd ) ,
file = sys . stderr )
print ( " \n {} *** Error message: \" {} \" " . format ( prefix , foutput ) ,
file = sys . stderr )
2018-11-16 17:37:56 -05:00
print ( " returncode {} ; expected {} " . format ( proc . returncode ,
exit_codes ) )
2018-02-14 14:09:21 -05:00
print ( " \n {} *** Aborting test run. " . format ( prefix ) , file = sys . stderr )
print ( " \n \n {} *** stdout *** " . format ( proc . stdout ) , file = sys . stderr )
print ( " \n \n {} *** stderr *** " . format ( proc . stderr ) , file = sys . stderr )
2018-02-23 12:16:38 -05:00
raise PluginMgrTestFail (
stage , output ,
' " {} " did not complete successfully ' . format ( prefix ) )
2018-02-14 14:09:20 -05:00
selftests: tc-testing: Add matchJSON to tdc
This allows the use of a matchJSON field in tests to match
against JSON output from the command under test, if that
command outputs JSON.
You specify what you want to match against as a JSON array
or object in the test's matchJSON field. You can leave out
any fields you don't want to match against that are present
in the output and they will be skipped.
An example matchJSON value would look like this:
"matchJSON": [
{
"Value": {
"neighIP": {
"family": 4,
"addr": "AQIDBA==",
"width": 32
},
"nsflags": 142,
"ncflags": 0,
"LLADDR": "ESIzRFVm"
}
}
]
The real output from the command under test might have some
extra fields that we don't care about for matching, and
since we didn't include them in our matchJSON value, those
fields will not be attempted to be matched. If everything
we included above has the same values as the real command
output, the test will pass.
The matchJSON field's type must be the same as the command
output's type, otherwise the test will fail. So if the
command outputs an array, then the value of matchJSON must
also be an array.
If matchJSON is an array, it must not contain more elements
than the command output's array, otherwise the test will
fail.
Signed-off-by: Jeremy Carter <jeremy@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20221024111603.2185410-1-victor@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-10-24 11:16:03 +00:00
def verify_by_json ( procout , res , tidx , args , pm ) :
try :
outputJSON = json . loads ( procout )
except json . JSONDecodeError :
res . set_result ( ResultState . fail )
res . set_failmsg ( ' Cannot decode verify command \' s output. Is it JSON? ' )
return res
matchJSON = json . loads ( json . dumps ( tidx [ ' matchJSON ' ] ) )
if type ( outputJSON ) != type ( matchJSON ) :
failmsg = ' Original output and matchJSON value are not the same type: output: {} != matchJSON: {} '
failmsg = failmsg . format ( type ( outputJSON ) . __name__ , type ( matchJSON ) . __name__ )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
if len ( matchJSON ) > len ( outputJSON ) :
failmsg = " Your matchJSON value is an array, and it contains more elements than the command under test \' s output: \n command output (length: {} ): \n {} \n matchJSON value (length: {} ): \n {} "
failmsg = failmsg . format ( len ( outputJSON ) , outputJSON , len ( matchJSON ) , matchJSON )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
res = find_in_json ( res , outputJSON , matchJSON , 0 )
return res
def find_in_json ( res , outputJSONVal , matchJSONVal , matchJSONKey = None ) :
if res . get_result ( ) == ResultState . fail :
return res
if type ( matchJSONVal ) == list :
res = find_in_json_list ( res , outputJSONVal , matchJSONVal , matchJSONKey )
elif type ( matchJSONVal ) == dict :
res = find_in_json_dict ( res , outputJSONVal , matchJSONVal )
else :
res = find_in_json_other ( res , outputJSONVal , matchJSONVal , matchJSONKey )
if res . get_result ( ) != ResultState . fail :
res . set_result ( ResultState . success )
return res
return res
def find_in_json_list ( res , outputJSONVal , matchJSONVal , matchJSONKey = None ) :
if ( type ( matchJSONVal ) != type ( outputJSONVal ) ) :
failmsg = ' Original output and matchJSON value are not the same type: output: {} != matchJSON: {} '
failmsg = failmsg . format ( outputJSONVal , matchJSONVal )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
if len ( matchJSONVal ) > len ( outputJSONVal ) :
failmsg = " Your matchJSON value is an array, and it contains more elements than the command under test \' s output: \n command output (length: {} ): \n {} \n matchJSON value (length: {} ): \n {} "
failmsg = failmsg . format ( len ( outputJSONVal ) , outputJSONVal , len ( matchJSONVal ) , matchJSONVal )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
for matchJSONIdx , matchJSONVal in enumerate ( matchJSONVal ) :
res = find_in_json ( res , outputJSONVal [ matchJSONIdx ] , matchJSONVal ,
matchJSONKey )
return res
def find_in_json_dict ( res , outputJSONVal , matchJSONVal ) :
for matchJSONKey , matchJSONVal in matchJSONVal . items ( ) :
if type ( outputJSONVal ) == dict :
if matchJSONKey not in outputJSONVal :
failmsg = ' Key not found in json output: {} : {} \n Matching against output: {} '
failmsg = failmsg . format ( matchJSONKey , matchJSONVal , outputJSONVal )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
else :
failmsg = ' Original output and matchJSON value are not the same type: output: {} != matchJSON: {} '
failmsg = failmsg . format ( type ( outputJSON ) . __name__ , type ( matchJSON ) . __name__ )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return rest
if type ( outputJSONVal ) == dict and ( type ( outputJSONVal [ matchJSONKey ] ) == dict or
type ( outputJSONVal [ matchJSONKey ] ) == list ) :
if len ( matchJSONVal ) > 0 :
res = find_in_json ( res , outputJSONVal [ matchJSONKey ] , matchJSONVal , matchJSONKey )
# handling corner case where matchJSONVal == [] or matchJSONVal == {}
else :
res = find_in_json_other ( res , outputJSONVal , matchJSONVal , matchJSONKey )
else :
res = find_in_json ( res , outputJSONVal , matchJSONVal , matchJSONKey )
return res
def find_in_json_other ( res , outputJSONVal , matchJSONVal , matchJSONKey = None ) :
if matchJSONKey in outputJSONVal :
if matchJSONVal != outputJSONVal [ matchJSONKey ] :
failmsg = ' Value doesn \' t match: {} : {} != {} \n Matching against output: {} '
failmsg = failmsg . format ( matchJSONKey , matchJSONVal , outputJSONVal [ matchJSONKey ] , outputJSONVal )
res . set_result ( ResultState . fail )
res . set_failmsg ( failmsg )
return res
return res
2018-02-14 14:09:21 -05:00
def run_one_test ( pm , args , index , tidx ) :
2018-03-08 15:27:44 -05:00
global NAMES
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
ns = NAMES [ ' NS ' ]
dev0 = NAMES [ ' DEV0 ' ]
dev1 = NAMES [ ' DEV1 ' ]
dummy = NAMES [ ' DUMMY ' ]
2018-02-14 14:09:20 -05:00
result = True
tresult = " "
tap = " "
2018-12-06 17:42:26 -05:00
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
2018-02-14 14:09:21 -05:00
if args . verbose > 0 :
print ( " \t ==================== \n =====> " , end = " " )
2018-02-14 14:09:20 -05:00
print ( " Test " + tidx [ " id " ] + " : " + tidx [ " name " ] )
2018-02-14 14:09:21 -05:00
2019-02-28 17:38:40 -05:00
if ' skip ' in tidx :
if tidx [ ' skip ' ] == ' yes ' :
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
res . set_result ( ResultState . skip )
res . set_errormsg ( ' Test case designated as skipped. ' )
2019-07-08 21:34:26 -04:00
pm . call_pre_case ( tidx , test_skip = True )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
pm . call_post_execute ( tidx )
2019-02-28 17:38:40 -05:00
return res
2023-03-29 11:54:53 +02:00
if ' dependsOn ' in tidx :
if ( args . verbose > 0 ) :
print ( ' probe command for test skip ' )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
( p , procout ) = exec_cmd ( tidx , args , pm , ' execute ' , tidx [ ' dependsOn ' ] )
2023-03-29 11:54:53 +02:00
if p :
if ( p . returncode != 0 ) :
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
res . set_result ( ResultState . skip )
res . set_errormsg ( ' probe command: test skipped. ' )
pm . call_pre_case ( tidx , test_skip = True )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
pm . call_post_execute ( tidx )
2023-03-29 11:54:53 +02:00
return res
2018-03-08 15:27:44 -05:00
# populate NAMES with TESTID for this test
NAMES [ ' TESTID ' ] = tidx [ ' id ' ]
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
NAMES [ ' NS ' ] = ' {} - {} ' . format ( NAMES [ ' NS ' ] , tidx [ ' random ' ] )
NAMES [ ' DEV0 ' ] = ' {} id {} ' . format ( NAMES [ ' DEV0 ' ] , tidx [ ' id ' ] )
NAMES [ ' DEV1 ' ] = ' {} id {} ' . format ( NAMES [ ' DEV1 ' ] , tidx [ ' id ' ] )
NAMES [ ' DUMMY ' ] = ' {} id {} ' . format ( NAMES [ ' DUMMY ' ] , tidx [ ' id ' ] )
2018-03-08 15:27:44 -05:00
2019-07-08 21:34:26 -04:00
pm . call_pre_case ( tidx )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
prepare_env ( tidx , args , pm , ' setup ' , " -----> prepare stage " , tidx [ " setup " ] )
2018-02-14 14:09:21 -05:00
if ( args . verbose > 0 ) :
print ( ' -----> execute stage ' )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
pm . call_pre_execute ( tidx )
( p , procout ) = exec_cmd ( tidx , args , pm , ' execute ' , tidx [ " cmdUnderTest " ] )
2018-11-16 17:37:56 -05:00
if p :
exit_code = p . returncode
else :
exit_code = None
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
pm . call_post_execute ( tidx )
2018-02-14 14:09:20 -05:00
2018-11-16 17:37:56 -05:00
if ( exit_code is None or exit_code != int ( tidx [ " expExitCode " ] ) ) :
print ( " exit: {!r} " . format ( exit_code ) )
print ( " exit: {} " . format ( int ( tidx [ " expExitCode " ] ) ) )
#print("exit: {!r} {}".format(exit_code, int(tidx["expExitCode"])))
2018-12-06 17:42:26 -05:00
res . set_result ( ResultState . fail )
res . set_failmsg ( ' Command exited with {} , expected {} \n {} ' . format ( exit_code , tidx [ " expExitCode " ] , procout ) )
2018-02-14 14:09:20 -05:00
print ( procout )
else :
2018-02-14 14:09:21 -05:00
if args . verbose > 0 :
print ( ' -----> verify stage ' )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
( p , procout ) = exec_cmd ( tidx , args , pm , ' verify ' , tidx [ " verifyCmd " ] )
2018-02-23 12:16:38 -05:00
if procout :
selftests: tc-testing: Add matchJSON to tdc
This allows the use of a matchJSON field in tests to match
against JSON output from the command under test, if that
command outputs JSON.
You specify what you want to match against as a JSON array
or object in the test's matchJSON field. You can leave out
any fields you don't want to match against that are present
in the output and they will be skipped.
An example matchJSON value would look like this:
"matchJSON": [
{
"Value": {
"neighIP": {
"family": 4,
"addr": "AQIDBA==",
"width": 32
},
"nsflags": 142,
"ncflags": 0,
"LLADDR": "ESIzRFVm"
}
}
]
The real output from the command under test might have some
extra fields that we don't care about for matching, and
since we didn't include them in our matchJSON value, those
fields will not be attempted to be matched. If everything
we included above has the same values as the real command
output, the test will pass.
The matchJSON field's type must be the same as the command
output's type, otherwise the test will fail. So if the
command outputs an array, then the value of matchJSON must
also be an array.
If matchJSON is an array, it must not contain more elements
than the command output's array, otherwise the test will
fail.
Signed-off-by: Jeremy Carter <jeremy@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20221024111603.2185410-1-victor@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-10-24 11:16:03 +00:00
if ' matchJSON ' in tidx :
verify_by_json ( procout , res , tidx , args , pm )
elif ' matchPattern ' in tidx :
match_pattern = re . compile (
str ( tidx [ " matchPattern " ] ) , re . DOTALL | re . MULTILINE )
match_index = re . findall ( match_pattern , procout )
if len ( match_index ) != int ( tidx [ " matchCount " ] ) :
res . set_result ( ResultState . fail )
res . set_failmsg ( ' Could not match regex pattern. Verify command output: \n {} ' . format ( procout ) )
else :
res . set_result ( ResultState . success )
2018-12-06 17:42:26 -05:00
else :
selftests: tc-testing: Add matchJSON to tdc
This allows the use of a matchJSON field in tests to match
against JSON output from the command under test, if that
command outputs JSON.
You specify what you want to match against as a JSON array
or object in the test's matchJSON field. You can leave out
any fields you don't want to match against that are present
in the output and they will be skipped.
An example matchJSON value would look like this:
"matchJSON": [
{
"Value": {
"neighIP": {
"family": 4,
"addr": "AQIDBA==",
"width": 32
},
"nsflags": 142,
"ncflags": 0,
"LLADDR": "ESIzRFVm"
}
}
]
The real output from the command under test might have some
extra fields that we don't care about for matching, and
since we didn't include them in our matchJSON value, those
fields will not be attempted to be matched. If everything
we included above has the same values as the real command
output, the test will pass.
The matchJSON field's type must be the same as the command
output's type, otherwise the test will fail. So if the
command outputs an array, then the value of matchJSON must
also be an array.
If matchJSON is an array, it must not contain more elements
than the command output's array, otherwise the test will
fail.
Signed-off-by: Jeremy Carter <jeremy@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20221024111603.2185410-1-victor@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-10-24 11:16:03 +00:00
res . set_result ( ResultState . fail )
res . set_failmsg ( ' Must specify a match option: matchJSON or matchPattern \n {} ' . format ( procout ) )
2018-02-23 12:16:38 -05:00
elif int ( tidx [ " matchCount " ] ) != 0 :
2018-12-06 17:42:26 -05:00
res . set_result ( ResultState . fail )
res . set_failmsg ( ' No output generated by verify command. ' )
2018-02-23 12:16:38 -05:00
else :
2018-12-06 17:42:26 -05:00
res . set_result ( ResultState . success )
2018-02-14 14:09:20 -05:00
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
prepare_env ( tidx , args , pm , ' teardown ' , ' -----> teardown stage ' , tidx [ ' teardown ' ] , procout )
pm . call_post_case ( tidx )
2018-02-14 14:09:21 -05:00
2018-02-14 14:09:20 -05:00
index + = 1
2018-03-08 15:27:44 -05:00
# remove TESTID from NAMES
del ( NAMES [ ' TESTID ' ] )
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
# Restore names
NAMES [ ' NS ' ] = ns
NAMES [ ' DEV0 ' ] = dev0
NAMES [ ' DEV1 ' ] = dev1
NAMES [ ' DUMMY ' ] = dummy
2018-12-06 17:42:26 -05:00
return res
2017-06-16 17:22:35 -04:00
2023-09-19 10:54:03 -03:00
def prepare_run ( pm , args , testlist ) :
2017-06-16 17:22:35 -04:00
tcount = len ( testlist )
2018-02-23 12:16:38 -05:00
emergency_exit = False
emergency_exit_message = ' '
try :
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
pm . call_pre_suite ( tcount , testlist )
2018-02-23 12:16:38 -05:00
except Exception as ee :
ex_type , ex , ex_tb = sys . exc_info ( )
print ( ' Exception {} {} (caught in pre_suite). ' .
format ( ex_type , ex ) )
traceback . print_tb ( ex_tb )
emergency_exit_message = ' EMERGENCY EXIT, call_pre_suite failed with exception {} {} \n ' . format ( ex_type , ex )
emergency_exit = True
if emergency_exit :
2023-09-19 10:54:03 -03:00
pm . call_post_suite ( 1 )
2018-02-23 12:16:38 -05:00
return emergency_exit_message
2023-09-19 10:54:03 -03:00
def purge_run ( pm , index ) :
pm . call_post_suite ( index )
def test_runner ( pm , args , filtered_tests ) :
"""
Driver function for the unit tests .
Prints information about the tests being run , executes the setup and
teardown commands and the command under test itself . Also determines
success / failure based on the information in the test case and generates
TAP output accordingly .
"""
testlist = filtered_tests
tcount = len ( testlist )
index = 1
tap = ' '
badtest = None
stage = None
tsr = TestSuiteReport ( )
2017-06-16 17:22:35 -04:00
for tidx in testlist :
2017-10-26 18:24:43 -07:00
if " flower " in tidx [ " category " ] and args . device == None :
2019-07-29 19:18:12 -04:00
errmsg = " Tests using the DEV2 variable must define the name of a "
errmsg + = " physical NIC with the -d option when running tdc. \n "
errmsg + = " Test has been skipped. "
2018-02-23 12:16:38 -05:00
if args . verbose > 1 :
2019-07-29 19:18:12 -04:00
print ( errmsg )
2018-12-06 17:42:26 -05:00
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
res . set_result ( ResultState . skip )
2019-07-29 19:18:12 -04:00
res . set_errormsg ( errmsg )
2018-12-06 17:42:26 -05:00
tsr . add_resultdata ( res )
selftests: tc-testing: Add matchJSON to tdc
This allows the use of a matchJSON field in tests to match
against JSON output from the command under test, if that
command outputs JSON.
You specify what you want to match against as a JSON array
or object in the test's matchJSON field. You can leave out
any fields you don't want to match against that are present
in the output and they will be skipped.
An example matchJSON value would look like this:
"matchJSON": [
{
"Value": {
"neighIP": {
"family": 4,
"addr": "AQIDBA==",
"width": 32
},
"nsflags": 142,
"ncflags": 0,
"LLADDR": "ESIzRFVm"
}
}
]
The real output from the command under test might have some
extra fields that we don't care about for matching, and
since we didn't include them in our matchJSON value, those
fields will not be attempted to be matched. If everything
we included above has the same values as the real command
output, the test will pass.
The matchJSON field's type must be the same as the command
output's type, otherwise the test will fail. So if the
command outputs an array, then the value of matchJSON must
also be an array.
If matchJSON is an array, it must not contain more elements
than the command output's array, otherwise the test will
fail.
Signed-off-by: Jeremy Carter <jeremy@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20221024111603.2185410-1-victor@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-10-24 11:16:03 +00:00
index + = 1
2017-10-26 18:24:43 -07:00
continue
2018-02-14 14:09:20 -05:00
try :
badtest = tidx # in case it goes bad
2018-12-06 17:42:26 -05:00
res = run_one_test ( pm , args , index , tidx )
tsr . add_resultdata ( res )
2018-02-23 12:16:38 -05:00
except PluginMgrTestFail as pmtf :
ex_type , ex , ex_tb = sys . exc_info ( )
stage = pmtf . stage
message = pmtf . message
output = pmtf . output
2018-12-06 17:42:26 -05:00
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
2024-01-24 15:19:33 -03:00
res . set_result ( ResultState . fail )
2018-12-06 17:42:26 -05:00
res . set_errormsg ( pmtf . message )
res . set_failmsg ( pmtf . output )
tsr . add_resultdata ( res )
index + = 1
2018-02-23 12:16:38 -05:00
print ( message )
print ( ' Exception {} {} (caught in test_runner, running test {} {} {} stage {} ) ' .
format ( ex_type , ex , index , tidx [ ' id ' ] , tidx [ ' name ' ] , stage ) )
print ( ' --------------- ' )
print ( ' traceback ' )
traceback . print_tb ( ex_tb )
print ( ' --------------- ' )
if stage == ' teardown ' :
print ( ' accumulated output for this test: ' )
if pmtf . output :
print ( pmtf . output )
print ( ' --------------- ' )
2018-02-14 14:09:20 -05:00
break
index + = 1
2017-06-16 17:22:35 -04:00
2018-02-14 14:09:21 -05:00
# if we failed in setup or teardown,
2018-02-23 12:16:38 -05:00
# fill in the remaining tests with ok-skipped
2018-02-14 14:09:20 -05:00
count = index
2018-02-28 15:36:19 -05:00
2018-12-06 17:42:26 -05:00
if tcount + 1 != count :
for tidx in testlist [ count - 1 : ] :
res = TestResult ( tidx [ ' id ' ] , tidx [ ' name ' ] )
res . set_result ( ResultState . skip )
msg = ' skipped - previous {} failed {} {} ' . format ( stage ,
index , badtest . get ( ' id ' , ' --Unknown-- ' ) )
res . set_errormsg ( msg )
tsr . add_resultdata ( res )
count + = 1
2018-03-08 15:28:03 -05:00
if args . pause :
print ( ' Want to pause \n Press enter to continue ... ' )
if input ( sys . stdin ) :
print ( ' got something on stdin ' )
2023-09-19 10:54:03 -03:00
return ( index , tsr )
def mp_bins ( alltests ) :
serial = [ ]
parallel = [ ]
for test in alltests :
if ' nsPlugin ' not in test [ ' plugins ' ] :
serial . append ( test )
else :
# We can only create one netdevsim device at a time
if ' netdevsim/new_device ' in str ( test [ ' setup ' ] ) :
serial . append ( test )
else :
parallel . append ( test )
return ( serial , parallel )
def __mp_runner ( tests ) :
( _ , tsr ) = test_runner ( mp_pm , mp_args , tests )
return tsr . _testsuite
def test_runner_mp ( pm , args , alltests ) :
prepare_run ( pm , args , alltests )
( serial , parallel ) = mp_bins ( alltests )
batches = [ parallel [ n : n + 32 ] for n in range ( 0 , len ( parallel ) , 32 ) ]
batches . insert ( 0 , serial )
print ( " Executing {} tests in parallel and {} in serial " . format ( len ( parallel ) , len ( serial ) ) )
2023-11-17 14:12:08 -03:00
print ( " Using {} batches and {} workers " . format ( len ( batches ) , args . mp ) )
2023-09-19 10:54:03 -03:00
# We can't pickle these objects so workaround them
global mp_pm
mp_pm = pm
global mp_args
mp_args = args
with Pool ( args . mp ) as p :
pres = p . map ( __mp_runner , batches )
tsr = TestSuiteReport ( )
for trs in pres :
for res in trs :
tsr . add_resultdata ( res )
# Passing an index is not useful in MP
purge_run ( pm , None )
return tsr
def test_runner_serial ( pm , args , alltests ) :
prepare_run ( pm , args , alltests )
if args . verbose :
print ( " Executing {} tests in serial " . format ( len ( alltests ) ) )
( index , tsr ) = test_runner ( pm , args , alltests )
purge_run ( pm , index )
2017-06-16 17:22:35 -04:00
2018-12-06 17:42:26 -05:00
return tsr
2017-06-16 17:22:35 -04:00
def has_blank_ids ( idlist ) :
"""
Search the list for empty ID fields and return true / false accordingly .
"""
return not ( all ( k for k in idlist ) )
def load_from_file ( filename ) :
"""
2017-10-31 14:29:03 -04:00
Open the JSON file containing the test cases and return them
as list of ordered dictionary objects .
"""
try :
with open ( filename ) as test_data :
testlist = json . load ( test_data , object_pairs_hook = OrderedDict )
except json . JSONDecodeError as jde :
print ( ' IGNORING test case file {} \n \t BECAUSE: {} ' . format ( filename , jde ) )
testlist = list ( )
else :
idlist = get_id_list ( testlist )
if ( has_blank_ids ( idlist ) ) :
for k in testlist :
k [ ' filename ' ] = filename
2017-06-16 17:22:35 -04:00
return testlist
2023-09-19 10:54:03 -03:00
def identity ( string ) :
return string
2017-06-16 17:22:35 -04:00
def args_parse ( ) :
"""
Create the argument parser .
"""
parser = argparse . ArgumentParser ( description = ' Linux TC unit tests ' )
2023-09-19 10:54:03 -03:00
parser . register ( ' type ' , None , identity )
2017-06-16 17:22:35 -04:00
return parser
def set_args ( parser ) :
"""
Set the command line arguments for tdc .
"""
2018-12-06 17:42:26 -05:00
parser . add_argument (
' --outfile ' , type = str ,
help = ' Path to the file in which results should be saved. ' +
' Default target is the current directory. ' )
2018-02-14 14:09:19 -05:00
parser . add_argument (
' -p ' , ' --path ' , type = str ,
help = ' The full path to the tc executable to use ' )
sg = parser . add_argument_group (
' selection ' , ' select which test cases: ' +
' files plus directories; filtered by categories plus testids ' )
ag = parser . add_argument_group (
' action ' , ' select action to perform on selected test cases ' )
sg . add_argument (
' -D ' , ' --directory ' , nargs = ' + ' , metavar = ' DIR ' ,
help = ' Collect tests from the specified directory(ies) ' +
' (default [tc-tests]) ' )
sg . add_argument (
' -f ' , ' --file ' , nargs = ' + ' , metavar = ' FILE ' ,
help = ' Run tests from the specified file(s) ' )
sg . add_argument (
' -c ' , ' --category ' , nargs = ' * ' , metavar = ' CATG ' , default = [ ' +c ' ] ,
help = ' Run tests only from the specified category/ies, ' +
' or if no category/ies is/are specified, list known categories. ' )
sg . add_argument (
' -e ' , ' --execute ' , nargs = ' + ' , metavar = ' ID ' ,
help = ' Execute the specified test cases with specified IDs ' )
ag . add_argument (
' -l ' , ' --list ' , action = ' store_true ' ,
help = ' List all test cases, or those only within the specified category ' )
ag . add_argument (
' -s ' , ' --show ' , action = ' store_true ' , dest = ' showID ' ,
help = ' Display the selected test cases ' )
ag . add_argument (
' -i ' , ' --id ' , action = ' store_true ' , dest = ' gen_id ' ,
help = ' Generate ID numbers for new test cases ' )
parser . add_argument (
' -v ' , ' --verbose ' , action = ' count ' , default = 0 ,
help = ' Show the commands that are being run ' )
2018-02-28 15:36:19 -05:00
parser . add_argument (
2018-12-06 17:42:26 -05:00
' --format ' , default = ' tap ' , const = ' tap ' , nargs = ' ? ' ,
choices = [ ' none ' , ' xunit ' , ' tap ' ] ,
help = ' Specify the format for test results. (Default: TAP) ' )
2017-10-26 18:24:43 -07:00
parser . add_argument ( ' -d ' , ' --device ' ,
2019-07-29 19:18:12 -04:00
help = ' Execute test cases that use a physical device, ' +
' where DEVICE is its name. (If not defined, tests ' +
' that require a physical device will be skipped) ' )
2018-03-08 15:28:03 -05:00
parser . add_argument (
' -P ' , ' --pause ' , action = ' store_true ' ,
help = ' Pause execution just before post-suite stage ' )
2023-09-19 10:54:03 -03:00
parser . add_argument (
' -J ' , ' --multiprocess ' , type = int , default = 1 , dest = ' mp ' ,
help = ' Run tests in parallel whenever possible ' )
2017-06-16 17:22:35 -04:00
return parser
2018-02-14 14:09:21 -05:00
def check_default_settings ( args , remaining , pm ) :
2017-06-16 17:22:35 -04:00
"""
2018-02-14 14:09:21 -05:00
Process any arguments overriding the default settings ,
and ensure the settings are correct .
2017-06-16 17:22:35 -04:00
"""
# Allow for overriding specific settings
global NAMES
if args . path != None :
2018-02-23 12:16:37 -05:00
NAMES [ ' TC ' ] = args . path
2017-10-26 18:24:43 -07:00
if args . device != None :
2018-02-23 12:16:37 -05:00
NAMES [ ' DEV2 ' ] = args . device
2018-12-06 17:42:24 -05:00
if ' TIMEOUT ' not in NAMES :
NAMES [ ' TIMEOUT ' ] = None
2017-06-16 17:22:35 -04:00
if not os . path . isfile ( NAMES [ ' TC ' ] ) :
print ( " The specified tc path " + NAMES [ ' TC ' ] + " does not exist. " )
exit ( 1 )
2018-02-14 14:09:21 -05:00
pm . call_check_args ( args , remaining )
2017-06-16 17:22:35 -04:00
def get_id_list ( alltests ) :
"""
Generate a list of all IDs in the test cases .
"""
return [ x [ " id " ] for x in alltests ]
def check_case_id ( alltests ) :
"""
Check for duplicate test case IDs .
"""
idl = get_id_list ( alltests )
return [ x for x in idl if idl . count ( x ) > 1 ]
def does_id_exist ( alltests , newid ) :
"""
Check if a given ID already exists in the list of test cases .
"""
idl = get_id_list ( alltests )
return ( any ( newid == x for x in idl ) )
def generate_case_ids ( alltests ) :
"""
If a test case has a blank ID field , generate a random hex ID for it
and then write the test cases back to disk .
"""
for c in alltests :
if ( c [ " id " ] == " " ) :
while True :
2018-02-23 22:57:35 +03:00
newid = str ( ' {:04x} ' . format ( random . randrange ( 16 * * 4 ) ) )
2017-06-16 17:22:35 -04:00
if ( does_id_exist ( alltests , newid ) ) :
continue
else :
c [ ' id ' ] = newid
break
ufilename = [ ]
for c in alltests :
if ( ' filename ' in c ) :
ufilename . append ( c [ ' filename ' ] )
ufilename = get_unique_item ( ufilename )
for f in ufilename :
testlist = [ ]
for t in alltests :
if ' filename ' in t :
if t [ ' filename ' ] == f :
del t [ ' filename ' ]
testlist . append ( t )
outfile = open ( f , " w " )
json . dump ( testlist , outfile , indent = 4 )
2018-03-29 15:58:10 -04:00
outfile . write ( " \n " )
2017-06-16 17:22:35 -04:00
outfile . close ( )
2018-02-14 14:09:19 -05:00
def filter_tests_by_id ( args , testlist ) :
'''
Remove tests from testlist that are not in the named id list .
If id list is empty , return empty list .
'''
newlist = list ( )
if testlist and args . execute :
target_ids = args . execute
if isinstance ( target_ids , list ) and ( len ( target_ids ) > 0 ) :
newlist = list ( filter ( lambda x : x [ ' id ' ] in target_ids , testlist ) )
return newlist
def filter_tests_by_category ( args , testlist ) :
'''
Remove tests from testlist that are not in a named category .
'''
answer = list ( )
if args . category and testlist :
test_ids = list ( )
for catg in set ( args . category ) :
if catg == ' +c ' :
continue
print ( ' considering category {} ' . format ( catg ) )
for tc in testlist :
if catg in tc [ ' category ' ] and tc [ ' id ' ] not in test_ids :
answer . append ( tc )
test_ids . append ( tc [ ' id ' ] )
return answer
2017-06-16 17:22:35 -04:00
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
def set_random ( alltests ) :
for tidx in alltests :
tidx [ ' random ' ] = random . getrandbits ( 32 )
2019-06-24 21:00:27 -04:00
2017-06-16 17:22:35 -04:00
def get_test_cases ( args ) :
"""
If a test case file is specified , retrieve tests from that file .
Otherwise , glob for all json files in subdirectories and load from
each one .
2018-02-14 14:09:19 -05:00
Also , if requested , filter by category , and add tests matching
certain ids .
2017-06-16 17:22:35 -04:00
"""
import fnmatch
2018-02-14 14:09:19 -05:00
flist = [ ]
testdirs = [ ' tc-tests ' ]
if args . file :
# at least one file was specified - remove the default directory
testdirs = [ ]
for ff in args . file :
if not os . path . isfile ( ff ) :
2018-02-14 14:09:21 -05:00
print ( " IGNORING file " + ff + " \n \t BECAUSE does not exist. " )
2018-02-14 14:09:19 -05:00
else :
flist . append ( os . path . abspath ( ff ) )
if args . directory :
testdirs = args . directory
for testdir in testdirs :
for root , dirnames , filenames in os . walk ( testdir ) :
2017-06-16 17:22:35 -04:00
for filename in fnmatch . filter ( filenames , ' *.json ' ) :
2018-02-14 14:09:19 -05:00
candidate = os . path . abspath ( os . path . join ( root , filename ) )
if candidate not in testdirs :
flist . append ( candidate )
alltestcases = list ( )
2017-06-16 17:22:35 -04:00
for casefile in flist :
2018-02-14 14:09:19 -05:00
alltestcases = alltestcases + ( load_from_file ( casefile ) )
allcatlist = get_test_categories ( alltestcases )
allidlist = get_id_list ( alltestcases )
testcases_by_cats = get_categorized_testlist ( alltestcases , allcatlist )
idtestcases = filter_tests_by_id ( args , alltestcases )
cattestcases = filter_tests_by_category ( args , alltestcases )
cat_ids = [ x [ ' id ' ] for x in cattestcases ]
if args . execute :
if args . category :
alltestcases = cattestcases + [ x for x in idtestcases if x [ ' id ' ] not in cat_ids ]
else :
alltestcases = idtestcases
else :
if cat_ids :
alltestcases = cattestcases
else :
# just accept the existing value of alltestcases,
# which has been filtered by file/directory
pass
return allcatlist , allidlist , testcases_by_cats , alltestcases
2017-06-16 17:22:35 -04:00
2019-06-24 21:00:27 -04:00
def set_operation_mode ( pm , parser , args , remaining ) :
2017-06-16 17:22:35 -04:00
"""
Load the test case data and process remaining arguments to determine
what the script should do for this run , and call the appropriate
function .
"""
2018-02-14 14:09:19 -05:00
ucat , idlist , testcases , alltests = get_test_cases ( args )
2017-06-16 17:22:35 -04:00
if args . gen_id :
if ( has_blank_ids ( idlist ) ) :
alltests = generate_case_ids ( alltests )
else :
print ( " No empty ID fields found in test files. " )
exit ( 0 )
duplicate_ids = check_case_id ( alltests )
if ( len ( duplicate_ids ) > 0 ) :
print ( " The following test case IDs are not unique: " )
print ( str ( set ( duplicate_ids ) ) )
print ( " Please correct them before continuing. " )
exit ( 1 )
if args . showID :
2018-02-14 14:09:19 -05:00
for atest in alltests :
print_test_case ( atest )
2017-06-16 17:22:35 -04:00
exit ( 0 )
2018-02-14 14:09:19 -05:00
if isinstance ( args . category , list ) and ( len ( args . category ) == 0 ) :
print ( " Available categories: " )
print_sll ( ucat )
exit ( 0 )
2017-06-16 17:22:35 -04:00
if args . list :
2020-04-07 13:13:25 -04:00
list_test_cases ( alltests )
exit ( 0 )
2017-06-16 17:22:35 -04:00
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
set_random ( alltests )
2021-12-03 10:53:21 +08:00
exit_code = 0 # KSFT_PASS
2018-02-14 14:09:21 -05:00
if len ( alltests ) :
2019-06-24 21:00:27 -04:00
req_plugins = pm . get_required_plugins ( alltests )
try :
args = pm . load_required_plugins ( req_plugins , parser , args , remaining )
except PluginDependencyException as pde :
print ( ' The following plugins were not found: ' )
print ( ' {} ' . format ( pde . missing_pg ) )
2023-09-19 10:54:03 -03:00
if args . mp > 1 :
catresults = test_runner_mp ( pm , args , alltests )
else :
catresults = test_runner_serial ( pm , args , alltests )
2021-12-03 10:53:21 +08:00
if catresults . count_failures ( ) != 0 :
exit_code = 1 # KSFT_FAIL
2018-12-06 17:42:26 -05:00
if args . format == ' none ' :
print ( ' Test results output suppression requested \n ' )
else :
print ( ' \n All test results: \n ' )
if args . format == ' xunit ' :
suffix = ' xml '
res = catresults . format_xunit ( )
elif args . format == ' tap ' :
suffix = ' tap '
res = catresults . format_tap ( )
print ( res )
print ( ' \n \n ' )
if not args . outfile :
fname = ' test-results. {} ' . format ( suffix )
else :
fname = args . outfile
with open ( fname , ' w ' ) as fh :
fh . write ( res )
fh . close ( )
if os . getenv ( ' SUDO_UID ' ) is not None :
os . chown ( fname , uid = int ( os . getenv ( ' SUDO_UID ' ) ) ,
gid = int ( os . getenv ( ' SUDO_GID ' ) ) )
2018-02-14 14:09:21 -05:00
else :
2018-12-06 17:42:26 -05:00
print ( ' No tests found \n ' )
2021-12-03 10:53:21 +08:00
exit_code = 4 # KSFT_SKIP
exit ( exit_code )
2017-06-16 17:22:35 -04:00
def main ( ) :
"""
Start of execution ; set up argument parser and get the arguments ,
and start operations .
"""
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
import resource
if sys . version_info . major < 3 or sys . version_info . minor < 8 :
sys . exit ( " tdc requires at least python 3.8 " )
resource . setrlimit ( resource . RLIMIT_NOFILE , ( 1048576 , 1048576 ) )
2017-06-16 17:22:35 -04:00
parser = args_parse ( )
parser = set_args ( parser )
2018-02-14 14:09:21 -05:00
pm = PluginMgr ( parser )
parser = pm . call_add_args ( parser )
2017-06-16 17:22:35 -04:00
( args , remaining ) = parser . parse_known_args ( )
2018-02-14 14:09:21 -05:00
args . NAMES = NAMES
2023-11-17 14:12:03 -03:00
args . mp = min ( args . mp , 4 )
2019-06-24 21:00:27 -04:00
pm . set_args ( args )
2018-02-14 14:09:21 -05:00
check_default_settings ( args , remaining , pm )
if args . verbose > 2 :
print ( ' args is {} ' . format ( args ) )
2017-06-16 17:22:35 -04:00
2023-11-24 12:42:47 -03:00
try :
set_operation_mode ( pm , parser , args , remaining )
except KeyboardInterrupt :
# Cleanup on Ctrl-C
pm . call_post_suite ( None )
2017-06-16 17:22:35 -04:00
if __name__ == " __main__ " :
main ( )