Commit c44ab592 authored by Luca Giordano's avatar Luca Giordano Committed by Daniel Silveira

Adds rtems examples

Adds testsuites rtems examples.
Corrects workingttcp rtems Makefiles (trying to) bugfix the printf()
problem.

refs: #125176, #122803

	new file:   rtems_examples/testsuites/sptests/config.h
	new file:   rtems_examples/testsuites/sptests/spcontext01/Makefile-5
	new file:   rtems_examples/testsuites/sptests/spcontext01/init.c
	new file:   rtems_examples/testsuites/support
	modified:   rtems_examples/workingttcp/Makefile-5
	modified:   rtems_examples/workingttcp/ut/Makefile-5
parent 320bbdc0
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "https://devel.rtems.org/newticket"
/* Define to the full name of this package. */
#define PACKAGE_NAME "rtems-c-src-tests-sptests"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "rtems-c-src-tests-sptests 5.0.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "rtems-c-src-tests-sptests"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "5.0.0"
/* if RTEMS_TEST_NO_PAUSE is enabled */
#define RTEMS_TEST_NO_PAUSE 1
/* The size of `time_t', as computed by sizeof. */
#define SIZEOF_TIME_T 8
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
RTEMS_API = 5
RTEMS_CPU = sparc
RTEMS_BSP = leon3
prefix = /opt/rtems/$(RTEMS_API)
exec_prefix = $(prefix)/$(RTEMS_CPU)-rtems$(RTEMS_API)
RTEMS_ROOT = $(prefix)
RTEMS_SHARE = $(RTEMS_ROOT)/share/rtems$(RTEMS_API)
PROJECT_ROOT = $(RTEMS_ROOT)/$(RTEMS_CPU)-rtems$(RTEMS_API)/$(RTEMS_BSP)
PROJECT_INCLUDE = $(PROJECT_ROOT)/lib/include
PROJECT_LIB = $(PROJECT_ROOT)/lib
BUILDDIR = b-$(RTEMS_BSP)
SUPPORT_INCLUDE = ../../support/include
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
DEPFLAGS = -MT $@ -MD -MP -MF $(basename $@).d
SYSFLAGS = -B $(PROJECT_LIB) -specs bsp_specs -qrtems
WARNFLAGS = -Wall
# -gstrict-dwarf -gdwarf-2 dropped due to some gdb incompatibilities
OPTFLAGS = -O2 -g -ffunction-sections -fdata-sections
EXEEXT = .exe
DOWNEXT = .ralf
CPPFLAGS = -I$(PROJECT_INCLUDE)/bsp -I$(SUPPORT_INCLUDE) #-I.. -DHAVE_CONFIG_H
CFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
CXXFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
ASFLAGS = $(CPU_CFLAGS)
LDFLAGS = -Wl,--gc-sections -Wl,--wrap=printf -Wl,--wrap=puts -Wl,--wrap=putchar
LINKFLAGS = $(SYSFLAGS) $(CPU_CFLAGS) $(LDFLAGS) $(OPTFLAGS)
CCLINK = $(CC) $(LINKFLAGS) -Wl,-Map,$(basename $@).map
CXXLINK = $(CXX) $(LINKFLAGS) -Wl,-Map,$(basename $@).map
$(BUILDDIR)/%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.S
$(CC) $(CPPFLAGS) -DASM $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
export PATH := $(RTEMS_ROOT)/bin:$(PATH)
export AR = $(RTEMS_CPU)-rtems$(RTEMS_API)-ar
export AS = $(RTEMS_CPU)-rtems$(RTEMS_API)-as
export CC = $(RTEMS_CPU)-rtems$(RTEMS_API)-gcc --pipe
#export CC = $(RTEMS_CPU)-rtems$(RTEMS_API)-gcc
export CXX = $(RTEMS_CPU)-rtems$(RTEMS_API)-g++
export LD = $(RTEMS_CPU)-rtems$(RTEMS_API)-ld
export NM = $(RTEMS_CPU)-rtems$(RTEMS_API)-nm
export OBJCOPY = $(RTEMS_CPU)-rtems$(RTEMS_API)-objcopy
export RANLIB = $(RTEMS_CPU)-rtems$(RTEMS_API)-ranlib
export SIZE = $(RTEMS_CPU)-rtems$(RTEMS_API)-size
export STRIP = $(RTEMS_CPU)-rtems$(RTEMS_API)-strip
APP = $(BUILDDIR)/init
APP_PIECES = init
APP_OBJS = $(APP_PIECES:%=$(BUILDDIR)/%.o)
APP_DEPS = $(APP_PIECES:%=$(BUILDDIR)/%.d)
all: $(BUILDDIR) $(APP)$(EXEEXT)
$(BUILDDIR):
mkdir $(BUILDDIR)
$(APP)$(EXEEXT): $(APP_OBJS)
$(CCLINK) $^ -lm -o $@
clean:
rm -rf $(BUILDDIR)
-include $(APP_DEPS)
/*
* Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "tmacros.h"
const char rtems_test_name[] = "SPCONTEXT 1";
#define ITERATION_COUNT 2000
#define PRIORITY_HIGH 2
#define PRIORITY_LOW 3
#define FINISH_EVENT RTEMS_EVENT_0
typedef struct {
rtems_id control_task;
rtems_id validate_tasks[3];
rtems_id timer;
size_t task_index;
int iteration_counter;
} test_context;
static test_context test_instance;
static void validate_task(rtems_task_argument arg)
{
_CPU_Context_validate(arg);
rtems_test_assert(0);
}
static void start_validate_task(
rtems_id *id,
uintptr_t pattern,
rtems_task_priority priority,
bool fp_unit
)
{
rtems_status_code sc;
rtems_attribute fpu_state;
fpu_state = fp_unit ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES;
sc = rtems_task_create(
rtems_build_name('V', 'A', 'L', 'I'),
priority,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
fpu_state,
id
);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_start(*id, validate_task, pattern);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
static void reset_timer_or_finish(test_context *self, rtems_id timer)
{
rtems_status_code sc;
int i = self->iteration_counter;
if (i < ITERATION_COUNT) {
self->iteration_counter = i + 1;
sc = rtems_timer_reset(timer);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
} else {
sc = rtems_event_send(self->control_task, FINISH_EVENT);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
}
static void switch_priorities(test_context *self)
{
rtems_status_code sc;
size_t index = self->task_index;
size_t next = (index + 1) % RTEMS_ARRAY_SIZE(self->validate_tasks);
size_t task_current_high = index;
size_t task_next_high = next;
rtems_task_priority priority;
self->task_index = next;
sc = rtems_task_set_priority(
self->validate_tasks[task_next_high],
PRIORITY_HIGH,
&priority
);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_set_priority(
self->validate_tasks[task_current_high],
PRIORITY_LOW,
&priority
);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
static void clobber_and_switch_timer(rtems_id timer, void *arg)
{
uintptr_t pattern = (uintptr_t) 0xffffffffffffffffU;
test_context *self = arg;
reset_timer_or_finish(self, self->timer);
switch_priorities(self);
_CPU_Context_volatile_clobber(pattern);
}
static void start_timer(test_context *self)
{
rtems_status_code sc;
sc = rtems_timer_create(rtems_build_name('C', 'L', 'S', 'W'), &self->timer);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_timer_fire_after(self->timer, 2, clobber_and_switch_timer, self);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
static void wait_for_finish(void)
{
rtems_status_code sc;
rtems_event_set out;
sc = rtems_event_receive(
FINISH_EVENT,
RTEMS_WAIT | RTEMS_EVENT_ALL,
RTEMS_NO_TIMEOUT,
&out
);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(out == FINISH_EVENT);
}
static void test(
test_context *self,
bool task_0_fpu,
bool task_1_fpu,
bool task_2_fpu
)
{
rtems_status_code sc;
uintptr_t pattern_0 = (uintptr_t) 0xaaaaaaaaaaaaaaaaU;
uintptr_t pattern_1 = (uintptr_t) 0x5555555555555555U;
uintptr_t pattern_2 = (uintptr_t) 0x0000000000000000U;
memset(self, 0, sizeof(*self));
self->control_task = rtems_task_self();
start_validate_task(
&self->validate_tasks[0],
pattern_0,
PRIORITY_HIGH,
task_0_fpu
);
start_validate_task(
&self->validate_tasks[1],
pattern_1,
PRIORITY_LOW,
task_1_fpu
);
start_validate_task(
&self->validate_tasks[2],
pattern_2,
PRIORITY_LOW,
task_2_fpu
);
start_timer(self);
wait_for_finish();
sc = rtems_task_delete(self->validate_tasks[0]);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_delete(self->validate_tasks[1]);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_delete(self->validate_tasks[2]);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_timer_delete(self->timer);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
static void test_context_is_executing(void)
{
#if defined(RTEMS_SMP)
/*
* Provide a stack area, since on some architectures the top/bottom of stack
* is initialized by _CPU_Context_Initialize().
*/
static char stack[1024];
Context_Control context;
bool is_executing;
memset(&context, 0, sizeof(context));
is_executing = _CPU_Context_Get_is_executing(&context);
rtems_test_assert(!is_executing);
_CPU_Context_Set_is_executing(&context, true);
is_executing = _CPU_Context_Get_is_executing(&context);
rtems_test_assert(is_executing);
_CPU_Context_Set_is_executing(&context, false);
is_executing = _CPU_Context_Get_is_executing(&context);
rtems_test_assert(!is_executing);
_CPU_Context_Set_is_executing(&context, true);
_CPU_Context_Initialize(
&context,
(void *) &stack[0],
sizeof(stack),
0,
NULL,
false,
NULL
);
is_executing = _CPU_Context_Get_is_executing(&context);
rtems_test_assert(is_executing);
#endif
}
static bool is_fp(int i)
{
return i != 0;
}
static const char *desc(int i)
{
return is_fp(i) ? "F" : "N";
}
static void Init(rtems_task_argument arg)
{
test_context *self = &test_instance;
int i;
int j;
int k;
TEST_BEGIN();
test_context_is_executing();
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
for (k = 0; k < 2; ++k) {
printf("Test configuration %s %s %s... ", desc(i), desc(j), desc(k));
test(self, is_fp(i), is_fp(j), is_fp(k));
printf("done\n");
}
}
}
TEST_END();
rtems_test_exit(0);
}
static void switch_extension(Thread_Control *executing, Thread_Control *heir)
{
uintptr_t pattern = (uintptr_t) 0xffffffffffffffffU;
_CPU_Context_volatile_clobber(pattern);
}
#define CONFIGURE_MICROSECONDS_PER_TICK 1000
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 4
#define CONFIGURE_MAXIMUM_TIMERS 1
#define CONFIGURE_INITIAL_EXTENSIONS \
{ .thread_switch = switch_extension }, \
RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/home/taste/work/development/rtems/kernel/rtems/testsuites/support/
\ No newline at end of file
......@@ -26,7 +26,7 @@ CPPFLAGS = -I$(PROJECT_INCLUDE)/bsp
CFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
CXXFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
ASFLAGS = $(CPU_CFLAGS)
LDFLAGS = -Wl,--gc-sections
LDFLAGS = -Wl,--gc-sections -Wl,--wrap=printf -Wl,--wrap=puts -Wl,--wrap=putchar
LINKFLAGS = $(SYSFLAGS) $(CPU_CFLAGS) $(LDFLAGS) $(OPTFLAGS)
CCLINK = $(CC) $(LINKFLAGS) -Wl,-Map,$(basename $@).map
......
......@@ -39,7 +39,7 @@ CPPFLAGS = -DGTEST -isystem $(GTEST_DIR)/include -I$(PROJECT_INCLUDE)/bsp
CFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
CXXFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS)
ASFLAGS = $(CPU_CFLAGS)
LDFLAGS = -Wl,--gc-sections
LDFLAGS = -Wl,--gc-sections -Wl,--wrap=printf -Wl,--wrap=puts -Wl,--wrap=putchar
LINKFLAGS = $(SYSFLAGS) $(CPU_CFLAGS) $(LDFLAGS) $(OPTFLAGS)
CCLINK = $(CC) $(LINKFLAGS) -Wl,-Map,$(basename $@).map
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment