Debian Codegraph @

build/swiftshader/test.sh

raw
1 #!/bin/bash
2 set -e
3
4 function print_help {
5 local self_name=$(basename "$0")
6 echo "This script issues docker commands for testing Filament with SwiftShader."
7 echo "The usual sequence of commands is: fetch, start, build filament release, and run."
8 echo ""
9 echo "Usage:"
10 echo " $self_name [command]"
11 echo ""
12 echo "Commands:"
13 echo " build filament [debug | release]"
14 echo " Use the container to build Filament."
15 echo " build swiftshader [debug | release]"
16 echo " Use the container to do a clean rebuild of SwiftShader."
17 echo " (Note that the container already has SwiftShader built.)"
18 echo " fetch"
19 echo " Download the docker image from the central repository."
20 echo " help"
21 echo " Print this help message."
22 echo " logs"
23 echo " Print messages from the container's kernel ring buffer."
24 echo " This is useful for diagnosing OOM issues."
25 echo " run [lldb]"
26 echo " Launch a test inside the container, optionally via lldb."
27 echo " shell"
28 echo " Interact with a bash prompt in the container."
29 echo " start"
30 echo " Start a container from the image."
31 echo " stop"
32 echo " Stop the container."
33 echo ""
34 }
35
36 # Change the current working directory to the Filament root.
37 pushd "$(dirname "$0")/../.." > /dev/null
38
39 if [[ "$1" == "build" ]] && [[ "$2" == "filament" ]]; then
40 docker exec runner filament/build.sh -t $3 gltf_viewer
41 exit $?
42 fi
43
44 if [[ "$1" == "build" ]] && [[ "$2" == "swiftshader" ]]; then
45 BUILD_TYPE="$3"
46 BUILD_TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}"
47 docker exec --workdir /trees/swiftshader runner rm -rf build
48 docker exec --workdir /trees/swiftshader runner mkdir build
49 docker exec --workdir /trees/swiftshader/build runner cmake -GNinja -DCMAKE_BUILD_TYPE="$BUILD_TYPE" ..
50 docker exec --workdir /trees/swiftshader/build runner ninja
51 exit $?
52 fi
53
54 if [[ "$1" == "fetch" ]]; then
55 docker pull ghcr.io/filament-assets/swiftshader:latest
56 docker tag ghcr.io/filament-assets/swiftshader:latest ssfilament
57 exit $?
58 fi
59
60 if [[ "$1" == "help" ]]; then
61 print_help
62 exit 0
63 fi
64
65 if [[ "$1" == "logs" ]]; then
66 docker exec runner dmesg --human --read-clear
67 exit $?
68 fi
69
70 if [[ "$1" == "run" ]] && [[ "$2" == "lldb" ]]; then
71 docker exec -i --workdir /trees/filament/results runner \
72 lldb --batch -o run -o bt -- \
73 ../out/cmake-release/samples/gltf_viewer \
74 --headless \
75 --batch ../libs/viewer/tests/basic.json \
76 --api vulkan
77 docker exec runner /trees/filament/build/swiftshader/gallery.py
78 exit $?
79 fi
80
81 if [[ "$1" == "run" ]]; then
82 docker exec --tty --workdir /trees/filament/results runner \
83 /usr/bin/catchsegv \
84 ../out/cmake-release/samples/gltf_viewer \
85 --headless \
86 --batch ../libs/viewer/tests/basic.json \
87 --api vulkan
88 docker exec runner /trees/filament/build/swiftshader/gallery.py
89 exit $?
90 fi
91
92 if [[ "$1" == "shell" ]]; then
93 docker exec --interactive --tty runner /bin/bash
94 exit $?
95 fi
96
97 # Notes on options being passed to docker's run command:
98 #
99 # - The memory constraint seems to prevent an OOM signal in GitHub Actions.
100 # - The cap / security args allow use of lldb and creation of core dumps.
101 # - The privileged arg allows use of dmesg for examining OOM logs.
102 #
103 # Currently, a GitHub Actions VM has 2 CPUs, 7 GB RAM, and 14 GB of SSD disk space.
104 #
105 # Please be aware that Docker Desktop might impose additional resource constraints, and that those
106 # settings can only be controlled with its GUI. We recommend at least 7 GB of memory and 2 GB swap.
107 if [[ "$1" == "start" ]]; then
108 mkdir -p results
109 docker run --tty --rm --detach --privileged \
110 --memory 6.5g \
111 --name runner \
112 --cap-add=SYS_PTRACE \
113 --security-opt seccomp=unconfined \
114 --security-opt apparmor=unconfined \
115 --volume `pwd`:/trees/filament \
116 --workdir /trees \
117 ssfilament
118 exit $?
119 fi
120
121 if [[ "$1" == "stop" ]]; then
122 docker container rm runner --force
123 exit $?
124 fi
125
126 print_help
127 exit 1