blob: 2d4e926764e1bec14aeaecf83244bb3e6d227609 [file] [log] [blame]
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# vec_cc_generated_test()
#
# CMake function to generate vector test from a given template.
#
# Parameters:
# NAME: Name of the op_code the test will verify
# TEMPLATE: mako template to use in generating the CPP file
# PREFIX: prefix to add to the target
# LINKOPTS: additional link options
# TIMEOUT: test specific timeout
#
# Note:
# This will generate an elf file that can be executed on target
# It also adds a test that can be run via CTest
function(vec_cc_generated_test)
cmake_parse_arguments(
_RULE
""
"NAME"
"TEMPLATE;PREFIX;LINKOPTS;TIMEOUT"
${ARGN}
)
set(_TEST_NAME "${_RULE_PREFIX}${_RULE_NAME}_test")
set(_OP_CODE ${_RULE_NAME})
string(REPLACE ".tpl" "" _TEST_SRC_FILENAME ${_RULE_TEMPLATE})
set(_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/generated/${_OP_CODE}/${_TEST_SRC_FILENAME})
find_file(_GEN_VEC_SCRIPT generate_vector_tests.py ${CMAKE_SOURCE_DIR}/scripts)
file(GLOB_RECURSE TEMPLATES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.tpl")
add_custom_command(
OUTPUT
${_TEST_SRC}
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/templates/${_RULE_TEMPLATE}
${TEMPLATES}
COMMAND python3 ${_GEN_VEC_SCRIPT}
--template-path=${CMAKE_CURRENT_SOURCE_DIR}/templates/
--template=${_RULE_TEMPLATE}
--out-path=${CMAKE_CURRENT_BINARY_DIR}/generated/${_OP_CODE}
--op=${_OP_CODE}
)
vec_cc_test(
NAME
${_TEST_NAME}
SRCS
${_TEST_SRC}
DEPS
softrvv
LINKOPTS
${_RULE_LINKOPTS}
TIMEOUT
${_RULE_TIMEOUT}
)
endfunction()
function(softrvv_vec_cc_generated_test)
cmake_parse_arguments(
_RULE
""
"NAME"
"TEMPLATE;LINKOPTS;TIMEOUT"
${ARGN}
)
vec_cc_generated_test(
NAME
${_RULE_NAME}
PREFIX
softrvv_
TEMPLATE
${_RULE_TEMPLATE}
LINKOPTS
${_RULE_LINKOPTS}
TIMEOUT
${_RULE_TIMEOUT}
)
endfunction()