|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// |
| 3 | +// Copyright(c) 2025 Intel Corporation. All rights reserved. |
| 4 | +// |
| 5 | +// Author: Adrian Bonislawski <adrian.bonislawski@intel.com> |
| 6 | + |
| 7 | +#include "tester_simple_dram_test.h" |
| 8 | +#include <sof/audio/component.h> |
| 9 | +#include <sof/audio/module_adapter/module/generic.h> |
| 10 | +#include <sof/lib/memory.h> |
| 11 | + |
| 12 | +/* |
| 13 | + * This is a simple test case for DRAM execution |
| 14 | + * The test case will copy every 2nd frame of data |
| 15 | + * by setting do_copy flag to true/false |
| 16 | + */ |
| 17 | + |
| 18 | +struct tester_module_simple_dram_test_data { |
| 19 | + bool do_copy_data; |
| 20 | +}; |
| 21 | + |
| 22 | +static int validate_l3_memory(void *ptr) |
| 23 | +{ |
| 24 | + if (!((POINTER_TO_UINT(ptr) >= L3_MEM_BASE_ADDR) && |
| 25 | + (POINTER_TO_UINT(ptr) < L3_MEM_BASE_ADDR + L3_MEM_SIZE))) |
| 26 | + return -EINVAL; |
| 27 | + |
| 28 | + return 0; |
| 29 | +} |
| 30 | + |
| 31 | +__cold static int simple_dram_test_case_init(struct processing_module *mod, void **ctx) |
| 32 | +{ |
| 33 | +#if !CONFIG_L3_HEAP |
| 34 | + return -EINVAL; |
| 35 | +#endif |
| 36 | + struct tester_module_simple_dram_test_data *data = |
| 37 | + rzalloc(0, 0, SOF_MEM_CAPS_L3, sizeof(*data)); |
| 38 | + |
| 39 | + if (!data) |
| 40 | + return -ENOMEM; |
| 41 | + |
| 42 | + if (validate_l3_memory(data) != 0) { |
| 43 | + rfree(data); |
| 44 | + return -EINVAL; |
| 45 | + } |
| 46 | + |
| 47 | + if (validate_l3_memory(tester_interface_simple_dram_test.init) != 0 || |
| 48 | + validate_l3_memory(tester_interface_simple_dram_test.process) != 0 || |
| 49 | + validate_l3_memory(tester_interface_simple_dram_test.free) != 0) { |
| 50 | + rfree(data); |
| 51 | + return -EINVAL; |
| 52 | + } |
| 53 | + |
| 54 | + data->do_copy_data = false; |
| 55 | + *ctx = data; |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +__cold static int simple_dram_test_case_process(void *ctx, struct processing_module *mod, |
| 60 | + struct sof_source **sources, int num_of_sources, |
| 61 | + struct sof_sink **sinks, int num_of_sinks, |
| 62 | + bool *do_copy) |
| 63 | +{ |
| 64 | + struct tester_module_simple_dram_test_data *data = ctx; |
| 65 | + |
| 66 | + /* copy every second cycle */ |
| 67 | + *do_copy = data->do_copy_data; |
| 68 | + data->do_copy_data = !data->do_copy_data; |
| 69 | + |
| 70 | + return 0; |
| 71 | +} |
| 72 | + |
| 73 | +__cold static int simple_dram_test_free(void *ctx, struct processing_module *mod) |
| 74 | +{ |
| 75 | + rfree(ctx); |
| 76 | + return 0; |
| 77 | +} |
| 78 | + |
| 79 | +const struct tester_test_case_interface tester_interface_simple_dram_test = { |
| 80 | + .init = simple_dram_test_case_init, |
| 81 | + .process = simple_dram_test_case_process, |
| 82 | + .free = simple_dram_test_free |
| 83 | +}; |
0 commit comments