Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
00376dcc
Commit
00376dcc
authored
4 years ago
by
Timo Koch
Committed by
Dennis Gläser
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[test] Add script to identify tests that are affected by a change
parent
aac8552b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2408
Feature/ci integration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/testing/findtests.py
+69
-0
69 additions, 0 deletions
bin/testing/findtests.py
with
69 additions
and
0 deletions
bin/testing/findtests.py
0 → 100755
+
69
−
0
View file @
00376dcc
#!/usr/bin/env python3
"""
Find those tests that are affected by changes
Run this in the build directory
Warning: This runs
'
make clean
'
on the build directory
"""
import
multiprocessing
as
mp
import
json
import
subprocess
from
glob
import
glob
from
subprocess
import
PIPE
import
os
import
sys
# Whether the two lists a and b have a common member
def
has_common_member
(
myset
,
mylist
):
return
not
myset
.
isdisjoint
(
mylist
)
def
make_dryrun
(
config
):
lines
=
subprocess
.
check_output
([
"
make
"
,
"
--dry-run
"
,
config
[
"
target
"
]],
encoding
=
'
ascii
'
).
splitlines
()
return
[
l
for
l
in
lines
if
"
g++
"
in
l
]
def
build_command_and_dir
(
config
,
cache
):
lines
=
make_dryrun
(
config
)
if
len
(
lines
)
==
0
:
with
open
(
cache
)
as
c
:
data
=
json
.
load
(
c
)
return
data
[
"
command
"
],
data
[
"
dir
"
]
else
:
(
_
,
dir
),
command
=
[
l
.
split
()
for
l
in
lines
[
0
].
split
(
"
&&
"
)]
with
open
(
cache
,
"
w
"
)
as
c
:
json
.
dump
({
"
command
"
:
command
,
"
dir
"
:
dir
},
c
)
return
command
,
dir
# find the changes files
changed_files
=
subprocess
.
check_output
([
"
git
"
,
"
diff-tree
"
,
"
-r
"
,
"
--name-only
"
,
"
HEAD
"
,
"
master
"
],
encoding
=
'
ascii
'
).
splitlines
()
changed_files
=
set
(
changed_files
)
def
is_affected_tests
(
test
):
with
open
(
test
)
as
config_file
:
config
=
json
.
load
(
config_file
)
command
,
dir
=
build_command_and_dir
(
config
,
"
TestTargets/
"
+
config
[
"
target
"
]
+
"
.json
"
)
# for some reason g++ writes to stderr
lines
=
subprocess
.
run
(
command
+
[
"
-MM
"
,
"
-H
"
],
stderr
=
PIPE
,
stdout
=
PIPE
,
cwd
=
dir
,
encoding
=
'
ascii
'
).
stderr
.
splitlines
()
# filter lines
project_dir
=
os
.
path
.
abspath
(
os
.
getcwd
().
rstrip
(
"
build-cmake
"
))
test_files
=
set
([
os
.
path
.
relpath
(
l
.
lstrip
(
"
.
"
),
project_dir
)
for
l
in
lines
if
project_dir
in
l
])
if
has_common_member
(
changed_files
,
test_files
):
return
True
,
config
[
"
name
"
],
config
[
"
target
"
]
return
False
,
config
[
"
name
"
],
config
[
"
target
"
]
if
__name__
==
'
__main__
'
:
subprocess
.
run
([
"
make
"
,
"
clean
"
])
subprocess
.
run
([
"
make
"
])
# create cache folder
os
.
makedirs
(
"
TestTargets
"
,
exist_ok
=
True
)
for
test
in
glob
(
"
TestMetaData/*json
"
):
print
(
is_affected_tests
(
test
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment