summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-24 22:13:37 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-11-24 22:22:17 -0500
commitbf2c4bc8c719159b4ddd1b40e032c449424abd5d (patch)
tree6be8255399cc3e95637c0cd7817ff4c19de02ae6
parent20748b34ad43f69ec127a4caab05196e2fd38705 (diff)
feat: distribution script fixed, improved linux compat, and extended network unit tests.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--compile_flags.txt3
-rw-r--r--include/ocl/core/config.hpp10
-rw-r--r--include/ocl/net/modem.hpp3
-rw-r--r--include/ocl/tests/hpptest.hpp17
-rwxr-xr-xmake_dist_linux.sh6
-rwxr-xr-xmake_dist_osx.sh6
-rw-r--r--tests/network_basic/CMakeLists.txt2
-rw-r--r--tests/network_basic/net_test.cc22
-rw-r--r--tests/network_basic/network_basic_test.cc40
-rwxr-xr-xtools/hpptest.py17
10 files changed, 81 insertions, 45 deletions
diff --git a/compile_flags.txt b/compile_flags.txt
index cc97734..2a37c5d 100644
--- a/compile_flags.txt
+++ b/compile_flags.txt
@@ -2,4 +2,5 @@
-std=c++20
-DEMBFS_28BIT_LBA
-xc++
--I/opt/homebrew/Cellar/boost/1.89.0/include \ No newline at end of file
+-I/opt/homebrew/Cellar/boost/1.89.0/include
+-I/usr/include \ No newline at end of file
diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp
index 2ea1399..de1ce76 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -12,10 +12,14 @@
#include <boost/core/demangle.hpp>
#include <boost/core/null_deleter.hpp>
#include <boost/container/allocator.hpp>
+#include <boost/assert.hpp>
-#include <memory>
-#include <iostream>
-#include <string>
+#ifdef __cplusplus
+/// DLL/Dylib/So specific macro.
+# define OCL_EXPORT_DECL extern "C" BOOST_SYMBOL_EXPORT
+#else
+# define OCL_EXPORT_DECL
+#endif
namespace ocl
{
diff --git a/include/ocl/net/modem.hpp b/include/ocl/net/modem.hpp
index 08d5ca5..29db748 100644
--- a/include/ocl/net/modem.hpp
+++ b/include/ocl/net/modem.hpp
@@ -14,6 +14,7 @@
#include <sys/socket.h>
#include <string>
#include <cstddef>
+#include <cstring>
#define OCL_MODEM_INTERFACE : public ocl::net::modem
@@ -23,6 +24,8 @@
namespace ocl::net
{
+ using namespace hpptest;
+
class modem;
/// =============================================================================
diff --git a/include/ocl/tests/hpptest.hpp b/include/ocl/tests/hpptest.hpp
index 0c7b4e5..0b5c54e 100644
--- a/include/ocl/tests/hpptest.hpp
+++ b/include/ocl/tests/hpptest.hpp
@@ -7,8 +7,11 @@
#pragma once
+#include <boost/config.hpp>
+#include <core/config.hpp>
#include <io/print.hpp>
-#include <cstdlib>
+#include <string.h>
+#include <unistd.h>
namespace ocl::hpptest
{
@@ -25,6 +28,10 @@ namespace ocl::hpptest
}
};
+#ifdef __linux__
+ using errno_t = error_t;
+#endif
+
struct posix_terminate final
{
template <bool stop_execution = true, errno_t args>
@@ -40,7 +47,7 @@ namespace ocl::hpptest
typedef bool condition_type;
template <condition_type expr = true>
- consteval inline void must_be()
+ consteval inline void must_pass()
{
#ifdef OCL_HPPTEST
OCL_HPPTEST_ASSERT(expr);
@@ -48,7 +55,7 @@ namespace ocl::hpptest
}
template <condition_type expect, typename on_fail>
- inline void must_be(condition_type cond) noexcept
+ inline void must_pass(condition_type cond) noexcept
{
if (cond != expect)
{
@@ -57,7 +64,7 @@ namespace ocl::hpptest
}
template <errno_t expect = 0>
- inline void must_be(errno_t ern) noexcept
+ inline void must_pass(errno_t ern) noexcept
{
if (ern != expect)
{
@@ -79,7 +86,7 @@ namespace ocl::hpptest
};
template <HRESULT expect = S_OK>
- inline void must_be(HRESULT hr) noexcept
+ inline void must_pass(HRESULT hr) noexcept
{
if (hr != expect)
{
diff --git a/make_dist_linux.sh b/make_dist_linux.sh
index ab78915..d576b98 100755
--- a/make_dist_linux.sh
+++ b/make_dist_linux.sh
@@ -20,12 +20,12 @@ outputDirTools=dist/
for f in include/ocl/*/*.hpp; do
baseName=`echo $f | cut -d "." -f 1`
-echo "RUN:" cp $f $outputDir$baseName
-cp $f $outputDirCmd$baseName
+echo "RUN:" cp $f $outputDir$baseName'.hpp'
+cp $f $outputDirCmd$baseName'.hpp'
done
for f in tools/*.py; do
baseName=`echo $f | cut -d "." -f 1`
-echo "RUN:" cp $baseName'.py' $outputDirTools$baseName
+echo "RUN:" cp $baseName'.py' $outputDirTools$baseName'.py'
cp $baseName'.py' $outputDirTools$baseName'.py'
done
diff --git a/make_dist_osx.sh b/make_dist_osx.sh
index 505c583..f6796f4 100755
--- a/make_dist_osx.sh
+++ b/make_dist_osx.sh
@@ -6,12 +6,12 @@ mkdir -p $outputDir
for f in include/ocl/*/*.hpp; do
baseName=`echo $f | cut -d "." -f 1`
-echo "RUN:" ditto $baseName.hpp $outputDir$baseName
-ditto $baseName.hpp $outputDir$baseName
+echo "RUN:" ditto $baseName.hpp $outputDir$baseName'.hpp'
+ditto $baseName.hpp $outputDir$baseName'.hpp'
done
for f in tools/*.py; do
baseName=`echo $f | cut -d "." -f 1`
echo "RUN:" ditto $baseName.py $outputDir$baseName
-ditto $baseName.py $outputDir$baseName
+ditto $baseName.py $outputDir$baseName'.py'
done
diff --git a/tests/network_basic/CMakeLists.txt b/tests/network_basic/CMakeLists.txt
index 88fa1c8..fb567d6 100644
--- a/tests/network_basic/CMakeLists.txt
+++ b/tests/network_basic/CMakeLists.txt
@@ -13,7 +13,7 @@ FetchContent_MakeAvailable(googletest)
enable_testing()
-add_executable(NetworkTestBasic net_test.cc)
+add_executable(NetworkTestBasic network_basic_test.cc)
target_link_libraries(NetworkTestBasic gtest_main)
set_property(TARGET NetworkTestBasic PROPERTY CXX_STANDARD 20)
diff --git a/tests/network_basic/net_test.cc b/tests/network_basic/net_test.cc
deleted file mode 100644
index 15090d0..0000000
--- a/tests/network_basic/net_test.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * File: tests/net_test.cc
- * Purpose: Network unit tests in C++
- * Author: Amlal El Mahrouss (amlal@nekernel.org)
- * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
- */
-
-#include <net/modem.hpp>
-#include <io/print.hpp>
-#include <tests/gtest.hpp>
-#include <cstring>
-
-TEST(NetworkTest, BasicNetworkUsage)
-{
- ocl::net::modem modem;
- modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::modem::local_address_ip4, true);
-
- EXPECT_TRUE(modem.is_valid());
-
- std::basic_string<char> buf_dst = "HELLO, NET!";
- EXPECT_TRUE(modem.transmit(buf_dst));
-}
diff --git a/tests/network_basic/network_basic_test.cc b/tests/network_basic/network_basic_test.cc
new file mode 100644
index 0000000..22f5aab
--- /dev/null
+++ b/tests/network_basic/network_basic_test.cc
@@ -0,0 +1,40 @@
+/*
+ * File: tests/net_test.cc
+ * Purpose: Network unit tests in C++
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
+ */
+
+#include <net/modem.hpp>
+#include <io/print.hpp>
+#include <tests/gtest.hpp>
+#include <cstring>
+
+/// @brief Basic Send Test
+TEST(NetworkTest, BasicNetworkTransmit)
+{
+ ocl::net::modem modem;
+ modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::modem::local_address_ip4, true);
+
+ EXPECT_TRUE(modem.is_valid());
+
+ std::basic_string<char> buf_dst = "HELLO, WORLD!";
+ EXPECT_TRUE(modem.transmit(buf_dst));
+}
+
+/// @brief Basic Receive test
+TEST(NetworkTest, BasicNetworkReceive)
+{
+ ocl::net::modem modem;
+ modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::modem::local_address_ip4, true);
+
+ EXPECT_TRUE(modem.is_valid());
+
+ std::basic_string<char> buf_dst;
+ buf_dst.reserve(512);
+
+ auto buf = buf_dst.data();
+ auto sz = buf_dst.size();
+
+ EXPECT_FALSE(modem.receive(buf, sz));
+}
diff --git a/tools/hpptest.py b/tools/hpptest.py
index 08c5719..76366c1 100755
--- a/tools/hpptest.py
+++ b/tools/hpptest.py
@@ -2,18 +2,21 @@
# -*- coding: utf-8 -*-
# HPPTEST: Header-only C++ library test runner.
-# Written by Amlal El Mahrouss.
-# Licensed under the Boost Software License
+# Author: Amlal El Mahrouss.
+# License Boost Software License 1.0
import sys, os
-COMPILER="clang++"
-INCLUDE_DIR="./dev/"
+CXX_COMPILER="clang++"
+CXX_INCLUDE_DIR="./include/"
CXX_STD="c++20"
+# Runs a simple compilation command to check if the test passes or not.
if __name__ == '__main__':
if len(sys.argv) == 3:
- ret = os.system(f"{COMPILER} -I{INCLUDE_DIR} -I{sys.argv[2]} -std={CXX_STD} -DOCL_HPPTEST '-DOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}")
+ ret = os.system(f"{CXX_COMPILER} -I{CXX_INCLUDE_DIR} -I{sys.argv[2]} -std={CXX_STD} -DOCL_HPPTEST '-DOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}")
if ret == 0:
- print("[HPPTEST] HPPTEST PASSES.")
-
+ print("[HPPTEST] TEST PASS.")
+ else:
+ print(f"[HPPTEST] TEST FAILED: RETURN CODE: {ret}")
+ print(f"COMMAND: {CXX_COMPILER} -I{CXX_INCLUDE_DIR} -I{sys.argv[2]} -std={CXX_STD} -DOCL_HPPTEST '-DOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}")