Import files From: Chris Minnoy <chris.minnoy@eu.sony.com> From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> From: Lukas Buricin <Lukas.Buricin@eu.sony.com> Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..0049032 --- /dev/null +++ b/COPYING
@@ -0,0 +1,36 @@ +***************** +License: MIT Plus +***************** +Copyright 2008 Sony Corporation of America + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this Library and associated documentation files (the +"Library"), to deal in the Library without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Library, and to +permit persons to whom the Library is furnished to do so, subject to +the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Library. + + If you modify the Library, you may copy and distribute your modified + version of the Library in object code or as an executable provided + that you also do one of the following: + + Accompany the modified version of the Library with the complete + corresponding machine-readable source code for the modified version + of the Library; or, + + Accompany the modified version of the Library with a written offer + for a complete machine-readable copy of the corresponding source + code of the modified version of the Library. + + +THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f029966 --- /dev/null +++ b/Makefile
@@ -0,0 +1,28 @@ +MAKEFLAGS += --no-print-directory + +# `make V=1' to have verbose output +ifneq ($(V),1) +Q = @ +endif + +SUITES := $(wildcard suite_*) +SUITES_CLEAN := $(patsubst %, %_clean_, $(SUITES)) + +.PHONY: all clean $(SUITES) $(SUITES_CLEAN) + +all: $(SUITES) + +clean: $(SUITES_CLEAN) + +$(SUITES): # FIXME link to mars library, so it gets build first + @echo Building in $@ + $(Q)$(MAKE) -C $@ + +$(SUITES_CLEAN): + @echo Cleaning in $(subst _clean_,,$@) + $(Q)$(MAKE) -C $(subst _clean_,,$@) clean + +# Use `make print-VARIABLE' to print the value of $(VARIABLE) +print-%: + @echo $* = "$($*)" +
diff --git a/TFP_TFN/black_box_test_1/Makefile b/TFP_TFN/black_box_test_1/Makefile new file mode 100644 index 0000000..0d92fcc --- /dev/null +++ b/TFP_TFN/black_box_test_1/Makefile
@@ -0,0 +1,44 @@ +## Makefile + +sample = black_box_test_1 + +MARS_LIB_SRC = ../../../mars-src/src +MARS_LIB_INC = ../../../mars-src/include + +include ../../config.mk +SPU_CFLAGS += -fstrict-aligned +PPU_LDFLAGS += -lcunit +SPU_LDFLAGS += -lcunit + +.PHONY: all marslibs clean rebuild run + +all: $(sample) + +$(sample): marslibs mpu_task.eo host.o + $(PPU_CC) $(PPU_CFLAGS) -o $@ mpu_task.eo host.o $(MARS_LIB_SRC)/host/lib/.libs/libmars.a $(MARS_LIB_SRC)/mpu/kernel/mars_kernel.eo $(PPU_LDFLAGS) + +host.o: host.c host_mpu_common.h + $(PPU_CC) $(PPU_CFLAGS) -c -o $@ $< -I$(MARS_LIB_INC)/host -I$(MARS_LIB_INC)/common + +mpu_task.eo: mpu_task.o + $(PPU_EMBEDSPU) $(PPU_CFLAGS) mpu_task_prog $< $@ + +mpu_task.o: mpu_task.c host_mpu_common.h + $(SPU_CC) $(SPU_CFLAGS) -o $@ $< $(MARS_LIB_SRC)/mpu/lib/libmars.a -I$(MARS_LIB_INC)/common -I$(MARS_LIB_INC)/mpu $(SPU_LDFLAGS) + +marslibs: + make -C$(MARS_LIB_SRC)/mpu/lib all CFLAGS+=" -Wall" + make -C$(MARS_LIB_SRC)/mpu/kernel all CFLAGS+=" -Wall" + make -C$(MARS_LIB_SRC)/host/lib all CFLAGS+=" -m64 -Wall -I/usr/lib/gcc/ppu/4.1.1/include" + +clean: + rm -f *.o *.eo $(sample) + + make -C$(MARS_LIB_SRC)/mpu/lib clean + make -C$(MARS_LIB_SRC)/mpu/kernel clean + make -C$(MARS_LIB_SRC)/host/lib clean + +rebuild: clean all + +run: all + ./$(sample)
diff --git a/TFP_TFN/black_box_test_1/host.c b/TFP_TFN/black_box_test_1/host.c new file mode 100644 index 0000000..6a3275d --- /dev/null +++ b/TFP_TFN/black_box_test_1/host.c
@@ -0,0 +1,908 @@ +#include <string.h> +#include <malloc.h> +#include <CUnit/Basic.h> +#include <libspe2.h> +#include <mars/mars.h> +#include "host_mpu_common.h" + +extern struct spe_program_handle mpu_task_prog; + +static struct mars_context mars, temp_mars; +static struct mars_task_id task_id, temp_task_id; +static struct mars_task_args task_args; +static struct mars_mutex mutex, temp_mutexes[2], *wrong_mutex_ptr; +static struct mars_task_barrier barrier, temp_barriers[2], *wrong_barrier_ptr; +static struct mars_task_event_flag event_flag, temp_event_flags[2], *wrong_event_flag_ptr; +static struct mars_task_queue queue, temp_queues[2], *wrong_queue_ptr; +static int8_t *queue_buffer; + +//***************************************************************************** +// MARS context initialize/finalize suite functions +//***************************************************************************** + +static void TFP_mars_initialize() +{ + int ret, spe_cnt, i; + + CU_ASSERT_EQUAL_MARS(ret = mars_initialize(&mars, 0), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_finalize(&mars); + + spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, 0); + + for (i = 0;i <= spe_cnt;i++) + { + CU_ASSERT_EQUAL_MARS(ret = mars_initialize(&mars, i), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_finalize(&mars); + } +} + +static void TFN_mars_initialize() +{ + int spe_cnt; + + spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, 0); + + CU_ASSERT_EQUAL_MARS(mars_initialize(NULL, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_initialize(NULL, spe_cnt), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_initialize(&mars, -1), MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS(mars_initialize(&mars, spe_cnt + 1), MARS_ERROR_PARAMS); +} + +static void TFP_mars_finalize() +{ + mars_initialize(&mars, 0); + CU_ASSERT_EQUAL_MARS(mars_finalize(&mars), MARS_SUCCESS); +} + +static void TFN_mars_finalize() +{ + CU_ASSERT_EQUAL_MARS(mars_finalize(NULL), MARS_ERROR_NULL); + + memset(&mars, 0, sizeof(struct mars_context)); + CU_ASSERT_EQUAL_MARS(mars_finalize(&mars), MARS_ERROR_STATE); +} + +//***************************************************************************** +// common suite functions +//***************************************************************************** + +static int init_common_suite() +{ + return mars_initialize(&mars, 0) != MARS_SUCCESS; +} + +static int clean_common_suite() +{ + return mars_finalize(&mars) != MARS_SUCCESS; +} + +//***************************************************************************** +// MARS task API suite functions +//***************************************************************************** + +static void TFP_mars_task_initialize() +{ + int ret; + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_initialize( + &mars, + &task_id, + NULL, + mpu_task_prog.elf_image, + 0), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_finalize(&task_id); + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_initialize( + &mars, + &task_id, + NULL, + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_finalize(&task_id); +} + +static void TFN_mars_task_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + NULL, + NULL, + NULL, + NULL, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + NULL, + NULL, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + NULL, + &task_id, + NULL, + NULL, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + NULL, + &task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + NULL, + NULL, + NULL, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + NULL, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_id, + NULL, + NULL, + 0), + MARS_ERROR_NULL); + + memset(&temp_mars, 0, sizeof(temp_mars)); + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &temp_mars, + &task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_id, + "no command", + mpu_task_prog.elf_image, + 1000000000), + MARS_ERROR_PARAMS); +} + +static void TFP_mars_task_finalize() +{ + mars_task_initialize( + &mars, + &task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + CU_ASSERT_EQUAL_MARS(mars_task_finalize(&task_id), MARS_SUCCESS); +} + +static void TFN_mars_task_finalize() +{ + CU_ASSERT_EQUAL_MARS(mars_task_finalize(NULL), MARS_ERROR_NULL); + + memset(&task_id, 0, sizeof(task_id)); + task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_finalize(&task_id), MARS_ERROR_PARAMS); +} + +static void TFP_mars_task_schedule() +{ + int ret, exit_code; + + mars_task_initialize( + &mars, + &task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + + CU_ASSERT_EQUAL_MARS(ret = mars_task_schedule(&task_id, NULL, 0), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS(ret = mars_task_schedule(&task_id, &task_args, 0), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS(ret = mars_task_schedule(&task_id, &task_args, 100), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS(ret = mars_task_schedule(&task_id, &task_args, 255), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&task_id, &exit_code); + + mars_task_finalize(&task_id); +} + +static void TFN_mars_task_schedule() +{ + mars_task_initialize( + &mars, + &task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + + CU_ASSERT_EQUAL_MARS(mars_task_schedule(NULL, NULL, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_schedule(NULL, &task_args, 0), MARS_ERROR_NULL); + + memset(&temp_task_id, 0, sizeof(temp_task_id)); + temp_task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_schedule(&temp_task_id, &task_args, 0), MARS_ERROR_PARAMS); + + mars_task_finalize(&task_id); +} + +static void TFP_mars_task_wait() +{ + int exit_code; + + mars_task_initialize( + &mars, + &task_id, + "sleep", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + CU_ASSERT_EQUAL_MARS(mars_task_wait(&task_id, &exit_code), MARS_SUCCESS); + + mars_task_schedule(&task_id, NULL, 0); + CU_ASSERT_EQUAL_MARS(mars_task_wait(&task_id, &exit_code), MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS(mars_task_wait(&task_id, &exit_code), MARS_SUCCESS); + + mars_task_finalize(&task_id); +} + +static void TFN_mars_task_wait() +{ + int exit_code; + + CU_ASSERT_EQUAL_MARS(mars_task_wait(NULL, &exit_code), MARS_ERROR_NULL); + + memset(&task_id, 0, sizeof(task_id)); + task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_wait(&task_id, &exit_code), MARS_ERROR_PARAMS); + + mars_task_initialize( + &mars, + &task_id, + "sleep", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + mars_task_wait(&task_id, &exit_code); + mars_task_finalize(&task_id); + //CU_ASSERT_EQUAL_MARS(mars_task_wait(&task_id, &exit_code), MARS_ERROR_STATE); +} + +static void TFP_mars_task_try_wait() +{ + int exit_code; + + mars_task_initialize( + &mars, + &task_id, + "sleep", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&task_id, &exit_code), MARS_SUCCESS); + + mars_task_wait(&task_id, &exit_code); + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&task_id, &exit_code), MARS_SUCCESS); + + mars_task_finalize(&task_id); +} + +static void TFN_mars_task_try_wait() +{ + int exit_code; + + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(NULL, NULL), MARS_ERROR_NULL); + + memset(&task_id, 0, sizeof(task_id)); + task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&task_id, &exit_code), MARS_ERROR_PARAMS); + + mars_task_initialize( + &mars, + &task_id, + "sleep", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + + mars_task_schedule(&task_id, NULL, 0); + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&task_id, &exit_code), MARS_ERROR_BUSY); + + mars_task_wait(&task_id, &exit_code); + mars_task_finalize(&task_id); + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&task_id, &exit_code), MARS_ERROR_STATE); +} + +//***************************************************************************** +// MARS mutex API suite functions +//***************************************************************************** + +static void TFP_mars_mutex_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(&mutex), MARS_SUCCESS); +} + +static void TFN_mars_mutex_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(NULL), MARS_ERROR_NULL); + + wrong_mutex_ptr = (struct mars_mutex*)((char*)temp_mutexes+3); + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(wrong_mutex_ptr), MARS_ERROR_ALIGN); +} + +static void TFP_mars_mutex_lock() +{ + int ret; + + mars_mutex_initialize(&mutex); + + CU_ASSERT_EQUAL_MARS(ret = mars_mutex_lock(&mutex), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_mutex_unlock(&mutex); +} + +static void TFN_mars_mutex_lock() +{ + mars_mutex_initialize(&mutex); + + CU_ASSERT_EQUAL_MARS(mars_mutex_lock(NULL), MARS_ERROR_NULL); + + wrong_mutex_ptr = (struct mars_mutex*)((char*)temp_mutexes+3); + CU_ASSERT_EQUAL_MARS(mars_mutex_lock(wrong_mutex_ptr), MARS_ERROR_ALIGN); +} + +static void TFP_mars_mutex_unlock() +{ + mars_mutex_initialize(&mutex); + + mars_mutex_lock(&mutex); + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(&mutex), MARS_SUCCESS); +} + +static void TFN_mars_mutex_unlock() +{ + mars_mutex_initialize(&mutex); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(NULL), MARS_ERROR_NULL); + + wrong_mutex_ptr = (struct mars_mutex*)((char*)temp_mutexes+3); + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(wrong_mutex_ptr), MARS_ERROR_ALIGN); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(&mutex), MARS_ERROR_STATE); +} + +//***************************************************************************** +// MARS barrier API suite functions +//***************************************************************************** + +static void TFP_mars_task_barrier_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, &barrier, 10), MARS_SUCCESS); +} + +static void TFN_mars_task_barrier_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(NULL, NULL, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(NULL, NULL, 10), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(NULL, &barrier, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(NULL, &barrier, 10), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, NULL, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, NULL, 10), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, &barrier, 0), MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, &barrier, 100), MARS_ERROR_LIMIT); + + wrong_barrier_ptr = (struct mars_task_barrier*)((char*)temp_barriers+3); + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&mars, wrong_barrier_ptr, 10), MARS_ERROR_ALIGN); + + memset(&temp_mars, 0, sizeof(temp_mars)); + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(&temp_mars, &barrier, 10), MARS_ERROR_NULL); +} + +//***************************************************************************** +// MARS task API suite functions +//***************************************************************************** + +static void TFP_mars_task_event_flag_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_MPU_TO_HOST, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_MPU_TO_HOST, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_MPU_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_MPU_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); +} + +static void TFN_mars_task_event_flag_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + NULL, + 0, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + NULL, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + NULL, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + NULL, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + &event_flag, + 0, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + &event_flag, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + NULL, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + NULL, + 0, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + NULL, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + NULL, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + NULL, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + 0, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 100), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + &event_flag, + 100, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_PARAMS); + + wrong_event_flag_ptr = (struct mars_task_event_flag*)((char*)temp_event_flags+3); + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &mars, + wrong_event_flag_ptr, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_ALIGN); + + memset(&temp_mars, 0, sizeof(temp_mars)); + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + &temp_mars, + &event_flag, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); +} + +//***************************************************************************** +// MARS shared data queue API suite functions +//***************************************************************************** + +static int init_queue_suite() +{ + queue_buffer = (int8_t*)memalign(MARS_TASK_QUEUE_ENTRY_ALIGN, 65536); + + return init_common_suite(); +} + +static int clean_queue_suite() +{ + free(queue_buffer); + + return clean_common_suite(); +} + +static void TFP_mars_task_queue_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4096, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4096, + MARS_TASK_QUEUE_MPU_TO_HOST), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4096, + MARS_TASK_QUEUE_MPU_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 10, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 100, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 256, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4095, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); +} + +static void TFN_mars_task_queue_initialize() +{ + wrong_queue_ptr = (struct mars_task_queue*)((char*)temp_queues+3); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4096, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 4096, + 100), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + &mars, + &queue, + queue_buffer, + 16, + 0, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_ERROR_PARAMS); +} + +#define INFO \ +"\ +Use 'p' and/or 'n' parameter to set a test suite.\n\ +\n\ + 'p' - (positive functional tests)\n\ + 'n' - (negative functional tests)\n\ +\n\ +Example:\n\ +./black_box_test_1 pn\n" + +int main(int argc, char** argv) +{ + int added, exit_code; + CU_pSuite pInitFinSuite, pTaskSuite, pMutexSuite, pBarrierSuite, pEventFlagSuite, + pQueueSuite; + + if (argc <= 1) + { + printf(INFO); + return 0; + } + + printf("\n********************************************************************************\n"); + printf("* Host tests *\n"); + printf("********************************************************************************\n"); + + positive = (int)(uint64_t)strstr(argv[1], "p"); + negative = (int)(uint64_t)strstr(argv[1], "n"); + + if (CU_initialize_registry() != CUE_SUCCESS) + return CU_get_error(); + + // Setup all test suites + pInitFinSuite = CU_add_suite("MARS context initialize/finalize", NULL, NULL); + pTaskSuite = CU_add_suite("MARS task API", init_common_suite, clean_common_suite); + pMutexSuite = CU_add_suite("MARS mutex API", init_common_suite, clean_common_suite); + pBarrierSuite = CU_add_suite("MARS barrier API", init_common_suite, clean_common_suite); + pEventFlagSuite = CU_add_suite("MARS event flag API", init_common_suite, clean_common_suite); + pQueueSuite = CU_add_suite("MARS shared data queue API", init_queue_suite, clean_queue_suite); + + added = pInitFinSuite && + pTaskSuite && + pMutexSuite && + pBarrierSuite && + pEventFlagSuite && + pQueueSuite; + + if (!added) + { + CU_cleanup_registry(); + return CU_get_error(); + } + + // Add all functional tests + CU_add_test_mars(pInitFinSuite, mars_initialize); + CU_add_test_mars(pInitFinSuite, mars_finalize); + + CU_add_test_mars(pTaskSuite, mars_task_initialize); + CU_add_test_mars(pTaskSuite, mars_task_finalize); + CU_add_test_mars(pTaskSuite, mars_task_schedule); + CU_add_test_mars(pTaskSuite, mars_task_wait); + CU_add_test_mars(pTaskSuite, mars_task_try_wait); + + CU_add_test_mars(pMutexSuite, mars_mutex_initialize); + CU_add_test_mars(pMutexSuite, mars_mutex_lock); + CU_add_test_mars(pMutexSuite, mars_mutex_unlock); + + CU_add_test_mars(pBarrierSuite, mars_task_barrier_initialize); + + CU_add_test_mars(pEventFlagSuite, mars_task_event_flag_initialize); + + CU_add_test_mars(pQueueSuite, mars_task_queue_initialize); + + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + // MPU part + + mars_initialize(&mars, 0); + + spe_test_params.positive = positive; + spe_test_params.negative = negative; + + mars_task_initialize( + &mars, + &spe_test_params.mars_task_schedule_task_id, + "no command", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + + mars_task_initialize( + &mars, + &spe_test_params.mars_task_wait_task_id, + "sleep", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + + spe_test_params.mutex_ea = (uint64_t)&mutex; + spe_test_params.barrier_ea = (uint64_t)&barrier; + spe_test_params.event_flag_ea = (uint64_t)&event_flag; + spe_test_params.queue_ea = (uint64_t)&queue; + spe_test_params.queue_buffer_ea = (uint64_t)queue_buffer; + + mars_task_initialize( + &mars, + &task_id, + "spe test", + mpu_task_prog.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX); + task_args.type.u64[0] = (uint64_t)&spe_test_params; + mars_task_schedule(&task_id, &task_args, 0); + mars_task_wait(&task_id, &exit_code); + mars_task_finalize(&task_id); + + mars_task_wait(&spe_test_params.mars_task_wait_task_id, &exit_code); + mars_task_finalize(&spe_test_params.mars_task_wait_task_id); + + mars_task_wait(&spe_test_params.mars_task_schedule_task_id, &exit_code); + mars_task_finalize(&spe_test_params.mars_task_schedule_task_id); + + mars_finalize(&mars); + + return CU_get_error(); +}
diff --git a/TFP_TFN/black_box_test_1/host_mpu_common.h b/TFP_TFN/black_box_test_1/host_mpu_common.h new file mode 100644 index 0000000..760f385 --- /dev/null +++ b/TFP_TFN/black_box_test_1/host_mpu_common.h
@@ -0,0 +1,78 @@ +#include <string.h> + +/** CU_ASSERT_EQUAL override to see return value + * Asserts that actual == expected. + * Reports failure with no other action. + */ + +int act_val, exp_val; +char print_msg[1024], print_msg_ret[30]; + +#define APPEND_RET(RET) if (act_val == RET) snprintf(print_msg_ret, 30, "%s", #RET); + +#define CU_ASSERT_EQUAL_MARS(actual, expected)\ +\ + {\ + act_val = (actual);\ + exp_val = (expected);\ + strncpy(print_msg, "CU_ASSERT_EQUAL_MARS(" #actual "," #expected "), function returned ", 1024);\ + APPEND_RET(MARS_SUCCESS)\ + else\ + APPEND_RET(MARS_ERROR_NULL)\ + else\ + APPEND_RET(MARS_ERROR_PARAMS)\ + else\ + APPEND_RET(MARS_ERROR_INTERNAL)\ + else\ + APPEND_RET(MARS_ERROR_MEMORY)\ + else\ + APPEND_RET(MARS_ERROR_ALIGN)\ + else\ + APPEND_RET(MARS_ERROR_LIMIT)\ + else\ + APPEND_RET(MARS_ERROR_STATE)\ + else\ + APPEND_RET(MARS_ERROR_FORMAT)\ + else\ + APPEND_RET(MARS_ERROR_BUSY)\ + else\ + snprintf(print_msg_ret, 30, "%i", act_val);\ + strncat(print_msg, print_msg_ret, 1023);\ + CU_assertImplementation((act_val == exp_val), __LINE__, (print_msg), __FILE__, "", CU_FALSE);\ + } + +static int positive, negative; +static char add_test_buffer[128]; + +#define CU_add_test_mars_pn(PN, SUITE, PREFIX, FUNCTION)\ +\ + if (PN)\ + {\ + strncpy(add_test_buffer, #PREFIX, 128);\ + strncat(add_test_buffer, #FUNCTION, 128);\ + if (!CU_add_test(SUITE, add_test_buffer, PREFIX##FUNCTION))\ + {\ + CU_cleanup_registry();\ + return CU_get_error();\ + }\ + } + +#define CU_add_test_mars(SUITE, FUNCTION)\ +\ + CU_add_test_mars_pn(positive, SUITE, TFP_, FUNCTION)\ + CU_add_test_mars_pn(negative, SUITE, TFN_, FUNCTION) + +struct SPE_TEST_PARAMS +{ + int positive; + int negative; + struct mars_task_id mars_task_schedule_task_id; + struct mars_task_id mars_task_wait_task_id; + uint64_t mutex_ea; + uint64_t barrier_ea; + uint64_t event_flag_ea; + uint64_t queue_ea; + uint64_t queue_buffer_ea; +}; + +static struct SPE_TEST_PARAMS spe_test_params;
diff --git a/TFP_TFN/black_box_test_1/mpu_task.c b/TFP_TFN/black_box_test_1/mpu_task.c new file mode 100644 index 0000000..078b5f1 --- /dev/null +++ b/TFP_TFN/black_box_test_1/mpu_task.c
@@ -0,0 +1,585 @@ +#include <stdio.h> +#include <unistd.h> +#include <CUnit/Basic.h> +#include "mars/mars.h" +#include "mars/mars_dma.h" +#include "mars/mars_task.h" +#include "host_mpu_common.h" + +static struct mars_task_id temp_task_id; +static struct mars_task_args task_args; +static struct mars_mutex mutex, temp_mutexes[2], *wrong_mutex_ptr; +static uint64_t wrong_mutex_ea; +static uint64_t wrong_barrier_ea; +static uint64_t wrong_event_flag_ea; + +static void TFP_mars_task_schedule() +{ + int ret, exit_code; + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_schedule( + &spe_test_params.mars_task_schedule_task_id, + NULL, + 0), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&spe_test_params.mars_task_schedule_task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_schedule( + &spe_test_params.mars_task_schedule_task_id, + &task_args, + 0), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&spe_test_params.mars_task_schedule_task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_schedule( + &spe_test_params.mars_task_schedule_task_id, + &task_args, + 100), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&spe_test_params.mars_task_schedule_task_id, &exit_code); + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_schedule( + &spe_test_params.mars_task_schedule_task_id, + &task_args, + 255), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_task_wait(&spe_test_params.mars_task_schedule_task_id, &exit_code); +} + +static void TFN_mars_task_schedule() +{ + CU_ASSERT_EQUAL_MARS(mars_task_schedule(NULL, NULL, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_schedule(NULL, &task_args, 0), MARS_ERROR_NULL); + + memset(&temp_task_id, 0, sizeof(temp_task_id)); + temp_task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_schedule(&temp_task_id, &task_args, 0), MARS_ERROR_PARAMS); +} + +static void TFP_mars_task_wait() +{ + int exit_code; + + CU_ASSERT_EQUAL_MARS( + mars_task_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_SUCCESS); + + mars_task_schedule(&spe_test_params.mars_task_wait_task_id, NULL, 0); + CU_ASSERT_EQUAL_MARS( + mars_task_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_SUCCESS); +} + +static void TFN_mars_task_wait() +{ + CU_ASSERT_EQUAL_MARS(mars_task_wait(NULL, NULL), MARS_ERROR_NULL); + + //memset(&temp_task_id, 0, sizeof(temp_task_id)); + //temp_task_id.workload_id = 200; + //CU_ASSERT_EQUAL_MARS(mars_task_wait(&temp_task_id), MARS_ERROR_PARAMS); +} + +static void TFP_mars_task_try_wait() +{ + int exit_code; + + CU_ASSERT_EQUAL_MARS( + mars_task_try_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_SUCCESS); + + mars_task_schedule(&spe_test_params.mars_task_wait_task_id, NULL, 0); + mars_task_wait(&spe_test_params.mars_task_wait_task_id, &exit_code); + CU_ASSERT_EQUAL_MARS( + mars_task_try_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_SUCCESS); +} + +static void TFN_mars_task_try_wait() +{ + int exit_code; + + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(NULL, NULL), MARS_ERROR_NULL); + + memset(&temp_task_id, 0, sizeof(temp_task_id)); + temp_task_id.workload_id = 200; + CU_ASSERT_EQUAL_MARS(mars_task_try_wait(&temp_task_id, &exit_code), MARS_ERROR_PARAMS); + + mars_task_schedule(&spe_test_params.mars_task_wait_task_id, NULL, 0); + CU_ASSERT_EQUAL_MARS( + mars_task_try_wait( + &spe_test_params.mars_task_wait_task_id, + &exit_code), + MARS_ERROR_BUSY); +} + +static void TFP_mars_mutex_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(spe_test_params.mutex_ea), MARS_SUCCESS); +} + +static void TFN_mars_mutex_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(0), MARS_ERROR_NULL); + + wrong_mutex_ea = spe_test_params.mutex_ea+3; + CU_ASSERT_EQUAL_MARS(mars_mutex_initialize(wrong_mutex_ea), MARS_ERROR_ALIGN); +} + +static void TFP_mars_mutex_lock() +{ + int ret; + + mars_mutex_initialize(spe_test_params.mutex_ea); + + CU_ASSERT_EQUAL_MARS(ret = mars_mutex_lock(spe_test_params.mutex_ea), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_mutex_unlock(spe_test_params.mutex_ea); +} + +static void TFN_mars_mutex_lock() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_lock(0), MARS_ERROR_NULL); + + wrong_mutex_ea = spe_test_params.mutex_ea+3; + CU_ASSERT_EQUAL_MARS(mars_mutex_lock(wrong_mutex_ea), MARS_ERROR_ALIGN); +} + +static void TFP_mars_mutex_unlock() +{ + mars_mutex_initialize(spe_test_params.mutex_ea); + + mars_mutex_lock(spe_test_params.mutex_ea); + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(spe_test_params.mutex_ea), MARS_SUCCESS); +} + +static void TFN_mars_mutex_unlock() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(0), MARS_ERROR_NULL); + + wrong_mutex_ea = spe_test_params.mutex_ea+3; + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(wrong_mutex_ea), MARS_ERROR_ALIGN); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock(spe_test_params.mutex_ea), MARS_ERROR_STATE); +} + +static void TFP_mars_mutex_lock_get() +{ + int ret; + + mars_mutex_initialize(spe_test_params.mutex_ea); + + CU_ASSERT_EQUAL_MARS(ret = mars_mutex_lock_get(spe_test_params.mutex_ea, &mutex), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_mutex_unlock(spe_test_params.mutex_ea); +} + +static void TFN_mars_mutex_lock_get() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_lock_get(0, NULL), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_mutex_lock_get(0, &mutex), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_mutex_lock_get(spe_test_params.mutex_ea, NULL), MARS_ERROR_NULL); + + wrong_mutex_ptr = (struct mars_mutex*)((char*)temp_mutexes+3); + CU_ASSERT_EQUAL_MARS(mars_mutex_lock_get(spe_test_params.mutex_ea, wrong_mutex_ptr), MARS_ERROR_ALIGN); + + wrong_mutex_ea = spe_test_params.mutex_ea+3; + CU_ASSERT_EQUAL_MARS(mars_mutex_lock_get(wrong_mutex_ea, &mutex), MARS_ERROR_ALIGN); +} + +static void TFP_mars_mutex_unlock_put() +{ + mars_mutex_initialize(spe_test_params.mutex_ea); + + mars_mutex_lock_get(spe_test_params.mutex_ea, &mutex); + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(spe_test_params.mutex_ea, &mutex), MARS_SUCCESS); +} + +static void TFN_mars_mutex_unlock_put() +{ + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(0, NULL), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(0, &mutex), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(spe_test_params.mutex_ea, NULL), MARS_ERROR_NULL); + + wrong_mutex_ptr = (struct mars_mutex*)((char*)temp_mutexes+3); + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(spe_test_params.mutex_ea, wrong_mutex_ptr), MARS_ERROR_ALIGN); + + wrong_mutex_ea = spe_test_params.mutex_ea+3; + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(wrong_mutex_ea, &mutex), MARS_ERROR_ALIGN); + + CU_ASSERT_EQUAL_MARS(mars_mutex_unlock_put(spe_test_params.mutex_ea, &mutex), MARS_ERROR_STATE); +} + +static void TFP_mars_task_barrier_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(spe_test_params.barrier_ea, 10), MARS_SUCCESS); +} + +static void TFN_mars_task_barrier_initialize() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(0, 0), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(0, 10), MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(spe_test_params.barrier_ea, 0), MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(spe_test_params.barrier_ea, 100), MARS_ERROR_LIMIT); + + wrong_barrier_ea = spe_test_params.barrier_ea+3; + CU_ASSERT_EQUAL_MARS(mars_task_barrier_initialize(wrong_barrier_ea, 10), MARS_ERROR_ALIGN); +} + +static void TFP_mars_task_barrier_notify() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_notify(spe_test_params.barrier_ea), MARS_SUCCESS); +} + +static void TFN_mars_task_barrier_notify() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_notify(0), MARS_ERROR_NULL); + + wrong_barrier_ea = spe_test_params.barrier_ea+3; + CU_ASSERT_EQUAL_MARS(mars_task_barrier_notify(wrong_barrier_ea), MARS_ERROR_ALIGN); +} + +static void TFP_mars_task_barrier_wait() +{ + mars_task_barrier_initialize(spe_test_params.barrier_ea, 1); + mars_task_barrier_notify(spe_test_params.barrier_ea); + CU_ASSERT_EQUAL_MARS(mars_task_barrier_wait(spe_test_params.barrier_ea), MARS_SUCCESS); +} + +static void TFN_mars_task_barrier_wait() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_wait(0), MARS_ERROR_NULL); + + wrong_barrier_ea = spe_test_params.barrier_ea+3; + CU_ASSERT_EQUAL_MARS(mars_task_barrier_wait(wrong_barrier_ea), MARS_ERROR_ALIGN); +} + +static void TFP_mars_task_barrier_try_wait() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_try_wait(spe_test_params.barrier_ea), MARS_SUCCESS); +} + +static void TFN_mars_task_barrier_try_wait() +{ + CU_ASSERT_EQUAL_MARS(mars_task_barrier_try_wait(0), MARS_ERROR_NULL); + + wrong_barrier_ea = spe_test_params.barrier_ea+3; + CU_ASSERT_EQUAL_MARS(mars_task_barrier_try_wait(wrong_barrier_ea), MARS_ERROR_ALIGN); +} + +static void TFP_mars_task_event_flag_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_MPU_TO_HOST, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_MPU_TO_HOST, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_MPU_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_MPU_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_MANUAL), + MARS_SUCCESS); +} + +static void TFN_mars_task_event_flag_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + 0, + 0, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + 0, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + 0, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + 0, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + + MARS_ERROR_NULL); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + 0, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + 0, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + 100), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + spe_test_params.event_flag_ea, + 100, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_PARAMS); + + wrong_event_flag_ea = spe_test_params.event_flag_ea+3; + CU_ASSERT_EQUAL_MARS( + mars_task_event_flag_initialize( + wrong_event_flag_ea, + MARS_TASK_EVENT_FLAG_HOST_TO_MPU, + MARS_TASK_EVENT_FLAG_CLEAR_AUTO), + MARS_ERROR_ALIGN); +} + +static void TFP_mars_task_queue_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4096, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4096, + MARS_TASK_QUEUE_MPU_TO_HOST), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4096, + MARS_TASK_QUEUE_MPU_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 10, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 100, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 256, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4095, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_SUCCESS); +} + +static void TFN_mars_task_queue_initialize() +{ + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4096, + 0), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 4096, + 100), + MARS_ERROR_PARAMS); + + CU_ASSERT_EQUAL_MARS( + mars_task_queue_initialize( + spe_test_params.queue_ea, + spe_test_params.queue_buffer_ea, + 16, + 0, + MARS_TASK_QUEUE_HOST_TO_MPU), + MARS_ERROR_PARAMS); +} + +int mars_task_main(const struct mars_task_args *task_args) +{ + int added; + CU_pSuite pTaskSuite, pMutexSuite, pBarrierSuite, pEventFlagSuite, pQueueSuite; + + if (strcmp(mars_task_get_name(), "sleep") == 0) + { + sleep(2); + return 0; + } + + if (strcmp(mars_task_get_name(), "spe test") != 0) + return 0; + + printf("\n********************************************************************************\n"); + printf("* MPU tests *\n"); + printf("********************************************************************************\n"); + + mars_dma_get_and_wait(&spe_test_params, task_args->type.u64[0], sizeof(spe_test_params), 0); + + positive = spe_test_params.positive; + negative = spe_test_params.negative; + + if (CU_initialize_registry() != CUE_SUCCESS) + return CU_get_error(); + + // Setup all test suites + pTaskSuite = CU_add_suite("MARS task API", NULL, NULL); + pMutexSuite = CU_add_suite("MARS mutex API", NULL, NULL); + pBarrierSuite = CU_add_suite("MARS barrier API", NULL, NULL); + pEventFlagSuite = CU_add_suite("MARS event flag API", NULL, NULL); + pQueueSuite = CU_add_suite("MARS shared data queue API", NULL, NULL); + + added = pTaskSuite && + pMutexSuite && + pBarrierSuite && + pEventFlagSuite && + pQueueSuite; + + if (!added) + { + CU_cleanup_registry(); + return CU_get_error(); + } + + // Add all functional tests + CU_add_test_mars(pTaskSuite, mars_task_schedule); + CU_add_test_mars(pTaskSuite, mars_task_wait); + CU_add_test_mars(pTaskSuite, mars_task_try_wait); + + CU_add_test_mars(pMutexSuite, mars_mutex_initialize); + CU_add_test_mars(pMutexSuite, mars_mutex_lock); + CU_add_test_mars(pMutexSuite, mars_mutex_unlock); + CU_add_test_mars(pMutexSuite, mars_mutex_lock_get); + CU_add_test_mars(pMutexSuite, mars_mutex_unlock_put); + + CU_add_test_mars(pBarrierSuite, mars_task_barrier_initialize); + CU_add_test_mars(pBarrierSuite, mars_task_barrier_notify); + CU_add_test_mars(pBarrierSuite, mars_task_barrier_wait); + CU_add_test_mars(pBarrierSuite, mars_task_barrier_try_wait) + + CU_add_test_mars(pEventFlagSuite, mars_task_event_flag_initialize); + + CU_add_test_mars(pQueueSuite, mars_task_queue_initialize); + + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + return CU_get_error(); +}
diff --git a/TPF/mutex_test_1/Makefile b/TPF/mutex_test_1/Makefile new file mode 100644 index 0000000..17814e0 --- /dev/null +++ b/TPF/mutex_test_1/Makefile
@@ -0,0 +1,43 @@ +## Makefile + +sample = mutex_test_1 + +MARS_LIB_SRC = ../../../mars-src/src +MARS_LIB_INC = ../../../mars-src/include + +include ../../config.mk + +SPU_CFLAGS += -fstrict-aligned + +.PHONY: all marslibs clean rebuild run + +all: $(sample) + +$(sample): marslibs mpu_task.eo host.o + $(PPU_CC) $(PPU_CFLAGS) -o $@ $(PPU_LDFLAGS) mpu_task.eo host.o $(MARS_LIB_SRC)/host/lib/.libs/libmars.a $(MARS_LIB_SRC)/mpu/kernel/mars_kernel.eo + +host.o: host.c host_mpu_common.h host_mutex.h + $(PPU_CC) $(PPU_CFLAGS) -c -o $@ $< -I$(MARS_LIB_INC)/host -I$(MARS_LIB_INC)/common -m64 + +mpu_task.eo: mpu_task.o + $(PPU_EMBEDSPU) $(PPU_CFLAGS) task_spe_prog $< $@ + +mpu_task.o: mpu_task.c host_mpu_common.h mpu_mutex.h $(MARS_LIB_SRC)/mpu/lib/libmars.a + $(SPU_CC) $(SPU_CFLAGS) -o $@ $< $(SPU_LDFLAGS) $(MARS_LIB_SRC)/mpu/lib/libmars.a -I$(MARS_LIB_INC)/common -I$(MARS_LIB_INC)/mpu + +marslibs: + make -C$(MARS_LIB_SRC)/mpu/kernel all CFLAGS+=" -Wall" + make -C$(MARS_LIB_SRC)/mpu/lib all CFLAGS+=" -Wall" + make -C$(MARS_LIB_SRC)/host/lib all CFLAGS+=" -m64 -Wall -I/usr/lib/gcc/ppu/4.1.1/include" + +clean: + rm -f *.o *.eo $(sample) + + make -C$(MARS_LIB_SRC)/mpu/kernel clean + make -C$(MARS_LIB_SRC)/mpu/lib clean + make -C$(MARS_LIB_SRC)/host/lib clean + +rebuild: clean all + +run: all + ./$(sample) 1
diff --git a/TPF/mutex_test_1/host.c b/TPF/mutex_test_1/host.c new file mode 100644 index 0000000..aab86c4 --- /dev/null +++ b/TPF/mutex_test_1/host.c
@@ -0,0 +1,182 @@ +#include <stdlib.h> +#include <malloc.h> +#include <string.h> +#include <libspe2.h> +#include <unistd.h> +#include <inttypes.h> +#include "mars/mars.h" +#include "host_mutex.h" + +#define INFO \ +"\n\ +MARS Mutex Test\n\ +--------------------\n\ +This program measures a Mutex reservation lost event probability.\n\ +\n\ +You can get more precise results by overriding loop count by number parameter.\n\ +Example:\n\ +./mutex_benchmark 500\n\ +\n" + +#define MIN_TASK_COUNT 1 +#define MAX_TASK_COUNT 16 +#define MIN_CALC_LOOP_COUNT 1 +#define MAX_CALC_LOOP_COUNT 65536 +#define DEFAULT_LOCK_COUNT 256 + +struct TASK_RESULT +{ + uint64_t result; + uint64_t unused; +} __attribute__((aligned(16))); + +extern struct spe_program_handle task_spe_prog; + +static struct mars_context mars; +static struct mars_task_params task_params; +static struct mars_task_id task_ids[MAX_TASK_COUNT]; +static struct mars_task_args task_args; +static struct mars_mutex mutex; +static struct TASK_RESULT tasks_results[MAX_TASK_COUNT]; + +#define MUTEX &mutex +#include "host_mpu_common.h" + +void print_border_line() +{ + int i; + + printf("|"); + for (i = 0;i < 157;i++) + printf("-"); + printf("|\n"); +} + +void print_table_header() +{ + int calc_loop_count, i; + + printf("\n"); + + print_border_line(); + + printf("| Mutex reservation lost event percentage - Host , MPU"); + for (i = 0;i < 104;i++) + printf(" "); + printf("|\n"); + + print_border_line(); + + printf("| loop count |"); + for (calc_loop_count = MIN_CALC_LOOP_COUNT;calc_loop_count <= MAX_CALC_LOOP_COUNT;calc_loop_count*=4) + printf("| %13i ",calc_loop_count); + printf("|\n"); + + printf("|------------||"); + for (calc_loop_count = MIN_CALC_LOOP_COUNT;calc_loop_count <= MAX_CALC_LOOP_COUNT;calc_loop_count*=4) + printf(" Host MPU |"); + printf("\n"); + + printf("| task count ||"); + for (calc_loop_count = MIN_CALC_LOOP_COUNT;calc_loop_count <= MAX_CALC_LOOP_COUNT;calc_loop_count*=4) + printf(" [%%] [%%] |"); + printf("\n"); + + print_border_line(); +} + +int main(int argc, char** argv) +{ + int task, task_count, lock_count, calc_loop_count; + + + + printf(INFO); + + + + if (argc == 2) + lock_count = atol(argv[1]); + else + { + lock_count = DEFAULT_LOCK_COUNT; + + printf("Choosing default lock count = %i\n\n", DEFAULT_LOCK_COUNT); + } + + + + mars_initialize(&mars, NULL); + + + + mars_mutex_initialize(&mutex); + + + + /********************/ + /* Host to MPU part */ + /********************/ + + print_table_header(); + + for (task_count = MIN_TASK_COUNT;task_count <= MAX_TASK_COUNT;task_count++) + { + printf("| %10i ||",task_count); + + for (calc_loop_count = MIN_CALC_LOOP_COUNT;calc_loop_count <= MAX_CALC_LOOP_COUNT;calc_loop_count*=4) + { + mutex.pad[0] = lock_count; + mutex.pad[1] = calc_loop_count; + + for (task = 0;task < task_count;task++) + { + task_params.name = "MPU Task"; + task_params.elf_image = task_spe_prog.elf_image; + task_params.context_save_size = MARS_TASK_CONTEXT_SAVE_SIZE_MAX; + + mars_task_initialize(&mars, &task_ids[task], &task_params); + } + + for (task = 0;task < task_count;task++) + { + task_args.type.u64[0] = (uint64_t)&mutex; + task_args.type.u64[1] = (uint64_t)&tasks_results[task]; + mars_task_schedule(&task_ids[task], &task_args, 0); + } + + reservation_lost = 0; + + process_locking(lock_count, calc_loop_count); + + printf(" %6.3f", 100.0*reservation_lost/lock_count); + + reservation_lost = 0; + + for (task = 0;task < task_count;task++) + { + mars_task_wait(&task_ids[task]); + + mars_task_finalize(&task_ids[task]); + + reservation_lost += tasks_results[task].result; + } + + printf(" %6.3f |", 100.0*reservation_lost/(task_count*lock_count)); + } + + printf("\n"); + } + + print_border_line(); + + + + mars_finalize(&mars); + + + + return 0; +} + +
diff --git a/TPF/mutex_test_1/host_mpu_common.h b/TPF/mutex_test_1/host_mpu_common.h new file mode 100644 index 0000000..61fa187 --- /dev/null +++ b/TPF/mutex_test_1/host_mpu_common.h
@@ -0,0 +1,21 @@ +static int64_t calc_counter = 0; + +static void process_locking(int64_t lock_count, int64_t calc_loop_count) +{ + int64_t lock, calc; + + for (lock = 0;lock < lock_count;lock++) + { + mars_mutex_lock(MUTEX); + + for (calc = 0;calc < calc_loop_count;calc++) + { + if ((calc % 2) == 0) + calc_counter += calc; + else + calc_counter -= calc; + } + + mars_mutex_unlock(MUTEX); + } +}
diff --git a/TPF/mutex_test_1/host_mutex.h b/TPF/mutex_test_1/host_mutex.h new file mode 100644 index 0000000..9e89ec9 --- /dev/null +++ b/TPF/mutex_test_1/host_mutex.h
@@ -0,0 +1,51 @@ +#include "mars_mutex_types.h" +#include "mars/mars_atomic.h" +#include "mars/mars_error.h" +#include "mars/mars_debug.h" + +int64_t reservation_lost __attribute__((aligned(16))) = 0; + +int mars_mutex_initialize(struct mars_mutex *mutex) +{ + MARS_CHECK_RET(mutex, MARS_ERROR_NULL); + MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + + mutex->lock = MARS_MUTEX_UNLOCKED; + + return MARS_SUCCESS; +} + +int mars_mutex_lock(struct mars_mutex *mutex) +{ + MARS_CHECK_RET(mutex, MARS_ERROR_NULL); + MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + + int64_t local_reservation_lost = -1; + + do { + local_reservation_lost++; + + do { + } while (atomic_get(&mutex->lock) == MARS_MUTEX_LOCKED); + } while (!atomic_put(&mutex->lock, MARS_MUTEX_LOCKED)); + + reservation_lost += local_reservation_lost; + + atomic_sync(); + + return MARS_SUCCESS; +} + +int mars_mutex_unlock(struct mars_mutex *mutex) +{ + MARS_CHECK_RET(mutex, MARS_ERROR_NULL); + MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE); + + mutex->lock = MARS_MUTEX_UNLOCKED; + + return MARS_SUCCESS; +}
diff --git a/TPF/mutex_test_1/mars_mutex_types.h b/TPF/mutex_test_1/mars_mutex_types.h new file mode 100644 index 0000000..b8af05c --- /dev/null +++ b/TPF/mutex_test_1/mars_mutex_types.h
@@ -0,0 +1,65 @@ +#ifndef MARS_MUTEX_TYPES_H +#define MARS_MUTEX_TYPES_H + +/** + * \file + * \ingroup group_mars_mutex + * \brief MARS Mutex Types + */ + +#if defined(__cplusplus) +extern "C" { +#endif + +#include <stdint.h> + +/** + * \ingroup group_mars_mutex + * \brief Size of mutex structure + */ +#define MARS_MUTEX_SIZE 128 + +/** + * \ingroup group_mars_mutex + * \brief Alignment of mutex structure + */ +#define MARS_MUTEX_ALIGN 128 + +/** + * \ingroup group_mars_mutex + * \brief Alignment mask of mutex structure + */ +#define MARS_MUTEX_ALIGN_MASK 0x7f + +/** + * \ingroup group_mars_mutex + * \brief Value of mutex lock variable in locked state + */ +#define MARS_MUTEX_LOCKED 0x1 + +/** + * \ingroup group_mars_mutex + * \brief Value of mutex lock variable in unlocked state + */ +#define MARS_MUTEX_UNLOCKED 0x0 + +/** + * \ingroup group_mars_mutex + * \brief MARS mutex structure + * + * An instance of this structure must be created when using the MARS Mutex API. + * + * If allocating a memory area for this structure, make sure to allocate + * a memory area that is aligned to \ref MARS_MUTEX_ALIGN bytes + * and of size \ref MARS_MUTEX_SIZE bytes. + */ +struct mars_mutex { + uint32_t lock; + uint32_t pad[31]; +} __attribute__((aligned(MARS_MUTEX_ALIGN))); + +#if defined(__cplusplus) +} +#endif + +#endif
diff --git a/TPF/mutex_test_1/mpu_mutex.h b/TPF/mutex_test_1/mpu_mutex.h new file mode 100644 index 0000000..a29e1cc --- /dev/null +++ b/TPF/mutex_test_1/mpu_mutex.h
@@ -0,0 +1,86 @@ +/#include "mars_mutex_types.h" +#include "mars/mars_atomic.h" +#include "mars/mars_dma.h" +#include "mars/mars_error.h" +#include "mars/mars_debug.h" + +static struct mars_mutex mutex; + +int64_t reservation_lost __attribute__((aligned(16))) = 0; + +int mars_mutex_initialize(uint64_t mutex_ea) +{ + MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL); + MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + + mutex.lock = MARS_MUTEX_UNLOCKED; + + mars_dma_put_and_wait(&mutex, mutex_ea, sizeof(struct mars_mutex), + MARS_DMA_TAG); + + return MARS_SUCCESS; +} + +int mars_mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex) +{ + MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL); + MARS_CHECK_RET(mutex, MARS_ERROR_NULL); + MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + + int status; + int64_t local_reservation_lost = -1; + + atomic_event_setup(); + + do { + local_reservation_lost++; + + atomic_get(mutex, mutex_ea); + + if (mutex->lock == MARS_MUTEX_LOCKED) { + atomic_event_wait(); + status = 1; + } else { + mutex->lock = MARS_MUTEX_LOCKED; + status = atomic_put(mutex, mutex_ea); + } + } while (status); + + atomic_event_restore(); +//if (local_reservation_lost > 0)printf("MPU: local_reservation_lost = %llu\n",local_reservation_lost); + reservation_lost += local_reservation_lost; + + return MARS_SUCCESS; +} + +int mars_mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex) +{ + MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL); + MARS_CHECK_RET(mutex, MARS_ERROR_NULL); + MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0, + MARS_ERROR_ALIGN); + MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE); + + mutex->lock = MARS_MUTEX_UNLOCKED; + + mars_dma_put_and_wait(mutex, mutex_ea, sizeof(struct mars_mutex), + MARS_DMA_TAG); + + return MARS_SUCCESS; +} + +int mars_mutex_lock(uint64_t mutex_ea) +{ + return mars_mutex_lock_get(mutex_ea, &mutex); +} + +int mars_mutex_unlock(uint64_t mutex_ea) +{ + return mars_mutex_unlock_put(mutex_ea, &mutex); +}
diff --git a/TPF/mutex_test_1/mpu_task.c b/TPF/mutex_test_1/mpu_task.c new file mode 100644 index 0000000..e8993d4 --- /dev/null +++ b/TPF/mutex_test_1/mpu_task.c
@@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include "mars/mars.h" +#include "mpu_mutex.h" + +static uint64_t mutex_ea; +static uint64_t result_ea; + +static struct mars_mutex mutex; + +static uint32_t lock_count; +static uint32_t calc_loop_count; + +#define MUTEX mutex_ea +#include "host_mpu_common.h" + +int mars_task_main(const struct mars_task_args *task_args) +{ + mutex_ea = task_args->type.u64[0]; + result_ea = task_args->type.u64[1]; + + mars_mutex_lock_get(mutex_ea, &mutex); + + lock_count = mutex.pad[0]; + calc_loop_count = mutex.pad[1]; + + mars_mutex_unlock(mutex_ea); + + process_locking(lock_count, calc_loop_count); + + mars_dma_put_and_wait(&reservation_lost, result_ea, 8, 0); + + return 0; +}
diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..fc23add --- /dev/null +++ b/config.mk
@@ -0,0 +1,15 @@ +## config.mk + +PPU_CROSS = ppu- +PPU_CC = $(PPU_CROSS)gcc +PPU_CPPFLAGS = +PPU_CFLAGS = $(CFLAGS) -Wall -O3 -funroll-loops +PPU_LDFLAGS = $(LDFLAGS) -lspe2 +PPU_EMBEDSPU = $(PPU_CROSS)embedspu + +SPU_CROSS = spu- +SPU_CC = $(SPU_CROSS)gcc +SPU_CFLAGS = -Wall -O3 -funroll-loops +SPU_LDFLAGS = \ + -Wl,-N -Wl,-gc-sections -Wl,--section-start,.init=0x10000 \ + -Wl,--entry,mars_entry -Wl,-u,mars_entry
diff --git a/suite_TFN/Makefile b/suite_TFN/Makefile new file mode 100644 index 0000000..4f0449a --- /dev/null +++ b/suite_TFN/Makefile
@@ -0,0 +1,84 @@ +# `make V=1' to have verbose output +ifneq ($(V),1) +Q = @ +endif + +#HOSTCC = ppu-gcc +HOSTCC = gcc +MPUCC = spu-gcc + +CFLAGS = -Wall -Werror -O3 +HOSTCFLAGS = $(CFLAGS) # Add ... +MPUCFLAGS = $(CFLAGS) # Add ... + +LFLAGS = -lcunit +HOSTLFLAGS = $(LFLAGS) # Add ... +MPULFLAGS = $(LFLAGS) # Add ... + +TARGETS = test_host # test_mpu + + +.PHONY: all clean + +all: $(TARGETS) + +clean: + $(Q)$(RM) tests.h $(TARGETS) $(HOSTOBJS) $(MPU_OBJS) + + +HOSTSRCS := $(wildcard *_host.c) +HOSTOBJS := $(patsubst %.c, %.o, $(HOSTSRCS)) + +MPUSRCS := $(wildcard *_mpu.c) +MPUOBJS := $(patsubst %.c, %.o, $(MPUSRCS)) + +# Make hackery to create the list of tests +TESTSRCS := $(wildcard test_*.c) +TESTS := $(subst test_,,$(TESTSRCS)) +TESTS := $(subst _host.c,,$(TESTS)) +TESTS := $(subst _mpu.c,,$(TESTS)) +TESTS := $(sort $(TESTS)) +LPAREN := ( +RPAREN := ) +TESTDEFS := $(addprefix DEF_TEST$(LPAREN), $(addsuffix $(RPAREN), $(TESTS))) + +tests.h: $(TESTSRCS) + @echo "GEN $@" + $(Q)echo "$(TESTDEFS)" > tests.h + +test_host: $(HOSTOBJS) + @echo "HOSTLD $@" + $(Q)$(HOSTCC) $(HOSTLFLAGS) -o $@ $(HOSTOBJS) + +test_mpu: $(MPUOBJS) + @echo "MPULD $@" + $(Q)$(MPUCC) $(MPULFLAGS) -o $@ $(MPUOBJS) + +%_host.o: %_host.c + @echo "HOSTCC $@" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< + +%_mpu.o: %_mpu.c + @echo "MPUCC $@" + $(Q)$(MPUCC) $(MPUCFLAGS) -c -o $@ $< + +suite_host.o: tests.h +suite_mpu.o: tests.h + + +# For debugging +%_host.i: %_host.c + @echo "HOSTCC $<" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -E -o $@ $< + +%_mpu.i: %_mpu.c + @echo "MPUCC $<" + $(Q)$(MPUCC) $(MPUCFLAGS) -E -o $@ $< + +suite_host.i: tests.h +suite_mpu.i: tests.h + + +# Use `make print-VARIABLE' to print the value of $(VARIABLE) +print-%: + @echo $* = "$($*)"
diff --git a/suite_TFN/suite_host.c b/suite_TFN/suite_host.c new file mode 100644 index 0000000..1792930 --- /dev/null +++ b/suite_TFN/suite_host.c
@@ -0,0 +1,50 @@ +#include <CUnit/Basic.h> + +#include <stdlib.h> +#include <stdio.h> + + +#define DEF_TEST(test) extern void run_ ## test (void); +#include "tests.h" +#undef DEF_TEST + + +static CU_TestInfo tests[] = { +#define DEF_TEST(test) { #test, run_ ## test }, +#include "tests.h" +#undef DEF_TEST + { NULL, } +}; + +static int init_suite_TPF(void) +{ + return 0; +} + +static int clean_suite_TPF(void) +{ + return 0; +} + +static CU_SuiteInfo suites[] = { + { "Suite TPF", init_suite_TPF, clean_suite_TPF, tests }, + { NULL, } +}; + +int main(int argc, char *argv[]) +{ + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + if (CUE_SUCCESS != CU_register_suites(suites)) + return CU_get_error(); + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + return CU_get_error(); +}
diff --git a/suite_TFN/test_001_host.c b/suite_TFN/test_001_host.c new file mode 100644 index 0000000..c42f5ff --- /dev/null +++ b/suite_TFN/test_001_host.c
@@ -0,0 +1,7 @@ +#include <CUnit/CUnit.h> + +void run_001(void) +{ + CU_PASS("success"); +} +
diff --git a/suite_TFN/test_002_host.c b/suite_TFN/test_002_host.c new file mode 100644 index 0000000..fafcf8f --- /dev/null +++ b/suite_TFN/test_002_host.c
@@ -0,0 +1,8 @@ +#include <CUnit/CUnit.h> + +void run_002(void) +{ + CU_FAIL("failure"); +} + +
diff --git a/suite_TFP/Makefile b/suite_TFP/Makefile new file mode 100644 index 0000000..4e64542 --- /dev/null +++ b/suite_TFP/Makefile
@@ -0,0 +1,91 @@ +## Makefile + +include ../config.mk + +# `make V=1' to have verbose output +ifneq ($(V),1) +Q = @ +endif + +MARS_LIB_SRC = ../../mars-src/src +MARS_LIB_INC = ../../mars-src/include + +PPU_CFLAGS += $(CFLAGS) -I$(MARS_LIB_INC)/common -I$(MARS_LIB_INC)/host -m64 +SPU_CFLAGS += $(CFLAGS) -I$(MARS_LIB_INC)/common -I$(MARS_LIB_INC)/mpu + +PPU_LDFLAGS += $(LFLAGS) $(MARS_LIB_SRC)/host/lib/.libs/libmars.a $(MARS_LIB_SRC)/host/lib/mars-kernel.eo -lcunit +SPU_LDFLAGS += $(LFLAGS) $(MARS_LIB_SRC)/mpu/lib/libmars.a + +TARGETS = test_host test_mpu + + +.PHONY: all clean + +all: $(TARGETS) + +clean: + $(Q)$(RM) tests.h $(TARGETS) *.o *.eo *~ + + +HOSTSRCS := $(wildcard *_host.c) +HOSTOBJS := $(patsubst %.c, %.o, $(HOSTSRCS)) +HOSTOBJS += test_mpu.eo + +MPUSRCS := $(wildcard *_mpu.c) +MPUOBJS := $(patsubst %.c, %.o, $(MPUSRCS)) + +# Make hackery to create the list of tests +TESTSRCS := $(wildcard test_*.c) +TESTS := $(subst test_,,$(TESTSRCS)) +TESTS := $(subst _host.c,,$(TESTS)) +TESTS := $(subst _mpu.c,,$(TESTS)) +TESTS := $(sort $(TESTS)) +LPAREN := ( +RPAREN := ) +TESTDEFS := $(addprefix DEF_TEST$(LPAREN), $(addsuffix $(RPAREN), $(TESTS))) + +tests.h: $(TESTSRCS) + @echo "GEN $@" + $(Q)echo "$(TESTDEFS)" > tests.h + +test_host: $(HOSTOBJS) + @echo "PPU_LD $@" + $(Q)$(PPU_CC) -o $@ $(HOSTOBJS) $(PPU_CFLAGS) $(PPU_LDFLAGS) + +test_mpu: $(MPUOBJS) + @echo "SPU_LD $@" + $(Q)$(SPU_CC) -o $@ $(MPUOBJS) $(SPU_CFLAGS) $(SPU_LDFLAGS) + +%_host.o: %_host.c + @echo "PPU_CC $@" + $(Q)$(PPU_CC) $(PPU_CFLAGS) -c -o $@ $< + +%_mpu.o: %_mpu.c + @echo "SPU_CC $@" + $(Q)$(SPU_CC) $(SPU_CFLAGS) -c -o $@ $< + +%_mpu.eo: %_mpu + @echo "PPU_EMBEDSPU $@" + $(Q)$(PPU_EMBEDSPU) $(PPU_CFLAGS) $< $< $@ + + +suite_host.o: tests.h +suite_mpu.o: tests.h + + +# For debugging +%_host.i: %_host.c + @echo "PPU_CC $<" + $(Q)$(PPU_CC) $(PPU_CFLAGS) -E -o $@ $< + +%_mpu.i: %_mpu.c + @echo "SPU_CC $<" + $(Q)$(SPU_CC) $(SPU_CFLAGS) -E -o $@ $< + +suite_host.i: tests.h +suite_mpu.i: tests.h + + +# Use `make print-VARIABLE' to print the value of $(VARIABLE) +print-%: + @echo $* = "$($*)"
diff --git a/suite_TFP/host_common.c b/suite_TFP/host_common.c new file mode 100644 index 0000000..fba441b --- /dev/null +++ b/suite_TFP/host_common.c
@@ -0,0 +1,89 @@ +#include "host_common.h" + +#define APPEND_SIG(SIG) if (sig == SIG) snprintf(sig_text, 30, "%s", #SIG); + +void append_sig(char* buffer, int buf_len, int sig) +{ + char sig_text[30]; + APPEND_SIG(SIGHUP) + else + APPEND_SIG(SIGINT) + else + APPEND_SIG(SIGQUIT) + else + APPEND_SIG(SIGILL) + else + APPEND_SIG(SIGTRAP) + else + APPEND_SIG(SIGABRT) + else + APPEND_SIG(SIGIOT) + else + APPEND_SIG(SIGBUS) + else + APPEND_SIG(SIGFPE) + else + APPEND_SIG(SIGKILL) + else + APPEND_SIG(SIGUSR1) + else + APPEND_SIG(SIGSEGV) + else + APPEND_SIG(SIGUSR2) + else + APPEND_SIG(SIGPIPE) + else + APPEND_SIG(SIGALRM) + else + APPEND_SIG(SIGTERM) + else + APPEND_SIG(SIGSTKFLT) + else + APPEND_SIG(SIGCHLD) + else + APPEND_SIG(SIGCONT) + else + APPEND_SIG(SIGSTOP) + else + APPEND_SIG(SIGTSTP) + else + APPEND_SIG(SIGTTIN) + else + APPEND_SIG(SIGTTOU) + else + APPEND_SIG(SIGURG) + else + APPEND_SIG(SIGXCPU) + else + APPEND_SIG(SIGXFSZ) + else + APPEND_SIG(SIGVTALRM) + else + APPEND_SIG(SIGPROF) + else + APPEND_SIG(SIGWINCH) + else + APPEND_SIG(SIGIO) + else + APPEND_SIG(SIGPOLL) + else +/* + APPEND_SIG(SIGLOST) + else +*/ + APPEND_SIG(SIGPWR) + else + APPEND_SIG(SIGSYS) + else + APPEND_SIG(SIGUNUSED) + else + +/* These should not be considered constants from userland. */ + APPEND_SIG(SIGRTMIN) + else + APPEND_SIG(SIGRTMAX) + else + snprintf(sig_text, 30, "%i", sig); + strncat(buffer, sig_text, buf_len-1); +} +
diff --git a/suite_TFP/host_common.h b/suite_TFP/host_common.h new file mode 100644 index 0000000..1ce5a86 --- /dev/null +++ b/suite_TFP/host_common.h
@@ -0,0 +1,63 @@ +#include <libspe2.h> +#include <signal.h> +#include <pthread.h> + +extern struct spe_program_handle test_mpu; + +void append_sig(char* buffer, int buf_len, int sig); + +#define THREAD_PROC_WITH_SIGNAL_HANDLER_ARG(proc_name, proc_code, process_arg)\ +\ +void proc_name##_signal_handler(int arg)\ +{\ + char print_msg[1024] = "ERROR: " #proc_name "_signal_handler was called with signal value: ";\ + append_sig(print_msg, 1024, arg);\ + CU_assertImplementation(0, __LINE__, (print_msg), __FILE__, "", CU_FALSE);\ +\ + pthread_exit(NULL);\ +}\ +\ +void* proc_name(void* arg)\ +{\ + signal(SIGSEGV, proc_name##_signal_handler);\ +\ + proc_code\ +\ + signal(SIGSEGV, NULL);\ +\ + if (process_arg)\ + *((int*)arg) = 1;\ +\ + return NULL;\ +} + +#define THREAD_PROC_WITH_SIGNAL_HANDLER(proc_name, proc_code) THREAD_PROC_WITH_SIGNAL_HANDLER_ARG(proc_name, proc_code, 0) + +#define TEST_PROC(proc_name, time_elapse_ms, proc_code)\ +\ +static pthread_t proc_name##_thread;\ +void* proc_name##_thread_proc(void* arg);\ +\ +void proc_name(void)\ +{\ + struct timespec req, rem;\ + char print_msg[1024];\ + int i;\ + volatile int proc_name##_thread_returned = 0;\ +\ + pthread_create(&proc_name##_thread, NULL, proc_name##_thread_proc, (void*)&proc_name##_thread_returned);\ +\ + req.tv_sec = 0;\ + req.tv_nsec = 1000000;\ +\ + for (i = 0;i < time_elapse_ms && !proc_name##_thread_returned;i++)\ + nanosleep(&req, &rem);\ +\ + if (!proc_name##_thread_returned)\ + {\ + strncpy(print_msg, "ERROR: " #proc_name " didn't return within reserved time, possible stalled", 1024);\ + CU_assertImplementation(0, __LINE__, (print_msg), __FILE__, "", CU_FALSE);\ + }\ +}\ +THREAD_PROC_WITH_SIGNAL_HANDLER_ARG(proc_name##_thread_proc, proc_code, 1) +
diff --git a/suite_TFP/host_mpu_common.c b/suite_TFP/host_mpu_common.c new file mode 100644 index 0000000..fabe78f --- /dev/null +++ b/suite_TFP/host_mpu_common.c
@@ -0,0 +1,47 @@ +#include <string.h> +#include <stdio.h> +#include "mars/mars.h" +#include "host_mpu_common.h" + +void append_ret_dec(char* buffer, int buf_len, int ret) +{ + char ret_text[30]; + snprintf(ret_text, 30, "%i", ret); + strncat(buffer, ret_text, buf_len-1); +} + +void append_ret_hex(char* buffer, int buf_len, int ret) +{ + char ret_text[30]; + snprintf(ret_text, 30, "%X", ret); + strncat(buffer, ret_text, buf_len-1); +} + +#define APPEND_RET_MARS(RET) if (ret == RET) snprintf(ret_text, 30, "%s", #RET); + +void append_ret_mars(char* buffer, int buf_len, int ret) +{ + char ret_text[30]; + APPEND_RET_MARS(MARS_SUCCESS) + else + APPEND_RET_MARS(MARS_ERROR_NULL) + else + APPEND_RET_MARS(MARS_ERROR_PARAMS) + else + APPEND_RET_MARS(MARS_ERROR_INTERNAL) + else + APPEND_RET_MARS(MARS_ERROR_MEMORY) + else + APPEND_RET_MARS(MARS_ERROR_ALIGN) + else + APPEND_RET_MARS(MARS_ERROR_LIMIT) + else + APPEND_RET_MARS(MARS_ERROR_STATE) + else + APPEND_RET_MARS(MARS_ERROR_FORMAT) + else + APPEND_RET_MARS(MARS_ERROR_BUSY) + else + snprintf(ret_text, 30, "%i", ret); + strncat(buffer, ret_text, buf_len-1); +}
diff --git a/suite_TFP/host_mpu_common.h b/suite_TFP/host_mpu_common.h new file mode 100644 index 0000000..4c63100 --- /dev/null +++ b/suite_TFP/host_mpu_common.h
@@ -0,0 +1,29 @@ +#include <string.h> + +#define TEST_ITEM_017_RET_VAL 0xABCDEF01 + +/** CU_ASSERT_EQUAL override to see return value + * Asserts that actual == expected. + * Reports failure with no other action. + */ + +int act_val, exp_val; +char print_msg[1024]; + +void append_ret_dec(char* buffer, int buf_len, int ret); +void append_ret_hex(char* buffer, int buf_len, int ret); +void append_ret_mars(char* buffer, int buf_len, int ret); + +#define CU_ASSERT_EQUAL_RET(actual, expected, suffix, ret_format)\ +\ + {\ + act_val = (actual);\ + exp_val = (expected);\ + strncpy(print_msg, "CU_ASSERT_EQUAL_" #suffix "(" #actual "," #expected "), first assertion argument value is ", 1024);\ + append_ret_##ret_format(print_msg, 1024, act_val);\ + CU_assertImplementation((act_val == exp_val), __LINE__, (print_msg), __FILE__, "", CU_FALSE);\ + } + +#define CU_ASSERT_EQUAL_VAL(actual, expected) CU_ASSERT_EQUAL_RET(actual, expected, VAL, dec) +#define CU_ASSERT_EQUAL_VALX(actual, expected) CU_ASSERT_EQUAL_RET(actual, expected, VALX, hex) +#define CU_ASSERT_EQUAL_MARS(actual, expected) CU_ASSERT_EQUAL_RET(actual, expected, MARS, mars)
diff --git a/suite_TFP/suite_host.c b/suite_TFP/suite_host.c new file mode 100644 index 0000000..88f6018 --- /dev/null +++ b/suite_TFP/suite_host.c
@@ -0,0 +1,105 @@ +#include <CUnit/Basic.h> +#include <CUnit/Console.h> +#include <CUnit/Automated.h> + +#include <stdlib.h> +#include <stdio.h> +#include "host_mpu_common.c" +#include "host_common.c" + + +#define DEF_TEST(test) extern void run_ ## test (void); +#include "tests.h" +#undef DEF_TEST + + +static CU_TestInfo tests[] = { +#define DEF_TEST(test) { #test, run_ ## test }, +#include "tests.h" +#undef DEF_TEST + { NULL, } +}; + +static int init_suite_TPF(void) +{ + return 0; +} + +static int clean_suite_TPF(void) +{ + return 0; +} + +static CU_SuiteInfo suites[] = { + { "Suite TPF", init_suite_TPF, clean_suite_TPF, tests }, + { NULL, } +}; + +static void print_help(void) { + printf("-a\tautomated generating xml\n"); + printf("-b\tbasic output to stdout\n"); + printf("\t\t--n\tnormal\n"); + printf("\t\t--v\tverbose\n"); + printf("\t\t--s\tsilent\n"); + printf("-i\tinteractive\n"); + printf("-help\tthis help\n"); +} + +int main(int argc, char *argv[]) +{ + CU_BasicRunMode basic_mode = CU_BRM_NORMAL; + int run_mode = 1; /* 0 = automated, 1 = basic, 2 = console */ + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + if (CUE_SUCCESS != CU_register_suites(suites)) + return CU_get_error(); + + /* parse command line arguments */ + if (argc > 1) { + int i; + for (i = 1; i < argc; ++i) { + int length = strlen(argv[i]); + const char * p = argv[i]; + if (length >= 2 && p[0] == '-') { + ++p; + if (length >= 3 && p[0] == '-') { + ++p; + if (strcmp(p, "n") == 0) basic_mode = CU_BRM_NORMAL; + else if (strcmp(argv[i], "v") == 0) basic_mode = CU_BRM_VERBOSE; + else if (strcmp(argv[i], "s") == 0) basic_mode = CU_BRM_SILENT; + } + else { + if (strcmp(p, "a") == 0) run_mode = 0; + else if (strcmp(p, "b") == 0) run_mode = 1; + else if (strcmp(p, "i") == 0) run_mode = 2; + else if (strcmp(p, "help") == 0) { print_help(); exit(0); } + } + } + } + } + + /* set basic mode */ + CU_basic_set_mode(basic_mode); + + switch (run_mode) { + case 0: /* Run all tests giving xml output */ + CU_automated_run_tests(); + break; + case 1: /* Run all tests with stdout output */ + CU_basic_run_tests(); + break; + case 2: /* Run in console mode */ + CU_console_run_tests(); + break; + } + + CU_cleanup_registry(); + + return CU_get_error(); +} + +
diff --git a/suite_TFP/suite_mpu.c b/suite_TFP/suite_mpu.c new file mode 100644 index 0000000..0902c7c --- /dev/null +++ b/suite_TFP/suite_mpu.c
@@ -0,0 +1,11 @@ +#include "mars/mars.h" +#include <string.h> +#include "host_mpu_common.h" + +int mars_task_main(const struct mars_task_args *task_args) +{ + if (strcmp(mars_task_get_name(), "017") == 0) + return TEST_ITEM_017_RET_VAL; + + return 0; +}
diff --git a/suite_TFP/test_001_host.c b/suite_TFP/test_001_host.c new file mode 100644 index 0000000..57817eb --- /dev/null +++ b/suite_TFP/test_001_host.c
@@ -0,0 +1,15 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" + +static struct mars_context mars; + +TEST_PROC(run_001, 1000, + + int ret; + + CU_ASSERT_EQUAL_MARS(ret = mars_initialize(&mars, 1), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_002_host.c b/suite_TFP/test_002_host.c new file mode 100644 index 0000000..cafeac3 --- /dev/null +++ b/suite_TFP/test_002_host.c
@@ -0,0 +1,19 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +static struct mars_context mars; + +TEST_PROC(run_002, 1000, + + int ret; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + CU_ASSERT_EQUAL_MARS(ret = mars_initialize(&mars, spe_cnt), MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_finalize(&mars); +) + +
diff --git a/suite_TFP/test_003_host.c b/suite_TFP/test_003_host.c new file mode 100644 index 0000000..dd1b930 --- /dev/null +++ b/suite_TFP/test_003_host.c
@@ -0,0 +1,33 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" + +#define THREAD_COUNT 16 + +static pthread_t thread_handles[THREAD_COUNT]; +static struct mars_context mars_contexts[THREAD_COUNT]; + +THREAD_PROC_WITH_SIGNAL_HANDLER(run_003_work_thread_proc, + + int ret; + + CU_ASSERT_EQUAL_MARS( + ret = mars_initialize( + (struct mars_context*)arg, + 1), + MARS_SUCCESS); + if (ret == MARS_SUCCESS) + mars_finalize((struct mars_context*)arg); +) + +TEST_PROC(run_003, 1000, + + int i; + + for (i = 0;i < THREAD_COUNT;i++) + pthread_create(&thread_handles[i], NULL, run_003_work_thread_proc, (void*)&mars_contexts[i]); + + for (i = 0;i < THREAD_COUNT;i++) + pthread_join(thread_handles[i], NULL); +)
diff --git a/suite_TFP/test_004_host.c b/suite_TFP/test_004_host.c new file mode 100644 index 0000000..27d4cbd --- /dev/null +++ b/suite_TFP/test_004_host.c
@@ -0,0 +1,18 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +static struct mars_context mars; + +TEST_PROC(run_004, 1000, + + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + mars_initialize(&mars, spe_cnt); + + CU_ASSERT_EQUAL_MARS(mars_finalize(&mars), MARS_SUCCESS); +) + +
diff --git a/suite_TFP/test_005_host.c b/suite_TFP/test_005_host.c new file mode 100644 index 0000000..692cf6f --- /dev/null +++ b/suite_TFP/test_005_host.c
@@ -0,0 +1,31 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" + +#define THREAD_COUNT 16 + +static pthread_t thread_handles[THREAD_COUNT]; +static struct mars_context mars_contexts[THREAD_COUNT]; + +void* run_005_work_thread_proc(void* arg) +{ + mars_initialize(&mars_contexts[(uint64_t)arg], 1); + + CU_ASSERT_EQUAL_MARS( + mars_finalize(&mars_contexts[(uint64_t)arg]), + MARS_SUCCESS); + + return NULL; +} + +TEST_PROC(run_005, 1000, + + int i; + + for (i = 0;i < THREAD_COUNT;i++) + pthread_create(&thread_handles[i], NULL, run_005_work_thread_proc, (void*)(intptr_t)i); + + for (i = 0;i < THREAD_COUNT;i++) + pthread_join(thread_handles[i], NULL); +)
diff --git a/suite_TFP/test_006_host.c b/suite_TFP/test_006_host.c new file mode 100644 index 0000000..cfa30c5 --- /dev/null +++ b/suite_TFP/test_006_host.c
@@ -0,0 +1,49 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" + +#define THREAD_COUNT 16 + +static pthread_t thread_handles_1[THREAD_COUNT]; +static pthread_t thread_handles_2[THREAD_COUNT]; +static struct mars_context mars_contexts_1[THREAD_COUNT]; +static struct mars_context mars_contexts_2[THREAD_COUNT]; + +void* run_006_work_thread_proc(void* arg) +{ + CU_ASSERT_EQUAL_MARS( + mars_initialize((struct mars_context*)arg, 1), + MARS_SUCCESS); + + CU_ASSERT_EQUAL_MARS( + mars_finalize((struct mars_context*)arg), + MARS_SUCCESS); + + return NULL; +} + +TEST_PROC(run_006, 1000, + + int i; + + for (i = 0;i < THREAD_COUNT;i++) + pthread_create( + &thread_handles_1[i], + NULL, + run_006_work_thread_proc, + (void*)&mars_contexts_1[i]); + + for (i = 0;i < THREAD_COUNT;i++) + pthread_create( + &thread_handles_2[i], + NULL, + run_006_work_thread_proc, + (void*)&mars_contexts_2[i]); + + for (i = 0;i < THREAD_COUNT;i++) + pthread_join(thread_handles_1[i], NULL); + + for (i = 0;i < THREAD_COUNT;i++) + pthread_join(thread_handles_2[i], NULL); +)
diff --git a/suite_TFP/test_007_host.c b/suite_TFP/test_007_host.c new file mode 100644 index 0000000..51aa531 --- /dev/null +++ b/suite_TFP/test_007_host.c
@@ -0,0 +1,25 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" +#include "mars/mars_task.h" + +static struct mars_context mars; +static struct mars_task_id task_id; + +TEST_PROC(run_007, 1000, + + mars_initialize(&mars, 1); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_id, + NULL, + test_mpu.elf_image, + 0), + MARS_SUCCESS); + mars_task_finalize(&task_id); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_008_host.c b/suite_TFP/test_008_host.c new file mode 100644 index 0000000..19e90fc --- /dev/null +++ b/suite_TFP/test_008_host.c
@@ -0,0 +1,25 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" +#include "mars/mars_task.h" + +static struct mars_context mars; +static struct mars_task_id task_id; + +TEST_PROC(run_008, 1000, + + mars_initialize(&mars, 1); + + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_id, + NULL, + test_mpu.elf_image, + MARS_TASK_CONTEXT_SAVE_SIZE_MAX), + MARS_SUCCESS); + mars_task_finalize(&task_id); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_009_host.c b/suite_TFP/test_009_host.c new file mode 100644 index 0000000..46ad1fc --- /dev/null +++ b/suite_TFP/test_009_host.c
@@ -0,0 +1,40 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" +#include "mars/mars_task.h" + +#define MAX_TASKS 256 + +static struct mars_context mars; +static struct mars_task_id task_ids[MAX_TASKS]; + +TEST_PROC(run_009, 1000, + + int i; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + CU_ASSERT(spe_cnt <= MAX_TASKS); + + if (spe_cnt > MAX_TASKS) + spe_cnt = MAX_TASKS; + + mars_initialize(&mars, spe_cnt); + + for (i = 0;i < spe_cnt;i++) + { + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_ids[i], + NULL, + test_mpu.elf_image, + 0), + MARS_SUCCESS); + } + + for (i = 0;i < spe_cnt;i++) + mars_task_finalize(&task_ids[i]); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_010_host.c b/suite_TFP/test_010_host.c new file mode 100644 index 0000000..c3ea639 --- /dev/null +++ b/suite_TFP/test_010_host.c
@@ -0,0 +1,40 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" +#include "mars/mars_task.h" + +#define MAX_TASKS 256 + +static struct mars_context mars; +static struct mars_task_id task_ids[MAX_TASKS]; + +TEST_PROC(run_010, 1000, + + int i; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1) + 1; + + CU_ASSERT(spe_cnt <= MAX_TASKS); + + if (spe_cnt > MAX_TASKS) + spe_cnt = MAX_TASKS; + + mars_initialize(&mars, spe_cnt); + + for (i = 0;i < spe_cnt;i++) + { + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_ids[i], + NULL, + test_mpu.elf_image, + 0), + MARS_SUCCESS); + } + + for (i = 0;i < spe_cnt;i++) + mars_task_finalize(&task_ids[i]); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_011_host.c b/suite_TFP/test_011_host.c new file mode 100644 index 0000000..6fc3d62 --- /dev/null +++ b/suite_TFP/test_011_host.c
@@ -0,0 +1,33 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include "mars/mars.h" +#include "mars/mars_task.h" +#include "mars/mars_workload_types.h" + +static struct mars_context mars; +static struct mars_task_id task_ids[MARS_WORKLOAD_MAX]; + +TEST_PROC(run_011, 1000, + + int i; + + mars_initialize(&mars, 0); + + for (i = 0;i < MARS_WORKLOAD_MAX;i++) + { + CU_ASSERT_EQUAL_MARS( + mars_task_initialize( + &mars, + &task_ids[i], + NULL, + test_mpu.elf_image, + 0), + MARS_SUCCESS); + } + + for (i = 0;i < MARS_WORKLOAD_MAX;i++) + mars_task_finalize(&task_ids[i]); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_012_host.c b/suite_TFP/test_012_host.c new file mode 100644 index 0000000..b03fc66 --- /dev/null +++ b/suite_TFP/test_012_host.c
@@ -0,0 +1,44 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +#define TASK_COUNT 16 + +static struct mars_context mars; +static struct mars_task_id task_ids[TASK_COUNT]; +static pthread_t thread_handles[TASK_COUNT]; + +THREAD_PROC_WITH_SIGNAL_HANDLER(run_012_work_thread_proc, + + int ret; + + CU_ASSERT_EQUAL_MARS( + ret = mars_task_initialize( + &mars, + (struct mars_task_id*)arg, + NULL, + test_mpu.elf_image, + 0), + MARS_SUCCESS); + + if (ret == MARS_SUCCESS) + mars_task_finalize((struct mars_task_id*)arg); +) + +TEST_PROC(run_012, 1000, + + int i; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + mars_initialize(&mars, spe_cnt); + + for (i = 0;i < TASK_COUNT;i++) + pthread_create(&thread_handles[i], NULL, run_012_work_thread_proc, (void*)&task_ids[i]); + + for (i = 0;i < TASK_COUNT;i++) + pthread_join(thread_handles[i], NULL); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_013_host.c b/suite_TFP/test_013_host.c new file mode 100644 index 0000000..beb80c1 --- /dev/null +++ b/suite_TFP/test_013_host.c
@@ -0,0 +1,18 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +static struct mars_context mars; +static struct mars_task_id task_id; + +TEST_PROC(run_013, 1000, + + mars_initialize(&mars, 1); + + mars_task_initialize(&mars, &task_id, NULL, test_mpu.elf_image, 0); + CU_ASSERT_EQUAL_MARS(mars_task_finalize(&task_id), MARS_SUCCESS); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_014_host.c b/suite_TFP/test_014_host.c new file mode 100644 index 0000000..6b900b6 --- /dev/null +++ b/suite_TFP/test_014_host.c
@@ -0,0 +1,22 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +static struct mars_context mars; +static struct mars_task_id task_id; + +TEST_PROC(run_014, 1000, + + int exit_code; + + mars_initialize(&mars, 1); + + mars_task_initialize(&mars, &task_id, NULL, test_mpu.elf_image, 0); + mars_task_schedule(&task_id, NULL, 0); + mars_task_wait(&task_id, &exit_code); + CU_ASSERT_EQUAL_MARS(mars_task_finalize(&task_id), MARS_SUCCESS); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_015_host.c b/suite_TFP/test_015_host.c new file mode 100644 index 0000000..42a3451 --- /dev/null +++ b/suite_TFP/test_015_host.c
@@ -0,0 +1,41 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +#define TASK_COUNT 16 + +static struct mars_context mars; +static struct mars_task_id task_ids[TASK_COUNT]; +static pthread_t thread_handles[TASK_COUNT]; + +THREAD_PROC_WITH_SIGNAL_HANDLER(run_015_work_thread_proc, + + mars_task_initialize( + &mars, + (struct mars_task_id*)arg, + NULL, + test_mpu.elf_image, + 0); + + CU_ASSERT_EQUAL_MARS( + mars_task_finalize((struct mars_task_id*)arg), + MARS_SUCCESS) +) + +TEST_PROC(run_015, 1000, + + int i; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + mars_initialize(&mars, spe_cnt); + + for (i = 0;i < TASK_COUNT;i++) + pthread_create(&thread_handles[i], NULL, run_015_work_thread_proc, (void*)&task_ids[i]); + + for (i = 0;i < TASK_COUNT;i++) + pthread_join(thread_handles[i], NULL); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_016_host.c b/suite_TFP/test_016_host.c new file mode 100644 index 0000000..5574a2f --- /dev/null +++ b/suite_TFP/test_016_host.c
@@ -0,0 +1,57 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +#define TASK_COUNT 16 + +static struct mars_context mars; +static struct mars_task_id task_ids_1[TASK_COUNT]; +static struct mars_task_id task_ids_2[TASK_COUNT]; +static pthread_t thread_handles_1[TASK_COUNT]; +static pthread_t thread_handles_2[TASK_COUNT]; + +THREAD_PROC_WITH_SIGNAL_HANDLER(run_016_work_thread_proc, + + mars_task_initialize( + &mars, + (struct mars_task_id*)arg, + NULL, + test_mpu.elf_image, + 0); + + CU_ASSERT_EQUAL_MARS( + mars_task_finalize((struct mars_task_id*)arg), + MARS_SUCCESS) +) + +TEST_PROC(run_016, 1000, + + int i; + int spe_cnt = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + + mars_initialize(&mars, spe_cnt); + + for (i = 0;i < TASK_COUNT;i++) + pthread_create( + &thread_handles_1[i], + NULL, + run_016_work_thread_proc, + (void*)&task_ids_1[i]); + + for (i = 0;i < TASK_COUNT;i++) + pthread_create( + &thread_handles_2[i], + NULL, + run_016_work_thread_proc, + (void*)&task_ids_2[i]); + + for (i = 0;i < TASK_COUNT;i++) + pthread_join(thread_handles_1[i], NULL); + + for (i = 0;i < TASK_COUNT;i++) + pthread_join(thread_handles_2[i], NULL); + + mars_finalize(&mars); +)
diff --git a/suite_TFP/test_017_host.c b/suite_TFP/test_017_host.c new file mode 100644 index 0000000..79830a0 --- /dev/null +++ b/suite_TFP/test_017_host.c
@@ -0,0 +1,23 @@ +#include <CUnit/CUnit.h> +#include "host_mpu_common.h" +#include "host_common.h" +#include <libspe2.h> +#include "mars/mars.h" + +static struct mars_context mars; +static struct mars_task_id task_id; + +TEST_PROC(run_017, 1000, + + int exit_code; + + mars_initialize(&mars, 1); + + mars_task_initialize(&mars, &task_id, "017", test_mpu.elf_image, 0); + mars_task_schedule(&task_id, NULL, 0); + mars_task_wait(&task_id, &exit_code); + mars_task_finalize(&task_id); + CU_ASSERT_EQUAL_VALX(exit_code, TEST_ITEM_017_RET_VAL); + + mars_finalize(&mars); +)
diff --git a/suite_TPF/Makefile b/suite_TPF/Makefile new file mode 100644 index 0000000..4f0449a --- /dev/null +++ b/suite_TPF/Makefile
@@ -0,0 +1,84 @@ +# `make V=1' to have verbose output +ifneq ($(V),1) +Q = @ +endif + +#HOSTCC = ppu-gcc +HOSTCC = gcc +MPUCC = spu-gcc + +CFLAGS = -Wall -Werror -O3 +HOSTCFLAGS = $(CFLAGS) # Add ... +MPUCFLAGS = $(CFLAGS) # Add ... + +LFLAGS = -lcunit +HOSTLFLAGS = $(LFLAGS) # Add ... +MPULFLAGS = $(LFLAGS) # Add ... + +TARGETS = test_host # test_mpu + + +.PHONY: all clean + +all: $(TARGETS) + +clean: + $(Q)$(RM) tests.h $(TARGETS) $(HOSTOBJS) $(MPU_OBJS) + + +HOSTSRCS := $(wildcard *_host.c) +HOSTOBJS := $(patsubst %.c, %.o, $(HOSTSRCS)) + +MPUSRCS := $(wildcard *_mpu.c) +MPUOBJS := $(patsubst %.c, %.o, $(MPUSRCS)) + +# Make hackery to create the list of tests +TESTSRCS := $(wildcard test_*.c) +TESTS := $(subst test_,,$(TESTSRCS)) +TESTS := $(subst _host.c,,$(TESTS)) +TESTS := $(subst _mpu.c,,$(TESTS)) +TESTS := $(sort $(TESTS)) +LPAREN := ( +RPAREN := ) +TESTDEFS := $(addprefix DEF_TEST$(LPAREN), $(addsuffix $(RPAREN), $(TESTS))) + +tests.h: $(TESTSRCS) + @echo "GEN $@" + $(Q)echo "$(TESTDEFS)" > tests.h + +test_host: $(HOSTOBJS) + @echo "HOSTLD $@" + $(Q)$(HOSTCC) $(HOSTLFLAGS) -o $@ $(HOSTOBJS) + +test_mpu: $(MPUOBJS) + @echo "MPULD $@" + $(Q)$(MPUCC) $(MPULFLAGS) -o $@ $(MPUOBJS) + +%_host.o: %_host.c + @echo "HOSTCC $@" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< + +%_mpu.o: %_mpu.c + @echo "MPUCC $@" + $(Q)$(MPUCC) $(MPUCFLAGS) -c -o $@ $< + +suite_host.o: tests.h +suite_mpu.o: tests.h + + +# For debugging +%_host.i: %_host.c + @echo "HOSTCC $<" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -E -o $@ $< + +%_mpu.i: %_mpu.c + @echo "MPUCC $<" + $(Q)$(MPUCC) $(MPUCFLAGS) -E -o $@ $< + +suite_host.i: tests.h +suite_mpu.i: tests.h + + +# Use `make print-VARIABLE' to print the value of $(VARIABLE) +print-%: + @echo $* = "$($*)"
diff --git a/suite_TPF/suite_host.c b/suite_TPF/suite_host.c new file mode 100644 index 0000000..1792930 --- /dev/null +++ b/suite_TPF/suite_host.c
@@ -0,0 +1,50 @@ +#include <CUnit/Basic.h> + +#include <stdlib.h> +#include <stdio.h> + + +#define DEF_TEST(test) extern void run_ ## test (void); +#include "tests.h" +#undef DEF_TEST + + +static CU_TestInfo tests[] = { +#define DEF_TEST(test) { #test, run_ ## test }, +#include "tests.h" +#undef DEF_TEST + { NULL, } +}; + +static int init_suite_TPF(void) +{ + return 0; +} + +static int clean_suite_TPF(void) +{ + return 0; +} + +static CU_SuiteInfo suites[] = { + { "Suite TPF", init_suite_TPF, clean_suite_TPF, tests }, + { NULL, } +}; + +int main(int argc, char *argv[]) +{ + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + if (CUE_SUCCESS != CU_register_suites(suites)) + return CU_get_error(); + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + return CU_get_error(); +}
diff --git a/suite_TPF/test_001_host.c b/suite_TPF/test_001_host.c new file mode 100644 index 0000000..c42f5ff --- /dev/null +++ b/suite_TPF/test_001_host.c
@@ -0,0 +1,7 @@ +#include <CUnit/CUnit.h> + +void run_001(void) +{ + CU_PASS("success"); +} +
diff --git a/suite_TPF/test_002_host.c b/suite_TPF/test_002_host.c new file mode 100644 index 0000000..fafcf8f --- /dev/null +++ b/suite_TPF/test_002_host.c
@@ -0,0 +1,8 @@ +#include <CUnit/CUnit.h> + +void run_002(void) +{ + CU_FAIL("failure"); +} + +
diff --git a/suite_TST/Makefile b/suite_TST/Makefile new file mode 100644 index 0000000..4f0449a --- /dev/null +++ b/suite_TST/Makefile
@@ -0,0 +1,84 @@ +# `make V=1' to have verbose output +ifneq ($(V),1) +Q = @ +endif + +#HOSTCC = ppu-gcc +HOSTCC = gcc +MPUCC = spu-gcc + +CFLAGS = -Wall -Werror -O3 +HOSTCFLAGS = $(CFLAGS) # Add ... +MPUCFLAGS = $(CFLAGS) # Add ... + +LFLAGS = -lcunit +HOSTLFLAGS = $(LFLAGS) # Add ... +MPULFLAGS = $(LFLAGS) # Add ... + +TARGETS = test_host # test_mpu + + +.PHONY: all clean + +all: $(TARGETS) + +clean: + $(Q)$(RM) tests.h $(TARGETS) $(HOSTOBJS) $(MPU_OBJS) + + +HOSTSRCS := $(wildcard *_host.c) +HOSTOBJS := $(patsubst %.c, %.o, $(HOSTSRCS)) + +MPUSRCS := $(wildcard *_mpu.c) +MPUOBJS := $(patsubst %.c, %.o, $(MPUSRCS)) + +# Make hackery to create the list of tests +TESTSRCS := $(wildcard test_*.c) +TESTS := $(subst test_,,$(TESTSRCS)) +TESTS := $(subst _host.c,,$(TESTS)) +TESTS := $(subst _mpu.c,,$(TESTS)) +TESTS := $(sort $(TESTS)) +LPAREN := ( +RPAREN := ) +TESTDEFS := $(addprefix DEF_TEST$(LPAREN), $(addsuffix $(RPAREN), $(TESTS))) + +tests.h: $(TESTSRCS) + @echo "GEN $@" + $(Q)echo "$(TESTDEFS)" > tests.h + +test_host: $(HOSTOBJS) + @echo "HOSTLD $@" + $(Q)$(HOSTCC) $(HOSTLFLAGS) -o $@ $(HOSTOBJS) + +test_mpu: $(MPUOBJS) + @echo "MPULD $@" + $(Q)$(MPUCC) $(MPULFLAGS) -o $@ $(MPUOBJS) + +%_host.o: %_host.c + @echo "HOSTCC $@" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< + +%_mpu.o: %_mpu.c + @echo "MPUCC $@" + $(Q)$(MPUCC) $(MPUCFLAGS) -c -o $@ $< + +suite_host.o: tests.h +suite_mpu.o: tests.h + + +# For debugging +%_host.i: %_host.c + @echo "HOSTCC $<" + $(Q)$(HOSTCC) $(HOSTCFLAGS) -E -o $@ $< + +%_mpu.i: %_mpu.c + @echo "MPUCC $<" + $(Q)$(MPUCC) $(MPUCFLAGS) -E -o $@ $< + +suite_host.i: tests.h +suite_mpu.i: tests.h + + +# Use `make print-VARIABLE' to print the value of $(VARIABLE) +print-%: + @echo $* = "$($*)"
diff --git a/suite_TST/suite_host.c b/suite_TST/suite_host.c new file mode 100644 index 0000000..1792930 --- /dev/null +++ b/suite_TST/suite_host.c
@@ -0,0 +1,50 @@ +#include <CUnit/Basic.h> + +#include <stdlib.h> +#include <stdio.h> + + +#define DEF_TEST(test) extern void run_ ## test (void); +#include "tests.h" +#undef DEF_TEST + + +static CU_TestInfo tests[] = { +#define DEF_TEST(test) { #test, run_ ## test }, +#include "tests.h" +#undef DEF_TEST + { NULL, } +}; + +static int init_suite_TPF(void) +{ + return 0; +} + +static int clean_suite_TPF(void) +{ + return 0; +} + +static CU_SuiteInfo suites[] = { + { "Suite TPF", init_suite_TPF, clean_suite_TPF, tests }, + { NULL, } +}; + +int main(int argc, char *argv[]) +{ + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + if (CUE_SUCCESS != CU_register_suites(suites)) + return CU_get_error(); + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + return CU_get_error(); +}
diff --git a/suite_TST/test_001_host.c b/suite_TST/test_001_host.c new file mode 100644 index 0000000..4da05ef --- /dev/null +++ b/suite_TST/test_001_host.c
@@ -0,0 +1,7 @@ +#include <CUnit/CUnit.h> + +void run_001(void) +{ + CU_PASS("failure"); +} +
diff --git a/suite_TST/test_002_host.c b/suite_TST/test_002_host.c new file mode 100644 index 0000000..fafcf8f --- /dev/null +++ b/suite_TST/test_002_host.c
@@ -0,0 +1,8 @@ +#include <CUnit/CUnit.h> + +void run_002(void) +{ + CU_FAIL("failure"); +} + +