Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edk2-test-parser
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SystemReady
edk2-test-parser
Commits
0e8f32de
Unverified
Commit
0e8f32de
authored
4 years ago
by
Jeffrey Booher-Kaeding
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #10 from vstehle/for-jeffrey
Template and filter
parents
cd007bb7
26e1667b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+32
-0
32 additions, 0 deletions
README.md
parser.py
+67
-2
67 additions, 2 deletions
parser.py
with
99 additions
and
2 deletions
README.md
+
32
−
0
View file @
0e8f32de
...
...
@@ -32,6 +32,21 @@ $ ./parser.py --sort \
'group,descr,set guid,test set,sub set,guid,name,log' ...
```
### Filtering data
The
`--filter`
option allows to specify a python3 expression, which is used as a
filter. The expression is evaluated for each test; if it evaluates to True the
test is kept, otherwise it is omitted. The expression has access to the test
as dict "x".
Example command, which keeps only the failed tests:
```
{.sh}
$ ./parser.py --filter "x['result'] == 'FAILURE'" ...
```
Filtering takes place after the configuration rules, which are described below.
## Configuration file
It is possible to use a configuration file with command line option
`--config
...
...
@@ -97,6 +112,23 @@ Try it with:
$ ./parser.py --config sample.yaml ...
```
### Generating a configuration template
To ease the writing of yaml configurations, there is a
`--template`
option to
generate a configuration "template" from the results of a run:
```
{.sh}
$ ./parser.py --template template.yaml ...
```
This generated configuration can then be further edited manually.
*
Tests with result "PASS" are omitted.
*
The following tests fields are omitted from the generated rule "criteria":
"iteration", "start date" and "start time".
*
The generated rule "criteria" "log" field is filtered to remove the leading
path before C filename.
## Notes
### Known Issues:
*
"comment" is currently not implemented, as formatting is not currently consistent, should reflect the comments from the test.
...
...
This diff is collapsed.
Click to expand it.
parser.py
+
67
−
2
View file @
0e8f32de
...
...
@@ -7,6 +7,7 @@ import argparse
import
csv
import
logging
import
json
import
re
from
packaging
import
version
try
:
...
...
@@ -314,6 +315,21 @@ def use_config(cross_check, filename):
sanitize_yaml
(
conf
)
apply_rules
(
cross_check
,
conf
)
# Filter tests data
# Filter is a python expression, which is evaluated for each test
# When the expression evaluates to True, the test is kept
# Otherwise it is dropped
def
filter_data
(
cross_check
,
Filter
):
logging
.
debug
(
f
"
Filtering with `
{
Filter
}
'"
)
# This function "wraps" the filter and is called for each test
def
function
(
x
):
return
eval
(
Filter
)
return
list
(
filter
(
function
,
cross_check
))
# Sort tests data in-place
# sort_keys is a comma-separated list
# The first key has precedence, then the second, etc.
...
...
@@ -359,6 +375,44 @@ def gen_yaml(cross_check, filename):
yaml
.
dump
(
cross_check
,
yamlfile
,
Dumper
=
Dumper
)
# Generate yaml config template
# This is to help writing yaml config.
# We omit tests with result PASS.
# We omit some tests keys: iteration and dates.
# We remove the leading directory from C filename in log.
def
gen_template
(
cross_check
,
filename
):
assert
(
'
yaml
'
in
sys
.
modules
)
logging
.
debug
(
f
'
Generate
{
filename
}
'
)
omitted_keys
=
set
([
'
iteration
'
,
'
start date
'
,
'
start time
'
])
t
=
[]
i
=
1
for
x
in
cross_check
:
if
x
[
'
result
'
]
==
'
PASS
'
:
continue
r
=
{
'
rule
'
:
f
'
Generated rule (
{
i
}
)
'
,
'
criteria
'
:
{},
'
update
'
:
{
'
result
'
:
'
TEMPLATE
'
},
}
for
key
,
value
in
x
.
items
():
if
key
in
omitted_keys
:
continue
if
key
==
'
log
'
:
value
=
re
.
sub
(
r
'
^/.*/
'
,
''
,
value
)
r
[
'
criteria
'
][
key
]
=
value
t
.
append
(
r
)
i
+=
1
with
open
(
filename
,
'
w
'
)
as
yamlfile
:
yaml
.
dump
(
t
,
yamlfile
,
Dumper
=
Dumper
)
# Combine or two databases db1 and db2 coming from ekl and seq files
# respectively into a single cross_check database
# Tests in db1, which were not meant to be run according to db2 have their
...
...
@@ -447,6 +501,7 @@ def main():
'
--debug
'
,
action
=
'
store_true
'
,
help
=
'
Turn on debug messages
'
)
parser
.
add_argument
(
'
--sort
'
,
help
=
'
Comma-separated list of keys to sort output on
'
)
parser
.
add_argument
(
'
--filter
'
,
help
=
'
Python expression to filter results
'
)
parser
.
add_argument
(
'
log_file
'
,
nargs
=
'
?
'
,
default
=
'
sample.ekl
'
,
help
=
'
Input .ekl filename
'
)
...
...
@@ -462,6 +517,8 @@ def main():
parser
.
add_argument
(
'
--config
'
,
help
=
'
Input .yaml configuration filename
'
)
parser
.
add_argument
(
'
--yaml
'
,
help
=
'
Output .yaml filename
'
)
parser
.
add_argument
(
'
--template
'
,
help
=
'
Output .yaml config template filename
'
)
args
=
parser
.
parse_args
()
...
...
@@ -495,6 +552,10 @@ def main():
if
'
config
'
in
args
and
args
.
config
is
not
None
:
use_config
(
cross_check
,
args
.
config
)
# Filter tests data, if requested
if
args
.
filter
is
not
None
:
cross_check
=
filter_data
(
cross_check
,
args
.
filter
)
# Sort tests data in-place, if requested
if
args
.
sort
is
not
None
:
sort_data
(
cross_check
,
args
.
sort
)
...
...
@@ -558,6 +619,10 @@ def main():
if
'
yaml
'
in
args
and
args
.
yaml
is
not
None
:
gen_yaml
(
cross_check
,
args
.
yaml
)
# Generate yaml config template if requested
if
'
template
'
in
args
and
args
.
template
is
not
None
:
gen_template
(
cross_check
,
args
.
template
)
# command line argument 3&4, key are to support a key & value search.
# these will be displayed in CLI
if
args
.
find_key
is
not
None
and
args
.
find_value
is
not
None
:
...
...
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