1#!/bin/bash 2 3pushd $(dirname "$0") > /dev/null 4 5RunImplicitLayerTest() 6{ 7 # Check for local implicit directory. 8 : "${HOME:?}" 9 local implicitDirectory="$HOME/.local/share/vulkan/implicit_layer.d" 10 if [ ! -d "$implicitDirectory" ] 11 then 12 mkdir -p "$implicitDirectory" 13 fi 14 15 # Check for the shared object. 16 local sharedObject="libVkLayer_test.so" 17 local layerDirectory="./layers" 18 if [ ! -f "$layerDirectory/$sharedObject" ] 19 then 20 echo "The file, $layerDirectory/$sharedObject, can not be found." >&2 21 return 1 22 fi 23 24 # Check for the json which does not include the optional enable environment variable. 25 local json="VkLayer_test.json" 26 if [ ! -f "$layerDirectory/$json" ] 27 then 28 echo "The file, $layerDirectory/$json, can not be found." >&2 29 return 1 30 fi 31 32 # Copy the test layer into the implicit directory. 33 if ! cp "$layerDirectory/$sharedObject" "$implicitDirectory/" || ! cp "$layerDirectory/$json" "$implicitDirectory/" 34 then 35 echo "unable to install test layer" >&2 36 return 1 37 fi 38 39 # Test without setting enable environment variable. The loader should not load the layer. 40 output=$(GTEST_FILTER=ImplicitLayer.Present \ 41 ./vk_loader_validation_tests 2>&1) 42 if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance" 43 then 44 echo "test layer detected but enable environment variable was not set" >&2 45 return 1 46 fi 47 48 # Test enable environment variable with good value. The loader should load the layer. 49 output=$(ENABLE_LAYER_TEST_1=enable \ 50 GTEST_FILTER=ImplicitLayer.Present \ 51 ./vk_loader_validation_tests 2>&1) 52 if ! echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance" 53 then 54 echo "test layer not detected" >&2 55 return 1 56 fi 57 58 # Test enable environment variable with bad value. The loader should not load the layer. 59 output=$(ENABLE_LAYER_TEST_1=wrong \ 60 GTEST_FILTER=ImplicitLayer.Present \ 61 ./vk_loader_validation_tests 2>&1) 62 if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance" 63 then 64 echo "test layer detected but enable environment variable was set to wrong value" >&2 65 return 1 66 fi 67 68 # Test disable environment variable. The loader should not load the layer. 69 output=$(DISABLE_LAYER_TEST_1=value \ 70 GTEST_FILTER=ImplicitLayer.Present \ 71 ./vk_loader_validation_tests 2>&1) 72 if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance" 73 then 74 echo "test layer detected but disable environment variable was set" >&2 75 return 1 76 fi 77 78 # Remove the enable environment variable. 79 if ! sed -i '/enable_environment\|ENABLE_LAYER_TEST_1\|},/d' "$implicitDirectory/$json" 80 then 81 echo "unable to remove enable environment variable" >&2 82 return 1 83 fi 84 85 # Test without setting enable environment variable. The loader should load the layer. 86 output=$(GTEST_FILTER=ImplicitLayer.Present \ 87 ./vk_loader_validation_tests 2>&1) 88 if ! echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance" 89 then 90 echo "test layer not detected" >&2 91 return 1 92 fi 93 94 # Remove the test layer. 95 if ! rm "$implicitDirectory/$sharedObject" || ! rm "$implicitDirectory/$json" 96 then 97 echo "unable to uninstall test layer" >&2 98 return 1 99 fi 100 101 echo "ImplicitLayer test PASSED" 102} 103 104! RunImplicitLayerTest && echo "ImplicitLayer test FAILED" >&2 && exit 1 105 106popd > /dev/null 107