From patchwork Thu Dec 7 20:52:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Freihofer X-Patchwork-Id: 35866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 965B2C4167B for ; Thu, 7 Dec 2023 20:53:30 +0000 (UTC) Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mx.groups.io with SMTP id smtpd.web11.103254.1701982406172201397 for ; Thu, 07 Dec 2023 12:53:26 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PRQgPJD/; spf=pass (domain: gmail.com, ip: 209.85.128.41, mailfrom: adrian.freihofer@gmail.com) Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40b2ddab817so14884755e9.3 for ; Thu, 07 Dec 2023 12:53:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701982404; x=1702587204; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=I8qDj+rye2Z8K52oSfBPWSKrv6fh5SKAitVWCR7EFdA=; b=PRQgPJD/3qI7mdXQWzgsHUqw4kH7FYY4sZNCrrqNKVPy35nQgpI2jvf2IpGa3+/yCQ PXxonXSF2Ls6UMI7tTIkIWRti796HShMQAgbrC0WMKAqny2QNjjIkG5acZR/++yYkRxA 6qMPHcZ2lZhjUSkBGqV8N6lLYCXirgps5ctLHkwp8+37bYPnjlK4BMgWaBbPegUqmLNk zd1uht3c3PztLLVGBFy3YCd2LSdNTAsz0LLmjxe3QCKlPy+UupOTaSQtdjd8Jbk9Dz2d 1VsjtnwSzmGvdMi9lF1xtEmgOtcb1qR3AXuuk9Eklovey6HD0hCzW3Pp/I+t8u69yDUU dBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701982404; x=1702587204; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=I8qDj+rye2Z8K52oSfBPWSKrv6fh5SKAitVWCR7EFdA=; b=KJ+wWNunt5/5CO8e67BX+bWFnhIj6EnUu9F8XGLseedeA7Ur8rb+6CG6pwt8YEqglK KbT22W6zUh6T+GamtE2/M1IOh3APMN8XLnY2ykO55TwQ2aDmefDiALZwo69+a7RaOeZI aI+jFo8xG7lQ9aRPJNJ7yc+R4DJj2u2b/wJh5kIwqFOHbiCVvbwM1UxBmLFMicsppNb8 mJAhiqu8EKHi+/lLAsNTGFUA5woWkIFeShA1l7J6HmOD+fPxKGZijGFzZs2XgEKWwx9z PaDotsCAMpnXhQGXGHbyEXCKjZPots9FjK7sRY1AM6JRc3vVW1N9wlxm6k2jefsYq9uH sXuA== X-Gm-Message-State: AOJu0YxmilINMWsl6KhY+Ogoge0d26y24qlI2gkpADd3iSV5hmkvKR+5 yoFrVo40K2Da5es5yKghhf64UPVvOGo= X-Google-Smtp-Source: AGHT+IFuSLeFLDxXURuuEQzWP5yhMKcvGR093v9KFms3Mibx8bUICC/sB3jyUep4mdGKjmBtoNSsKA== X-Received: by 2002:a05:600c:2986:b0:40b:5e59:da8b with SMTP id r6-20020a05600c298600b0040b5e59da8bmr1630899wmd.158.1701982404103; Thu, 07 Dec 2023 12:53:24 -0800 (PST) Received: from wsadrian16.fritz.box ([2a02:169:59a6:0:55c4:f628:91f3:4287]) by smtp.gmail.com with ESMTPSA id ay41-20020a05600c1e2900b004063cd8105csm3032484wmb.22.2023.12.07.12.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:53:23 -0800 (PST) From: Adrian Freihofer X-Google-Original-From: Adrian Freihofer To: openembedded-core@lists.openembedded.org Cc: Adrian Freihofer Subject: [PATCH 1/4] cmake-qemu.bbclass: make it more usable Date: Thu, 7 Dec 2023 21:52:48 +0100 Message-ID: <20231207205251.4152034-1-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 07 Dec 2023 20:53:30 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/191973 Make the cmake-qemu.bbclass more usable: - Drop the CMAKE_EXEWRAPPER_ENABLED variable (which does not make much sense without the second commit of the original patch series). - Inherit qemu to make the cmake-qemu a drop in replacement for cmake. Signed-off-by: Adrian Freihofer --- meta/classes-recipe/cmake-qemu.bbclass | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/meta/classes-recipe/cmake-qemu.bbclass b/meta/classes-recipe/cmake-qemu.bbclass index 76b748f3406..46a89e2827b 100644 --- a/meta/classes-recipe/cmake-qemu.bbclass +++ b/meta/classes-recipe/cmake-qemu.bbclass @@ -5,18 +5,22 @@ # # Not all platforms are supported by Qemu. Using qemu-user therefore # involves a certain risk, which is also the reason why this feature -# is not activated by default. +# is not part of the main cmake class by default. +# +# One use case is the execution of cross-compiled unit tests with CTest +# on the build machine. If CMAKE_EXEWRAPPER_ENABLED is configured, +# cmake --build --target test +# works transparently with qemu-user. If the cmake project is developed +# with this use case in mind this works very nicely also out of an IDE +# configured to use cmake-native for cross compiling. -inherit qemu +inherit qemu cmake -CMAKE_EXEWRAPPER_ENABLED:class-native = "False" -CMAKE_EXEWRAPPER_ENABLED:class-nativesdk = "False" -CMAKE_EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" -DEPENDS:append = "${@' qemu-native' if d.getVar('CMAKE_EXEWRAPPER_ENABLED') == 'True' else ''}" +DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}" cmake_do_generate_toolchain_file:append:class-target() { - if [ "${CMAKE_EXEWRAPPER_ENABLED}" = "True" ]; then - # Write out a qemu wrapper that will be used as exe_wrapper so that camake + if [ "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" ]; then + # Write out a qemu wrapper that will be used as exe_wrapper so that cmake # can run target helper binaries through that. This also allows to execute ctest. qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_HOST}', ['${STAGING_DIR_HOST}/${libdir}','${STAGING_DIR_HOST}/${base_libdir}'])}" echo "#!/bin/sh" > "${WORKDIR}/cmake-qemuwrapper" From patchwork Thu Dec 7 20:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Freihofer X-Patchwork-Id: 35868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ACB9C10DCE for ; Thu, 7 Dec 2023 20:53:40 +0000 (UTC) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.groups.io with SMTP id smtpd.web11.103260.1701982412777181830 for ; Thu, 07 Dec 2023 12:53:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dOxqdHim; spf=pass (domain: gmail.com, ip: 209.85.128.51, mailfrom: adrian.freihofer@gmail.com) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40c07ed92fdso14350755e9.3 for ; Thu, 07 Dec 2023 12:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701982411; x=1702587211; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D6YXLAuf6RMChsFeAlVFpcjgzmBAUL2Y+E7aa24iWto=; b=dOxqdHim8nL832Pdb4dNfpVanS1PkRdIG63fPknVME//QcDQWAmBficB5vhGdk66CN PmvszkcG04Dl4xEMO/isWABox4arD99YqTalB7lTOZvl3ZcqwK3GqY3nQkHT0VIz+1Oi UukfYIWoDXGA/6MeSyPFgSpoT2horNaksophUZSRE447D3YU5f/UnT9Aiw6ATer6Nvr1 pl44X35PB077jN3vg8TgPECMgTgMwlJlw6Euv5S4/UVWfXqvMjwkPP0hB+xkkS9m/Naa n4m1phMPFP4RfG8mGmIjeOA8bgj9LAqYv8VTI4rXpHRyTasKTOG6LwMusv7ZeEGuGlSQ ndQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701982411; x=1702587211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D6YXLAuf6RMChsFeAlVFpcjgzmBAUL2Y+E7aa24iWto=; b=rraWskvriDDlmM3q9JP/hLWSeq7vmFl1EyHGJbW3kGF1Lnph7SpPYPIp4GRgb9vCZJ rBOZbCKvglP8dnhuHss6DtWKjXHdHolV7scPg+Irt+Auy4auAvN6IfMVPUB99SMsgzIu JweWMQchZcgJGeXJcDWjfA3RVp3L9upznXPxrBkSu6RRDvyhN696KbS1tl59NS51c5am w21Kyr1u4m3OjLAE2vb0t4EPoK1xlKzMEIAK/qsT7lK5zn3MXNXdzvFq7yMQqq1Ut0RY oSBXetWN9iTkwHC5hzuGZozS0/ZBz3z1M73d0c2jEeG04YxnJ4jBSHi4TNRcJXWy5o4E etgg== X-Gm-Message-State: AOJu0YwbfmVVN6kOvPPA2pHZR+8+HTGz9jsZBPG5238rvm5sS8x6CpJ7 5fdR8/HDoplPrrvoKjdZ/rnAVLeay0Q= X-Google-Smtp-Source: AGHT+IEmyTO9SBvFdHaNb/btvJ+gAzq2Po+aY3nAYPeR0u00AM/OqZ/uZR4RwW9O/pHDJHeVaJWF0A== X-Received: by 2002:a05:600c:5388:b0:40c:d4d:68ec with SMTP id hg8-20020a05600c538800b0040c0d4d68ecmr1886707wmb.183.1701982410691; Thu, 07 Dec 2023 12:53:30 -0800 (PST) Received: from wsadrian16.fritz.box ([2a02:169:59a6:0:55c4:f628:91f3:4287]) by smtp.gmail.com with ESMTPSA id ay41-20020a05600c1e2900b004063cd8105csm3032484wmb.22.2023.12.07.12.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:53:30 -0800 (PST) From: Adrian Freihofer X-Google-Original-From: Adrian Freihofer To: openembedded-core@lists.openembedded.org Cc: Adrian Freihofer Subject: [PATCH 2/4] oe-selftest: add a cpp-example recipe Date: Thu, 7 Dec 2023 21:52:49 +0100 Message-ID: <20231207205251.4152034-2-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207205251.4152034-1-adrian.freihofer@siemens.com> References: <20231207205251.4152034-1-adrian.freihofer@siemens.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 07 Dec 2023 20:53:40 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/191974 This simple C++ project supports compilation with CMake and Meson. (Autotool support could be added later on.) It's supposed to be used with oe-selftest. An artificial project has several advantages over compiling a normal CMake or Meson based project for testing purposes: - It is much faster because it can be kept minimalistic - It can cover multiple odd corner cases - No one will change it in an unpredictable way - It can support multiple build tools with only one C++ codebase Signed-off-by: Adrian Freihofer --- meta-selftest/recipes-test/cpp/.gitignore | 1 + .../recipes-test/cpp/cmake-example.bb | 25 ++++++++ .../recipes-test/cpp/cmake-example/run-ptest | 10 +++ .../recipes-test/cpp/cpp-example.inc | 24 ++++++++ .../recipes-test/cpp/files/CMakeLists.txt | 61 +++++++++++++++++++ .../cpp/files/cpp-example-lib.cpp | 33 ++++++++++ .../cpp/files/cpp-example-lib.hpp | 21 +++++++ .../recipes-test/cpp/files/cpp-example.cpp | 18 ++++++ .../recipes-test/cpp/files/meson.build | 38 ++++++++++++ .../recipes-test/cpp/files/meson.options | 3 + .../cpp/files/test-cpp-example.cpp | 25 ++++++++ .../recipes-test/cpp/meson-example.bb | 27 ++++++++ .../recipes-test/cpp/meson-example/run-ptest | 10 +++ 13 files changed, 296 insertions(+) create mode 100644 meta-selftest/recipes-test/cpp/.gitignore create mode 100644 meta-selftest/recipes-test/cpp/cmake-example.bb create mode 100644 meta-selftest/recipes-test/cpp/cmake-example/run-ptest create mode 100644 meta-selftest/recipes-test/cpp/cpp-example.inc create mode 100644 meta-selftest/recipes-test/cpp/files/CMakeLists.txt create mode 100644 meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp create mode 100644 meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp create mode 100644 meta-selftest/recipes-test/cpp/files/cpp-example.cpp create mode 100644 meta-selftest/recipes-test/cpp/files/meson.build create mode 100644 meta-selftest/recipes-test/cpp/files/meson.options create mode 100644 meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp create mode 100644 meta-selftest/recipes-test/cpp/meson-example.bb create mode 100644 meta-selftest/recipes-test/cpp/meson-example/run-ptest diff --git a/meta-selftest/recipes-test/cpp/.gitignore b/meta-selftest/recipes-test/cpp/.gitignore new file mode 100644 index 00000000000..30d388a12b7 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/.gitignore @@ -0,0 +1 @@ +build* \ No newline at end of file diff --git a/meta-selftest/recipes-test/cpp/cmake-example.bb b/meta-selftest/recipes-test/cpp/cmake-example.bb new file mode 100644 index 00000000000..aecfcf780a3 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/cmake-example.bb @@ -0,0 +1,25 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +SUMMARY = "A C++ example compiled with cmake." + +require cpp-example.inc + +SRC_URI += "file://CMakeLists.txt" + +inherit cmake-qemu + +PACKAGECONFIG[failing_test] = "-DFAILING_TEST=ON" + +FILES:${PN}-ptest += "${bindir}/test-cmake-example" + +do_run_tests () { + bbnote ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD} + eval ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD} +} +do_run_tests[doc] = "Run cmake --target=test using qemu-user" + +addtask do_run_tests after do_compile diff --git a/meta-selftest/recipes-test/cpp/cmake-example/run-ptest b/meta-selftest/recipes-test/cpp/cmake-example/run-ptest new file mode 100644 index 00000000000..94b620a1984 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/cmake-example/run-ptest @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +test-cmake-example + +# Note: run-ptests exits with exit value from test-cmake-example diff --git a/meta-selftest/recipes-test/cpp/cpp-example.inc b/meta-selftest/recipes-test/cpp/cpp-example.inc new file mode 100644 index 00000000000..ad374be9d08 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/cpp-example.inc @@ -0,0 +1,24 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +DEPENDS += "json-c" + +PV = "1.0" + +SRC_URI = "\ + file://cpp-example.cpp \ + file://cpp-example-lib.hpp \ + file://cpp-example-lib.cpp \ + file://test-cpp-example.cpp \ + file://run-ptest \ +" + +S = "${WORKDIR}" + +inherit ptest diff --git a/meta-selftest/recipes-test/cpp/files/CMakeLists.txt b/meta-selftest/recipes-test/cpp/files/CMakeLists.txt new file mode 100644 index 00000000000..6fa6917d89b --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/CMakeLists.txt @@ -0,0 +1,61 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +cmake_minimum_required(VERSION 3.22) + +project(cmake-example + VERSION 1.0.0 + LANGUAGES CXX +) + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) +option(FAILING_TEST "Compile a failing unit test to test the test infrastructure" OFF) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED On) +set(CMAKE_CXX_EXTENSIONS Off) + +include(GNUInstallDirs) + +# Linking a small library makes the example more useful for testing. +find_package(json-c) + +# A simple library linking json-c library found by pkgconfig +add_library(cmake-example-lib cpp-example-lib.cpp cpp-example-lib.hpp) +set_target_properties(cmake-example-lib PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +) +target_link_libraries(cmake-example-lib PRIVATE json-c::json-c) + +install(TARGETS cmake-example-lib + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +# A simple executable linking the library +add_executable(cmake-example cpp-example.cpp) +target_link_libraries(cmake-example PRIVATE cmake-example-lib) + +install(TARGETS cmake-example + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +# A simple test executable for testing the library +add_executable(test-cmake-example test-cpp-example.cpp) +target_link_libraries(test-cmake-example PRIVATE cmake-example-lib) + +if (FAILING_TEST) + target_compile_definitions(test-cmake-example PRIVATE FAIL_COMPARISON_STR="foo") +endif(FAILING_TEST) + +install(TARGETS test-cmake-example + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +include(CTest) +add_test(NAME test-cmake-example COMMAND test-cmake-example) diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp new file mode 100644 index 00000000000..d3dc976864b --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp @@ -0,0 +1,33 @@ +/* + * Copyright OpenEmbedded Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "cpp-example-lib.hpp" + +const std::string &CppExample::get_string() +{ + return test_string; +} + +const char *CppExample::get_json_c_version() +{ + return json_c_version(); +} + +void CppExample::print_json() +{ + struct json_object *jobj; + const int flag = JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY; + + jobj = json_object_new_object(); + json_object_object_add(jobj, "test_string", json_object_new_string(test_string.c_str())); + + std::cout << json_object_to_json_string_ext(jobj, flag) << std::endl; + + json_object_put(jobj); // Delete the json object +} diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp new file mode 100644 index 00000000000..0ad9e7b7b2d --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp @@ -0,0 +1,21 @@ +/* + * Copyright OpenEmbedded Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +struct CppExample +{ + inline static const std::string test_string = "cpp-example-lib Magic: 123456789"; + + /* Retrieve a constant string */ + const std::string &get_string(); + /* Retrieve a constant string from a library */ + const char *get_json_c_version(); + /* Call a more advanced function from a library */ + void print_json(); +}; diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp new file mode 100644 index 00000000000..9889554e0cb --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp @@ -0,0 +1,18 @@ +/* + * Copyright OpenEmbedded Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include "cpp-example-lib.hpp" + +#include + +int main() +{ + auto cpp_example = CppExample(); + std::cout << "C++ example linking " << cpp_example.get_string() << std::endl; + std::cout << "Linking json-c version " << cpp_example.get_json_c_version() << std::endl; + cpp_example.print_json(); + return 0; +} diff --git a/meta-selftest/recipes-test/cpp/files/meson.build b/meta-selftest/recipes-test/cpp/files/meson.build new file mode 100644 index 00000000000..0e2b55f3a2b --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/meson.build @@ -0,0 +1,38 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +project('meson-example', 'cpp', + version: '1.0.0', + default_options: ['cpp_std=c++17'] + ) + +jsoncdep = dependency('json-c') + +if get_option('FAILING_TEST').enabled() + add_project_arguments('-DFAIL_COMPARISON_STR=foo', language: 'cpp') +endif + +mesonexlib = shared_library('mesonexlib', + 'cpp-example-lib.cpp', 'cpp-example-lib.hpp', + version: meson.project_version(), + soversion: meson.project_version().split('.')[0], + dependencies : jsoncdep, + install : true + ) + +executable('mesonex', + 'cpp-example.cpp', + link_with : mesonexlib, + install : true + ) + +test_mesonex = executable('test-mesonex', + 'test-cpp-example.cpp', + link_with : mesonexlib, + install : true +) + +test('meson example test', test_mesonex) diff --git a/meta-selftest/recipes-test/cpp/files/meson.options b/meta-selftest/recipes-test/cpp/files/meson.options new file mode 100644 index 00000000000..58a0bf9e611 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/meson.options @@ -0,0 +1,3 @@ + +option('FAILING_TEST', type : 'feature', value : 'disabled', + description : 'Compile a failing unit test to test the test infrastructure') diff --git a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp new file mode 100644 index 00000000000..83c9bfa8444 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp @@ -0,0 +1,25 @@ +/* +* Copyright OpenEmbedded Contributors +* +* SPDX-License-Identifier: MIT +*/ + +#include "cpp-example-lib.hpp" + +#include + +/* This is for creating a failing test for testing the test infrastructure */ +#ifndef FAIL_COMPARISON_STR +#define FAIL_COMPARISON_STR "" +#endif + +int main() { + auto cpp_example = CppExample(); + auto ret_string = cpp_example.get_string(); + if(0 == ret_string.compare(CppExample::test_string + FAIL_COMPARISON_STR)) { + std::cout << "PASS: " << ret_string << " = " << CppExample::test_string << std::endl; + } else { + std::cout << "FAIL: " << ret_string << " != " << CppExample::test_string << std::endl; + return 1; + } +} diff --git a/meta-selftest/recipes-test/cpp/meson-example.bb b/meta-selftest/recipes-test/cpp/meson-example.bb new file mode 100644 index 00000000000..14a7ca8dc91 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/meson-example.bb @@ -0,0 +1,27 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +SUMMARY = "A C++ example compiled with meson." + +require cpp-example.inc + +SRC_URI += "\ + file://meson.build \ + file://meson.options \ +" + +inherit pkgconfig meson + +PACKAGECONFIG[failing_test] = "-DFAILING_TEST=enabled" + +FILES:${PN}-ptest += "${bindir}/test-mesonex" + +do_run_tests () { + meson test -C "${B}" --no-rebuild +} +do_run_tests[doc] = "Run meson test using qemu-user" + +addtask do_run_tests after do_compile diff --git a/meta-selftest/recipes-test/cpp/meson-example/run-ptest b/meta-selftest/recipes-test/cpp/meson-example/run-ptest new file mode 100644 index 00000000000..b1804f00961 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/meson-example/run-ptest @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +test-mesonex + +# Note: run-ptests exits with exit value from test-mesonex From patchwork Thu Dec 7 20:52:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Freihofer X-Patchwork-Id: 35867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73E9AC4167B for ; Thu, 7 Dec 2023 20:53:40 +0000 (UTC) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by mx.groups.io with SMTP id smtpd.web10.103709.1701982414189961902 for ; Thu, 07 Dec 2023 12:53:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HEtVuCaH; spf=pass (domain: gmail.com, ip: 209.85.128.53, mailfrom: adrian.freihofer@gmail.com) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40c0a074e71so14205725e9.1 for ; Thu, 07 Dec 2023 12:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701982412; x=1702587212; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XLNyDKm3dcWJBmJuDUQQ3AefYl+J4tad/WlxXVHQAB4=; b=HEtVuCaH8rbOI5GaADkvq2z1N+38QRbuMQ86qneCWAdyy1eymLLWslH1/S0r3Hu3qU iaCVWF6eY7qugCIMC3OMI060rL1HiWLN/2f8nAwOjXKPtikwH/wtzt75XIWM+qYOZ3Fd Go+PoosStbwk0sVZvuaqt4hJuECHybiay3uYEKE5/nqlHq86AHSScShubRkLkNgxijw4 xypS/HaSjVQYbsUOs1TSuWYV8I/3+Ui7yOFLseaE42eP1H4aN8Q3EE2Y/sp6bQpXeaOk Efy2Rtml6EFYBQ1Z19vbqgD835KWnjpSkZkYznVtKkc/Kvqt+XlbEk03atMR8Ctr24k1 1Dsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701982412; x=1702587212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XLNyDKm3dcWJBmJuDUQQ3AefYl+J4tad/WlxXVHQAB4=; b=TxVGRFGpgL0pWZfcotQCaQl52wXdZG6sDYXNEAhVKghpMYvxcA/wdZ4YuPkwGC/NLc Sck7XOzhTtFqppSJmvDHZqF77rXnqMcaVDdWFC9k6d7laHMj+1oPArzcodOArfciNVpm CDdr6X0IbZmz/OuEC9Bjn/9KAaA0o6JbDtB8VVxqf8EH2To07Kg8OFYkh+Z3IlEIFKSS P/jBLUwvDIDfmAa6HtciPED0y4x2Ey5srqbszj6EgKO5H4h0eJqDqXmBB5xyJzwqzc+Q T3GCj47WUnPeQbhtxjdM0fwQwSNFh4aykfLoLapuVuNj4j15k2GuhQXbtEswTm7f4FYx ZE5w== X-Gm-Message-State: AOJu0YxFbAzGWCihDa8oFOU5d1H2YDsyAINmJEz8XXpFV/N2hic+TZvM CT5XcVGUFw/jPBRMrq9d4OcpP0Th3Oc= X-Google-Smtp-Source: AGHT+IFX4pN4DyPJLa9yGbruMIJ3d8vsUHrYJFqphUiaSesFofT3oZ7nkNFgxwgEaPeoyHuialAfqg== X-Received: by 2002:a05:600c:468e:b0:40b:5e1b:54a7 with SMTP id p14-20020a05600c468e00b0040b5e1b54a7mr1869025wmo.51.1701982412155; Thu, 07 Dec 2023 12:53:32 -0800 (PST) Received: from wsadrian16.fritz.box ([2a02:169:59a6:0:55c4:f628:91f3:4287]) by smtp.gmail.com with ESMTPSA id ay41-20020a05600c1e2900b004063cd8105csm3032484wmb.22.2023.12.07.12.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:53:31 -0800 (PST) From: Adrian Freihofer X-Google-Original-From: Adrian Freihofer To: openembedded-core@lists.openembedded.org Cc: Adrian Freihofer Subject: [PATCH 3/4] oeqa/core/decorator: add skip if not qemu-usermode Date: Thu, 7 Dec 2023 21:52:50 +0100 Message-ID: <20231207205251.4152034-3-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207205251.4152034-1-adrian.freihofer@siemens.com> References: <20231207205251.4152034-1-adrian.freihofer@siemens.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 07 Dec 2023 20:53:40 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/191975 Add a decorator to skip tests which require the qemu-usermode machine feature. Signed-off-by: Adrian Freihofer --- meta/lib/oeqa/core/decorator/data.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/meta/lib/oeqa/core/decorator/data.py b/meta/lib/oeqa/core/decorator/data.py index de881e097ab..5444b2cb751 100644 --- a/meta/lib/oeqa/core/decorator/data.py +++ b/meta/lib/oeqa/core/decorator/data.py @@ -185,6 +185,16 @@ class skipIfNotQemu(OETestDecorator): if not self.case.td.get('MACHINE', '').startswith('qemu'): self.case.skipTest('Test only runs on qemu machines') +@registerDecorator +class skipIfNotQemuUsermode(OETestDecorator): + """ + Skip test if MACHINE_FEATURES does not contain qemu-usermode + """ + def setUpDecorator(self): + self.logger.debug("Checking if MACHINE_FEATURES does not contain qemu-usermode") + if 'qemu-usermode' not in self.case.td.get('MACHINE_FEATURES', '').split(): + self.case.skipTest('Test requires qemu-usermode in MACHINE_FEATURES') + @registerDecorator class skipIfQemu(OETestDecorator): """ From patchwork Thu Dec 7 20:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Freihofer X-Patchwork-Id: 35869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82E5DC10DC3 for ; Thu, 7 Dec 2023 20:53:40 +0000 (UTC) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.groups.io with SMTP id smtpd.web10.103710.1701982415795400553 for ; Thu, 07 Dec 2023 12:53:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MNnhRxzL; spf=pass (domain: gmail.com, ip: 209.85.128.51, mailfrom: adrian.freihofer@gmail.com) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40c05ce04a8so16131295e9.0 for ; Thu, 07 Dec 2023 12:53:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701982414; x=1702587214; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lzvwhVBLaFwCFnKT7Wy3sABu5MEzs8VM3acdZVZIRbA=; b=MNnhRxzLv/gNiMtSbVcxc1AHUibolVDYxv9bFnsE3Z86m/MXXePqkEDyYavRrllpcE /8s+hrHZfSgFBrY1qv83ceVOQG6lsRLrEauEOnBJUMf1Bjbl800GBzlvokKW5lbH7hd6 8TbpjtptYDrsv/8eKEbGaW6Bd6w1CbNabGOrDX3bGZOQlOjeiQveT1D0Da1UXcTOtLFM 2Uq/I/kc4LfizrspHFgBBT3opAdqbXPPYGyBQNbN8GMgHN7gOyfe5MlGNlLlhnZ7c/cn bAwIEJ0+udJVKridi1tRNM506lzzwDcXi7ZEL/zS0ArLLh8PyoUQfeR+UbHpmSOfzIzf SuUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701982414; x=1702587214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lzvwhVBLaFwCFnKT7Wy3sABu5MEzs8VM3acdZVZIRbA=; b=imWn18j8AOhOIrK8kdgQAONbQq5nxkFFsxefVNvT71uP+kclqRna/49tsm7I0jcw3T lA/Lvi36EGn+F+wpb/73TZ/zjsPrDXvXDLfE0cKyQg0Gkk95TJdkhZjoxfQZoyAsXlv7 4+Kc6Lq5Ds8ZfqexBcAG/jRF3iaklFNkv3nU5P0aiOBOrefDs3xYLP3mieYvpewd26XJ vIcCjNGrS3HV7VX5p4QyGgSx9luIWyYzhJHeN4BCm91Z7vrGAlAZRx0jTXaHn4slfdUi XwGsDoDR05StszYuA4FkZEs2QZY3PjNtQ42lkn4CXE6o/hmW5u+G/AgYrUoC50C5kKPG fl3Q== X-Gm-Message-State: AOJu0YzDhGo5u6jgLVhQlFffOTYURvfuVS3yTT94iZQ3e88rquIwmw39 TstRJ+mLgW6nkpvUcADS4A2oxElCWo8= X-Google-Smtp-Source: AGHT+IGdTvHqd+0sD3S22kdgoNR7V61nCTlEku9+7t4Y9MCkOq7tKzPA5PFjGDreje7xM54cCr+dbA== X-Received: by 2002:a05:600c:4704:b0:40b:385f:24b5 with SMTP id v4-20020a05600c470400b0040b385f24b5mr914045wmo.15.1701982413998; Thu, 07 Dec 2023 12:53:33 -0800 (PST) Received: from wsadrian16.fritz.box ([2a02:169:59a6:0:55c4:f628:91f3:4287]) by smtp.gmail.com with ESMTPSA id ay41-20020a05600c1e2900b004063cd8105csm3032484wmb.22.2023.12.07.12.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:53:33 -0800 (PST) From: Adrian Freihofer X-Google-Original-From: Adrian Freihofer To: openembedded-core@lists.openembedded.org Cc: Adrian Freihofer Subject: [PATCH 4/4] oe-selftest: add tests for C and C++ build tools Date: Thu, 7 Dec 2023 21:52:51 +0100 Message-ID: <20231207205251.4152034-4-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207205251.4152034-1-adrian.freihofer@siemens.com> References: <20231207205251.4152034-1-adrian.freihofer@siemens.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 07 Dec 2023 20:53:40 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/191976 Add new file for C and C++ build tools. The initial implemmentation contains a class for CMake and one for Meson. At least these first tests for the qemu-usermode share most of the code. That's why there is only one c_ccp.py file and not for example a cmake.py and a meson.py file. Signed-off-by: Adrian Freihofer --- meta/lib/oeqa/selftest/cases/c_cpp.py | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 meta/lib/oeqa/selftest/cases/c_cpp.py diff --git a/meta/lib/oeqa/selftest/cases/c_cpp.py b/meta/lib/oeqa/selftest/cases/c_cpp.py new file mode 100644 index 00000000000..9a70ce29f56 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/c_cpp.py @@ -0,0 +1,60 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.selftest.case import OESelftestTestCase +from oeqa.core.decorator.data import skipIfNotQemuUsermode +from oeqa.utils.commands import bitbake + + +class CCppTests(OESelftestTestCase): + + @skipIfNotQemuUsermode() + def _qemu_usermode(self, recipe_name): + self.add_command_to_tearDown("bitbake -c clean %s" % recipe_name) + bitbake("%s -c run_tests" % recipe_name) + + @skipIfNotQemuUsermode() + def _qemu_usermode_failing(self, recipe_name): + config = 'PACKAGECONFIG:pn-%s = "failing_test"' % recipe_name + self.write_config(config) + self.add_command_to_tearDown("bitbake -c clean %s" % recipe_name) + result = bitbake("%s -c run_tests" % recipe_name, ignore_status=True) + self.assertNotEqual(0, result.status, "command: %s is expected to fail but passed, status: %s, output: %s, error: %s" % ( + result.command, result.status, result.output, result.error)) + + +class CMakeTests(CCppTests): + def test_cmake_qemu(self): + """Test for cmake-qemu.bbclass good case + + compile the cmake-example and verify the CTests pass in qemu-user. + qemu-user is configured by CMAKE_CROSSCOMPILING_EMULATOR. + """ + self._qemu_usermode("cmake-example") + + def test_cmake_qemu_failing(self): + """Test for cmake-qemu.bbclass bad case + + Break the comparison in the test code and verify the CTests do not pass. + """ + self._qemu_usermode_failing("cmake-example") + + +class MesonTests(CCppTests): + def test_meson_qemu(self): + """Test the qemu-user feature of the meson.bbclass good case + + compile the meson-example and verify the Unit Test pass in qemu-user. + qemu-user is configured by meson's exe_wrapper option. + """ + self._qemu_usermode("meson-example") + + def test_meson_qemu_failing(self): + """Test the qemu-user feature of the meson.bbclass bad case + + Break the comparison in the test code and verify the Unit Test does not pass in qemu-user. + """ + self._qemu_usermode_failing("meson-example")