xref: /aosp_15_r20/external/swiftshader/tests/kokoro/gcp_ubuntu/docker.sh (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1#!/bin/bash
2
3# Copyright 2022 The SwiftShader Authors. All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#    http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e # Fail on any error.
18
19function show_cmds { set -x; }
20function hide_cmds { { set +x; } 2>/dev/null; }
21function task_begin {
22    TASK_NAME="$@"
23    SECONDS=0
24}
25function print_last_task_duration {
26    if [ ! -z "${TASK_NAME}" ]; then
27        echo "${TASK_NAME} completed in $(($SECONDS / 3600))h$((($SECONDS / 60) % 60))m$(($SECONDS % 60))s"
28    fi
29}
30function status {
31    echo ""
32    echo ""
33    print_last_task_duration
34    echo ""
35    echo "*****************************************************************"
36    echo "* $@"
37    echo "*****************************************************************"
38    echo ""
39    task_begin $@
40}
41
42CLONE_SRC_DIR="$(pwd)"
43
44. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
45
46using cmake-3.17.2
47using gcc-9
48
49status "Cloning to clean source directory at '${SRC_DIR}'"
50
51mkdir -p ${SRC_DIR}
52cd ${SRC_DIR}
53git clone ${CLONE_SRC_DIR} .
54
55mkdir -p build && cd build
56
57if [[ -z "${REACTOR_BACKEND}" ]]; then
58  REACTOR_BACKEND="LLVM"
59fi
60
61# Lower the amount of debug info, to reduce Kokoro build times.
62SWIFTSHADER_LESS_DEBUG_INFO=1
63
64status "Generating CMake build files"
65cmake .. \
66    "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" \
67    "-DREACTOR_BACKEND=${REACTOR_BACKEND}" \
68    "-DSWIFTSHADER_LLVM_VERSION=${LLVM_VERSION}" \
69    "-DREACTOR_VERIFY_LLVM_IR=1" \
70    "-DSWIFTSHADER_LESS_DEBUG_INFO=${SWIFTSHADER_LESS_DEBUG_INFO}" \
71    "-DSWIFTSHADER_BUILD_BENCHMARKS=1"
72
73status "Building"
74cmake --build . -- -j $(nproc)
75
76status "Running unit tests"
77
78cd .. # Some tests must be run from project root
79
80build/ReactorUnitTests
81build/system-unittests
82build/vk-unittests
83
84status "Building and running rr::Print unit tests"
85
86cd build
87cmake .. "-DREACTOR_ENABLE_PRINT=1"
88cmake --build . --target ReactorUnitTests -- -j $(nproc)
89cmake .. "-DREACTOR_ENABLE_PRINT=0"
90cd ..
91build/ReactorUnitTests --gtest_filter=ReactorUnitTests.Print*
92
93status "Building and testing with REACTOR_EMIT_ASM_FILE"
94
95cd build
96cmake .. "-DREACTOR_EMIT_ASM_FILE=1"
97cmake --build . --target ReactorUnitTests -- -j $(nproc)
98cmake .. "-DREACTOR_EMIT_ASM_FILE=0"
99cd ..
100build/ReactorUnitTests --gtest_filter=ReactorUnitTests.EmitAsm
101
102#status "Building with REACTOR_EMIT_DEBUG_INFO"
103#
104#cd build
105#cmake .. "-DREACTOR_EMIT_DEBUG_INFO=1"
106#cmake --build . --target ReactorUnitTests -- -j $(nproc)
107#cmake .. "-DREACTOR_EMIT_DEBUG_INFO=0"
108#cd ..
109
110#status "Building with REACTOR_EMIT_PRINT_LOCATION"
111#
112#cd build
113#cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=1"
114#cmake --build . --target ReactorUnitTests -- -j $(nproc)
115#cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=0"
116#cd ..
117
118status "Done"
119