Skip to content

Commit 4e2c87b

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#472 from diffblue/owen-jones-diffblue/make-csvsa-tests-robust
SEC-518: Make CSVSA tests robust to changing locations
2 parents 329c444 + 4cb5f71 commit 4e2c87b

File tree

6 files changed

+41
-29
lines changed

6 files changed

+41
-29
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import pytest
21
from regression.CSVSA.csvsa_driver import CsvsaDriver
32

43

54
folder_name = 'TestIncompatibleTypes'
65

7-
@pytest.mark.xfail(strict=True)
6+
87
def test_tolerate_unreachable_functions():
9-
pytest.xfail("Callsite numbers vary on CI / local run.")
10-
118
csvsa_driver = \
129
CsvsaDriver(folder_name).with_test_function('test').with_show_goto_functions(False)
1310
with csvsa_driver.run() as csvsa_expectation:
1411
csvsa_expectation.check_successful_run()
15-
csvsa_expectation.check_matches("Callsite at 43 may call: java::CSVSA.TestIncompatibleTypes.C.f")
16-
csvsa_expectation.check_does_not_match("Callsite at 43 may call: java::CSVSA.TestIncompatibleTypes.B.f")
12+
csvsa_expectation.check_matches_regex(
13+
"Callsite at [\d]+ \(CSVSA/TestIncompatibleTypes/Test.java:10\) may call: "
14+
"java::CSVSA.TestIncompatibleTypes.C.f:\(\)V")
15+
csvsa_expectation.check_does_not_match_regex(
16+
"Callsite at [\d]+ \(CSVSA/TestIncompatibleTypes/Test.java:10\) may call: "
17+
"java::CSVSA.TestIncompatibleTypes.B.f")
Binary file not shown.
Binary file not shown.
155 Bytes
Binary file not shown.
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import pytest
2-
31
from regression.CSVSA.csvsa_driver import CsvsaDriver
4-
2+
import pytest
53
folder_name = 'TestOpaqueTypePromotion'
64

75

8-
@pytest.mark.xfail(strict=True)
6+
@pytest.mark.xfail(strict=True, reason="Unknown failure")
97
def test_opaque_type_promotion():
108
csvsa_driver = \
119
CsvsaDriver(folder_name).with_test_function('test').with_show_goto_functions(False)
1210
with csvsa_driver.run() as csvsa_expectation:
1311
csvsa_expectation.check_successful_run()
14-
csvsa_expectation.check_matches("Callsite at 17 may call: java::CSVSA.TestOpaqueTypePromotion.ConcreteTest.f:()V")
15-
csvsa_expectation.check_matches("Callsite at 25 (java::CSVSA.TestOpaqueTypePromotion.AbstractTest.f:()V) stubbed")
16-
csvsa_expectation.check_matches("Callsite at 43 (java::CSVSA.TestOpaqueTypePromotion.Opaque.f:()V) stubbed")
12+
csvsa_expectation.check_matches_regex(
13+
"Callsite at [\d]+ \(CSVSA/TestOpaqueTypePromotion/Test.java:10\) may call: "
14+
"java::CSVSA.TestOpaqueTypePromotion.ConcreteTest.f:\(\)V")
15+
csvsa_expectation.check_matches_regex(
16+
"Callsite at [\d]+ \(CSVSA/TestOpaqueTypePromotion/Test.java:14\) for "
17+
"java::CSVSA.TestOpaqueTypePromotion.AbstractTest.f:\(\)V stubbed")
18+
csvsa_expectation.check_matches_regex(
19+
"Callsite at [\d]+ \(CSVSA/TestOpaqueTypePromotion/Test.java:19\) for "
20+
"java::CSVSA.TestOpaqueTypePromotion.Opaque.f:\(\)V stubbed")

src/pointer-analysis/context_sensitive_value_set_analysis.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -650,31 +650,38 @@ void csvsa_function_contextt::print_tree(
650650
}
651651
for(const auto &child : callee_nodes)
652652
{
653+
auto inst = prog.instructions.begin();
654+
while(inst != prog.instructions.end() &&
655+
inst->location_number < child.first)
656+
{
657+
++inst;
658+
}
659+
INVARIANT(
660+
inst != prog.instructions.end() && inst->location_number == child.first,
661+
"child map key should correspond to a program location number");
662+
663+
std::ostringstream line_start;
664+
line_start << pad_space << "Callsite at " << child.first;
665+
666+
if(!inst->source_location.get_file().empty())
667+
{
668+
line_start << " (" << inst->source_location.get_file() << ":"
669+
<< inst->source_location.get_line() << ")";
670+
}
671+
653672
if(child.second.empty())
654673
{
655-
auto inst = prog.instructions.begin();
656-
while(inst != prog.instructions.end() &&
657-
inst->location_number < child.first)
658-
++inst;
659-
if(inst == prog.instructions.end())
660-
throw "Bad entry in child map #1?";
661-
if(inst->location_number != child.first)
662-
throw "Bad entry in child map #2?";
663674
const auto &function = to_code_function_call(inst->code).function();
664-
out << pad_space << "Callsite at " << child.first << " ("
665-
<< function.get(ID_C_class) << "." << function.get(ID_component_name)
666-
<< ") stubbed\n";
675+
out << line_start.str() << " for " << function.get(ID_identifier)
676+
<< " stubbed\n";
667677
}
668678
else
669679
{
670680
for(const auto &call : child.second)
671681
{
672-
out << pad_space << "Callsite at " << child.first
673-
<< " may call: " << call.first << "\n";
674-
std::ostringstream oss;
675-
oss << pad_space << "Callee " << call.first << ":\n";
682+
out << line_start.str() << " may call: " << call.first << "\n";
676683
if(driver.edge_is_recursive(context_number, call.second))
677-
oss << " (recursive edge)\n";
684+
out << " (recursive edge)\n";
678685
else
679686
{
680687
driver.get_context(call.second)

0 commit comments

Comments
 (0)