support/testing: boost: new runtime tests
PATCH 1/1 support/testing: boost: new runtime tests
Implement a set of test cases for boost.
Each symbol in boost.mk gets its own testcase.
It's currently based on boost 1.83 and should be extended when new libraries are added.
MPI and Graph-Parallel currently have a build issue which needs to be fixed before test-cases can be added.
---
RFC: I decided to go for one test case for each module. If you think
this is too much I could reduce it.
Pipeline passed: https://gitlab.com/heinemml/buildroot/-/pipelines/2907184573
--- DEVELOPERS | 2 + .../package/br2-external/boost/Config.in | 1 + .../package/br2-external/boost/external.desc | 1 + .../package/br2-external/boost/external.mk | 1 + .../package/boost-runtime-test/CMakeLists.txt | 60 ++++ .../package/boost-runtime-test/Config.in | 6 + .../boost-runtime-test/boost-runtime-test.mk | 32 ++ .../src/boost-atomic-test.cpp | 23 ++ .../src/boost-chrono-test.cpp | 24 ++ .../src/boost-container-test.cpp | 34 ++ .../src/boost-context-test.cpp | 24 ++ .../src/boost-contract-test.cpp | 38 +++ .../src/boost-coroutine-test.cpp | 32 ++ .../src/boost-date-time-test.cpp | 21 ++ .../src/boost-exception-test.cpp | 30 ++ .../src/boost-fiber-test.cpp | 29 ++ .../src/boost-filesystem-test.cpp | 34 ++ .../src/boost-graph-test.cpp | 46 +++ .../src/boost-iostreams-test.cpp | 47 +++ .../src/boost-json-test.cpp | 24 ++ .../src/boost-locale-test.cpp | 21 ++ .../boost-runtime-test/src/boost-log-test.cpp | 34 ++ .../src/boost-math-test.cpp | 30 ++ .../src/boost-nowide-test.cpp | 35 +++ .../src/boost-program-options-test.cpp | 51 +++ .../src/boost-python-test.cpp | 26 ++ .../src/boost-random-test.cpp | 31 ++ .../src/boost-regex-test.cpp | 23 ++ .../src/boost-serialization-test.cpp | 44 +++ .../src/boost-stacktrace-test.cpp | 20 ++ .../src/boost-system-test.cpp | 20 ++ .../src/boost-test-test.cpp | 23 ++ .../src/boost-thread-test.cpp | 26 ++ .../src/boost-timer-test.cpp | 21 ++ .../src/boost-type-erasure-test.cpp | 37 +++ .../boost-runtime-test/src/boost-url-test.cpp | 26 ++ .../src/boost-wave-test.cpp | 33 ++ support/testing/tests/package/test_boost.py | 292 ++++++++++++++++++ 38 files changed, 1302 insertions(+) create mode 100644 support/testing/tests/package/br2-external/boost/Config.in create mode 100644 support/testing/tests/package/br2-external/boost/external.desc create mode 100644 support/testing/tests/package/br2-external/boost/external.mk create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/CMakeLists.txt create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/Config.in create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/boost-runtime-test.mk create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-atomic-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-chrono-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-container-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-context-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-contract-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-coroutine-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-date-time-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-exception-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-fiber-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-filesystem-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-graph-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-iostreams-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-json-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-locale-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-log-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-math-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-nowide-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-program-options-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-python-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-random-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-regex-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-serialization-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-stacktrace-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-system-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-test-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-thread-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-timer-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-type-erasure-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-url-test.cpp create mode 100644 support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-wave-test.cpp create mode 100644 support/testing/tests/package/test_boost.py
DEVELOPERS +2 -0
@@ -2464,6 +2464,8 @@ F: package/protobuf/ F: package/sdbus-cpp/ F: package/spdlog/ F: package/sqlitecpp/ +F: support/testing/tests/package/br2-external/boost/ +F: support/testing/tests/package/test_boost.py N: Michael Trimarchi <[email protected]> F: board/bsh/
support/testing/tests/package/br2-external/boost/Config.in new file +1 -0
@@ -0,0 +1 @@ +source "$BR2_EXTERNAL_BOOST_RUNTIME_TEST_PATH/package/boost-runtime-test/Config.in"
support/testing/tests/package/br2-external/boost/external.desc new file +1 -0
@@ -0,0 +1 @@ +name: BOOST_RUNTIME_TEST
support/testing/tests/package/br2-external/boost/external.mk new file +1 -0
@@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_BOOST_RUNTIME_TEST_PATH)/package/*/*.mk))
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/CMakeLists.txt new file +60 -0
60 lines not on this page · raw message
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/Config.in new file +6 -0
@@ -0,0 +1,6 @@ +config BR2_PACKAGE_BOOST_RUNTIME_TEST + bool "boost-runtime-test" + depends on BR2_PACKAGE_BOOST + help + Test programs for the Boost libraries. A test program is + built for each enabled Boost library.
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/boost-runtime-test.mk new file +32 -0
@@ -0,0 +1,32 @@ +################################################################################ +# +# boost-runtime-test +# +################################################################################ + +BOOST_RUNTIME_TEST_SITE = $(BOOST_RUNTIME_TEST_PKGDIR) +BOOST_RUNTIME_TEST_SITE_METHOD = local +BOOST_RUNTIME_TEST_DEPENDENCIES = boost + +BOOST_RUNTIME_TEST_ALL_LIBS = \ + atomic chrono container context contract coroutine date_time \ + exception fiber filesystem graph iostreams json locale log math \ + nowide program_options random regex serialization stacktrace \ + system test thread timer type_erasure url wave + +BOOST_RUNTIME_TEST_LIBS = \ + $(foreach lib,$(BOOST_RUNTIME_TEST_ALL_LIBS), \ + $(if $(BR2_PACKAGE_BOOST_$(call UPPERCASE,$(lib))),$(lib))) + +# Link flags come from the cmake config files installed by boost +BOOST_RUNTIME_TEST_CONF_OPTS = \ + -DBOOST_RUNTIME_TEST_LIBS="$(subst $(space),;,$(strip $(BOOST_RUNTIME_TEST_LIBS)))" + +ifeq ($(BR2_PACKAGE_BOOST_PYTHON),y) +BOOST_RUNTIME_TEST_DEPENDENCIES += python3 +BOOST_RUNTIME_TEST_CONF_OPTS += \ + -DBOOST_RUNTIME_TEST_PYTHON_INCLUDE_DIR=$(STAGING_DIR)/usr/include/python$(PYTHON3_VERSION_MAJOR) \ + -DBOOST_RUNTIME_TEST_PYTHON_SITE_DIR=lib/python$(PYTHON3_VERSION_MAJOR)/site-packages +endif + +$(eval $(cmake-package))
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-atomic-test.cpp new file +23 -0
@@ -0,0 +1,23 @@ +#include <boost/atomic.hpp> + +#include <iostream> + +int main() +{ + boost::atomic<int> counter(0); + for (int i = 0; i < 10; i++) + counter.fetch_add(1, boost::memory_order_relaxed); + + int expected = 10; + if (!counter.compare_exchange_strong(expected, 42)) + return 1; + if (!counter.is_lock_free()) + return 1; + + // wait/notify are implemented in libboost_atomic + counter.wait(0); + counter.notify_all(); + + std::cout << "atomic: " << counter.load() << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-chrono-test.cpp new file +24 -0
@@ -0,0 +1,24 @@ +#include <boost/chrono.hpp> +#include <boost/chrono/process_cpu_clocks.hpp> + +#include <chrono> +#include <iostream> +#include <thread> + +int main() +{ + namespace bc = boost::chrono; + + bc::steady_clock::time_point start = bc::steady_clock::now(); + bc::process_real_cpu_clock::time_point cpu_start = bc::process_real_cpu_clock::now(); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + bc::milliseconds elapsed = bc::duration_cast<bc::milliseconds>(bc::steady_clock::now() - start); + + if (elapsed.count() < 50) + return 1; + if (bc::process_real_cpu_clock::now() < cpu_start) + return 1; + + std::cout << "chrono: elapsed>=50ms" << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-container-test.cpp new file +34 -0
@@ -0,0 +1,34 @@ +#include <boost/container/flat_map.hpp> +#include <boost/container/pmr/monotonic_buffer_resource.hpp> +#include <boost/container/pmr/vector.hpp> +#include <boost/container/small_vector.hpp> + +#include <iostream> +#include <string> + +int main() +{ + boost::container::flat_map<std::string, int> map; + map["b"] = 2; + map["a"] = 1; + if (map.begin()->first != "a") + return 1; + + boost::container::small_vector<int, 4> small{1, 2, 3, 4, 5}; + if (small.size() != 5) + return 1; + + // pmr memory resources are implemented in libboost_container + char buffer[256]; + boost::container::pmr::monotonic_buffer_resource resource(buffer, sizeof(buffer)); + boost::container::pmr::vector<int> values(&resource); + for (int i = 0; i < 10; i++) + values.push_back(i); + + int sum = 0; + for (int v : values) + sum += v; + + std::cout << "container: sum=" << sum << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-context-test.cpp new file +24 -0
@@ -0,0 +1,24 @@ +#include <boost/context/fiber.hpp> + +#include <iostream> +#include <utility> + +namespace ctx = boost::context; + +int main() +{ + int total = 0; + ctx::fiber worker{[&total](ctx::fiber &&caller) { + for (int i = 1; i <= 3; i++) { + total += i; + caller = std::move(caller).resume(); + } + return std::move(caller); + }}; + + for (int i = 0; i < 3; i++) + worker = std::move(worker).resume(); + + std::cout << "context: " << total << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-contract-test.cpp new file +38 -0
@@ -0,0 +1,38 @@ +#include <boost/contract.hpp> + +#include <iostream> +#include <stdexcept> + +static int sqrt_floor(int x) +{ + int result = 0; + boost::contract::check c = boost::contract::function() + .precondition([&] { BOOST_CONTRACT_ASSERT(x >= 0); }) + .postcondition([&] { + BOOST_CONTRACT_ASSERT(result * result <= x); + BOOST_CONTRACT_ASSERT((result + 1) * (result + 1) > x); + }); + + while ((result + 1) * (result + 1) <= x) + result++; + return result; +} + +int main() +{ + boost::contract::set_precondition_failure([](boost::contract::from) { + throw std::runtime_error("precondition failed"); + }); + + if (sqrt_floor(17) != 4) + return 1; + + try { + sqrt_floor(-1); + return 1; + } catch (const std::runtime_error &) { + } + + std::cout << "contract: precondition enforced" << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-coroutine-test.cpp new file +32 -0
@@ -0,0 +1,32 @@ +#define BOOST_COROUTINES_NO_DEPRECATION_WARNING +#include <boost/coroutine/asymmetric_coroutine.hpp> + +#include <iostream> + +typedef boost::coroutines::asymmetric_coroutine<int> coro_t; + +int main() +{ + coro_t::pull_type fibonacci([](coro_t::push_type &sink) { + int a = 0, b = 1; + for (int i = 0; i < 10; i++) { + sink(a); + int next = a + b; + a = b; + b = next; + } + }); + + int count = 0, last = 0; + while (fibonacci) { + last = fibonacci.get(); + count++; + fibonacci(); + } + + if (count != 10 || last != 34) + return 1; + + std::cout << "coroutine: fib(9)=" << last << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-date-time-test.cpp new file +21 -0
@@ -0,0 +1,21 @@ +#include <boost/date_time/gregorian/gregorian.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + +#include <iostream> + +int main() +{ + namespace greg = boost::gregorian; + namespace pt = boost::posix_time; + + greg::date day = greg::from_simple_string("2024-02-28") + greg::days(1); + if (day != greg::date(2024, greg::Feb, 29)) + return 1; + if (greg::to_iso_extended_string(day + greg::days(1)) != "2024-03-01") + return 1; + + pt::ptime time = pt::time_from_string("2024-02-29 12:30:00") + pt::hours(12); + + std::cout << "date_time: " << pt::to_iso_extended_string(time) << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-exception-test.cpp new file +30 -0
@@ -0,0 +1,30 @@ +#include <boost/exception/all.hpp> +#include <boost/exception_ptr.hpp> + +#include <exception> +#include <iostream> + +typedef boost::error_info<struct tag_error_code, int> error_code_info; + +struct test_error : virtual boost::exception, virtual std::exception {}; + +int main() +{ + boost::exception_ptr saved; + try { + BOOST_THROW_EXCEPTION(test_error() << error_code_info(42)); + } catch (...) { + saved = boost::current_exception(); + } + + try { + boost::rethrow_exception(saved); + } catch (const test_error &e) { + const int *code = boost::get_error_info<error_code_info>(e); + if (!code || *code != 42) + return 1; + std::cout << "exception: error_code=" << *code << std::endl; + return 0; + } + return 1; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-fiber-test.cpp new file +29 -0
@@ -0,0 +1,29 @@ +#include <boost/fiber/all.hpp> + +#include <iostream> + +int main() +{ + boost::fibers::buffered_channel<int> channel(8); + int sum = 0; + + boost::fibers::fiber producer([&channel] { + for (int i = 1; i <= 5; i++) + channel.push(i); + channel.close(); + }); + boost::fibers::fiber consumer([&channel, &sum] { + int value; + while (channel.pop(value) == boost::fibers::channel_op_status::success) + sum += value; + }); + + producer.join(); + consumer.join(); + + if (sum != 15) + return 1; + + std::cout << "fiber: sum=" << sum << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-filesystem-test.cpp new file +34 -0
@@ -0,0 +1,34 @@ +#include <boost/filesystem.hpp> + +#include <fstream> +#include <iostream> + +namespace fs = boost::filesystem; + +int main() +{ + fs::path dir = fs::temp_directory_path() / fs::unique_path("boost-fs-%%%%-%%%%"); + fs::create_directories(dir / "sub"); + { + std::ofstream out((dir / "sub" / "file.txt").string()); + out << "hello"; + } + + if (fs::file_size(dir / "sub" / "file.txt") != 5) + return 1; + + fs::rename(dir / "sub" / "file.txt", dir / "moved.txt"); + + int entries = 0; + for (fs::recursive_directory_iterator it(dir), end; it != end; ++it) + entries++; + if (entries != 2) + return 1; + + fs::remove_all(dir); + if (fs::exists(dir)) + return 1; + + std::cout << "filesystem: stem=" << fs::path("/a/b/c.txt").stem().string() << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-graph-test.cpp new file +46 -0
46 lines not on this page · raw message
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-iostreams-test.cpp new file +47 -0
47 lines not on this page · raw message
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-json-test.cpp new file +24 -0
@@ -0,0 +1,24 @@ +#include <boost/json.hpp> + +#include <iostream> + +namespace json = boost::json; + +int main() +{ + json::value doc = json::parse( + R"({"name": "buildroot", "libs": ["boost", "sqlite"], "version": 2026})"); + json::object &obj = doc.as_object(); + + if (obj.at("libs").as_array().size() != 2) + return 1; + + obj["version"] = obj.at("version").as_int64() + 1; + + json::object result; + result["name"] = obj.at("name"); + result["version"] = obj.at("version"); + + std::cout << "json: " << json::serialize(result) << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-locale-test.cpp new file +21 -0
@@ -0,0 +1,21 @@ +#include <boost/locale.hpp> + +#include <iostream> +#include <string> + +int main() +{ + // "grüße" in UTF-8 + const std::string utf8 = "gr\xc3\xbc\xc3\x9f" "e"; + + std::wstring wide = boost::locale::conv::utf_to_utf<wchar_t>(utf8); + if (wide.size() != 5) + return 1; + if (boost::locale::conv::utf_to_utf<char>(wide) != utf8) + return 1; + + boost::locale::generator gen; + std::cout.imbue(gen("en_US.UTF-8")); + std::cout << boost::locale::format("locale: {1} characters") % wide.size() << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-log-test.cpp new file +34 -0
@@ -0,0 +1,34 @@ +#include <boost/log/expressions.hpp> +#include <boost/log/trivial.hpp> +#include <boost/log/utility/setup/file.hpp> + +#include <fstream> +#include <iostream> +#include <iterator> +#include <string> + +namespace logging = boost::log; +namespace expr = boost::log::expressions; +namespace keywords = boost::log::keywords; + +int main() +{ + const char *path = "/tmp/boost-log-test.log"; + + logging::add_file_log( + keywords::file_name = path, + keywords::auto_flush = true, + keywords::format = (expr::stream << "[" << logging::trivial::severity + << "] " << expr::smessage)); + logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info); + + BOOST_LOG_TRIVIAL(debug) << "hidden"; + BOOST_LOG_TRIVIAL(info) << "visible"; + BOOST_LOG_TRIVIAL(error) << "problem"; + logging::core::get()->remove_all_sinks(); + + std::ifstream in(path); + std::string content((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()); + std::cout << content; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-math-test.cpp new file +30 -0
@@ -0,0 +1,30 @@ +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/tr1.hpp> + +#include <cmath> +#include <iomanip> +#include <iostream> + +static bool close(double a, double b) +{ + return std::fabs(a - b) < 1e-9; +} + +int main() +{ + // tgamma comes from libboost_math_c99, cyl_bessel_j and legendre from libboost_math_tr1 + double gamma = boost::math::tr1::tgamma(5.0); + double bessel = boost::math::tr1::cyl_bessel_j(0.0, 1.0); + double legendre = boost::math::tr1::legendre(2, 0.5); + + if (!close(gamma, 24.0) || !close(bessel, 0.765197686557966) || !close(legendre, -0.125)) + return 1; + if (!close(boost::math::tgamma(5.0), gamma)) + return 1; + + std::cout << std::fixed << std::setprecision(6) + << "math: tgamma(5)=" << gamma + << " J0(1)=" << bessel + << " P2(0.5)=" << legendre << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-nowide-test.cpp new file +35 -0
@@ -0,0 +1,35 @@ +#include <boost/nowide/convert.hpp> +#include <boost/nowide/cstdlib.hpp> +#include <boost/nowide/fstream.hpp> + +#include <cstring> +#include <iostream> +#include <string> + +int main() +{ + // "grüße" in UTF-8 + const std::string utf8 = "gr\xc3\xbc\xc3\x9f" "e"; + + std::wstring wide = boost::nowide::widen(utf8); + if (wide.size() != 5 || boost::nowide::narrow(wide) != utf8) + return 1; + + const char *path = "/tmp/boost-nowide-test.txt"; + { + boost::nowide::ofstream out(path); + out << "nowide"; + } + boost::nowide::ifstream in(path); + std::string word; + in >> word; + + if (boost::nowide::setenv("BOOST_NOWIDE_TEST", "1", 1) != 0) + return 1; + const char *env = boost::nowide::getenv("BOOST_NOWIDE_TEST"); + if (!env || std::strcmp(env, "1") != 0) + return 1; + + std::cout << "nowide: " << word << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-program-options-test.cpp new file +51 -0
51 lines not on this page · raw message
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-python-test.cpp new file +26 -0
@@ -0,0 +1,26 @@ +#include <boost/python.hpp> + +#include <string> + +static std::string greet(const std::string &name) +{ + return "hello " + name; +} + +struct counter { + int value = 0; + void add(int n) + { + value += n; + } +}; + +BOOST_PYTHON_MODULE(boost_python_test) +{ + namespace bp = boost::python; + + bp::def("greet", greet); + bp::class_<counter>("Counter") + .def("add", &counter::add) + .def_readonly("value", &counter::value); +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-random-test.cpp new file +31 -0
@@ -0,0 +1,31 @@ +#include <boost/random/mersenne_twister.hpp> +#include <boost/random/random_device.hpp> +#include <boost/random/uniform_int_distribution.hpp> + +#include <iostream> + +int main() +{ + // The C++ standard specifies the 10000th output of a default-seeded mt19937 + boost::random::mt19937 gen; + for (int i = 0; i < 9999; i++) + gen(); + boost::uint32_t value = gen(); + if (value != 4123659995u) + return 1; + + boost::random::uniform_int_distribution<> dice(1, 6); + boost::random::mt19937 a(42), b(42); + if (dice(a) != dice(b)) + return 1; + + // random_device is implemented in libboost_random + boost::random::random_device device; + boost::random::mt19937 seeded(device()); + int roll = dice(seeded); + if (roll < 1 || roll > 6) + return 1; + + std::cout << "random: mt19937 10000th=" << value << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-regex-test.cpp new file +23 -0
@@ -0,0 +1,23 @@ +#include <boost/regex.hpp> + +#include <iostream> +#include <string> +#include <vector> + +int main() +{ + const boost::regex email(R"((\w+)@(\w+)\.org)"); + const std::string text = "contact: [email protected], [email protected]"; + + std::vector<std::string> users; + for (boost::sregex_iterator it(text.begin(), text.end(), email), end; it != end; ++it) + users.push_back((*it)[1]); + if (users.size() != 2 || users[0] != "buildroot" || users[1] != "other") + return 1; + + const boost::regex date(R"((\d+)-(\d+)-(\d+))"); + std::string reformatted = boost::regex_replace(std::string("2026-10-02"), date, "$3.$2.$1"); + + std::cout << "regex: " << reformatted << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-serialization-test.cpp new file +44 -0
44 lines not on this page · raw message
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-stacktrace-test.cpp new file +20 -0
@@ -0,0 +1,20 @@ +#include <boost/stacktrace.hpp> + +#include <iostream> + +__attribute__((noinline)) static boost::stacktrace::stacktrace capture() +{ + return boost::stacktrace::stacktrace(); +} + +int main() +{ + boost::stacktrace::stacktrace trace = capture(); + if (trace.empty()) + return 1; + if (boost::stacktrace::to_string(trace).empty()) + return 1; + + std::cout << "stacktrace: frames=" << trace.size() << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-system-test.cpp new file +20 -0
@@ -0,0 +1,20 @@ +#include <boost/system/error_code.hpp> +#include <boost/system/system_error.hpp> + +#include <cerrno> +#include <iostream> + +int main() +{ + boost::system::error_code ec(ENOENT, boost::system::generic_category()); + if (ec != boost::system::errc::no_such_file_or_directory) + return 1; + + try { + throw boost::system::system_error(ec, "open"); + } catch (const boost::system::system_error &e) { + std::cout << "system: " << e.code().message() << std::endl; + return 0; + } + return 1; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-test-test.cpp new file +23 -0
@@ -0,0 +1,23 @@ +#define BOOST_TEST_MODULE boost_runtime_test +#include <boost/test/unit_test.hpp> + +#include <stdexcept> +#include <string> + +BOOST_AUTO_TEST_CASE(arithmetic) +{ + BOOST_TEST(2 + 2 == 4); +} + +BOOST_AUTO_TEST_CASE(strings) +{ + std::string name = "boost"; + BOOST_TEST(name.size() == 5u); + BOOST_CHECK_THROW(throw std::runtime_error("expected"), std::runtime_error); +} + +// Only run explicitly, to check that failures are reported +BOOST_AUTO_TEST_CASE(failing, *boost::unit_test::disabled()) +{ + BOOST_TEST(1 == 2); +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-thread-test.cpp new file +26 -0
@@ -0,0 +1,26 @@ +#include <boost/thread.hpp> + +#include <iostream> + +int main() +{ + boost::mutex mutex; + int counter = 0; + + boost::thread_group workers; + for (int i = 0; i < 4; i++) { + workers.create_thread([&mutex, &counter] { + for (int j = 0; j < 1000; j++) { + boost::lock_guard<boost::mutex> lock(mutex); + counter++; + } + }); + } + workers.join_all(); + + if (counter != 4000 || boost::thread::hardware_concurrency() < 1) + return 1; + + std::cout << "thread: counter=" << counter << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-timer-test.cpp new file +21 -0
@@ -0,0 +1,21 @@ +#include <boost/timer/timer.hpp> + +#include <chrono> +#include <iostream> +#include <thread> + +int main() +{ + boost::timer::cpu_timer timer; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + timer.stop(); + + boost::timer::cpu_times elapsed = timer.elapsed(); + if (elapsed.wall < 100000000LL) + return 1; + if (timer.format().empty()) + return 1; + + std::cout << "timer: wall>=100ms" << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-type-erasure-test.cpp new file +37 -0
@@ -0,0 +1,37 @@ +#include <boost/mpl/vector.hpp> +#include <boost/type_erasure/any.hpp> +#include <boost/type_erasure/builtin.hpp> +#include <boost/type_erasure/dynamic_any_cast.hpp> +#include <boost/type_erasure/operators.hpp> +#include <boost/type_erasure/register_binding.hpp> +#include <boost/type_erasure/relaxed.hpp> + +#include <iostream> + +namespace te = boost::type_erasure; +namespace mpl = boost::mpl; + +typedef te::any<mpl::vector<te::copy_constructible<>, te::typeid_<>, te::relaxed>> basic_any; +typedef mpl::vector<te::copy_constructible<>, te::typeid_<>, te::incrementable<>, + te::ostreamable<>, te::relaxed> + printable_concept; +typedef te::any<printable_concept> printable_any; + +int main() +{ + // dynamic_any_cast looks bindings up by the target's full concept + te::register_binding<printable_concept, int>(); + + basic_any value(1); + printable_any printable = te::dynamic_any_cast<printable_any>(value); + ++printable; + + try { + te::dynamic_any_cast<printable_any>(basic_any(1.5)); + return 1; + } catch (const te::bad_any_cast &) { + } + + std::cout << "type_erasure: " << printable << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-url-test.cpp new file +26 -0
@@ -0,0 +1,26 @@ +#include <boost/url.hpp> + +#include <iostream> + +namespace urls = boost::urls; + +int main() +{ + auto parsed = urls::parse_uri( + "https://buildroot.org:8080/downloads/index.html?ver=2026.11&arch=arm#top"); + if (!parsed) + return 1; + + urls::url url = *parsed; + if (url.host() != "buildroot.org" || url.port_number() != 8080) + return 1; + + url.params().set("arch", "aarch64"); + url.remove_fragment(); + + if (urls::parse_uri("not a uri")) + return 1; + + std::cout << "url: " << url.buffer() << std::endl; + return 0; +}
support/testing/tests/package/br2-external/boost/package/boost-runtime-test/src/boost-wave-test.cpp new file +33 -0
@@ -0,0 +1,33 @@ +#include <boost/wave.hpp> +#include <boost/wave/cpplexer/cpp_lex_iterator.hpp> +#include <boost/wave/cpplexer/cpp_lex_token.hpp> + +#include <iostream> +#include <string> + +typedef boost::wave::cpplexer::lex_token<> token_type; +typedef boost::wave::cpplexer::lex_iterator<token_type> lex_iterator_type; +typedef boost::wave::context<std::string::iterator, lex_iterator_type> context_type; + +int main() +{ + std::string input = + "#define GREETING(x) hello x\n" + "#if 1 + 1 == 2\n" + "GREETING(buildroot)\n" + "#else\n" + "wrong\n" + "#endif\n"; + + context_type ctx(input.begin(), input.end(), "test.cpp"); + std::string output; + for (context_type::iterator_type it = ctx.begin(); it != ctx.end(); ++it) + output += (*it).get_value().c_str(); + + if (output.find("hello buildroot") == std::string::npos || + output.find("wrong") != std::string::npos) + return 1; + + std::cout << "wave: hello buildroot" << std::endl; + return 0; +}
support/testing/tests/package/test_boost.py new file +292 -0
292 lines not on this page · raw message
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Le 02/10/2026 à 17:36, Michael Nosthoff via buildroot a écrit :
Quoted 2 lines
Implement a set of test cases for boost.
Each symbol in boost.mk gets its own testcase.
The boost source code already contains testcases. You can probably pick one of them for each boost library and compile it, without importing the testcase code into buildroot.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Hi Nicolas,
Quoted 7 lines · Nicolas Cavallari
Le 02/10/2026 à 17:36, Michael Nosthoff via buildroot a écrit :
Quoted 2 lines
Implement a set of test cases for boost.
Each symbol in boost.mk gets its own testcase.The boost source code already contains testcases. You can probably pick one of them for each boost library and compile it, without importing the testcase code into buildroot.
Good idea,
I'll look into it.
Regards,
Michael
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot