[sw/ottf] Restructure meson build targets for OTTF. For testing the OTTF, a single meson build target was constructed with an example test built in. This refactors the build targets to build the OTTF as a library that is linked with tests that are also defined as libraries. This makes building test binaries that use the OTTF similar to those that use the existing test_main.c test framework. Additionally, two example OTTF tests (one bare-metal and one concurrency) are added to provided examples of how to write on-device tests using the OTTF. This partially addresses a larger effort of refactoring the on-device test framework, as described in #8015. Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/sw/device/lib/testing/test_framework/example_ottf_test.c b/sw/device/lib/testing/test_framework/example_ottf_test.c deleted file mode 100644 index 37831aa..0000000 --- a/sw/device/lib/testing/test_framework/example_ottf_test.c +++ /dev/null
@@ -1,21 +0,0 @@ -// Copyright lowRISC contributors. -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 - -#include <sw/device/lib/testing/test_framework/ottf.h> - -#include "sw/device/lib/runtime/log.h" -#include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h" -#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h" -#include "sw/vendor/freertos_freertos_kernel/include/task.h" - -const test_config_t kTestConfig = { - .can_clobber_uart = false, - .enable_concurrency = true, -}; - -bool test_main(void) { - LOG_INFO("Running on-device test as FreeRTOS task (%s) using the OTTF.", - pcTaskGetName(NULL)); - return true; -}
diff --git a/sw/device/lib/testing/test_framework/meson.build b/sw/device/lib/testing/test_framework/meson.build index 7e85d9f..4cbfce6 100644 --- a/sw/device/lib/testing/test_framework/meson.build +++ b/sw/device/lib/testing/test_framework/meson.build
@@ -79,11 +79,9 @@ ottf_sources = [ 'ottf.c', 'ottf_isrs.c', - 'example_ottf_test.c', 'freertos_hooks.c', 'freertos_port.S', 'freertos_port.c', - hw_ip_rv_timer_reg_h, join_paths(freertos_root ,'tasks.c'), join_paths(freertos_root ,'queue.c'), join_paths(freertos_root ,'list.c'), @@ -94,9 +92,9 @@ '../../../../vendor/freertos_freertos_kernel/portable/GCC/RISC-V') # OpenTitan Test Framework (OTTF) -sw_lib_ottf = declare_dependency( +sw_lib_testing_ottf = declare_dependency( link_with: static_library( - 'sw_lib_ottf', + 'sw_lib_testing_ottf', sources: ottf_sources, include_directories: ottf_incdirs, c_args: [
diff --git a/sw/device/tests/meson.build b/sw/device/tests/meson.build index 1c96b1f..25b6fa2 100644 --- a/sw/device/tests/meson.build +++ b/sw/device/tests/meson.build
@@ -26,6 +26,41 @@ } ############################################################################### +# OTTF Example Tests +############################################################################### +ottf_example_bare_metal_test_lib = declare_dependency( + link_with: static_library( + 'ottf_example_bare_metal_test_lib', + sources: ['ottf_example_bare_metal_test.c'], + dependencies: [ + sw_lib_runtime_log, + ], + ), +) +sw_tests += { + 'ottf_example_bare_metal_test_lib': { + 'library': ottf_example_bare_metal_test_lib, + 'use_ottf': true, + } +} + +ottf_example_concurrency_test_lib = declare_dependency( + link_with: static_library( + 'ottf_example_concurrency_test_lib', + sources: ['ottf_example_concurrency_test.c'], + dependencies: [ + sw_lib_runtime_log, + ], + ), +) +sw_tests += { + 'ottf_example_concurrency_test_lib': { + 'library': ottf_example_concurrency_test_lib, + 'use_ottf': true, + } +} + +############################################################################### # Smoke Tests ############################################################################### rv_plic_smoketest_lib = declare_dependency( @@ -636,17 +671,32 @@ # (unsigned) test binaries loaded with ROM from sw/device/boot_rom/ foreach sw_test_name, sw_test_info : sw_tests foreach device_name, device_lib : sw_lib_arch_core_devices - sw_test_elf = executable( - sw_test_name + '_' + device_name, - name_suffix: 'elf', - dependencies: [ - riscv_crt, - device_lib, - sw_test_info['library'], - sw_lib_irq_handlers, - sw_lib_testing_test_main, - ], - ) + if 'use_ottf' in sw_test_info + # test target with OTTF + sw_test_elf = executable( + sw_test_name + '_' + device_name, + name_suffix: 'elf', + dependencies: [ + riscv_crt, + device_lib, + sw_test_info['library'], + sw_lib_testing_ottf, + ], + ) + else + # test target with bare metal on-device test framework + sw_test_elf = executable( + sw_test_name + '_' + device_name, + name_suffix: 'elf', + dependencies: [ + riscv_crt, + device_lib, + sw_test_info['library'], + sw_lib_irq_handlers, + sw_lib_testing_test_main, + ], + ) + endif target_name = sw_test_name + '_@0@_' + device_name @@ -921,69 +971,3 @@ build_by_default: true, ) endforeach - -# OpenTitan (FreeRTOS) Test Framework -foreach device_name, device_lib : sw_lib_arch_core_devices - ottf_elf = executable( - 'ottf_' + device_name, - name_suffix: 'elf', - dependencies: [ - riscv_crt, - device_lib, - sw_lib_ottf, - sw_lib_irq_handlers, - ], - ) - - target_name = 'ottf_@0@_' + device_name - - ottf_dis = custom_target( - target_name.format('dis'), - input: ottf_elf, - kwargs: elf_to_dis_custom_target_args, - ) - - ottf_bin = custom_target( - target_name.format('bin'), - input: ottf_elf, - kwargs: elf_to_bin_custom_target_args, - ) - - ottf_vmem32 = custom_target( - target_name.format('vmem32'), - input: ottf_bin, - kwargs: bin_to_vmem32_custom_target_args, - ) - - ottf_vmem64 = custom_target( - target_name.format('vmem64'), - input: ottf_bin, - kwargs: bin_to_vmem64_custom_target_args, - ) - - ottf_scr_vmem64 = custom_target( - target_name.format('scrambled'), - input: ottf_vmem64, - output: flash_image_outputs, - command: flash_image_command, - depend_files: flash_image_depend_files, - build_by_default: true, - ) - - custom_target( - target_name.format('export'), - command: export_target_command, - depend_files: [export_target_depend_files,], - input: [ - ottf_elf, - ottf_dis, - ottf_bin, - ottf_vmem32, - ottf_vmem64, - ottf_scr_vmem64 - ], - output: target_name.format('export'), - build_always_stale: true, - build_by_default: true, - ) -endforeach
diff --git a/sw/device/tests/ottf_example_bare_metal_test.c b/sw/device/tests/ottf_example_bare_metal_test.c new file mode 100644 index 0000000..bbf22b9 --- /dev/null +++ b/sw/device/tests/ottf_example_bare_metal_test.c
@@ -0,0 +1,16 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#include "sw/device/lib/runtime/log.h" +#include "sw/device/lib/testing/test_framework/ottf.h" + +const test_config_t kTestConfig = { + .can_clobber_uart = false, + .enable_concurrency = false, +}; + +bool test_main(void) { + LOG_INFO("Running on-device test on bare-metal using the OTTF."); + return true; +}
diff --git a/sw/device/tests/ottf_example_concurrency_test.c b/sw/device/tests/ottf_example_concurrency_test.c new file mode 100644 index 0000000..564755c --- /dev/null +++ b/sw/device/tests/ottf_example_concurrency_test.c
@@ -0,0 +1,16 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#include "sw/device/lib/runtime/log.h" +#include "sw/device/lib/testing/test_framework/ottf.h" + +const test_config_t kTestConfig = { + .can_clobber_uart = false, + .enable_concurrency = true, +}; + +bool test_main(void) { + LOG_INFO("Running on-device test as FreeRTOS task using the OTTF."); + return true; +}