-
Notifications
You must be signed in to change notification settings - Fork 116
/
Test2.cpp
132 lines (113 loc) · 4.21 KB
/
Test2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//===- Software-Analysis-Teaching Assignment 2-------------------------------------//
//
// SVF: Static Value-Flow Analysis Framework for Source Code
//
// Copyright (C) <2013->
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//===-----------------------------------------------------------------------===//
/*
// Software-Analysis-Teaching Assignment 2 : Source Sink ICFG DFS Traversal
//
//
*/
#include <iostream>
#include "Assignment-2.h"
void Test1()
{
std::vector<std::string> moduleNameVec = {"./Assignment-2/testcase/bc/test1.ll"};
SVFModule *svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
/// Build Program Assignment Graph (SVFIR)
SVFIRBuilder builder(svfModule);
SVFIR *pag = builder.build();
ICFG *icfg = pag->getICFG();
// If you want to test your own case, plase change the dump name
icfg->dump("./Assignment-2/testcase/dot/test1.ll.icfg");
ICFGTraversal *gt = new ICFGTraversal(pag);
for (const CallICFGNode *src : gt->identifySources())
{
for (const CallICFGNode *snk : gt->identifySinks())
{
gt->reachability(src, snk);
}
}
std::set<std::string> expected = {"START->17->1->7->END"};
assert(expected == gt->getPaths() && "test1 failed!");
std::cout << "test1 passed!" << "\n";
SVFIR::releaseSVFIR();
LLVMModuleSet::releaseLLVMModuleSet();
delete gt;
}
void Test2()
{
// Your current workingspace dir}/Assignment-2/testCase/
std::vector<std::string> moduleNameVec = {"./Assignment-2/testcase/bc/test2.ll"};
SVFModule *svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
/// Build Program Assignment Graph (SVFIR)
SVFIRBuilder builder(svfModule);
SVFIR *pag = builder.build();
ICFG *icfg = pag->getICFG();
// If you want to test your own case, plase change the dump name
icfg->dump("./Assignment-2/testcase/dot/test2.ll.icfg");
ICFGTraversal *gt = new ICFGTraversal(pag);
for (const CallICFGNode *src : gt->identifySources())
{
for (const CallICFGNode *snk : gt->identifySinks())
{
gt->reachability(src, snk);
}
}
std::set<std::string> expected = {"START->6->7->8->9->10->1->5->2->11->14->END", "START->6->7->8->9->12->1->5->2->13->16->END"};
assert(expected == gt->getPaths() && "test2 failed!");
std::cout << "test2 passed!" << "\n";
LLVMModuleSet::releaseLLVMModuleSet();
SVFIR::releaseSVFIR();
delete gt;
}
void Test3()
{
// Your current workingspace dir}/Assignment-2/testCase/
std::vector<std::string> moduleNameVec = {"./Assignment-2/testcase/bc/test3.ll"};
SVFModule *svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
/// Build Program Assignment Graph (SVFIR)
SVFIRBuilder builder(svfModule);
SVFIR *pag = builder.build();
ICFG *icfg = pag->getICFG();
// If you want to test your own case, plase change the dump name
icfg->dump("./Assignment-2/testcase/dot/test3.ll.icfg");
ICFGTraversal *gt = new ICFGTraversal(pag);
for (const CallICFGNode *src : gt->identifySources())
{
for (const CallICFGNode *snk : gt->identifySinks())
{
gt->reachability(src, snk);
}
}
std::set<std::string> expected = {"START->11->12->13->14->3->8->9->4->15->16->3->8->9->4->17->18->19->END"};
assert(expected == gt->getPaths() && "test3 failed!");
std::cout << "test3 passed!" << "\n";
LLVMModuleSet::releaseLLVMModuleSet();
SVFIR::releaseSVFIR();
delete gt;
}
void Test()
{
Test1();
Test2();
Test3();
}
int main()
{
Test();
return 0;
}