Skip to content

Commit 5b37ee4

Browse files
committed
Re-factor TestOutput into a param module.
1 parent 90db9b3 commit 5b37ee4

File tree

5 files changed

+79
-40
lines changed

5 files changed

+79
-40
lines changed

csharp/ql/test/library-tests/dataflow/library/FlowSummaries.ql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import shared.FlowSummaries
22
import semmle.code.csharp.dataflow.internal.ExternalFlow
3-
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl::Private::External
3+
import External
44

5-
private class IncludeAllSummarizedCallable extends IncludeSummarizedCallable {
6-
IncludeAllSummarizedCallable() { exists(this) }
5+
module TestSummaryInput implements TestSummaryInputSig {
6+
class RelevantSummarizedCallable = IncludeSummarizedCallable;
77
}
88

9-
private class IncludeNeutralSummarizedCallable extends RelevantNeutralCallable {
10-
/** Gets a string representing the callable in semi-colon separated format for use in flow summaries. */
11-
final override string getCallableCsv() { result = asPartialNeutralModel(this) }
9+
module TestNeutralInput implements TestNeutralInputSig {
10+
class RelevantNeutralCallable instanceof NeutralCallable {
11+
final string getCallableCsv() { result = asPartialNeutralModel(this) }
12+
13+
string toString() { result = super.toString() }
14+
}
1215
}
1316

1417
module TestSourceSinkInput implements TestSourceSinkInputSig {
@@ -25,4 +28,6 @@ module TestSourceSinkInput implements TestSourceSinkInputSig {
2528
}
2629
}
2730

31+
import TestSummaryOutput<TestSummaryInput>
32+
import TestNeutralOutput<TestNeutralInput>
2833
import TestSourceSinkOutput<TestSourceSinkInput>

csharp/ql/test/library-tests/dataflow/library/FlowSummariesFiltered.ql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import shared.FlowSummaries
22
private import semmle.code.csharp.dataflow.internal.ExternalFlow
33

4-
class IncludeFilteredSummarizedCallable extends IncludeSummarizedCallable {
5-
IncludeFilteredSummarizedCallable() { exists(this) }
4+
module TestSummaryInput implements TestSummaryInputSig {
5+
class RelevantSummarizedCallable = IncludeSummarizedCallable;
6+
}
7+
8+
import TestSummaryOutput<TestSummaryInput>
69

10+
class IncludeFilteredSummarizedCallable extends RelevantSummarizedCallable {
711
/**
812
* Holds if flow is propagated between `input` and `output` and
913
* if there is no summary for a callable in a `base` class or interface
@@ -12,10 +16,10 @@ class IncludeFilteredSummarizedCallable extends IncludeSummarizedCallable {
1216
override predicate relevantSummary(
1317
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
1418
) {
15-
super.propagatesFlow(input, output, preservesValue) and
19+
this.(SummarizedCallableImpl).propagatesFlow(input, output, preservesValue) and
1620
not exists(IncludeSummarizedCallable rsc |
1721
isBaseCallableOrPrototype(rsc) and
18-
rsc.propagatesFlow(input, output, preservesValue) and
22+
rsc.(SummarizedCallableImpl).propagatesFlow(input, output, preservesValue) and
1923
this.(UnboundCallable).overridesOrImplementsUnbound(rsc)
2024
)
2125
}

csharp/ql/test/library-tests/frameworks/EntityFramework/FlowSummaries.ql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import shared.FlowSummaries
33
import semmle.code.csharp.frameworks.EntityFramework::EntityFramework
44
import semmle.code.csharp.dataflow.internal.ExternalFlow as ExternalFlow
55

6-
private class IncludeEFSummarizedCallable extends IncludeSummarizedCallable instanceof EFSummarizedCallable
7-
{ }
6+
module TestSummaryInput implements TestSummaryInputSig {
7+
class RelevantSummarizedCallable extends IncludeSummarizedCallable instanceof EFSummarizedCallable
8+
{ }
9+
}
10+
11+
import TestSummaryOutput<TestSummaryInput>
812

913
query predicate sourceNode(DataFlow::Node node, string kind) {
1014
ExternalFlow::sourceNode(node, kind)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl::Private
22
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl::Public
3-
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl::Private::TestOutput
43
private import semmle.code.csharp.dataflow.internal.ExternalFlow
54

6-
abstract class IncludeSummarizedCallable extends RelevantSummarizedCallable {
5+
class IncludeSummarizedCallable instanceof SummarizedCallableImpl {
76
IncludeSummarizedCallable() {
87
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic()
98
}
109

1110
/** Gets a string representing the callable in semi-colon separated format for use in flow summaries. */
12-
final override string getCallableCsv() { result = asPartialModel(this) }
11+
final string getCallableCsv() { result = asPartialModel(this) }
12+
13+
string toString() { result = super.toString() }
1314
}

shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,32 +1751,31 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
17511751
}
17521752
}
17531753

1754+
signature module TestSummaryInputSig {
1755+
/**
1756+
* A class of callables where the flow summary should be included
1757+
* in the `summary/1` query predicate.
1758+
*/
1759+
class RelevantSummarizedCallable instanceof SummarizedCallableImpl {
1760+
/** Gets the string representation of this callable used by `summary/1`. */
1761+
string getCallableCsv();
1762+
}
1763+
}
1764+
17541765
/** Provides a query predicate for outputting a set of relevant flow summaries. */
1755-
module TestOutput {
1756-
final private class SummarizedCallableImplFinal = SummarizedCallableImpl;
1766+
module TestSummaryOutput<TestSummaryInputSig TestInput> {
1767+
private import TestInput
17571768

1758-
/** A flow summary to include in the `summary/1` query predicate. */
1759-
abstract class RelevantSummarizedCallable extends SummarizedCallableImplFinal {
1760-
/** Gets the string representation of this callable used by `summary/1`. */
1761-
abstract string getCallableCsv();
1769+
final class RelevantSummarizedCallableFinal = TestInput::RelevantSummarizedCallable;
17621770

1771+
class RelevantSummarizedCallable extends RelevantSummarizedCallableFinal instanceof SummarizedCallableImpl
1772+
{
17631773
/** Holds if flow is propagated between `input` and `output`. */
17641774
predicate relevantSummary(
17651775
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
17661776
) {
17671777
super.propagatesFlow(input, output, preservesValue)
17681778
}
1769-
}
1770-
1771-
/** A model to include in the `neutral/1` query predicate. */
1772-
abstract class RelevantNeutralCallable instanceof NeutralCallable {
1773-
/** Gets the string representation of this callable used by `neutral/1`. */
1774-
abstract string getCallableCsv();
1775-
1776-
/**
1777-
* Gets the kind of the neutral.
1778-
*/
1779-
string getKind() { result = super.getKind() }
17801779

17811780
string toString() { result = super.toString() }
17821781
}
@@ -1795,13 +1794,6 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
17951794
c.hasProvenance(result)
17961795
}
17971796

1798-
private string renderProvenanceNeutral(NeutralCallable c) {
1799-
exists(Provenance p | p.isManual() and c.hasProvenance(p) and result = p.toString())
1800-
or
1801-
not c.hasManualModel() and
1802-
c.hasProvenance(result)
1803-
}
1804-
18051797
/**
18061798
* Holds if there exists a relevant summary callable with information roughly corresponding to `csv`.
18071799
* Used for testing.
@@ -1822,6 +1814,39 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
18221814
+ renderProvenance(c) // provenance
18231815
)
18241816
}
1817+
}
1818+
1819+
signature module TestNeutralInputSig {
1820+
/**
1821+
* A class of callables where the neutral model should be included
1822+
* in the `neutral/1` query predicate.
1823+
*/
1824+
class RelevantNeutralCallable instanceof NeutralCallable {
1825+
/** Gets the string representation of this callable used by `neutral/1`. */
1826+
string getCallableCsv();
1827+
}
1828+
}
1829+
1830+
module TestNeutralOutput<TestNeutralInputSig TestInput> {
1831+
private import TestInput
1832+
1833+
final class RelevantNeutralCallableFinal = TestInput::RelevantNeutralCallable;
1834+
1835+
class RelevantNeutralCallable extends RelevantNeutralCallableFinal instanceof NeutralCallable {
1836+
/**
1837+
* Gets the kind of the neutral.
1838+
*/
1839+
string getKind() { result = super.getKind() }
1840+
1841+
string toString() { result = super.toString() }
1842+
}
1843+
1844+
private string renderProvenance(NeutralCallable c) {
1845+
exists(Provenance p | p.isManual() and c.hasProvenance(p) and result = p.toString())
1846+
or
1847+
not c.hasManualModel() and
1848+
c.hasProvenance(result)
1849+
}
18251850

18261851
/**
18271852
* Holds if there exists a relevant neutral callable with information roughly corresponding to `csv`.
@@ -1833,7 +1858,7 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
18331858
csv =
18341859
c.getCallableCsv() // Callable information
18351860
+ c.getKind() + ";" // kind
1836-
+ renderProvenanceNeutral(c) // provenance
1861+
+ renderProvenance(c) // provenance
18371862
)
18381863
}
18391864
}

0 commit comments

Comments
 (0)