ci: bare-metal: use nginx to get results from DUT

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2655
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5661>
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ab22434..498e1fd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -336,7 +336,7 @@
     - .fdo.container-build@debian
     - .container
   variables:
-    FDO_DISTRIBUTION_TAG: &arm_test-base "2020-07-09-cache"
+    FDO_DISTRIBUTION_TAG: &arm_test-base "2020-07-18-nginx"
 
 .use-arm_test-base:
   extends:
@@ -354,7 +354,7 @@
   extends:
     - .use-arm_test-base
   variables:
-    FDO_DISTRIBUTION_TAG: &arm64_test "2020-07-09-cache"
+    FDO_DISTRIBUTION_TAG: &arm64_test "2020-07-18-nginx"
 
 .use-arm64_test:
   variables:
diff --git a/.gitlab-ci/bare-metal/fastboot.sh b/.gitlab-ci/bare-metal/fastboot.sh
index ad4a665..9adda12 100755
--- a/.gitlab-ci/bare-metal/fastboot.sh
+++ b/.gitlab-ci/bare-metal/fastboot.sh
@@ -45,6 +45,13 @@
   exit 1
 fi
 
+if [ -z "$BM_WEBDAV_IP" -o -z "$BM_WEBDAV_PORT" ]; then
+  echo "BM_WEBDAV_IP and/or BM_WEBDAV_PORT is not set - no results will be uploaded from DUT!"
+  WEBDAV_CMDLINE=""
+else
+  WEBDAV_CMDLINE="webdav=http://$BM_WEBDAV_IP:$BM_WEBDAV_PORT"
+fi
+
 set -ex
 
 # Clear out any previous run's artifacts.
@@ -72,9 +79,17 @@
   --create artifacts/fastboot.img \
   -k Image.gz-dtb \
   -r rootfs.cpio.gz \
-  -c cmdline="$BM_CMDLINE"
+  -c cmdline="$BM_CMDLINE $WEBDAV_CMDLINE"
 rm Image.gz-dtb
 
+# Start nginx to get results from DUT
+if [ -n "$WEBDAV_CMDLINE" ]; then
+  ln -s `pwd`/results /results
+  sed -i s/80/$BM_WEBDAV_PORT/g /etc/nginx/sites-enabled/default
+  sed -i s/www-data/root/g /etc/nginx/nginx.conf
+  nginx
+fi
+
 # Start watching serial, and power up the device.
 if [ -n "$BM_SERIAL" ]; then
   $BM/serial-buffer.py $BM_SERIAL | tee artifacts/serial-output.txt &
diff --git a/.gitlab-ci/bare-metal/init.sh b/.gitlab-ci/bare-metal/init.sh
index 9dfef68..00bee38 100755
--- a/.gitlab-ci/bare-metal/init.sh
+++ b/.gitlab-ci/bare-metal/init.sh
@@ -13,6 +13,18 @@
 echo "nameserver 8.8.8.8" > /etc/resolv.conf
 
 if sh $BARE_METAL_TEST_SCRIPT; then
+  OK=1
+else
+  OK=0
+fi
+
+# upload artifacts via webdav
+WEBDAV=$(cat /proc/cmdline | tr " " "\n" | grep webdav | cut -d '=' -f 2 || true)
+if [ -n "$WEBDAV" ]; then
+  find /results -type f -exec curl -T {} $WEBDAV/{} \;
+fi
+
+if [ $OK -eq 1 ]; then
     echo "bare-metal result: pass"
 else
     echo "bare-metal result: fail"
diff --git a/.gitlab-ci/bare-metal/nginx-default-site b/.gitlab-ci/bare-metal/nginx-default-site
new file mode 100644
index 0000000..7c46fa2
--- /dev/null
+++ b/.gitlab-ci/bare-metal/nginx-default-site
@@ -0,0 +1,20 @@
+server {
+    listen 80 default_server;
+    listen [::]:80 default_server;
+
+    server_name _;
+
+    location / {
+        dav_methods     PUT;
+        dav_ext_methods PROPFIND OPTIONS;
+        dav_access      user:rw group:rw all:r;
+
+        client_body_temp_path   /tmp;
+        client_max_body_size    0;
+        create_full_put_path    on;
+
+        root /results;
+
+        autoindex     on;
+    }
+}
diff --git a/.gitlab-ci/container/arm_test-base.sh b/.gitlab-ci/container/arm_test-base.sh
index 5f5be04..9b3da12 100644
--- a/.gitlab-ci/container/arm_test-base.sh
+++ b/.gitlab-ci/container/arm_test-base.sh
@@ -24,6 +24,7 @@
         flex \
         git \
         netcat \
+        nginx-full \
         python3-distutils \
         python3-minimal \
         python3-serial \
@@ -37,4 +38,8 @@
 apt install -t buster-backports -y --no-remove \
     meson
 
+# setup nginx
+sed -i '/gzip_/ s/#\ //g' /etc/nginx/nginx.conf
+cp .gitlab-ci/bare-metal/nginx-default-site  /etc/nginx/sites-enabled/default
+
 . .gitlab-ci/container/container_post_build.sh
diff --git a/.gitlab-ci/create-rootfs.sh b/.gitlab-ci/create-rootfs.sh
index e9a2c78..21c2844 100644
--- a/.gitlab-ci/create-rootfs.sh
+++ b/.gitlab-ci/create-rootfs.sh
@@ -4,6 +4,7 @@
 
 apt-get -y install --no-install-recommends \
     ca-certificates \
+    curl \
     initramfs-tools \
     libpng16-16 \
     strace \
diff --git a/docs/ci/bare-metal.rst b/docs/ci/bare-metal.rst
index b14e995..800469e 100644
--- a/docs/ci/bare-metal.rst
+++ b/docs/ci/bare-metal.rst
@@ -28,9 +28,8 @@
 gitlab-runner system, since the initramfs is what contains the Mesa
 testing payload.
 
-The boards should have networking, so that (in a future iteration of
-this code) we can extract the dEQP .xml results to artifacts on
-gitlab.
+The boards should have networking, so that we can extract the dEQP .xml
+results to artifacts on gitlab.
 
 Requirements (servo)
 --------------------
@@ -104,8 +103,8 @@
 serial console and fastboot USB devices (--device arguments don't
 apply to devices that show up after container start, which is the case
 with fastboot, and the servo serial devices are actually links to
-/dev/pts).  We use host network mode so that we can (in the future)
-spin up a server to collect XML results for fastboot.
+/dev/pts).  We use host network mode so that we can spin up a nginx
+server to collect XML results for fastboot.
 
 Once you've added your boards, you're going to need to add a little
 more customization in ``/etc/gitlab-runner/config.toml``.  First, add
@@ -119,5 +118,10 @@
     name = "google-freedreno-db410c-1"
     environment = ["BM_SERIAL=/dev/ttyDB410c8", "BM_POWERUP=google-power-up.sh 8", "BM_FASTBOOT_SERIAL=15e9e390"]
 
+If you want to collect the results for fastboot you need to add the following
+two board-specific environment variables ``BM_WEBDAV_IP`` and ``BM_WEBDAV_PORT``.
+These represent the IP address of the docker host and the board specific port number
+that gets used to start a nginx server.
+
 Once you've updated your runners' configs, restart with ``sudo service
 gitlab-runner restart``