Skip to content

Commit

Permalink
[test] add function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Dec 27, 2023
1 parent 4fcf3fc commit 1f76651
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CGraph-ninja-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ rm -rf build

cmake -G Ninja -Bbuild
cd build || { ! echo "enter ninja-build failed"; exit 1; }
ninja
ninja -j8
echo -e "\033[34m congratulations, automatic compile CGraph finish by ninja... \033[0m"
23 changes: 23 additions & 0 deletions src/CBasic/CStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ class CSTATUS {
return STATUS_CRASH == error_code_;
}

/**
* 设置异常信息
* @param code
* @param info
* @return
*/
CSTATUS* setInfo(int code, const std::string& info) {
error_code_ = code;
error_info_ = (STATUS_OK == error_code_) ? CGRAPH_EMPTY : info;
return this;
}

/**
* 设置异常信息
* @param info
* @return
*/
CSTATUS* setErrorInfo(const std::string& info) {
error_code_ = STATUS_ERR;
error_info_ = info;
return this;
}

private:
int error_code_ = STATUS_OK; // 错误码信息
std::string error_info_; // 错误信息描述
Expand Down
2 changes: 2 additions & 0 deletions test/Functional/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

set(CGRAPH_FUNCTIONAL_LIST
test-functional-01
test-functional-02
)

foreach(func ${CGRAPH_FUNCTIONAL_LIST})
Expand Down
40 changes: 40 additions & 0 deletions test/Functional/test-functional-01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************
@Author: Chunel
@Contact: [email protected]
@File: test-functional-01.cpp
@Time: 2023/12/27 23:16
@Desc:
***************************/

#include "../_Materials/TestGNodes.h"

using namespace CGraph;

void test_functional_01() {
GPipelinePtr pipeline = GPipelineFactory::create();
CStatus status;
GElementPtr a, b, c, d, e, f, g, h, i, j = nullptr;
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&a, {});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&b, {});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&c, {a});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&d, {b});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&e, {b, c});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&f, {c});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&g, {d, e, f});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&h, {f});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&i, {g, h});
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&j, {h});

status = pipeline->process(1000000);
if (status.isErr()) {
std::cout << status.getInfo() << std::endl;
}

GPipelineFactory::remove(pipeline);
}


int main() {
test_functional_01();
return 0;
}
63 changes: 63 additions & 0 deletions test/Functional/test-functional-02.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/***************************
@Author: Chunel
@Contact: [email protected]
@File: test-functional-02.cpp
@Time: 2023/12/27 23:30
@Desc:
***************************/


#include "../_Materials/TestGNodes.h"

using namespace CGraph;

void test_functional_02() {
GPipelinePtr pipeline = GPipelineFactory::create();
CStatus status;
GElementPtr a,b,c,d,e,f,g,h,i,j,k,l,m,n = nullptr;
GElementPtr region1, region2, cluster1, cluster2 = nullptr;

status += pipeline->registerGElement<TestMaterialAdd1GNode>(&a, {}, "a");

b = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo({}, "b"));
c = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo({}, "c"));

d = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo({}, "d"));
e = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo("e", 3));
f = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo("f"));
cluster1 = pipeline->createGGroup<GCluster>({e, f}, {d}, "cluster1");

g = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo({d}, "g"));
region2 = pipeline->createGGroup<GRegion>({d, cluster1, g}, {}, "region2", 2);

region1 = pipeline->createGGroup<GRegion>({b, c, region2});

i = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo("i"));
j = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo("j"));
k = pipeline->createGNode<TestMaterialAdd1GNode>(GNodeInfo("k"));
cluster2 = pipeline->createGGroup<GCluster>({i, j, k}, {a, region1}, "cluster2");

status += pipeline->registerGElement<GRegion>(&region1, {}, "region1", 3);
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&h, {region1}, "h");
status += pipeline->registerGElement<GCluster>(&cluster2, {a, region1}, "cluster2");
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&l, {a}, "l");

status += pipeline->registerGElement<TestMaterialAdd1GNode>(&m, {h, cluster2}, "m");
status += pipeline->registerGElement<TestMaterialAdd1GNode>(&n, {l, cluster2}, "n");

{
UTimeCounter counter;
status = pipeline->process(10000);
}

if (status.isErr()) {
std::cout << status.getInfo() << std::endl;
}
GPipelineFactory::remove(pipeline);
}


int main() {
test_functional_02();
return 0;
}
1 change: 1 addition & 0 deletions test/Performance/test-performance-03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void test_performance_03() {
GPipelineFactory::remove(pipeline);
}


int main() {
test_performance_03();
return 0;
Expand Down
17 changes: 15 additions & 2 deletions test/_Materials/TestGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@

#include "CGraph.h"

std::atomic<unsigned int> g_test_cnt = {0};
std::atomic<unsigned int> g_test_node_cnt = {0};
class TestMaterialAdd1GNode : public CGraph::GNode {
public:
CStatus init() override {
g_test_node_cnt = 0;
return CStatus();
}

CStatus run() override {
g_test_cnt++;
g_test_node_cnt++;
return CStatus();
}

CStatus destroy() override {
CStatus status;
if (0 != g_test_node_cnt % 10000) {
status.setErrorInfo("test node count is " + std::to_string(g_test_node_cnt.load()));
}
return status;
}
};

#endif //CGRAPH_TESTGNODES_H

0 comments on commit 1f76651

Please sign in to comment.