From b052dc8e79289308e721ca534c80e06d2c0188b4 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nicolas.pope@utu.fi> Date: Sat, 7 May 2022 08:08:55 +0100 Subject: [PATCH] Add code quality CI --- .gitlab-ci.yml | 9 ++++-- .vscode/settings.json | 64 +++++++++++++++++++++++++++++++++++++++- test/net_integration.cpp | 33 ++++++++++++--------- 3 files changed, 89 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26c32b5..a59819b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,9 +12,14 @@ stages: sast: stage: test + include: - template: Security/SAST.gitlab-ci.yml +include: +- template: Code-Quality.gitlab-ci.yml + + image: ubuntu:jammy linux:build: @@ -27,9 +32,9 @@ linux:build: - docker script: - - DEBIAN_FRONTEND=noninteractive apt update && apt install -y build-essential uuid-dev git libmsgpack-dev liburiparser-dev libgnutls28-dev cmake ninja-build + - DEBIAN_FRONTEND=noninteractive apt update && apt install -y build-essential uuid-dev git libmsgpack-dev liburiparser-dev libgnutls28-dev cmake ninja-build cppcheck - mkdir build && cd build - - cmake $CI_PROJECT_DIR -GNinja -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DUSE_CPPCHECK=FALSE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB + - cmake $CI_PROJECT_DIR -GNinja -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DUSE_CPPCHECK=TRUE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB - ninja #cache: diff --git a/.vscode/settings.json b/.vscode/settings.json index 23e9642..4ac5f26 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,68 @@ "files.associations": { "deque": "cpp", "string": "cpp", - "vector": "cpp" + "vector": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "shared_mutex": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/test/net_integration.cpp b/test/net_integration.cpp index 4b88036..7901256 100644 --- a/test/net_integration.cpp +++ b/test/net_integration.cpp @@ -13,14 +13,14 @@ using std::chrono::milliseconds; // --- Support ----------------------------------------------------------------- -/*static bool try_for(int count, const std::function<bool()> &f) { +static bool try_for(int count, const std::function<bool()> &f) { int i=count; while (i-- > 0) { if (f()) return true; sleep_for(milliseconds(10)); } return false; -}*/ +} // --- Tests ------------------------------------------------------------------- @@ -126,39 +126,44 @@ TEST_CASE("Listen and Connect", "[net]") { } } -/*TEST_CASE("Universe::onConnect()", "[net]") { - Universe a; - Universe b; +TEST_CASE("Self::onConnect()", "[net]") { + ftl::protocol::reset(); + + auto self = ftl::createDummySelf(); - a.listen(ftl::URI("tcp://localhost:0")); - auto uri = "tcp://localhost:" + std::to_string(a.getListeningURIs().front().getPort()); + self->listen(ftl::URI("tcp://localhost:0")); + + auto uri = "tcp://localhost:" + std::to_string(self->getListeningURIs().front().getPort()); SECTION("single valid remote init connection") { bool done = false; - a.onConnect([&done](Peer *p) { + auto h = self->onConnect([&](const std::shared_ptr<ftl::protocol::Node> &p_listening) { done = true; + return true; }); - b.connect(uri)->waitConnection(); + auto n = ftl::createNode(uri)->waitConnection(); - REQUIRE( try_for(20, [&done]{ return done; }) ); + bool result = try_for(20, [&done]{ return done; }); + REQUIRE( result ); } SECTION("single valid init connection") { bool done = false; - b.onConnect([&done](Peer *p) { + auto h = ftl::getSelf()->onConnect([&](const std::shared_ptr<ftl::protocol::Node> &p_listening) { done = true; + return true; }); - b.connect(uri)->waitConnection(); - //sleep_for(milliseconds(100)); + auto n = ftl::createNode(uri)->waitConnection(); + REQUIRE( done ); } } -TEST_CASE("Universe::onDisconnect()", "[net]") { +/*TEST_CASE("Universe::onDisconnect()", "[net]") { Universe a; Universe b; -- GitLab