Skip to content

Commit dc62eed

Browse files
author
bjjwwang
committed
first commit
1 parent 2f1d5a0 commit dc62eed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2871
-1423
lines changed

Assignment-1/Assignment-1.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===- Software-Analysis-Teaching Assignment 1-------------------------------------//
1+
2+
//===- SVF-Teaching Assignment 1-------------------------------------//
23
//
34
// SVF: Static Value-Flow Analysis Framework for Source Code
45
//
@@ -21,7 +22,7 @@
2122
//===-----------------------------------------------------------------------===//
2223

2324
/*
24-
// Software-Analysis-Teaching Assignment 1 : Graph Traversal
25+
// SVF-Teaching Assignment 1 : Graph Traversal
2526
//
2627
//
2728
*/
@@ -35,11 +36,11 @@ using namespace std;
3536
/// Print the path in the format "START: 1->2->4->5->END", where -> indicate an edge connecting two node IDs
3637
void GraphTraversal::printPath(std::vector<const Node *> &path)
3738
{
38-
39+
3940
};
4041

4142
/// TODO: Implement your depth first search here to traverse each program path (once for any loop) from src to dst
4243
void GraphTraversal::DFS(set<const Node *> &visited, vector<const Node *> &path, const Node *src, const Node *dst)
4344
{
44-
45+
4546
}

Assignment-1/Assignment-1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- Software-Analysis-Teaching Assignment 1-------------------------------------//
1+
//===- SVF-Teaching Assignment 1-------------------------------------//
22
//
33
// SVF: Static Value-Flow Analysis Framework for Source Code
44
//
@@ -21,7 +21,7 @@
2121
//===-----------------------------------------------------------------------===//
2222

2323
/*
24-
// Software-Analysis-Teaching Assignment 1 : Graph Traversal
24+
// SVF-Teaching Assignment 1 : Graph Traversal
2525
//
2626
//
2727
*/
@@ -125,4 +125,4 @@ class GraphTraversal
125125
std::set<std::string> paths;
126126
};
127127

128-
#endif
128+
#endif

Assignment-1/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
add_executable(assign-1 Assignment-1.cpp Test1.cpp)
2-
set_target_properties( assign-1 PROPERTIES
3-
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
1+
cmake_minimum_required(VERSION 3.23)
2+
PROJECT(UTS-Software-Engineer-Studio-Marking)
3+
4+
file(GLOB SRC1 test-exes/Test.cpp *.cpp)
5+
add_executable(assign-1 ${SRC1})
6+
7+

Assignment-1/Test1.cpp

Lines changed: 0 additions & 87 deletions
This file was deleted.

Assignment-1/test-exes/Test.cpp

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
//===- SVF-Teaching Assignment 1-------------------------------------//
2+
//
3+
// SVF: Static Value-Flow Analysis Framework for Source Code
4+
//
5+
// Copyright (C) <2013->
6+
//
7+
8+
// This program is free software: you can redistribute it and/or modify
9+
// it under the terms of the GNU General Public License as published by
10+
// the Free Software Foundation, either version 3 of the License, or
11+
// (at your option) any later version.
12+
13+
// This program is distributed in the hope that it will be useful,
14+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
// GNU General Public License for more details.
17+
18+
// You should have received a copy of the GNU General Public License
19+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
//
21+
//===-----------------------------------------------------------------------===//
22+
23+
/*
24+
// SVF-Teaching Assignment 1 : Graph Traversal
25+
//
26+
//
27+
*/
28+
29+
30+
#include "../Assignment-1.h"
31+
#include <assert.h>
32+
#include <map>
33+
#include <fstream> // for GraphBuilderFromFile
34+
#include <string> // for GraphBuilderFromFile
35+
#include <sstream> // for GraphBuilderFromFile
36+
using namespace std;
37+
38+
int totalPassedCases = 0;
39+
//test
40+
//build graph in brief way
41+
void build_g(Graph* g, Node* n1, Node* n2)
42+
{
43+
Edge *edge = new Edge(n1, n2);
44+
n1->addOutEdge(edge);
45+
g->addNode(n1);
46+
g->addNode(n2);
47+
48+
}
49+
50+
/*
51+
* You can build a Graph from a file written by yourself
52+
*
53+
* The file should follow the format:
54+
* Node: nodeID
55+
* Edge: nodeID -> NodeID
56+
*
57+
* like:
58+
1
59+
2
60+
3
61+
1 -> 2
62+
2 -> 3
63+
*/
64+
void Test(std::string file){
65+
66+
std::map<int,Node*> id2Nodes;
67+
std::set<std::string> expected;
68+
Graph *g = new Graph();
69+
int source = 0;
70+
int target = 0;
71+
72+
string line;
73+
ifstream myfile(file.c_str());
74+
if (myfile.is_open())
75+
{
76+
while (myfile.good())
77+
{
78+
getline(myfile, line);
79+
80+
int token_count = 0;
81+
string tmps;
82+
istringstream ss(line);
83+
while (ss.good())
84+
{
85+
ss >> tmps;
86+
token_count++;
87+
}
88+
89+
if (token_count == 0 || token_count == 1)
90+
continue;
91+
92+
/// create nodes
93+
else if (token_count == 2)
94+
{
95+
string dummy;
96+
int nodeId;
97+
string nodetype;
98+
istringstream ss(line);
99+
ss >> dummy;
100+
ss >> nodeId;
101+
Node *node = new Node(nodeId);
102+
id2Nodes[nodeId] = node;
103+
g->addNode(node);
104+
}
105+
/// create edges
106+
else if (token_count == 3)
107+
{
108+
int nodeSrc;
109+
int nodeDst;
110+
string ed;
111+
istringstream ss(line);
112+
ss >> nodeSrc;
113+
ss >> ed;
114+
ss >> nodeDst;
115+
assert(id2Nodes.find(nodeSrc)!=id2Nodes.end() && "src node has not been created");
116+
assert(id2Nodes.find(nodeDst)!=id2Nodes.end() && "dst node has not been created");
117+
Edge *edge = new Edge(id2Nodes[nodeSrc], id2Nodes[nodeDst]);
118+
id2Nodes[nodeSrc]->addOutEdge(edge);
119+
}
120+
/// correct answer "1 => 2 START: 1->2->4->5->END"
121+
else if (token_count == 5){
122+
string dummy;
123+
string start;
124+
string end;
125+
istringstream ss(line);
126+
ss >> source;
127+
ss >> dummy;
128+
ss >> target;
129+
ss >> start;
130+
ss >> end;
131+
expected.insert(start + " " + end);
132+
}
133+
else{
134+
assert(false && "format not supported");
135+
}
136+
}
137+
}
138+
139+
std::set<const Node *> visited;
140+
std::vector<const Node *> path;
141+
GraphTraversal *dfs = new GraphTraversal();
142+
assert(id2Nodes.find(source)!=id2Nodes.end() && "source node was not found!");
143+
assert(id2Nodes.find(target)!=id2Nodes.end() && "target node was not found!");
144+
dfs->DFS(visited, path, id2Nodes[source], id2Nodes[target]);
145+
146+
string filename = file.substr(file.find_last_of("/") + 1);
147+
if(dfs->getPaths() == expected){
148+
std::cerr << "Testcase " << filename << " passed!\n";
149+
totalPassedCases++;
150+
}
151+
else
152+
std::cerr << "Testcase " << filename << " failed!\n";
153+
154+
delete dfs;
155+
delete g;
156+
157+
}
158+
159+
int main(int argc, char *argv[])
160+
{
161+
162+
assert(argc == 2 && "only allow one input file to build graph");
163+
164+
Test(argv[1]);
165+
166+
return 0;
167+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node 1
2+
node 2
3+
node 3
4+
node 4
5+
node 5
6+
7+
1 -> 2
8+
1 -> 3
9+
2 -> 4
10+
3 -> 4
11+
4 -> 5
12+
4 -> 2
13+
1 => 5 START: 1->2->4->5->END
14+
1 => 5 START: 1->3->4->5->END
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node 1
2+
node 2
3+
node 3
4+
node 4
5+
node 5
6+
7+
1 -> 2
8+
1 -> 3
9+
2 -> 4
10+
3 -> 4
11+
4 -> 5
12+
5 -> 2
13+
14+
1 => 5 START: 1->2->4->5->END
15+
1 => 5 START: 1->3->4->5->END
16+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
node 1
2+
node 2
3+
node 3
4+
node 4
5+
node 5
6+
7+
1 -> 2
8+
1 -> 3
9+
2 -> 4
10+
3 -> 4
11+
4 -> 5
12+
2 -> 5
13+
14+
1 => 5 START: 1->2->5->END
15+
1 => 5 START: 1->2->4->5->END
16+
1 => 5 START: 1->3->4->5->END
17+

0 commit comments

Comments
 (0)