diff --git a/CGraph-ninja-build.sh b/CGraph-ninja-build.sh index 6e6ad32f..33dd09e7 100644 --- a/CGraph-ninja-build.sh +++ b/CGraph-ninja-build.sh @@ -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" diff --git a/src/CBasic/CStatus.h b/src/CBasic/CStatus.h index 1f8ed11d..82d25c55 100644 --- a/src/CBasic/CStatus.h +++ b/src/CBasic/CStatus.h @@ -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_; // 错误信息描述 diff --git a/test/Functional/CMakeLists.txt b/test/Functional/CMakeLists.txt index 06708b3f..22dae225 100644 --- a/test/Functional/CMakeLists.txt +++ b/test/Functional/CMakeLists.txt @@ -1,5 +1,7 @@ set(CGRAPH_FUNCTIONAL_LIST + test-functional-01 + test-functional-02 ) foreach(func ${CGRAPH_FUNCTIONAL_LIST}) diff --git a/test/Functional/test-functional-01.cpp b/test/Functional/test-functional-01.cpp new file mode 100644 index 00000000..9dc61699 --- /dev/null +++ b/test/Functional/test-functional-01.cpp @@ -0,0 +1,40 @@ +/*************************** +@Author: Chunel +@Contact: chunel@foxmail.com +@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(&a, {}); + status += pipeline->registerGElement(&b, {}); + status += pipeline->registerGElement(&c, {a}); + status += pipeline->registerGElement(&d, {b}); + status += pipeline->registerGElement(&e, {b, c}); + status += pipeline->registerGElement(&f, {c}); + status += pipeline->registerGElement(&g, {d, e, f}); + status += pipeline->registerGElement(&h, {f}); + status += pipeline->registerGElement(&i, {g, h}); + status += pipeline->registerGElement(&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; +} diff --git a/test/Functional/test-functional-02.cpp b/test/Functional/test-functional-02.cpp new file mode 100644 index 00000000..ff5de556 --- /dev/null +++ b/test/Functional/test-functional-02.cpp @@ -0,0 +1,63 @@ +/*************************** +@Author: Chunel +@Contact: chunel@foxmail.com +@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(&a, {}, "a"); + + b = pipeline->createGNode(GNodeInfo({}, "b")); + c = pipeline->createGNode(GNodeInfo({}, "c")); + + d = pipeline->createGNode(GNodeInfo({}, "d")); + e = pipeline->createGNode(GNodeInfo("e", 3)); + f = pipeline->createGNode(GNodeInfo("f")); + cluster1 = pipeline->createGGroup({e, f}, {d}, "cluster1"); + + g = pipeline->createGNode(GNodeInfo({d}, "g")); + region2 = pipeline->createGGroup({d, cluster1, g}, {}, "region2", 2); + + region1 = pipeline->createGGroup({b, c, region2}); + + i = pipeline->createGNode(GNodeInfo("i")); + j = pipeline->createGNode(GNodeInfo("j")); + k = pipeline->createGNode(GNodeInfo("k")); + cluster2 = pipeline->createGGroup({i, j, k}, {a, region1}, "cluster2"); + + status += pipeline->registerGElement(®ion1, {}, "region1", 3); + status += pipeline->registerGElement(&h, {region1}, "h"); + status += pipeline->registerGElement(&cluster2, {a, region1}, "cluster2"); + status += pipeline->registerGElement(&l, {a}, "l"); + + status += pipeline->registerGElement(&m, {h, cluster2}, "m"); + status += pipeline->registerGElement(&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; +} diff --git a/test/Performance/test-performance-03.cpp b/test/Performance/test-performance-03.cpp index 2ffc510e..8de7093e 100644 --- a/test/Performance/test-performance-03.cpp +++ b/test/Performance/test-performance-03.cpp @@ -46,6 +46,7 @@ void test_performance_03() { GPipelineFactory::remove(pipeline); } + int main() { test_performance_03(); return 0; diff --git a/test/_Materials/TestGNodes.h b/test/_Materials/TestGNodes.h index 5e4a39db..b024d4b2 100644 --- a/test/_Materials/TestGNodes.h +++ b/test/_Materials/TestGNodes.h @@ -13,13 +13,26 @@ #include "CGraph.h" -std::atomic g_test_cnt = {0}; +std::atomic 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