From a78d1e730586992e1a84d7f9e0d29cd7e5969f74 Mon Sep 17 00:00:00 2001 From: brenodetomini Date: Sun, 11 Feb 2024 14:02:28 -0300 Subject: [PATCH] fix: fixing int_vb test and adding optimization flags to release Fixing int_vb test Adding optimization flags to release --- CMakeLists.txt | 2 +- src/version.hpp | 4 ++-- tests/protocol/test_types.cpp | 33 +++++++++++---------------------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b45ef3..88ae301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(ENV{TARGET} "x86_64-linux-gnu") set(CMAKE_CXX_FLAGS "-Wall -fvisibility=hidden -fvisibility-inlines-hidden -Wformat -Wformat-security") set(CMAKE_CXX_FLAGS_DEBUG "-g2 -O0") -set(CMAKE_CXX_FLAGS_RELEASE "-fstack-protector-all -pie -fPIE -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O3 -g2") +set(CMAKE_CXX_FLAGS_RELEASE "-fstack-protector-all -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O3 -g2 -march=native -pipe -flto=auto") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") enable_testing() diff --git a/src/version.hpp b/src/version.hpp index d0b7685..3608ae0 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -1,5 +1,5 @@ #define MQTTD_VERSION_MAJOR 0 #define MQTTD_VERSION_MINOR 0 #define MQTTD_VERSION_PATCH 1 -#define MQTTD_COMMIT_HASH fd49879ba9e777030db160223c904c842f2983a6 -#define MQTTD_BUILD_TIMESTAMP 1707613195 +#define MQTTD_COMMIT_HASH 886ee7f2818fe80673157c1c370958d143d9fb5d +#define MQTTD_BUILD_TIMESTAMP 1707670632 diff --git a/tests/protocol/test_types.cpp b/tests/protocol/test_types.cpp index 4f5acef..ccba3b5 100644 --- a/tests/protocol/test_types.cpp +++ b/tests/protocol/test_types.cpp @@ -5,71 +5,60 @@ TEST_CASE("Variable Byte Integer Encoding", "[Variable Byte Integer]") { int_vb num1 = 42; - std::vector expected_bytes1 = {std::byte(42), std::byte(0), - std::byte(0), std::byte(0)}; + std::vector expected_bytes1 = {std::byte(42)}; REQUIRE(num1.as_bytes() == expected_bytes1); int_vb num2 = 2048; - std::vector expected_bytes2 = {std::byte(128), std::byte(16), - std::byte(0), std::byte(0)}; + std::vector expected_bytes2 = {std::byte(128), std::byte(16)}; REQUIRE(num2.as_bytes() == expected_bytes2); REQUIRE_THROWS_AS([&](){ int_vb num3 = 4294967167;}(), std::runtime_error); int_vb num4 = 0; - std::vector expected_bytes4 = {std::byte(0), std::byte(0), - std::byte(0), std::byte(0)}; + std::vector expected_bytes4 = {std::byte(0)}; REQUIRE(num4.as_bytes() == expected_bytes4); int_vb num5 = 16383; - std::vector expected_bytes5 = {std::byte(255), std::byte(127), - std::byte(0), std::byte(0)}; + std::vector expected_bytes5 = {std::byte(255), std::byte(127)}; REQUIRE(num5.as_bytes() == expected_bytes5); int_vb num6 = 2097151; - std::vector expected_bytes6 = {std::byte(255), std::byte(255), - std::byte(127), std::byte(0)}; + std::vector expected_bytes6 = {std::byte(255), std::byte(255), std::byte(127)}; REQUIRE(num6.as_bytes() == expected_bytes6); } TEST_CASE("VariableByte Integer Decoding", "[Variable Byte Integer]") { // Caso de teste 1 uint32_t expected_num1 = 42; - std::vector bytes1 = {std::byte(42), std::byte(0), - std::byte(0), std::byte(0)}; + std::vector bytes1 = {std::byte(42)}; int_vb num1(bytes1); REQUIRE(uint32_t(num1) == expected_num1); // Caso de teste 2 uint32_t expected_num2 = 2048; - std::vector bytes2 = {std::byte(128), std::byte(16), - std::byte(0), std::byte(0)}; + std::vector bytes2 = {std::byte(128), std::byte(16)}; int_vb num2(bytes2); REQUIRE(uint32_t(num2) == expected_num2); // Caso de teste 3 - std::vector bytes3 = {std::byte(255), std::byte(255), - std::byte(255), std::byte(255)}; + std::vector bytes3 = {std::byte(255), std::byte(255), std::byte(255), std::byte(255)}; REQUIRE_THROWS_AS([&](){int_vb num3(bytes3);}(), std::runtime_error); // Caso de teste 4 uint32_t expected_num4 = 0; - std::vector bytes4 = {std::byte(0), std::byte(0), - std::byte(0), std::byte(0)}; + std::vector bytes4 = {std::byte(0), std::byte(0)}; int_vb num4(bytes4); REQUIRE(uint32_t(num4) == expected_num4); // Caso de teste 5 uint32_t expected_num5 = 16383; - std::vector bytes5 = {std::byte(255), std::byte(127), - std::byte(0), std::byte(0)}; + std::vector bytes5 = {std::byte(255), std::byte(127)}; int_vb num5(bytes5); REQUIRE(uint32_t(num5) == expected_num5); // Caso de teste 6 uint32_t expected_num6 = 2097151; - std::vector bytes6 = {std::byte(255), std::byte(255), - std::byte(127), std::byte(0)}; + std::vector bytes6 = {std::byte(255), std::byte(255), std::byte(127)}; int_vb num6(bytes6); REQUIRE(uint32_t(num6) == expected_num6); }