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
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
+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
...
@@ -13,43 +13,65 @@ from glob import glob
from
subprocess
import
PIPE
from
subprocess
import
PIPE
import
os
import
os
# Whether the two lists a and b have a common member
# Whether the two lists a and b have a common member
def
has_common_member
(
myset
,
mylist
):
def
has_common_member
(
myset
,
mylist
):
return
not
myset
.
isdisjoint
(
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
):
# make dry run and return the compilation command
lines
=
make_dryrun
(
config
)
def
get_compile_command
(
testConfig
):
if
len
(
lines
)
==
0
:
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
:
with
open
(
cache
)
as
c
:
data
=
json
.
load
(
c
)
data
=
json
.
load
(
c
)
return
data
[
"
command
"
],
data
[
"
dir
"
]
return
data
[
"
command
"
],
data
[
"
dir
"
]
else
:
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
:
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
):
cacheFile
=
"
TestTargets/
"
+
testConfig
[
"
target
"
]
+
"
.json
"
with
open
(
test
)
as
config_file
:
command
,
dir
=
build_command_and_dir
(
testConfig
,
cacheFile
)
config
=
json
.
load
(
config_file
)
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
# 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
# filter only headers from this project and turn them into relative paths
project_dir
=
os
.
path
.
abspath
(
os
.
getcwd
().
rstrip
(
"
build-cmake
"
))
projectDir
=
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
])
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
):
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__
'
:
if
__name__
==
'
__main__
'
:
...
@@ -60,7 +82,6 @@ if __name__ == '__main__':
...
@@ -60,7 +82,6 @@ if __name__ == '__main__':
help
=
'
The source tree (default: `HEAD`)
'
)
help
=
'
The source tree (default: `HEAD`)
'
)
parser
.
add_argument
(
'
-t
'
,
'
--target
'
,
required
=
False
,
default
=
'
master
'
,
parser
.
add_argument
(
'
-t
'
,
'
--target
'
,
required
=
False
,
default
=
'
master
'
,
help
=
'
The tree to compare against (default: `master`)
'
)
help
=
'
The tree to compare against (default: `master`)
'
)
args
=
vars
(
parser
.
parse_args
())
args
=
vars
(
parser
.
parse_args
())
# find the changes files
# find the changes files
...
@@ -70,11 +91,24 @@ if __name__ == '__main__':
...
@@ -70,11 +91,24 @@ if __name__ == '__main__':
encoding
=
'
ascii
'
).
splitlines
()
encoding
=
'
ascii
'
).
splitlines
()
changed_files
=
set
(
changed_files
)
changed_files
=
set
(
changed_files
)
# clean build directory
subprocess
.
run
([
"
make
"
,
"
clean
"
])
subprocess
.
run
([
"
make
"
,
"
clean
"
])
subprocess
.
run
([
"
make
"
])
subprocess
.
run
([
"
make
"
])
# create cache folder
# create cache folder
os
.
makedirs
(
"
TestTargets
"
,
exist_ok
=
True
)
os
.
makedirs
(
"
TestTargets
"
,
exist_ok
=
True
)
# detect affected tests
print
(
"
Detecting affected tests:
"
)
count
=
0
affectedTests
=
{}
for
test
in
glob
(
"
TestMetaData/*json
"
):
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