Skip to content

Commit

Permalink
[sw/tests] Adding Meson infrastructure for integration of closed and …
Browse files Browse the repository at this point in the history
…open source chip level testing.

Adding one flag called closed_source_dir to Meson
options file.
Added closed_source dir under sw/device/tests.
Added weak hook functions in ottf.c file.
Added example test called closed_entropy_src_smoketest that can
overwritten the weak functions in ottf.c file with closed source code
found under closed_source_dir path.
Fixes #10852

Signed-off-by: Maayan Kashani <maayan.kashani@nuvoton.com>
  • Loading branch information
MaayanKashani authored and timothytrippel committed Mar 15, 2022
1 parent cb8755c commit e1548e4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
6 changes: 6 additions & 0 deletions meson_options.txt
Expand Up @@ -25,3 +25,9 @@ option(
type: 'boolean',
value: false,
)

option(
'closed_source_dir',
type: 'string',
value: '',
)
10 changes: 9 additions & 1 deletion sw/device/lib/testing/test_framework/ottf.c
Expand Up @@ -8,6 +8,7 @@
#include <stddef.h>

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
Expand Down Expand Up @@ -54,11 +55,18 @@ static void report_test_status(bool result) {
test_status_set(result ? kTestStatusPassed : kTestStatusFailed);
}

OT_WEAK bool closed_source_pre_test_hook(void) { return true; }

OT_WEAK bool closed_source_post_test_hook(void) { return true; }

// A wrapper function is required to enable `test_main()` and test teardown
// logic to be invoked as a FreeRTOS task. This wrapper can be used by tests
// that are run on bare-metal.
static void test_wrapper(void *task_parameters) {
bool result = test_main();
// Invoke weak symbol that can be overriden in closed source code.
bool result = closed_source_pre_test_hook();

result = result && test_main() && closed_source_post_test_hook();
report_test_status(result);
}

Expand Down
37 changes: 37 additions & 0 deletions sw/device/tests/closed_source/meson.build
@@ -0,0 +1,37 @@
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# All build targets below will be built in closed source environment only.
# In order to build these targets, 'build_closed_source' and 'closed_source_dir'
# build flags should be defined.

closed_source_dir = get_option('closed_source_dir')
closed_source_test_path = 'sw/device/tests/'

hookfile = join_paths(closed_source_dir , closed_source_test_path, \
'ip_config_hooks.c')

###############################################################################
# Closed source test libraries.
###############################################################################
closed_source_config_hooks_lib = static_library(
'closed_source_config_hooks_lib',
sources: [hookfile],
dependencies: [
sw_lib_runtime_log,
],
)
closed_source_config_hooks_dep = declare_dependency(
link_with: closed_source_config_hooks_lib,
)

###############################################################################
# Closed source test.
###############################################################################
sw_tests += {
'closed_entropy_src_smoketest': {
'library': entropy_src_smoketest_lib,
'link_with_closed_configs': true,
}
}
44 changes: 34 additions & 10 deletions sw/device/tests/meson.build
Expand Up @@ -993,6 +993,13 @@ subdir('autogen')
###############################################################################
subdir('sim_dv')

###############################################################################
# Closed Source Test Libraries
###############################################################################
if (get_option('closed_source_dir') != '')
subdir('closed_source')
endif

###############################################################################
# Other Tests
###############################################################################
Expand Down Expand Up @@ -1054,16 +1061,33 @@ foreach sw_test_name, sw_test_info : sw_tests
ottf_lib,
]
endif

sw_test_elf = executable(
sw_test_name + '_' + device_name,
name_suffix: 'elf',
dependencies: [
shared_test_deps,
sw_test_info['library'],
],
)


if (get_option('closed_source_dir') != '') and \
'link_with_closed_configs' in sw_test_info and \
sw_test_info['link_with_closed_configs']
sw_test_elf = executable(
sw_test_name + '_' + device_name,
name_suffix: 'elf',
# Need to force the linker to examine (strong) symbols that may have a
# weak implementation in the (static) test library.
link_whole: closed_source_config_hooks_lib,
dependencies: [
shared_test_deps,
sw_test_info['library'],
closed_source_config_hooks_dep,
],
)
else
sw_test_elf = executable(
sw_test_name + '_' + device_name,
name_suffix: 'elf',
dependencies: [
shared_test_deps,
sw_test_info['library'],
],
)
endif

target_name = sw_test_name + '_@0@_' + device_name

sw_test_dis = custom_target(
Expand Down

0 comments on commit e1548e4

Please sign in to comment.