1e5c31af7Sopenharmony_ci#!/usr/bin/env bash
2e5c31af7Sopenharmony_ci#
3e5c31af7Sopenharmony_ci# Copyright 2023-2024 The Khronos Group Inc.
4e5c31af7Sopenharmony_ci#
5e5c31af7Sopenharmony_ci# SPDX-License-Identifier: Apache-2.0
6e5c31af7Sopenharmony_ci
7e5c31af7Sopenharmony_ci# testBuild - invoke Makefile with the right options to build the test spec
8e5c31af7Sopenharmony_ci# that is found under build_tests.
9e5c31af7Sopenharmony_ci
10e5c31af7Sopenharmony_ci# Usage: testBuild
11e5c31af7Sopenharmony_ci
12e5c31af7Sopenharmony_ci# Build the test spec in various configurations:
13e5c31af7Sopenharmony_cifunction build_spec() {
14e5c31af7Sopenharmony_ci  build=$1
15e5c31af7Sopenharmony_ci  options=$2
16e5c31af7Sopenharmony_ci
17e5c31af7Sopenharmony_ci  echo "-----------------------"
18e5c31af7Sopenharmony_ci  echo "Building gen-$build ..."
19e5c31af7Sopenharmony_ci
20e5c31af7Sopenharmony_ci  # Clean existing build, if any
21e5c31af7Sopenharmony_ci  rm -rf build_tests/gen-$build
22e5c31af7Sopenharmony_ci
23e5c31af7Sopenharmony_ci  # Note: let options expand, do not quote
24e5c31af7Sopenharmony_ci  ./makeSpec -spec $options -genpath build_tests/gen-$build -test html
25e5c31af7Sopenharmony_ci}
26e5c31af7Sopenharmony_ci
27e5c31af7Sopenharmony_ci# Core:
28e5c31af7Sopenharmony_cibuild_spec core "core"
29e5c31af7Sopenharmony_cibuild_spec core-1.0 "core -version 1.0"
30e5c31af7Sopenharmony_ci# With VK_EXT_host_image_copy
31e5c31af7Sopenharmony_cibuild_spec hic "core -extension VK_EXT_host_image_copy"
32e5c31af7Sopenharmony_cibuild_spec hic-1.0 "core -extension VK_EXT_host_image_copy -version 1.0"
33e5c31af7Sopenharmony_ci# With VK_KHR_copy_commands2
34e5c31af7Sopenharmony_cibuild_spec copy2-1.0 "core -version 1.0 -extension VK_KHR_copy_commands2"
35e5c31af7Sopenharmony_ci# All:
36e5c31af7Sopenharmony_cibuild_spec all "all"
37e5c31af7Sopenharmony_cibuild_spec all-1.0 "all -version 1.0"
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_ci# Test valid usage generation as well
40e5c31af7Sopenharmony_ciecho "-----------------------"
41e5c31af7Sopenharmony_ciecho "Generating valid usage ..."
42e5c31af7Sopenharmony_ci./makeSpec -spec all -genpath build_tests/gen-validusage -test validusage
43e5c31af7Sopenharmony_ci
44e5c31af7Sopenharmony_ciecho
45e5c31af7Sopenharmony_ciecho "======================="
46e5c31af7Sopenharmony_ci
47e5c31af7Sopenharmony_ci# Verify the results against expectations.  Note: do this after generating all
48e5c31af7Sopenharmony_ci# builds.  This is to support the build_tests/update-expectations script that
49e5c31af7Sopenharmony_ci# copies the results over the expectations.
50e5c31af7Sopenharmony_ciresult=0
51e5c31af7Sopenharmony_cifor build in core core-1.0 hic hic-1.0 copy2-1.0 all all-1.0; do
52e5c31af7Sopenharmony_ci  echo "Verifying gen-$build is as expected..."
53e5c31af7Sopenharmony_ci  if ! diff build_tests/expectations/$build.html build_tests/gen-$build/out/html/vkspec.html; then
54e5c31af7Sopenharmony_ci    echo "  FAILED"
55e5c31af7Sopenharmony_ci    result=1
56e5c31af7Sopenharmony_ci  fi
57e5c31af7Sopenharmony_cidone
58e5c31af7Sopenharmony_ci
59e5c31af7Sopenharmony_ciecho "Verifying validusage in gen-validusage is as expected..."
60e5c31af7Sopenharmony_ciif ! diff build_tests/expectations/validusage.json build_tests/gen-validusage/out/validation/validusage.json; then
61e5c31af7Sopenharmony_ci  echo "  FAILED"
62e5c31af7Sopenharmony_ci  result=1
63e5c31af7Sopenharmony_cifi
64e5c31af7Sopenharmony_ci
65e5c31af7Sopenharmony_ciif [ "$result" -ne 0 ]; then
66e5c31af7Sopenharmony_ci  echo
67e5c31af7Sopenharmony_ci  echo "All tests have been built successfully, but the results do not match the"
68e5c31af7Sopenharmony_ci  echo "expectations."
69e5c31af7Sopenharmony_ci  echo "If trivial, you can review the diff per the above output."
70e5c31af7Sopenharmony_ci  echo "Otherwise, please review each failing output at:"
71e5c31af7Sopenharmony_ci  echo "  - build_tests/gen-*/out/html/vkspec.html, and"
72e5c31af7Sopenharmony_ci  echo "  - build_tests/gen-validusage/out/validation/validusage.json"
73e5c31af7Sopenharmony_ci  echo "And ensure they are acceptable.  In that case, update the expectations with:"
74e5c31af7Sopenharmony_ci  echo "  $ cd build_tests && ./update-expectations"
75e5c31af7Sopenharmony_ci  exit 1
76e5c31af7Sopenharmony_cifi
77e5c31af7Sopenharmony_ci
78e5c31af7Sopenharmony_ciecho "Success"
79