From a0abe34748c8ca3c2c0de073bff13559eb912243 Mon Sep 17 00:00:00 2001 From: Tulio Magno Quites Machado Filho Date: Nov 25 2022 13:22:07 +0000 Subject: Add 2 new tests that validate the ppc64le long double ABI This patch is highly based on the ppc64le-long-double test that was available in the previous commit. However, it adds an extra step that ignores mock if the test is run inside an unprivileged container solution. The first test (exp) evaluates if clang is able to build C programs for both IBM double-double as well as IEEE 128-bit long double. As Fedora uses glibc by default, which supports both scenarios, both executables should work. The second test (parse) uses clang in order to evaluate if C++ programs built with default parameters and linking against libc++ use IEEE 128-bit long double. This test should be extended in the future in order to evaluate that clang is able to generate C++ programs for both IBM double-double and IEEE 128-bit long double using libstdc++. This can't be enabled now because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81122 . --- diff --git a/ppc64le-long-double/exp.c b/ppc64le-long-double/exp.c new file mode 100644 index 0000000..56dc872 --- /dev/null +++ b/ppc64le-long-double/exp.c @@ -0,0 +1,11 @@ +/* Use a libm funcion that returns well-known results depending on the long + double format being used. */ + +#include +#include + +int main() { + printf("%La\n", expl(1.0L)); + + return 0; +} diff --git a/ppc64le-long-double/main.fmf b/ppc64le-long-double/main.fmf new file mode 100644 index 0000000..02f25c5 --- /dev/null +++ b/ppc64le-long-double/main.fmf @@ -0,0 +1,43 @@ +summary: Test binary compatibility of the long double format on ppc64le +test: $WITH_SCL ./runtest.sh +duration: 1h +framework: shell +tier: 1 +component: + - llvm-toolset + - clang +extra-summary: /tools/clang/ppc64le-long-double +extra-task: /tools/clang/ppc64le-long-double +extra-nitrate: TC#0614129 + +adjust: + # Common requirements when LLVM is not SCL-ized + - require+: + - clang + when: "collection is not defined" + + - because: "Fedora CI runs in x86_64 only, emulate with qemu and mock" + require+: + - qemu-user-static + - mock + test: ./runtest-fedora.sh + when: distro == fedora and arch == x86_64 + continue: false + + - enabled: false + when: arch != ppc64le + + - require+: + - gcc + when: distro != fedora + + # Requirements for SCL-ized LLVM + - require+: + - llvm-toolset-13.0-clang + when: "collection == llvm-toolset-13.0" + - require+: + - llvm-toolset-14.0-clang + when: "collection == llvm-toolset-14.0" + - require+: + - llvm-toolset-15.0-clang + when: "collection == llvm-toolset-15.0" diff --git a/ppc64le-long-double/parse.cpp b/ppc64le-long-double/parse.cpp new file mode 100644 index 0000000..a2eb734 --- /dev/null +++ b/ppc64le-long-double/parse.cpp @@ -0,0 +1,15 @@ +/* Check how the C++ standard library parses the following number correctly. + On IBM double-double, the 7 least significant bits are messed up. + On IEEE 128-bit long double, this number is correctly represented. */ +#include +#include + +int main() { + long double d; + std::stringstream ss("0x1.5bf0a8b1457695355fb8ac404e7ap+1"); + + ss >> d; + printf("%La\n", d); + + return 0; +} diff --git a/ppc64le-long-double/runtest-fedora.sh b/ppc64le-long-double/runtest-fedora.sh new file mode 100755 index 0000000..3177313 --- /dev/null +++ b/ppc64le-long-double/runtest-fedora.sh @@ -0,0 +1,47 @@ +set -e + +fedora_release=`rpm -E %{fedora}` +mock_root=fedora-$fedora_release-ppc64le +triple=ppc64le-redhat-linux + +mock_cmd="mock -r $mock_root --isolation=simple" + +run_test () { + test_name=$1 + expected=$2 + + echo "Running $test_name" + echo "Expected output: $expected" + actual=$($mock_cmd -q --shell ./$test_name) + echo "Actual output: $actual" + + if [[ x$expected == x$actual ]]; then + return 0; + else + return 1; + fi +} + +# Avoid running mock in unsupported environments, e.g. on a non-privileged +# container. +if $mock_cmd -q --shell true; then + $mock_cmd --install clang libcxx-devel + + # glibc supports both long double types, so the following should work. + $mock_cmd --copyin exp.c /builddir/exp.c + $mock_cmd -q --shell -- clang -mabi=ibmlongdouble -fno-builtin exp.c -o exp-ibm -lm + $mock_cmd -q --shell -- clang -mabi=ieeelongdouble -fno-builtin exp.c -o exp-ieee -lm + + run_test exp-ibm "0x1.5bf0a8b1457695355fb8ac404ecp+1" + run_test exp-ieee "0x1.5bf0a8b1457695355fb8ac404e7ap+1" + + # Test if libc++ is providing the correct ABI. + $mock_cmd --copyin parse.cpp /builddir/parse.cpp + $mock_cmd -q --shell -- clang++ -stdlib=libc++ -fno-builtin parse.cpp -o parse -lm + + if [[ $fedora_release -gt 37 ]]; then + run_test parse "0x1.5bf0a8b1457695355fb8ac404e7ap+1" + else + run_test parse "0x1.5bf0a8b1457695355fb8ac404e8p+1" + fi +fi diff --git a/ppc64le-long-double/runtest.sh b/ppc64le-long-double/runtest.sh new file mode 100755 index 0000000..be357d5 --- /dev/null +++ b/ppc64le-long-double/runtest.sh @@ -0,0 +1,29 @@ +set -e + +triple=ppc64le-redhat-linux + + +run_test () { + test_name=$1 + expected=$2 + + echo "Running $test_name" + echo "Expected output: $expected" + actual=$(./$test_name) + echo "Actual output: $actual" + + if [[ x$expected == x$actual ]]; then + return 0; + else + return 1; + fi +} + +# glibc supports both long double types, so the following should work. +clang -mabi=ibmlongdouble -fno-builtin exp.c -o exp-ibm -lm +clang -mabi=ieeelongdouble -fno-builtin exp.c -o exp-ieee -lm + +run_test exp-ibm "0x1.5bf0a8b1457695355fb8ac404ecp+1" +run_test exp-ieee "0x1.5bf0a8b1457695355fb8ac404e7ap+1" + +# TODO: Build and run the parse test when CentOS/RHEL get libc++-devel.