-
Notifications
You must be signed in to change notification settings - Fork 186
Deviation between dbms_utplsql_code_coverage and html_reporter #1124
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
Comments
@TobiasDo1 This is an interesting case. Does the code coverage run contain a test case that passes an identical value for p_short_desc AND a different value for p_description (l_description must be NOT NULL)? IMO this is is required to get full coverage of this code section. So my assumption is, that your tests in fact do not cover this code section and the result is correct. |
Hello Philipp, thanks for your quick reply. Well, indeed I think that this one line is not being covered, but I would have expected that only line 338 is being marked red in the html output. I did run the identical test a 2nd time and now the html shows lines 337 and 338 to be uncovered. According to dbms_utplsql_code_coverage line 337 should be covered. That is what looks weird to me. Best regards |
@TobiasDo1 I was too quick with my assumption. Sorry about that. When run_id 14881 corresponds to the HTML output than this looks wrong. Can you please provide the version information as described in https://github.com/utPLSQL/utPLSQL/issues/new?assignees=&labels=&template=bug_report.md&title=? Thank you. |
Sure, here they are. ut_version: banner: nls_session_parameters: port_string: |
Thanks @TobiasDo1. That looks good. Now we need to make this reproducible in our environment. |
@TobiasDo1: How exactly do you reproduce the HTML Report? |
I am running code coverage option out of the context menu from the sql developer plugin. And checking sys coverage via: SELECT LISTAGG(ccb.col,',') WITHIN GROUP (ORDER BY ccb.col) AS col, where run_id is latest. |
Thanks. I try to reproduce it over the weekend. |
I tried to reproduce it with the following function under test: create or replace function f (
a1 in varchar2,
a2 in varchar2,
b1 in varchar2,
b2 in varchar2
) return integer is
begin
if a1 is not null and a2 is null
or a1 is null and a2 is not null
or a1 != a2
or b1 is not null and b2 is null
or b1 is null and b2 is not null
or b1 != b2
then
return 1;
end if;
return 0;
end;
/ I created the package create or replace package test_f is
--%suite
--%test
procedure p_null_null_null_null;
--%test
procedure p_a_a_b_b;
--%test
procedure p_a1_a2_null_null;
end;
/
create or replace package body test_f is
procedure p_null_null_null_null is
begin
ut.expect(f(null, null, null, null)).to_equal(0);
end;
procedure p_a_a_b_b is
begin
ut.expect(f('a', 'a', 'b', 'b')).to_equal(0);
end;
procedure p_a1_a2_null_null is
begin
ut.expect(f('a1', 'a2', null, null)).to_equal(1);
end;
end;
/ I ran all tests from SQLDeveloper connected as user When I run the complete package When I run only When I run only When I run only For me the results are plausible (beside the counters when running the complete package, but I do not consider this a utPLSQL issue). utPLSQL combines the result from the PL/SQL Profiler and the results from the 12.2 Code Block Coverage. The tables are installed in the utPLSQL schema. So, to validate if HTML report for code coverage is valid, you have to query the right tables. For example for the last run this would be something like this: with
obj as (
select *
from dba_objects
where owner = 'PLSCOPE'
and object_name = 'F'
and object_type = 'FUNCTION'
),
source as (
select s.*
from dba_source s
join obj
on obj.owner = s.owner
and obj.object_type = s.type
and obj.object_name = s.name
),
coverage_runs as (
select *
from ut3.ut_coverage_runs
where block_coverage_id = (
select max(block_coverage_id)
from ut3.ut_coverage_runs
)
),
line_coverage as (
select d.line#,
case
when sum(d.total_occur) = 0 and sum(d.total_time) > 0 then
1
else
sum(d.total_occur)
end line_coverage_count
from obj
join ut3.plsql_profiler_units u
on u.unit_owner = obj.owner
and u.unit_type = obj.object_type
and u.unit_name = obj.object_name
join ut3.plsql_profiler_data d
on u.runid = d.runid
and u.unit_number = d.unit_number
join coverage_runs r
on r.line_coverage_id = u.runid
group by d.line#
),
block_coverage as (
select line as line,
count(block) as blocks,
sum(covered) as covered_blocks
from (
select ccb.line,
ccb.block,
max(ccb.covered) as covered
from obj
join ut3.dbmspcc_units ccu
on ccu.object_id = obj.object_id
join coverage_runs r
on r.block_coverage_id = ccu.run_id
left join ut3.dbmspcc_blocks ccb
on ccu.run_id = ccb.run_id
and ccu.object_id = ccb.object_id
group by ccb.line, ccb.block
)
group by line
having count(block) > 1
)
select s.line, s.text, lc.line_coverage_count, bc.blocks, bc.covered_blocks
from source s
left join line_coverage lc
on s.line = lc.line#
left join block_coverage bc
on s.line = bc.line
order by s.line; I ran that query as a DBA and the result was: So this should explain on what data the HTML code coverage report is based. Primary on line coverage. For lines containing more than one block also block coverage is considered. There is some logic to identify relevant lines in the utPLSQL code, which this query does not reflect. It's important to handle Oracle version specific issues and identify what is 100%. However, the query should provide all pieces relevant for a single line of code. IMO the HTML Code Coverage report is correct and it correctly reflects the data gathered by the PL/SQL Profiler and the 12.2 Code Block Coverage. I consider this issue more a question regarding the relationship of 12.2 Code Block Coverage and the HTML Code Coverage report. |
Good morning Philipp, |
In the schema where utPLSQL v3 is installed. The default is |
Hmm, when you've installed utPLSQL 3.1.10 in an Oracle Database 19.7, then the table The script And |
Hello Philipp, I tried to reinstall the utplsql framework once again on one of our DBs. These are the log files. But still no ut_coverage_runs table For installation I took latest 3.1.10 utplsql.zip from Downloads section from github (2020-02-23) |
Right, This table was added in this PR and currently available only on the develop branch. I will install the 3.1.10 in an environment and amend the query for this version. |
In utPLSQL 3.1.10 the block coverage tables are all global temporary tables (it is different in the develop branch and will change with 3.1.11). You have to create the block coverage table with the API in the user running the tests: begin
dbms_plsql_code_coverage.create_coverage_tables(true);
end;
/ I've done that as user Then you can run the following query as a DBA user (change with
obj as (
select *
from dba_objects
where owner = 'PLSCOPE'
and object_name = 'F'
and object_type = 'FUNCTION'
),
source as (
select s.*
from dba_source s
join obj
on obj.owner = s.owner
and obj.object_type = s.type
and obj.object_name = s.name
),
line_coverage as (
select d.line#,
case
when sum(d.total_occur) = 0 and sum(d.total_time) > 0 then
1
else
sum(d.total_occur)
end line_coverage_count
from obj
join ut3.plsql_profiler_units u
on u.unit_owner = obj.owner
and u.unit_type = obj.object_type
and u.unit_name = obj.object_name
join ut3.plsql_profiler_data d
on u.runid = d.runid
and u.unit_number = d.unit_number
where u.runid in (
select max(r.runid)
from ut3.plsql_profiler_runs r
)
group by d.line#
),
block_coverage as (
select line as line,
count(block) as blocks,
sum(covered) as covered_blocks
from (
select ccb.line,
ccb.block,
max(ccb.covered) as covered
from obj
join plscope.dbmspcc_units ccu
on ccu.object_id = obj.object_id
left join plscope.dbmspcc_blocks ccb
on ccu.run_id = ccb.run_id
and ccu.object_id = ccb.object_id
where ccu.run_id in (
select max(r.run_id)
from plscope.dbmspcc_runs r
)
group by ccb.line, ccb.block
)
group by line
having count(block) > 1
)
select s.line, s.text, lc.line_coverage_count, bc.blocks, bc.covered_blocks
from source s
left join line_coverage lc
on s.line = lc.line#
left join block_coverage bc
on s.line = bc.line
order by s.line; The code coverage reports and query results in v3.1.10 and the current develop branch are the same. |
Thank you for the update. This issue was regarding the deviation of the code coverage tables and the HTML report. The HTML report of these three runs were different (line coverage is leading), right? - In this case I'd like to close this issue. I cannot explain why the line code coverage is different between the runs. If the test case is not flaky then the only explanation would be a bug in the PL/SQL Profiler. In your situation I would set a breakpoint at line 327 and inspect the values of Thank you. |
Hi Philipp, |
Hi all,
if I run html reporter on one unit test package and compare it with results from dbms_utplsql_code_coverage a deviation can be seen.
These is coming from dbms_utplsql_code_coverage:

It states that the only (partially) uncovered line is 338. Everything else is fine.
But the html output looks like this:

If you run this test multiple times, then sometimes it varies in the uncovered lines (i.e. it marks 337-338 or 338-339), but dbms_utplsql_code_coverage looks always the same.
Best regards
Tobias
The text was updated successfully, but these errors were encountered: