Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent run name filter at cmd line #1417

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,8 @@ positional arguments:
RUN_NAME Names of the analysis runs to show result summaries of.
This has the following format:
<run_name_1>:<run_name_2>:<run_name_3> where run names
can be a Python regex expression. So if you have
can contain * quantifiers which matches any number of
characters (zero or more). So if you have
run_1_a_name, run_2_b_name, run_2_c_name, run_3_d_name
then "run_2*:run_3_d_name" selects the last three runs.
Use 'CodeChecker cmd runs' to get the available runs.
Expand Down Expand Up @@ -1322,16 +1323,19 @@ optional arguments:
-b BASE_RUN, --basename BASE_RUN
The 'base' (left) side of the difference: this
analysis run is used as the initial state in the
comparison. The basename can be a Python regex which
is meant to cover the whole run name. So if you have
run_1_a_name, run_2_b_name and run_2_c_name then
run_.*_[ab]_name selects the first two.
comparison. The basename can contain * quantifiers
which matches any number of characters (zero or more).
So if you have run-a-1, run-a-2 and run-b-1 then
"run-a*" selects the first two.
-n NEW_RUN, --newname NEW_RUN
The 'new' (right) side of the difference: this
analysis run is compared to the -b/--basename run.
The parameter can be a run name(on the remote server)
or a local report directory (result of the analyze
command).
analysis run is compared to the -b/--basename run. The
parameter can be a run name(on the remote server) or a
local report directory (result of the analyze
command). In case of run name the newname can contain
* quantifiers which matches any number of characters
(zero or more). So if you have run-a-1, run-a-2 and
run-b-1 then "run-a*" selects the first two.
-s, --suppressed Filter results to only show suppressed entries.
(default: False)
--filter FILTER Filter results. The filter string has the following
Expand Down
37 changes: 17 additions & 20 deletions libcodechecker/cmd/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,29 +584,14 @@ def print_reports(client, reports, output_format):

client = setup_client(args.product_url)

report_dir_mode = False
if os.path.isdir(args.newname):
# If newname is a valid directory we assume that it is a report dir and
# we are in local compare mode.
report_dir_mode = True
else:
run_info = check_run_names(client, [args.newname])
newid = run_info[args.newname].runId

try:
basename_regex = '^' + args.basename + '$'
base_runs = filter(lambda run: re.match(basename_regex, run.name),
client.getRunData(None))
base_ids = map(lambda run: run.runId, base_runs)
except re.error:
LOG.error('Invalid regex format in ' + args.basename)
sys.exit(1)
base_runs = get_runs(client, [args.basename])
base_ids = map(lambda run: run.runId, base_runs)

if len(base_ids) == 0:
LOG.warning("No run names match the given pattern: " + args.basename)
sys.exit(1)

LOG.info("Matching against runs: " +
LOG.info("Matching base runs: " +
', '.join(map(lambda run: run.name, base_runs)))

cmp_data = ttypes.CompareData()
Expand All @@ -618,12 +603,24 @@ def print_reports(client, reports, output_format):
cmp_data.diffType = ttypes.DiffType.RESOLVED

results = []
if report_dir_mode:
if os.path.isdir(args.newname):
# If newname is a valid directory we assume that it is a report dir and
# we are in local compare mode.
results = get_diff_report_dir(client, base_ids,
os.path.abspath(args.newname),
cmp_data)
else:
cmp_data.runIds = [newid]
new_runs = get_runs(client, [args.newname])
cmp_data.runIds = map(lambda run: run.runId, new_runs)

if len(new_runs) == 0:
LOG.warning(
"No run names match the given pattern: " + args.newname)
sys.exit(1)

LOG.info("Matching new runs: " +
', '.join(map(lambda run: run.name, new_runs)))

results = get_diff_results(client, base_ids, cmp_data)

if len(results) == 0:
Expand Down
29 changes: 17 additions & 12 deletions libcodechecker/libhandlers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ def __register_results(parser):
help="Names of the analysis runs to show result "
"summaries of. This has the following format: "
"<run_name_1>:<run_name_2>:<run_name_3> "
"where run names can be a Python regex "
"expression. So if you have run_1_a_name, "
"run_2_b_name, run_2_c_name, run_3_d_name then"
"\"run_2*:run_3_d_name\" selects the last three"
"where run names can contain * quantifiers which "
"matches any number of characters (zero or "
"more). So if you have run_1_a_name, "
"run_2_b_name, run_2_c_name, run_3_d_name then "
"\"run_2*:run_3_d_name\" selects the last three "
"runs. Use 'CodeChecker cmd runs' to get the "
"available runs.")

Expand All @@ -189,11 +190,11 @@ def __register_diff(parser):
default=argparse.SUPPRESS,
help="The 'base' (left) side of the difference: this "
"analysis run is used as the initial state in "
"the comparison. The basename can be a Python "
"regex which is meant to cover the whole run "
"name. So if you have run_1_a_name, run_2_b_name "
"and run_2_c_name then run_.*_[ab]_name selects "
"the first two.")
"the comparison. The basename can contain * "
"quantifiers which matches any number of "
"characters (zero or more). So if you have "
"run-a-1, run-a-2 and run-b-1 "
"then \"run-a*\" selects the first two.")

parser.add_argument('-n', '--newname',
type=str,
Expand All @@ -203,11 +204,15 @@ def __register_diff(parser):
default=argparse.SUPPRESS,
help="The 'new' (right) side of the difference: this "
"analysis run is compared to the -b/--basename "
"run. The parameter can be a run name"
"run. The parameter can be a run name "
"(on the remote server) or a local "
"report directory "
"(result of the analyze command)."
)
"(result of the analyze command). In case of run "
"name the newname can contain * quantifiers "
"which matches any number of characters "
"(zero or more). So if you have "
"run-a-1, run-a-2 and run-b-1 "
"then \"run-a*\" selects the first two.")

__add_filtering_arguments(parser)

Expand Down
32 changes: 30 additions & 2 deletions tests/functional/diff/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,34 @@ def test_local_compare_res_count_new(self):
count = len(re.findall(r'\[core\.CallAndMessage\]', out))
self.assertEqual(count, 4)

def test_cmd_compare_remote_res_count_new(self):
"""
Count the new results with no filter in remote compare mode.
"""
base_run_name = self._run_names[0]
new_run_name = self._run_names[1]

# Change test_files_blablabla to test_*_blablabla
new_run_name = new_run_name.replace('files', '*')

diff_cmd = [self._codechecker_cmd, "cmd", "diff",
"--resolved",
"--url", self._url,
"-b", base_run_name,
"-n", new_run_name
]
print(diff_cmd)
process = subprocess.Popen(
diff_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=self._test_config['codechecker_cfg']['check_env'],
cwd=os.environ['TEST_WORKSPACE'])
out, err = process.communicate()
print(out+err)

# # 3 disappeared core.StackAddressEscape issues
count = len(re.findall(r'\[core\.StackAddressEscape\]', out))
self.assertEqual(count, 3)

def test_local_compare_res_count_resovled(self):
"""
Count the resolved results with no filter in local compare mode.
Expand Down Expand Up @@ -584,8 +612,8 @@ def test_local_compare_res_count_unresovled_regex(self):
"""
base_run_name = self._run_names[0]

# Change test_files_blablabla to test_.*_blablabla
base_run_name = base_run_name.replace('files', '.*')
# Change test_files_blablabla to test_*_blablabla
base_run_name = base_run_name.replace('files', '*')

diff_cmd = [self._codechecker_cmd, "cmd", "diff",
"--unresolved",
Expand Down