Files
atomthreads/tests/kern2.c
2010-01-14 01:53:45 +00:00

198 lines
5.0 KiB
C

/*
* Copyright (c) 2010, Kelvin Lawson. All rights reserved.
*
* 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.
* 3. No personal names or organizations' names associated with the
* Atomthreads project may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT 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 PROJECT 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.
*/
#include "atom.h"
#include "atomtests.h"
/**
* \b test_start
*
* Start kernel test.
*
* This is a basic test of the thread context-switch functionality. It
* creates twenty local (byte) variables and schedules the thread out
* for one second. If context-switch save/restore is not implemented
* correctly, you might expect one or more of these local variables to
* be corrupted by the time the thread is scheduled back in.
*
* Note that this is a fairly unsophisticated test, and a lot depends on
* how the compiler deals with the variables, as well as what code is
* executed while the thread is scheduled out. It should flag up any
* major problems with the context-switch, however.
*
* @retval Number of failures
*/
uint32_t test_start (void)
{
int failures;
uint8_t one = 1;
uint8_t two = 2;
uint8_t three = 3;
uint8_t four = 4;
uint8_t five = 5;
uint8_t six = 6;
uint8_t seven = 7;
uint8_t eight = 8;
uint8_t nine = 9;
uint8_t ten = 10;
uint8_t eleven = 11;
uint8_t twelve = 12;
uint8_t thirteen = 13;
uint8_t fourteen = 14;
uint8_t fifteen = 15;
uint8_t sixteen = 16;
uint8_t seventeen = 17;
uint8_t eighteen = 18;
uint8_t nineteen = 19;
uint8_t twenty = 20;
/* Default to zero failures */
failures = 0;
/* Sleep for one second */
atomTimerDelay(SYSTEM_TICKS_PER_SEC);
/* Check all variables contain expected values */
if (one != 1)
{
ATOMLOG (_STR("1(%d)\n"), one);
failures++;
}
if (two != 2)
{
ATOMLOG (_STR("2(%d)\n"), two);
failures++;
}
if (three != 3)
{
ATOMLOG (_STR("3(%d)\n"), three);
failures++;
}
if (four != 4)
{
ATOMLOG (_STR("4(%d)\n"), four);
failures++;
}
if (five != 5)
{
ATOMLOG (_STR("5(%d)\n"), five);
failures++;
}
if (six != 6)
{
ATOMLOG (_STR("6(%d)\n"), six);
failures++;
}
if (seven != 7)
{
ATOMLOG (_STR("7(%d)\n"), seven);
failures++;
}
if (eight != 8)
{
ATOMLOG (_STR("8(%d)\n"), eight);
failures++;
}
if (nine != 9)
{
ATOMLOG (_STR("9(%d)\n"), nine);
failures++;
}
if (ten != 10)
{
ATOMLOG (_STR("10(%d)\n"), ten);
failures++;
}
if (eleven != 11)
{
ATOMLOG (_STR("11(%d)\n"), eleven);
failures++;
}
if (twelve != 12)
{
ATOMLOG (_STR("12(%d)\n"), twelve);
failures++;
}
if (thirteen != 13)
{
ATOMLOG (_STR("13(%d)\n"), thirteen);
failures++;
}
if (fourteen != 14)
{
ATOMLOG (_STR("14(%d)\n"), fourteen);
failures++;
}
if (fifteen != 15)
{
ATOMLOG (_STR("15(%d)\n"), fifteen);
failures++;
}
if (sixteen != 16)
{
ATOMLOG (_STR("16(%d)\n"), sixteen);
failures++;
}
if (seventeen != 17)
{
ATOMLOG (_STR("17(%d)\n"), seventeen);
failures++;
}
if (eighteen != 18)
{
ATOMLOG (_STR("18(%d)\n"), eighteen);
failures++;
}
if (nineteen != 19)
{
ATOMLOG (_STR("19(%d)\n"), nineteen);
failures++;
}
if (twenty != 20)
{
ATOMLOG (_STR("20(%d)\n"), twenty);
failures++;
}
/* Log final status */
if (failures == 0)
{
ATOMLOG (_STR("Pass\n"));
}
else
{
ATOMLOG (_STR("Fail(%d)\n"), failures);
}
/* Quit */
return failures;
}