Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ab0f58

Browse files
committed
Added ability to publish coverage generated by test jobs running utPLSQL with coverage into main testing session coverage.
1 parent efa78a3 commit 4ab0f58

4 files changed

Lines changed: 78 additions & 6 deletions

File tree

source/api/ut_runner.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ create or replace package body ut_runner is
127127
l_run := ut_run(
128128
a_run_paths => l_paths,
129129
a_coverage_options => ut_coverage_options(
130-
coverage_run_id => sys_guid(),
130+
coverage_run_id => ut_coverage.get_coverage_run_id(),
131131
schema_names => l_coverage_schema_names,
132132
exclude_objects => ut_utils.convert_collection(a_exclude_objects),
133133
include_objects => ut_utils.convert_collection(a_include_objects),

source/core/coverage/ut_coverage.pkb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ create or replace package body ut_coverage is
1818

1919
g_develop_mode boolean not null := false;
2020
g_is_started boolean not null := false;
21+
g_coverage_run_id raw(32);
2122

2223
procedure set_develop_mode(a_develop_mode in boolean) is
2324
begin
@@ -231,6 +232,7 @@ create or replace package body ut_coverage is
231232
l_block_coverage_id integer;
232233
begin
233234
if not is_develop_mode() and not g_is_started then
235+
g_coverage_run_id := a_coverage_run_id;
234236
l_line_coverage_id := ut_coverage_helper_profiler.coverage_start( l_run_comment );
235237
l_block_coverage_id := ut_coverage_helper_block.coverage_start( l_run_comment );
236238
g_is_started := true;
@@ -256,7 +258,6 @@ create or replace package body ut_coverage is
256258
g_is_started := false;
257259
ut_coverage_helper_block.coverage_stop();
258260
ut_coverage_helper_profiler.coverage_stop();
259-
g_is_started := false;
260261
end if;
261262
end;
262263

@@ -314,7 +315,15 @@ create or replace package body ut_coverage is
314315
$end
315316

316317
return l_result_profiler_enrich;
317-
end get_coverage_data;
318+
end get_coverage_data;
319+
320+
function get_coverage_run_id return raw is
321+
begin
322+
if g_coverage_run_id is null then
323+
g_coverage_run_id := sys_guid();
324+
end if;
325+
return g_coverage_run_id;
326+
end;
318327

319328
end;
320329
/

source/core/coverage/ut_coverage.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ create or replace package ut_coverage authid current_user is
7474

7575
function get_coverage_data(a_coverage_options ut_coverage_options) return t_coverage;
7676

77+
function get_coverage_run_id return raw;
78+
7779
end;
7880
/

test/ut3_tester_helper/coverage_helper.pkb

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,75 @@ create or replace package body coverage_helper is
381381
return l_result_clob;
382382
end;
383383

384+
procedure copy_coverage_data_to_ut3(a_coverage_run_id raw) is
385+
pragma autonomous_transaction;
386+
l_current_coverage_run_id raw(32) := hextoraw(sys_context('UT3_INFO','COVERAGE_RUN_ID'));
387+
begin
388+
insert into ut3.ut_coverage_runs(coverage_run_id, line_coverage_id, block_coverage_id)
389+
select l_current_coverage_run_id, -line_coverage_id, -block_coverage_id
390+
from ut3_develop.ut_coverage_runs
391+
where coverage_run_id = a_coverage_run_id;
392+
393+
insert into ut3.plsql_profiler_runs(runid, related_run, run_owner, run_date, run_comment, run_total_time, run_system_info, run_comment1, spare1)
394+
select -runid, related_run, run_owner, run_date, run_comment, run_total_time, run_system_info, run_comment1, spare1
395+
from ut3_develop.plsql_profiler_runs c
396+
join ut3_develop.ut_coverage_runs r
397+
on r.line_coverage_id = c.runid
398+
where r.coverage_run_id = a_coverage_run_id;
399+
400+
insert into ut3.plsql_profiler_units(runid, unit_number, unit_type, unit_owner, unit_name, unit_timestamp, total_time, spare1, spare2)
401+
select -runid, unit_number, unit_type, unit_owner, unit_name, unit_timestamp, total_time, spare1, spare2
402+
from ut3_develop.plsql_profiler_units c
403+
join ut3_develop.ut_coverage_runs r
404+
on r.line_coverage_id = c.runid
405+
where r.coverage_run_id = a_coverage_run_id;
406+
407+
insert into ut3.plsql_profiler_data(runid, unit_number, line#, total_occur, total_time, min_time, max_time, spare1, spare2, spare3, spare4)
408+
select -runid, unit_number, line#, total_occur, total_time, min_time, max_time, spare1, spare2, spare3, spare4
409+
from ut3_develop.plsql_profiler_data c
410+
join ut3_develop.ut_coverage_runs r
411+
on r.line_coverage_id = c.runid
412+
where r.coverage_run_id = a_coverage_run_id;
413+
414+
insert into ut3.dbmspcc_runs(run_id, run_comment, run_owner, run_timestamp)
415+
select -run_id, run_comment, run_owner, run_timestamp
416+
from ut3_develop.dbmspcc_runs c
417+
join ut3_develop.ut_coverage_runs r
418+
on r.block_coverage_id = c.run_id
419+
where r.coverage_run_id = a_coverage_run_id;
420+
421+
insert into ut3.dbmspcc_units(run_id, object_id, owner, name, type, last_ddl_time)
422+
select -run_id, object_id, owner, name, type, last_ddl_time
423+
from ut3_develop.dbmspcc_units c
424+
join ut3_develop.ut_coverage_runs r
425+
on r.block_coverage_id = c.run_id
426+
where r.coverage_run_id = a_coverage_run_id;
427+
428+
insert into ut3.dbmspcc_blocks(run_id, object_id, block, line, col, covered, not_feasible)
429+
select -run_id, object_id, block, line, col, covered, not_feasible
430+
from ut3_develop.dbmspcc_blocks c
431+
join ut3_develop.ut_coverage_runs r
432+
on r.block_coverage_id = c.run_id
433+
where r.coverage_run_id = a_coverage_run_id;
434+
435+
commit;
436+
end;
437+
384438
function run_tests_as_job( a_run_command varchar2 ) return clob is
385439
l_plsql_block varchar2(32767);
386440
l_result_clob clob;
387-
pragma autonomous_transaction;
441+
l_coverage_id raw(32) := sys_guid();
388442
begin
389-
l_plsql_block := 'begin insert into test_results select * from table( {a_run_command} ); commit; end;';
443+
l_plsql_block := q'[
444+
begin
445+
ut3_develop.ut_runner.coverage_start(']'||rawtohex(l_coverage_id)||q'[');
446+
insert into test_results select * from table( {a_run_command} );
447+
commit;
448+
end;]';
390449
l_plsql_block := replace(l_plsql_block,'{a_run_command}',a_run_command);
391-
return run_code_as_job( l_plsql_block );
450+
l_result_clob := run_code_as_job( l_plsql_block );
451+
copy_coverage_data_to_ut3(l_coverage_id);
452+
return l_result_clob;
392453
end;
393454

394455
procedure create_dup_object_name is

0 commit comments

Comments
 (0)