fix: fixing int_vb test and adding optimization flags to release

Fixing int_vb test
Adding optimization flags to release
This commit is contained in:
brenodetomini
2024-02-11 14:02:28 -03:00
parent 886ee7f281
commit a78d1e7305
3 changed files with 14 additions and 25 deletions

View File

@@ -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 "-Wall -fvisibility=hidden -fvisibility-inlines-hidden -Wformat -Wformat-security")
set(CMAKE_CXX_FLAGS_DEBUG "-g2 -O0") 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") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
enable_testing() enable_testing()

View File

@@ -1,5 +1,5 @@
#define MQTTD_VERSION_MAJOR 0 #define MQTTD_VERSION_MAJOR 0
#define MQTTD_VERSION_MINOR 0 #define MQTTD_VERSION_MINOR 0
#define MQTTD_VERSION_PATCH 1 #define MQTTD_VERSION_PATCH 1
#define MQTTD_COMMIT_HASH fd49879ba9e777030db160223c904c842f2983a6 #define MQTTD_COMMIT_HASH 886ee7f2818fe80673157c1c370958d143d9fb5d
#define MQTTD_BUILD_TIMESTAMP 1707613195 #define MQTTD_BUILD_TIMESTAMP 1707670632

View File

@@ -5,71 +5,60 @@
TEST_CASE("Variable Byte Integer Encoding", "[Variable Byte Integer]") { TEST_CASE("Variable Byte Integer Encoding", "[Variable Byte Integer]") {
int_vb num1 = 42; int_vb num1 = 42;
std::vector<std::byte> expected_bytes1 = {std::byte(42), std::byte(0), std::vector<std::byte> expected_bytes1 = {std::byte(42)};
std::byte(0), std::byte(0)};
REQUIRE(num1.as_bytes() == expected_bytes1); REQUIRE(num1.as_bytes() == expected_bytes1);
int_vb num2 = 2048; int_vb num2 = 2048;
std::vector<std::byte> expected_bytes2 = {std::byte(128), std::byte(16), std::vector<std::byte> expected_bytes2 = {std::byte(128), std::byte(16)};
std::byte(0), std::byte(0)};
REQUIRE(num2.as_bytes() == expected_bytes2); REQUIRE(num2.as_bytes() == expected_bytes2);
REQUIRE_THROWS_AS([&](){ int_vb num3 = 4294967167;}(), std::runtime_error); REQUIRE_THROWS_AS([&](){ int_vb num3 = 4294967167;}(), std::runtime_error);
int_vb num4 = 0; int_vb num4 = 0;
std::vector<std::byte> expected_bytes4 = {std::byte(0), std::byte(0), std::vector<std::byte> expected_bytes4 = {std::byte(0)};
std::byte(0), std::byte(0)};
REQUIRE(num4.as_bytes() == expected_bytes4); REQUIRE(num4.as_bytes() == expected_bytes4);
int_vb num5 = 16383; int_vb num5 = 16383;
std::vector<std::byte> expected_bytes5 = {std::byte(255), std::byte(127), std::vector<std::byte> expected_bytes5 = {std::byte(255), std::byte(127)};
std::byte(0), std::byte(0)};
REQUIRE(num5.as_bytes() == expected_bytes5); REQUIRE(num5.as_bytes() == expected_bytes5);
int_vb num6 = 2097151; int_vb num6 = 2097151;
std::vector<std::byte> expected_bytes6 = {std::byte(255), std::byte(255), std::vector<std::byte> expected_bytes6 = {std::byte(255), std::byte(255), std::byte(127)};
std::byte(127), std::byte(0)};
REQUIRE(num6.as_bytes() == expected_bytes6); REQUIRE(num6.as_bytes() == expected_bytes6);
} }
TEST_CASE("VariableByte Integer Decoding", "[Variable Byte Integer]") { TEST_CASE("VariableByte Integer Decoding", "[Variable Byte Integer]") {
// Caso de teste 1 // Caso de teste 1
uint32_t expected_num1 = 42; uint32_t expected_num1 = 42;
std::vector<std::byte> bytes1 = {std::byte(42), std::byte(0), std::vector<std::byte> bytes1 = {std::byte(42)};
std::byte(0), std::byte(0)};
int_vb num1(bytes1); int_vb num1(bytes1);
REQUIRE(uint32_t(num1) == expected_num1); REQUIRE(uint32_t(num1) == expected_num1);
// Caso de teste 2 // Caso de teste 2
uint32_t expected_num2 = 2048; uint32_t expected_num2 = 2048;
std::vector<std::byte> bytes2 = {std::byte(128), std::byte(16), std::vector<std::byte> bytes2 = {std::byte(128), std::byte(16)};
std::byte(0), std::byte(0)};
int_vb num2(bytes2); int_vb num2(bytes2);
REQUIRE(uint32_t(num2) == expected_num2); REQUIRE(uint32_t(num2) == expected_num2);
// Caso de teste 3 // Caso de teste 3
std::vector<std::byte> bytes3 = {std::byte(255), std::byte(255), std::vector<std::byte> bytes3 = {std::byte(255), std::byte(255), std::byte(255), std::byte(255)};
std::byte(255), std::byte(255)};
REQUIRE_THROWS_AS([&](){int_vb num3(bytes3);}(), std::runtime_error); REQUIRE_THROWS_AS([&](){int_vb num3(bytes3);}(), std::runtime_error);
// Caso de teste 4 // Caso de teste 4
uint32_t expected_num4 = 0; uint32_t expected_num4 = 0;
std::vector<std::byte> bytes4 = {std::byte(0), std::byte(0), std::vector<std::byte> bytes4 = {std::byte(0), std::byte(0)};
std::byte(0), std::byte(0)};
int_vb num4(bytes4); int_vb num4(bytes4);
REQUIRE(uint32_t(num4) == expected_num4); REQUIRE(uint32_t(num4) == expected_num4);
// Caso de teste 5 // Caso de teste 5
uint32_t expected_num5 = 16383; uint32_t expected_num5 = 16383;
std::vector<std::byte> bytes5 = {std::byte(255), std::byte(127), std::vector<std::byte> bytes5 = {std::byte(255), std::byte(127)};
std::byte(0), std::byte(0)};
int_vb num5(bytes5); int_vb num5(bytes5);
REQUIRE(uint32_t(num5) == expected_num5); REQUIRE(uint32_t(num5) == expected_num5);
// Caso de teste 6 // Caso de teste 6
uint32_t expected_num6 = 2097151; uint32_t expected_num6 = 2097151;
std::vector<std::byte> bytes6 = {std::byte(255), std::byte(255), std::vector<std::byte> bytes6 = {std::byte(255), std::byte(255), std::byte(127)};
std::byte(127), std::byte(0)};
int_vb num6(bytes6); int_vb num6(bytes6);
REQUIRE(uint32_t(num6) == expected_num6); REQUIRE(uint32_t(num6) == expected_num6);
} }