Message ID | 20250113204447.14948-1-gavrosc@yahoo.com |
---|---|
State | New |
Headers | show |
Series | [meta-oe] Sanity test for cpp toolchain | expand |
Thank you for your submission. Patchtest identified one or more issues with the patch. Please see the log below for more information: --- Testing patch /home/patchtest/share/mboxes/meta-oe-Sanity-test-for-cpp-toolchain.patch FAIL: test bugzilla entry format: Bugzilla issue ID is not correctly formatted - specify it with format: "[YOCTO #<bugzilla ID>]" (test_mbox.TestMbox.test_bugzilla_entry_format) FAIL: test shortlog format: Commit shortlog (first line of commit message) should follow the format "<target>: <summary>" (test_mbox.TestMbox.test_shortlog_format) FAIL: test target mailing list: Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists (test_mbox.TestMbox.test_target_mailing_list) PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence) PASS: test author valid (test_mbox.TestMbox.test_author_valid) PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence) PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags) PASS: test max line length (test_metadata.TestMetadata.test_max_line_length) PASS: test mbox format (test_mbox.TestMbox.test_mbox_format) PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade) PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length) SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint) SKIP: pretest src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.pretest_src_uri_left_files) SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore) SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format) SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence) SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format) SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned) SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence) SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence) SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint) SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head) SKIP: test src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.test_src_uri_left_files) SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence) --- Please address the issues identified and submit a new revision of the patch, or alternatively, reply to this email with an explanation of why the patch should be accepted. If you believe these results are due to an error in patchtest, please submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category under 'Yocto Project Subprojects'). For more information on specific failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank you!
On 2025-01-13 3:44 p.m., Christos Gavros via lists.openembedded.org wrote: > Some users have reported issues which were caused because they were missing the right libstdc++-version-dev in their system. > A new function with the name 'check_cpp_toolchain' was added in sanity.bbclass in order to verify that the host system can compile and link successfully a 'hello world' c++ code. > In case the test fails , the build will abort > Fixes [YOCTO #bug-15712] Thanks for the patch. It's a good start! Repeating what I said on IRC about the patchtest errors: Maybe shortlog: sanity: test for cpp toolchain Drop the meta-oe prefix, this is oe-core and your email will automagically get an oe-core prefix as you can see above. YP BZ # is optional but patchtest documented the expected format. > > Signed-off-by: Christos Gavros<gavrosc@yahoo.com> > --- > meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > > diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass > index 7b8a497d5a..ca7f8117d6 100644 > --- a/meta/classes-global/sanity.bbclass > +++ b/meta/classes-global/sanity.bbclass > @@ -780,6 +780,44 @@ def sanity_check_locale(d): > except locale.Error: > raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d) > > +def check_cpp_toolchain(): > + # it checks if the c++ compiling and linking works properly in the native system The bug talks about testing, "linking to libstdc++" so best to mention that rather than have it implied. > + import os > + import subprocess > + from tempfile import NamedTemporaryFile > + > + try: > + with NamedTemporaryFile(delete=False, suffix=".cpp") as cpp_file: > + cpp_code = """ > + #include <iostream> > + int main() { > + std::cout << "Hello, World!" << std::endl; > + return 0; > + } > + """ > + cpp_file.write(cpp_code.encode('utf-8')) > + cpp_file_name = cpp_file.name > + > + output_binary = cpp_file_name + ".out" > + compile_command = ['g++', '-std=c++17', cpp_file_name, '-o', output_binary] Maybe use BUILD_CC here? Oddly, that variable isn't in the docs but BUILD_CC_ARCH is: https://docs.yoctoproject.org/ref-manual/variables.html#term-BUILD_CC_ARCH CC-ing Antonin to see if that's a bug. Yocto/OE supports or would like support more than just GCC mostly for target but it would be nice to use the compiler that BUILD_CC points to so that there isn't too much gcc hard-coded. > + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > + > + if result.returncode == 0: > + #os.remove(cpp_file_name) > + #os.remove(output_binary) Did you mean to leave these two lines commented out? If so why? Add a comment explaining why if needed. ../Randy > + return False > + else: > + bb.fatal(f"C++ toolchain check failed during compilation or linking. Error:\n{result.stderr.decode()}") > + return True > + except Exception as e: > + bb.fatal(f"An unexpected issue occured during the C++ toolchain check {str(e)}") > + return True > + finally: > + if cpp_file_name and os.path.exists(cpp_file_name): > + os.remove(cpp_file_name) > + if output_binary and os.path.exists(output_binary): > + os.remove(output_binary) > + > def check_sanity_everybuild(status, d): > import os, stat > # Sanity tests which test the users environment so need to run at each build (or are so cheap > @@ -975,6 +1013,8 @@ def check_sanity_everybuild(status, d): > # forms, such as /bin/dash, bin/bash, /bin/bash.bash ... > if '/dash' not in real_sh and '/bash' not in real_sh: > status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh) > + > + check_cpp_toolchain() > > def check_sanity(sanity_data): > class SanityStatus(object): > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#209743):https://lists.openembedded.org/g/openembedded-core/message/209743 > Mute This Topic:https://lists.openembedded.org/mt/110595436/3616765 > Group Owner:openembedded-core+owner@lists.openembedded.org > Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [randy.macleod@windriver.com] > -=-=-=-=-=-=-=-=-=-=-=- >
Hello Christos! I agree with Randy, this is a good start :) Le 13/01/2025 à 21:44, Christos Gavros via lists.openembedded.org a écrit : > Some users have reported issues which were caused because they were missing the right libstdc++-version-dev in their system. > A new function with the name 'check_cpp_toolchain' was added in sanity.bbclass in order to verify that the host system can compile and link successfully a 'hello world' c++ code. > In case the test fails , the build will abort > Fixes [YOCTO #bug-15712] Patch messages are usually wrapped at 75 characters Like in https://www.kernel.org/doc/html/latest/process/submitting-patches.html#the-canonical-patch-format but we did not document this rule... (This is loosely enforced by patchtest that starts complaining at 200 character lines) > Signed-off-by: Christos Gavros <gavrosc@yahoo.com> > --- > meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > > diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass > index 7b8a497d5a..ca7f8117d6 100644 > --- a/meta/classes-global/sanity.bbclass > +++ b/meta/classes-global/sanity.bbclass > @@ -780,6 +780,44 @@ def sanity_check_locale(d): > except locale.Error: > raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d) > > +def check_cpp_toolchain(): > + # it checks if the c++ compiling and linking works properly in the native system > + import os > + import subprocess > + from tempfile import NamedTemporaryFile > + > + try: > + with NamedTemporaryFile(delete=False, suffix=".cpp") as cpp_file: > + cpp_code = """ > + #include <iostream> > + int main() { > + std::cout << "Hello, World!" << std::endl; > + return 0; > + } > + """ > + cpp_file.write(cpp_code.encode('utf-8')) > + cpp_file_name = cpp_file.name > + > + output_binary = cpp_file_name + ".out" > + compile_command = ['g++', '-std=c++17', cpp_file_name, '-o', output_binary] > + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > + > + if result.returncode == 0: > + #os.remove(cpp_file_name) > + #os.remove(output_binary) > + return False > + else: > + bb.fatal(f"C++ toolchain check failed during compilation or linking. Error:\n{result.stderr.decode()}") If I understood correctly bb.fatal() here will prevent other sanity checks to run. The idea is to do as much of those checks as possible. You can reuse the pattern seen in other checks: the function either return an error message as a string or None. And then, calling the function like this: status.addresult(check_cpp_toolchain()) > + return True > + except Exception as e: > + bb.fatal(f"An unexpected issue occured during the C++ toolchain check {str(e)}") s/occured/occurred/ > + return True > + finally: > + if cpp_file_name and os.path.exists(cpp_file_name): > + os.remove(cpp_file_name) > + if output_binary and os.path.exists(output_binary): > + os.remove(output_binary) > + > def check_sanity_everybuild(status, d): > import os, stat > # Sanity tests which test the users environment so need to run at each build (or are so cheap > @@ -975,6 +1013,8 @@ def check_sanity_everybuild(status, d): > # forms, such as /bin/dash, bin/bash, /bin/bash.bash ... > if '/dash' not in real_sh and '/bash' not in real_sh: > status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh) > + > + check_cpp_toolchain() See above comment about calling status.addresult() > > def check_sanity(sanity_data): > class SanityStatus(object): If you need help implementing the recommended changes, don't hesitate to ask here or on IRC :) Regards,
Hi Randy, On Mon Jan 13, 2025 at 11:02 PM CET, Randy MacLeod wrote: [...] >> + >> + output_binary = cpp_file_name + ".out" >> + compile_command = ['g++', '-std=c++17', cpp_file_name, '-o', output_binary] > > Maybe use BUILD_CC here? > > Oddly, that variable isn't in the docs but BUILD_CC_ARCH is: > https://docs.yoctoproject.org/ref-manual/variables.html#term-BUILD_CC_ARCH > > CC-ing Antonin to see if that's a bug. Looks like a bug to me :) I've created one: https://bugzilla.yoctoproject.org/show_bug.cgi?id=15719 Thanks! Antonin
diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass index 7b8a497d5a..ca7f8117d6 100644 --- a/meta/classes-global/sanity.bbclass +++ b/meta/classes-global/sanity.bbclass @@ -780,6 +780,44 @@ def sanity_check_locale(d): except locale.Error: raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d) +def check_cpp_toolchain(): + # it checks if the c++ compiling and linking works properly in the native system + import os + import subprocess + from tempfile import NamedTemporaryFile + + try: + with NamedTemporaryFile(delete=False, suffix=".cpp") as cpp_file: + cpp_code = """ + #include <iostream> + int main() { + std::cout << "Hello, World!" << std::endl; + return 0; + } + """ + cpp_file.write(cpp_code.encode('utf-8')) + cpp_file_name = cpp_file.name + + output_binary = cpp_file_name + ".out" + compile_command = ['g++', '-std=c++17', cpp_file_name, '-o', output_binary] + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.returncode == 0: + #os.remove(cpp_file_name) + #os.remove(output_binary) + return False + else: + bb.fatal(f"C++ toolchain check failed during compilation or linking. Error:\n{result.stderr.decode()}") + return True + except Exception as e: + bb.fatal(f"An unexpected issue occured during the C++ toolchain check {str(e)}") + return True + finally: + if cpp_file_name and os.path.exists(cpp_file_name): + os.remove(cpp_file_name) + if output_binary and os.path.exists(output_binary): + os.remove(output_binary) + def check_sanity_everybuild(status, d): import os, stat # Sanity tests which test the users environment so need to run at each build (or are so cheap @@ -975,6 +1013,8 @@ def check_sanity_everybuild(status, d): # forms, such as /bin/dash, bin/bash, /bin/bash.bash ... if '/dash' not in real_sh and '/bash' not in real_sh: status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh) + + check_cpp_toolchain() def check_sanity(sanity_data): class SanityStatus(object):
Some users have reported issues which were caused because they were missing the right libstdc++-version-dev in their system. A new function with the name 'check_cpp_toolchain' was added in sanity.bbclass in order to verify that the host system can compile and link successfully a 'hello world' c++ code. In case the test fails , the build will abort Fixes [YOCTO #bug-15712] Signed-off-by: Christos Gavros <gavrosc@yahoo.com> --- meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)