2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2009-03-09 00:33:41 +01:00
|
|
|
* ostest/main.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2009-03-09 00:33:41 +01:00
|
|
|
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
2007-02-18 00:21:28 +01:00
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-01-28 16:45:39 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-23 17:06:22 +01:00
|
|
|
#include <nuttx/config.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <stdio.h>
|
2007-03-23 17:06:22 +01:00
|
|
|
#include <stdlib.h>
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <unistd.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <sched.h>
|
2007-09-09 13:58:50 +02:00
|
|
|
#include <nuttx/init.h>
|
2008-09-19 01:42:12 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include "ostest.h"
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Definitions
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#define PRIORITY 100
|
|
|
|
#define NARGS 4
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Data
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-11 22:16:56 +01:00
|
|
|
static const char arg1[] = "Arg1";
|
|
|
|
static const char arg2[] = "Arg2";
|
|
|
|
static const char arg3[] = "Arg3";
|
|
|
|
static const char arg4[] = "Arg4";
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2007-03-11 22:16:56 +01:00
|
|
|
static const char write_data1[] = "stdio_test: write fd=1\n";
|
|
|
|
static const char write_data2[] = "stdio_test: write fd=2\n";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SDCC
|
|
|
|
/* I am not yet certain why SDCC does not like the following
|
|
|
|
* initializer. It involves some issues with 2- vs 3-byte
|
|
|
|
* pointer types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char *g_argv[NARGS+1];
|
|
|
|
#else
|
|
|
|
static const char *g_argv[NARGS+1] = { arg1, arg2, arg3, arg4, NULL };
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-23 17:06:22 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
|
|
|
static struct mallinfo g_mmbefore;
|
|
|
|
static struct mallinfo g_mmprevious;
|
|
|
|
static struct mallinfo g_mmafter;
|
|
|
|
#endif
|
|
|
|
|
2007-07-01 00:35:23 +02:00
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
const char g_var1_name[] = "Variable1";
|
|
|
|
const char g_var1_value[] = "GoodValue1";
|
|
|
|
const char g_var2_name[] = "Variable2";
|
|
|
|
const char g_var2_value[] = "GoodValue2";
|
|
|
|
const char g_var3_name[] = "Variable3";
|
|
|
|
const char g_var3_value[] = "GoodValue3";
|
|
|
|
|
|
|
|
const char g_bad_value1[] = "BadValue1";
|
|
|
|
const char g_bad_value2[] = "BadValue2";
|
|
|
|
|
|
|
|
const char g_putenv_value[] = "Variable1=BadValue3";
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-03-23 17:06:22 +01:00
|
|
|
* Name: show_memory_usage
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-03-23 17:06:22 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
|
|
|
static void show_memory_usage(struct mallinfo *mmbefore,
|
|
|
|
struct mallinfo *mmafter)
|
|
|
|
{
|
|
|
|
printf("VARIABLE BEFORE AFTER\n");
|
|
|
|
printf("======== ======== ========\n");
|
|
|
|
printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
|
|
|
|
printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
|
|
|
|
printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
|
|
|
|
printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
|
|
|
|
printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define show_memory_usage(mm1, mm2)
|
|
|
|
#endif
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-03-23 17:06:22 +01:00
|
|
|
* Name: check_test_memory_usage
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-03-23 17:06:22 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
|
|
|
static void check_test_memory_usage(void)
|
|
|
|
{
|
|
|
|
/* Wait a little bit to let any threads terminate */
|
|
|
|
|
|
|
|
usleep(500*1000);
|
|
|
|
|
|
|
|
/* Get the current memory usage */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
g_mmafter = mallinfo();
|
|
|
|
#else
|
|
|
|
(void)mallinfo(&g_mmafter);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Show the change from the previous time */
|
|
|
|
|
|
|
|
printf("\nEnd of test memory usage:\n");
|
|
|
|
show_memory_usage(&g_mmprevious, &g_mmafter);
|
|
|
|
|
|
|
|
/* Set up for the next test */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
g_mmprevious = g_mmafter;
|
|
|
|
#else
|
|
|
|
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define check_test_memory_usage()
|
|
|
|
#endif
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-07-01 00:35:23 +02:00
|
|
|
* Name: show_environment
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-07-01 00:35:23 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
static void show_variable(const char *var_name, const char *exptd_value, boolean var_valid)
|
|
|
|
{
|
|
|
|
char *actual_value = getenv(var_name);
|
|
|
|
if (actual_value)
|
|
|
|
{
|
|
|
|
if (var_valid)
|
|
|
|
{
|
|
|
|
if (strcmp(actual_value, exptd_value) == 0)
|
|
|
|
{
|
|
|
|
printf("show_variable: Variable=%s has value=%s\n", var_name, exptd_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("show_variable: ERROR Variable=%s has the wrong value\n", var_name);
|
|
|
|
printf("show_variable: found=%s expected=%s\n", actual_value, exptd_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("show_variable: ERROR Variable=%s has a value when it should not\n", var_name);
|
|
|
|
printf("show_variable: value=%s\n", actual_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (var_valid)
|
|
|
|
{
|
|
|
|
printf("show_variable: ERROR Variable=%s has no value\n", var_name);
|
|
|
|
printf("show_variable: Should have had value=%s\n", exptd_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("show_variable: Variable=%s has no value\n", var_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-23 23:32:52 +01:00
|
|
|
static void show_environment(boolean var1_valid, boolean var2_valid, boolean var3_valid)
|
2007-07-01 00:35:23 +02:00
|
|
|
{
|
|
|
|
show_variable( g_var1_name, g_var1_value, var1_valid);
|
|
|
|
show_variable( g_var2_name, g_var2_value, var2_valid);
|
|
|
|
show_variable( g_var3_name, g_var3_value, var3_valid);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define show_environment()
|
|
|
|
#endif
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 22:16:56 +01:00
|
|
|
* Name: user_main
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 22:16:56 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
static int user_main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-03-23 17:06:22 +01:00
|
|
|
/* Sample the memory usage now */
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
|
|
|
usleep(500*1000);
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
g_mmbefore = mallinfo();
|
|
|
|
g_mmprevious = g_mmbefore;
|
|
|
|
#else
|
|
|
|
(void)mallinfo(&g_mmbefore);
|
2007-06-07 02:24:57 +02:00
|
|
|
memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
|
2007-03-23 17:06:22 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("\nuser_main: Begin argument test\n");
|
2007-02-20 23:39:56 +01:00
|
|
|
printf("user_main: Started with argc=%d\n", argc);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Verify passed arguments */
|
|
|
|
|
|
|
|
if (argc != NARGS + 1)
|
|
|
|
{
|
2007-03-01 22:05:55 +01:00
|
|
|
printf("user_main: Error expected argc=%d got argc=%d\n",
|
|
|
|
NARGS+1, argc);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= NARGS; i++)
|
|
|
|
{
|
2007-03-11 22:16:56 +01:00
|
|
|
printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= NARGS; i++)
|
|
|
|
{
|
2007-03-11 18:37:47 +01:00
|
|
|
if (strcmp(argv[i], g_argv[i-1]) != 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-03-01 22:05:55 +01:00
|
|
|
printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n",
|
2007-03-11 18:37:47 +01:00
|
|
|
i, g_argv[i-1], argv[i]);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-23 17:06:22 +01:00
|
|
|
check_test_memory_usage();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-07-01 00:35:23 +02:00
|
|
|
/* Check environment variables */
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
show_environment(TRUE, TRUE, TRUE);
|
|
|
|
|
|
|
|
unsetenv(g_var1_name);
|
|
|
|
show_environment(FALSE, TRUE, TRUE);
|
|
|
|
check_test_memory_usage();
|
|
|
|
|
|
|
|
clearenv();
|
|
|
|
show_environment(FALSE, FALSE, FALSE);
|
|
|
|
check_test_memory_usage();
|
|
|
|
#endif
|
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Top of test loop */
|
|
|
|
|
|
|
|
#if CONFIG_EXAMPLES_OSTEST_LOOPS > 1
|
|
|
|
for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++)
|
|
|
|
#elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0
|
|
|
|
for (;;)
|
|
|
|
#endif
|
|
|
|
{
|
2007-03-01 22:05:55 +01:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Checkout /dev/null */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: /dev/null test\n");
|
|
|
|
dev_null();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and pthread mutex */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: mutex test\n");
|
|
|
|
mutex_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-05 03:58:08 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)
|
|
|
|
/* Verify recursive mutexes */
|
|
|
|
|
|
|
|
printf("\nuser_main: recursive mutex test\n");
|
|
|
|
recursive_mutex_test();
|
|
|
|
check_test_memory_usage();
|
|
|
|
#endif
|
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthread cancellation */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: cancel test\n");
|
|
|
|
cancel_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and semaphores */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: semaphore test\n");
|
|
|
|
sem_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and condition variables */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: condition variable test\n");
|
2009-03-10 01:23:41 +01:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
|
|
|
printf("\n Skipping, Test logic incompatible with priority inheritance\n");
|
|
|
|
#else
|
2008-06-01 19:50:07 +02:00
|
|
|
cond_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2009-03-10 01:23:41 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-30 01:44:55 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and condition variable timed waits */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: timed wait test\n");
|
|
|
|
timedwait_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD)
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and message queues */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: message queue test\n");
|
|
|
|
mqueue_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-03-30 01:44:55 +02:00
|
|
|
|
|
|
|
#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthreads and message queues */
|
2007-03-30 01:44:55 +02:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: timed message queue test\n");
|
|
|
|
timedmqueue_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-30 01:44:55 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify signal handlers */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: signal handler test\n");
|
|
|
|
sighand_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS)
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify posix timers */
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: POSIX timer test\n");
|
|
|
|
timer_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-21 18:21:26 +01:00
|
|
|
#endif
|
|
|
|
|
2007-03-17 22:32:21 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify round robin scheduling */
|
2007-03-17 22:32:21 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: round-robin scheduler test\n");
|
|
|
|
rr_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-23 17:06:22 +01:00
|
|
|
#endif
|
|
|
|
|
2007-03-24 23:32:53 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Verify pthread barriers */
|
2007-03-24 23:32:53 +01:00
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nuser_main: barrier test\n");
|
|
|
|
barrier_test();
|
|
|
|
check_test_memory_usage();
|
2007-03-24 23:32:53 +01:00
|
|
|
#endif
|
|
|
|
|
2009-03-09 00:33:41 +01:00
|
|
|
#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
|
|
|
|
/* Verify priority inheritance */
|
|
|
|
|
|
|
|
printf("\nuser_main: priority inheritance test\n");
|
|
|
|
priority_inheritance();
|
|
|
|
check_test_memory_usage();
|
|
|
|
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
/* Compare memory usage at time user_start started until
|
|
|
|
* user_main exits. These should not be identical, but should
|
|
|
|
* be similar enough that we can detect any serious OS memory
|
|
|
|
* leaks.
|
|
|
|
*/
|
2007-03-23 17:06:22 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2008-06-01 19:50:07 +02:00
|
|
|
usleep(500*1000);
|
2007-03-23 17:06:22 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
2008-06-01 19:50:07 +02:00
|
|
|
g_mmafter = mallinfo();
|
2007-03-23 17:06:22 +01:00
|
|
|
#else
|
2008-06-01 19:50:07 +02:00
|
|
|
(void)mallinfo(&g_mmafter);
|
2007-03-23 17:06:22 +01:00
|
|
|
#endif
|
|
|
|
|
2008-06-01 19:50:07 +02:00
|
|
|
printf("\nFinal memory usage:\n");
|
|
|
|
show_memory_usage(&g_mmbefore, &g_mmafter);
|
2007-03-17 22:32:21 +01:00
|
|
|
#endif
|
2008-06-01 19:50:07 +02:00
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
printf("user_main: Exitting\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 22:16:56 +01:00
|
|
|
* Name: stdio_test
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 22:16:56 +01:00
|
|
|
|
|
|
|
static void stdio_test(void)
|
|
|
|
{
|
|
|
|
/* Verify that we can communicate */
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
|
|
write(1, write_data1, sizeof(write_data1)-1);
|
|
|
|
#endif
|
|
|
|
printf("stdio_test: Standard I/O Check: printf\n");
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 1
|
|
|
|
write(2, write_data2, sizeof(write_data2)-1);
|
|
|
|
#endif
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
|
|
|
fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* user_initialize
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
void user_initialize(void)
|
|
|
|
{
|
|
|
|
/* stub */
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:45:39 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* user_start
|
2008-01-28 16:45:39 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-11 18:37:47 +01:00
|
|
|
int user_start(int argc, char *argv[])
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2007-03-11 22:16:56 +01:00
|
|
|
/* Verify that stdio works first */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-11 22:16:56 +01:00
|
|
|
stdio_test();
|
2007-03-01 22:05:55 +01:00
|
|
|
|
2007-03-11 22:16:56 +01:00
|
|
|
#ifdef SDCC
|
2008-06-01 19:50:07 +02:00
|
|
|
/* I am not yet certain why SDCC does not like the following initilizers.
|
2007-03-11 22:16:56 +01:00
|
|
|
* It involves some issues with 2- vs 3-byte pointer types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_argv[0] = arg1;
|
|
|
|
g_argv[1] = arg2;
|
|
|
|
g_argv[2] = arg3;
|
|
|
|
g_argv[3] = arg4;
|
|
|
|
g_argv[4] = NULL;
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-07-01 00:35:23 +02:00
|
|
|
/* Set up some environment variables */
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
printf("user_start: putenv(%s)\n", g_putenv_value);
|
|
|
|
putenv(g_putenv_value); /* Varaible1=BadValue3 */
|
|
|
|
printf("user_start: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value);
|
|
|
|
setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */
|
|
|
|
|
|
|
|
printf("user_start: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1);
|
|
|
|
setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */
|
|
|
|
printf("user_start: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value);
|
|
|
|
setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */
|
|
|
|
|
|
|
|
printf("user_start: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
|
|
|
|
setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */
|
|
|
|
printf("user_start: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
|
|
|
|
setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */
|
|
|
|
show_environment(TRUE, TRUE, TRUE);
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Verify that we can spawn a new task */
|
|
|
|
|
2007-03-02 22:27:47 +01:00
|
|
|
#ifndef CONFIG_CUSTOM_STACK
|
2007-03-11 18:37:47 +01:00
|
|
|
result = task_create("ostest", PRIORITY, STACKSIZE, user_main, g_argv);
|
2007-03-02 22:27:47 +01:00
|
|
|
#else
|
2007-03-11 18:37:47 +01:00
|
|
|
result = task_create("ostest", PRIORITY, user_main, g_argv);
|
2007-03-02 22:27:47 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
if (result == ERROR)
|
|
|
|
{
|
2007-03-01 22:05:55 +01:00
|
|
|
printf("user_start: ERROR Failed to start user_main\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-08 19:34:11 +01:00
|
|
|
printf("user_start: Started user_main at PID=%d\n", result);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-03-01 22:05:55 +01:00
|
|
|
|
2009-02-28 15:24:48 +01:00
|
|
|
printf("user_start: Exitting\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|