gitlab-ci: Add ppc64el and s390x cross-build jobs

Using LLVM 8 for ppc64el and 7 for s390x (which hits some coroutine
related issues with LLVM 8).

There are some test failures we need to ignore for now. Also, the
timeout needs to be bumped from the default 30s for some tests, because
they can take longer under emulation.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3643>
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c7cf8ee..a194d6c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -112,7 +112,7 @@
     - .debian@container-ifnot-exists
     - .container
   variables:
-    DEBIAN_TAG: &x86_build "2020-01-14"
+    DEBIAN_TAG: &x86_build "2020-02-05"
 
 .use-x86_build:
   variables:
@@ -312,6 +312,7 @@
       -D gallium-va=false
       -D gallium-xa=false
       -D gallium-nine=false
+    LLVM_VERSION: "8"
 
 .meson-arm:
   extends:
@@ -342,7 +343,6 @@
     - .meson-arm
     - .ci-deqp-artifacts
   variables:
-    LLVM_VERSION: "8"
     VULKAN_DRIVERS: "freedreno,amd"
   script:
     - .gitlab-ci/meson-build.sh
@@ -467,6 +467,25 @@
       -D osmesa=classic
       -D werror=true
 
+meson-s390x:
+  extends:
+    - .meson-cross
+  variables:
+    CROSS: s390x
+    GALLIUM_DRIVERS: "swrast"
+    LLVM_VERSION: "7"
+  script:
+    - dpkg -i /var/cache/apt/archives/$CROSS/*.deb
+    - .gitlab-ci/meson-build.sh
+
+meson-ppc64el:
+  extends:
+    - meson-s390x
+  variables:
+    CROSS: ppc64el
+    GALLIUM_DRIVERS: "nouveau,swrast,virgl"
+    LLVM_VERSION: "8"
+
 meson-mingw32-x86_64:
   extends: .meson-build
   variables:
diff --git a/.gitlab-ci/container/x86_build.sh b/.gitlab-ci/container/x86_build.sh
index a66b1dd..141c198 100644
--- a/.gitlab-ci/container/x86_build.sh
+++ b/.gitlab-ci/container/x86_build.sh
@@ -5,7 +5,7 @@
 
 export DEBIAN_FRONTEND=noninteractive
 
-CROSS_ARCHITECTURES="i386"
+CROSS_ARCHITECTURES="i386 ppc64el s390x"
 for arch in $CROSS_ARCHITECTURES; do
     dpkg --add-architecture $arch
 done
@@ -75,13 +75,12 @@
       libxvmc-dev \
       libxxf86vm-dev \
       llvm-6.0-dev \
-      llvm-7-dev \
-      llvm-8-dev \
       llvm-9-dev \
       meson \
       pkg-config \
       python-mako \
       python3-mako \
+      qemu-user \
       scons \
       x11proto-dri2-dev \
       x11proto-gl-dev \
@@ -96,8 +95,32 @@
             libdrm-dev:${arch} \
             libelf-dev:${arch} \
             libexpat1-dev:${arch}
+
+    if [ "$arch" = "s390x" ]; then
+        LLVM_VERSION=7
+    else
+        LLVM_VERSION=8
+    fi
+
+    if [ "$arch" != "i386" ]; then
+        mkdir /var/cache/apt/archives/${arch}
+        apt-get install -y --no-remove \
+                libffi-dev:${arch} \
+                libllvm${LLVM_VERSION}:${arch} \
+                libstdc++6:${arch} \
+                libtinfo-dev:${arch} \
+
+        # Download llvm-* packages, but don't install them yet, since they can
+        # only be installed for one architecture at a time
+        apt-get install -o Dir::Cache::archives=/var/cache/apt/archives/$arch --download-only -y --no-remove \
+            llvm-${LLVM_VERSION}-dev:${arch}
+    fi
 done
 
+apt-get install -y --no-remove \
+      llvm-7-dev \
+      llvm-8-dev \
+
 # for 64bit windows cross-builds
 apt-get install -y --no-remove \
     libz-mingw-w64-dev \
@@ -193,9 +216,10 @@
   if [ "$arch" = "i386" ]; then
     # Work around a bug in debcrossgen that should be fixed in the next release
     sed -i "s|cpu_family = 'i686'|cpu_family = 'x86'|g" "$cross_file"
-    # Don't need wrapper for i386 executables
-    sed -i -e '/\[properties\]/a\' -e "needs_exe_wrapper = False" "$cross_file"
   fi
+
+  # Rely on qemu-user being configured in binfmt_misc on the host
+  sed -i -e '/\[properties\]/a\' -e "needs_exe_wrapper = False" "$cross_file"
 done
 
 
diff --git a/.gitlab-ci/cross-xfail-ppc64el b/.gitlab-ci/cross-xfail-ppc64el
new file mode 100644
index 0000000..aa120d0
--- /dev/null
+++ b/.gitlab-ci/cross-xfail-ppc64el
@@ -0,0 +1,4 @@
+lp_test_arit
+roundeven
+u_format_test
+u_half_test
\ No newline at end of file
diff --git a/.gitlab-ci/cross-xfail-s390x b/.gitlab-ci/cross-xfail-s390x
new file mode 100644
index 0000000..d8f0365
--- /dev/null
+++ b/.gitlab-ci/cross-xfail-s390x
@@ -0,0 +1,5 @@
+load_store_vectorizer
+lp_test_arit
+lp_test_format
+lp_test_printf
+u_format_test
diff --git a/src/compiler/glsl/glcpp/meson.build b/src/compiler/glsl/glcpp/meson.build
index 9fc8d9d..5f3d857 100644
--- a/src/compiler/glsl/glcpp/meson.build
+++ b/src/compiler/glsl/glcpp/meson.build
@@ -83,6 +83,7 @@
         '--@0@'.format(m),
       ],
       suite : ['compiler', 'glcpp'],
+      timeout: 60,
     )
   endforeach
 endif
diff --git a/src/compiler/glsl/tests/meson.build b/src/compiler/glsl/tests/meson.build
index e9272fe..5914627 100644
--- a/src/compiler/glsl/tests/meson.build
+++ b/src/compiler/glsl/tests/meson.build
@@ -88,6 +88,7 @@
     ),
   ],
   suite : ['compiler', 'glsl'],
+  timeout: 60,
 )
 
 test(
diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
index b35eb85..3151127 100644
--- a/src/compiler/nir/meson.build
+++ b/src/compiler/nir/meson.build
@@ -349,6 +349,7 @@
       dependencies : [dep_thread, idep_gtest, idep_nir, idep_mesautil],
     ),
     suite : ['compiler', 'nir'],
+    should_fail : meson.get_cross_property('xfail', '').contains('load_store_vectorizer'),
   )
 
   test(
diff --git a/src/gallium/drivers/llvmpipe/meson.build b/src/gallium/drivers/llvmpipe/meson.build
index d3542fa..570d1b2 100644
--- a/src/gallium/drivers/llvmpipe/meson.build
+++ b/src/gallium/drivers/llvmpipe/meson.build
@@ -125,6 +125,8 @@
         link_with : [libllvmpipe, libgallium],
       ),
       suite : ['llvmpipe'],
+      should_fail : meson.get_cross_property('xfail', '').contains(t),
+      timeout: 120,
     )
   endforeach
 endif
diff --git a/src/util/meson.build b/src/util/meson.build
index 7791be7..3b2ac08 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -248,6 +248,7 @@
       dependencies : [dep_m],
     ),
     suite : ['util'],
+    should_fail : meson.get_cross_property('xfail', '').contains('roundeven'),
   )
 
   # FIXME: this test crashes on windows
diff --git a/src/util/tests/fast_idiv_by_const/meson.build b/src/util/tests/fast_idiv_by_const/meson.build
index 2a341d1..00b2467 100644
--- a/src/util/tests/fast_idiv_by_const/meson.build
+++ b/src/util/tests/fast_idiv_by_const/meson.build
@@ -27,4 +27,5 @@
     include_directories : inc_common,
   ),
   suite : ['util'],
+  timeout: 60,
 )
diff --git a/src/util/tests/sparse_array/meson.build b/src/util/tests/sparse_array/meson.build
index 036591e..7c86efe 100644
--- a/src/util/tests/sparse_array/meson.build
+++ b/src/util/tests/sparse_array/meson.build
@@ -27,4 +27,5 @@
     include_directories : inc_common,
   ),
   suite : ['util'],
+  timeout: 60,
 )