|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Intel Corporation |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are met: |
| 7 | + * * Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * * Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in the |
| 11 | + * documentation and/or other materials provided with the distribution. |
| 12 | + * * Neither the name of the Intel Corporation nor the |
| 13 | + * names of its contributors may be used to endorse or promote products |
| 14 | + * derived from this software without specific prior written permission. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * |
| 28 | + * Author: Jakub Dabek <jakub.dabek@linux.intel.com> |
| 29 | + */ |
| 30 | + |
| 31 | +#include <stdint.h> |
| 32 | +#include <sof/audio/component.h> |
| 33 | +#include <sof/audio/pipeline.h> |
| 34 | +#include <sof/schedule.h> |
| 35 | +#include "pipeline_mocks.h" |
| 36 | +#include <stdarg.h> |
| 37 | +#include <stddef.h> |
| 38 | +#include <setjmp.h> |
| 39 | +#include <cmocka.h> |
| 40 | + |
| 41 | +static int setup(void **state) |
| 42 | +{ |
| 43 | + struct pipeline_new_setup_data *pipeline_data = malloc( |
| 44 | + sizeof(struct pipeline_new_setup_data)); |
| 45 | + |
| 46 | + if (pipeline_data == NULL) |
| 47 | + return -1; |
| 48 | + |
| 49 | + struct sof_ipc_pipe_new pipe_desc = { .core = 1, .priority = 2 }; |
| 50 | + |
| 51 | + pipeline_data->ipc_data = pipe_desc; |
| 52 | + |
| 53 | + *state = pipeline_data; |
| 54 | + return 0; |
| 55 | +} |
| 56 | + |
| 57 | +static int teardown(void **state) |
| 58 | +{ |
| 59 | + free(*state); |
| 60 | + return 0; |
| 61 | +} |
| 62 | + |
| 63 | +static void test_audio_pipeline_pipeline_new_creation(void **state) |
| 64 | +{ |
| 65 | + struct pipeline_new_setup_data *test_data = *state; |
| 66 | + |
| 67 | + /*Testing component*/ |
| 68 | + struct pipeline *result = pipeline_new(&test_data->ipc_data, |
| 69 | + test_data->comp_data); |
| 70 | + |
| 71 | + /*Pipeline should have been created so pointer can't be null*/ |
| 72 | + assert_non_null(result); |
| 73 | +} |
| 74 | + |
| 75 | +static void test_audio_pipeline_new_list_initialization(void **state) |
| 76 | +{ |
| 77 | + struct pipeline_new_setup_data *test_data = *state; |
| 78 | + |
| 79 | + /*Testing component*/ |
| 80 | + struct pipeline *result = pipeline_new(&test_data->ipc_data, |
| 81 | + test_data->comp_data); |
| 82 | + |
| 83 | + /*Check list initialization*/ |
| 84 | + assert_ptr_equal(&result->comp_list, result->comp_list.next); |
| 85 | + assert_ptr_equal(&result->buffer_list, result->buffer_list.next); |
| 86 | +} |
| 87 | + |
| 88 | +static void test_audio_pipeline_new_sheduler_init(void **state) |
| 89 | +{ |
| 90 | + struct pipeline_new_setup_data *test_data = *state; |
| 91 | + |
| 92 | + /*Testing component*/ |
| 93 | + struct pipeline *result = pipeline_new(&test_data->ipc_data, |
| 94 | + test_data->comp_data); |
| 95 | + |
| 96 | + /*Check if all parameters are passed to sheduler |
| 97 | + *(initialization) |
| 98 | + */ |
| 99 | + assert_int_equal(result->pipe_task.state, TASK_STATE_INIT); |
| 100 | + assert_int_equal(result->pipe_task.core, test_data->ipc_data.core); |
| 101 | +} |
| 102 | + |
| 103 | +static void test_audio_pipeline_new_sheduler_config(void **state) |
| 104 | +{ |
| 105 | + struct pipeline_new_setup_data *test_data = *state; |
| 106 | + |
| 107 | + /*Testing component*/ |
| 108 | + struct pipeline *result = pipeline_new(&test_data->ipc_data, |
| 109 | + test_data->comp_data); |
| 110 | + |
| 111 | + /*Pipeline should end in pre init state untli sheduler runs |
| 112 | + *task that initializes it |
| 113 | + */ |
| 114 | + assert_int_equal(COMP_STATE_INIT, result->status); |
| 115 | +} |
| 116 | + |
| 117 | +static void test_audio_pipeline_new_ipc_data_coppy(void **state) |
| 118 | +{ |
| 119 | + struct pipeline_new_setup_data *test_data = *state; |
| 120 | + |
| 121 | + /*Testing component*/ |
| 122 | + struct pipeline *result = pipeline_new(&test_data->ipc_data, |
| 123 | + test_data->comp_data); |
| 124 | + |
| 125 | + assert_memory_equal(&test_data->ipc_data, &result->ipc_pipe, |
| 126 | + sizeof(struct sof_ipc_pipe_new)); |
| 127 | +} |
| 128 | + |
| 129 | +int main(void) |
| 130 | +{ |
| 131 | + |
| 132 | + const struct CMUnitTest tests[] = { |
| 133 | + cmocka_unit_test(test_audio_pipeline_pipeline_new_creation), |
| 134 | + cmocka_unit_test(test_audio_pipeline_new_list_initialization), |
| 135 | + cmocka_unit_test(test_audio_pipeline_new_sheduler_init), |
| 136 | + cmocka_unit_test(test_audio_pipeline_new_sheduler_config), |
| 137 | + cmocka_unit_test(test_audio_pipeline_new_ipc_data_coppy), |
| 138 | + }; |
| 139 | + |
| 140 | + cmocka_set_message_output(CM_OUTPUT_TAP); |
| 141 | + |
| 142 | + return cmocka_run_group_tests(tests, setup, teardown); |
| 143 | +} |
0 commit comments