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
564451e2
Commit
564451e2
authored
3 years ago
by
Dennis Gläser
Browse files
Options
Downloads
Patches
Plain Diff
[bin][findtest] rearrange and comply with PEP8 style
parent
a774bc22
No related branches found
No related tags found
1 merge request
!2408
Feature/ci integration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/testing/findtests.py
+55
-21
55 additions, 21 deletions
bin/testing/findtests.py
with
55 additions
and
21 deletions
bin/testing/findtests.py
+
55
−
21
View file @
564451e2
...
...
@@ -13,43 +13,65 @@ from glob import glob
from
subprocess
import
PIPE
import
os
# 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
:
# make dry run and return the compilation command
def
get_compile_command
(
testConfig
):
lines
=
subprocess
.
check_output
([
"
make
"
,
"
--dry-run
"
,
testConfig
[
"
target
"
]],
encoding
=
'
ascii
'
).
splitlines
()
commands
=
list
(
filter
(
lambda
comm
:
'
g++
'
in
comm
,
lines
))
assert
len
(
commands
)
<=
1
return
commands
[
0
]
if
commands
else
None
# get the command and folder to compile the given test
def
build_command_and_dir
(
testConfig
,
cache
):
compCommand
=
get_compile_command
(
testConfig
)
if
compCommand
is
None
:
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
(
"
&&
"
)]
(
_
,
dir
),
command
=
[
comm
.
split
()
for
comm
in
compCommand
.
split
(
"
&&
"
)]
with
open
(
cache
,
"
w
"
)
as
c
:
json
.
dump
({
"
command
"
:
command
,
"
dir
"
:
dir
},
c
)
json
.
dump
({
"
command
"
:
command
,
"
dir
"
:
dir
},
c
)
return
command
,
dir
return
command
,
dir
# check if a test is affected by changes in the given files
def
is_affected_test
(
testConfigFile
,
changed_files
):
with
open
(
testConfigFile
)
as
configFile
:
testConfig
=
json
.
load
(
configFile
)
def
is_affected_test
(
test
,
changed_files
):
with
open
(
test
)
as
config_file
:
config
=
json
.
load
(
config_file
)
cacheFile
=
"
TestTargets/
"
+
testConfig
[
"
target
"
]
+
"
.json
"
command
,
dir
=
build_command_and_dir
(
testConfig
,
cacheFile
)
command
,
dir
=
build_command_and_dir
(
config
,
"
TestTargets/
"
+
config
[
"
target
"
]
+
"
.json
"
)
# detect headers included in this test
# -MM skips headers from system directories
# -H prints the name(+path) of each used header
# for some reason g++ writes to stderr
lines
=
subprocess
.
run
(
command
+
[
"
-MM
"
,
"
-H
"
],
stderr
=
PIPE
,
stdout
=
PIPE
,
cwd
=
dir
,
encoding
=
'
ascii
'
).
stderr
.
splitlines
()
headers
=
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
])
# filter only headers from this project and turn them into relative paths
projectDir
=
os
.
path
.
abspath
(
os
.
getcwd
().
rstrip
(
"
build-cmake
"
))
def
isProjectHeader
(
headerPath
):
return
projectDir
in
headerPath
test_files
=
set
([
os
.
path
.
relpath
(
header
.
lstrip
(
"
.
"
),
projectDir
)
for
header
in
filter
(
isProjectHeader
,
headers
)])
if
has_common_member
(
changed_files
,
test_files
):
return
True
,
c
onfig
[
"
name
"
],
c
onfig
[
"
target
"
]
return
True
,
testC
onfig
[
"
name
"
],
testC
onfig
[
"
target
"
]
return
False
,
c
onfig
[
"
name
"
],
c
onfig
[
"
target
"
]
return
False
,
testC
onfig
[
"
name
"
],
testC
onfig
[
"
target
"
]
if
__name__
==
'
__main__
'
:
...
...
@@ -60,7 +82,6 @@ if __name__ == '__main__':
help
=
'
The source tree (default: `HEAD`)
'
)
parser
.
add_argument
(
'
-t
'
,
'
--target
'
,
required
=
False
,
default
=
'
master
'
,
help
=
'
The tree to compare against (default: `master`)
'
)
args
=
vars
(
parser
.
parse_args
())
# find the changes files
...
...
@@ -70,11 +91,24 @@ if __name__ == '__main__':
encoding
=
'
ascii
'
).
splitlines
()
changed_files
=
set
(
changed_files
)
# clean build directory
subprocess
.
run
([
"
make
"
,
"
clean
"
])
subprocess
.
run
([
"
make
"
])
# create cache folder
os
.
makedirs
(
"
TestTargets
"
,
exist_ok
=
True
)
# detect affected tests
print
(
"
Detecting affected tests:
"
)
count
=
0
affectedTests
=
{}
for
test
in
glob
(
"
TestMetaData/*json
"
):
print
(
is_affected_test
(
test
,
changed_files
))
affected
,
name
,
target
=
is_affected_test
(
test
,
changed_files
)
if
affected
:
print
(
"
\t
- {}
"
.
format
(
name
))
affectedTests
[
name
]
=
{
'
target
'
:
target
}
count
+=
1
print
(
"
Detected {} affected tests
"
.
format
(
count
))
with
open
(
'
affectedtests.json
'
,
'
w
'
)
as
jsonFile
:
json
.
dump
(
affectedTests
,
jsonFile
)
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