git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9193 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
Giovanni Di Sirio 2016-04-01 09:08:17 +00:00
parent f2fdc06c4d
commit b472786cd2
7 changed files with 1046 additions and 24 deletions

View File

@ -3833,8 +3833,8 @@ static THD_FUNCTION(dyn_thread1, p) {
<value>Threads creation from Memory Heap.</value>
</brief>
<description>
<value>Two threads are started by allocating the memory from the Memory Heap then the remaining heap space is arbitrarily allocated and a third tread startup is attempted.&lt;br&gt;&#xD;
The test expects the first two threads to successfully start and the last one to fail.</value>
<value>Two threads are started by allocating the memory from the Memory Heap then a third thread is started with a huge stack requirement.&lt;br&gt;&#xD;
The test expects the first two threads to successfully start and the third one to fail.</value>
</description>
<condition>
<value>CH_CFG_USE_HEAP</value>
@ -3878,7 +3878,7 @@ test_assert(n1 == 1, "heap fragmented");]]></value>
</step>
<step>
<description>
<value>Creating 1, it is expected to succeed.</value>
<value>Creating thread 1, it is expected to succeed.</value>
</description>
<tags>
<value />
@ -3968,7 +3968,7 @@ The test expects the first four threads to successfully start and the last one t
<value />
</teardown_code>
<local_variables>
<value><![CDATA[unsigned i;
<value><![CDATA[unsigned i;
tprio_t prio;]]></value>
</local_variables>
</various_code>
@ -3981,7 +3981,7 @@ tprio_t prio;]]></value>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < 4; i++)
<value><![CDATA[for (i = 0; i < 4; i++)
chPoolFree(&mp1, wa[i]);]]></value>
</code>
</step>
@ -4004,10 +4004,10 @@ tprio_t prio;]]></value>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, dyn_thread1, "A");
threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, dyn_thread1, "B");
threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, dyn_thread1, "C");
threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, dyn_thread1, "D");
<value><![CDATA[threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, dyn_thread1, "A");
threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, dyn_thread1, "B");
threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, dyn_thread1, "C");
threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, dyn_thread1, "D");
threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, dyn_thread1, "E");]]></value>
</code>
</step>
@ -4019,12 +4019,12 @@ threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, dyn_thread1, "E");]
<value />
</tags>
<code>
<value><![CDATA[test_assert((threads[0] != NULL) &&
(threads[1] != NULL) &&
(threads[2] != NULL) &&
(threads[3] != NULL),
"thread creation failed");
test_assert(threads[4] == NULL,
<value><![CDATA[test_assert((threads[0] != NULL) &&
(threads[1] != NULL) &&
(threads[2] != NULL) &&
(threads[3] != NULL),
"thread creation failed");
test_assert(threads[4] == NULL,
"thread creation not failed");]]></value>
</code>
</step>
@ -4036,7 +4036,7 @@ test_assert(threads[4] == NULL,
<value />
</tags>
<code>
<value><![CDATA[test_wait_threads();
<value><![CDATA[test_wait_threads();
test_assert_sequence("ABCD", "invalid sequence");]]></value>
</code>
</step>
@ -4048,8 +4048,8 @@ test_assert_sequence("ABCD", "invalid sequence");]]></value>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < 4; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
<value><![CDATA[for (i = 0; i < 4; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");]]></value>
</code>
</step>
@ -4057,6 +4057,491 @@ test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");]]></value>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Benchmarks.</value>
</brief>
<description>
<value>This module implements a series of system benchmarks. The benchmarks are useful as a stress test and as a reference when comparing ChibiOS/RT with similar systems.&lt;br&gt;&#xD;
Objective of the test sequence is to provide a performance index for the most critical system subsystems. The performance numbers allow to discover performance regressions between successive ChibiOS/RT releases.</value>
</description>
<condition>
<value />
</condition>
<shared_code>
<value><![CDATA[#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__)
static semaphore_t sem1;
#endif
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
static mutex_t mtx1;
#endif
#if CH_CFG_USE_MESSAGES
static THD_FUNCTION(bmk_thread1, p) {
thread_t *tp;
msg_t msg;
(void)p;
do {
tp = chMsgWait();
msg = chMsgGet(tp);
chMsgRelease(tp, msg);
} while (msg);
}
NOINLINE static unsigned int msg_loop_test(thread_t *tp) {
systime_t start, end;
uint32_t n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
(void)chMsgSend(tp, 1);
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));
(void)chMsgSend(tp, 0);
return n;
}
#endif
static THD_FUNCTION(bmk_thread3, p) {
chThdExit((msg_t)p);
}
static THD_FUNCTION(bmk_thread4, p) {
msg_t msg;
thread_t *self = chThdGetSelfX();
(void)p;
chSysLock();
do {
chSchGoSleepS(CH_STATE_SUSPENDED);
msg = self->u.rdymsg;
} while (msg == MSG_OK);
chSysUnlock();
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Messages performance #1.</value>
</brief>
<description>
<value>A message server thread is created with a lower priority than the client thread, the messages throughput per second is measured and the result printed on the output log.</value>
</description>
<condition>
<value>CH_CFG_USE_MESSAGES</value>
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[uint32_t n;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>The messenger thread is started at a lower priority than the current thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, bmk_thread1, NULL);]]></value>
</code>
</step>
<step>
<description>
<value>The number of messages exchanged is counted in a one second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[n = msg_loop_test(threads[0]);
test_wait_threads();]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Messages performance #2.</value>
</brief>
<description>
<value>A message server thread is created with an higher priority than the client thread, the messages throughput per second is measured and the result printed on the output log.</value>
</description>
<condition>
<value>CH_CFG_USE_MESSAGES</value>
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[uint32_t n;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>The messenger thread is started at an higher priority than the current thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, bmk_thread1, NULL);]]></value>
</code>
</step>
<step>
<description>
<value>The number of messages exchanged is counted in a one second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[n = msg_loop_test(threads[0]);
test_wait_threads();]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Messages performance #3.</value>
</brief>
<description>
<value>A message server thread is created with an higher priority than the client thread, four lower priority threads crowd the ready list, the messages throughput per second is measured while the ready list and the result printed on the output log.</value>
</description>
<condition>
<value>CH_CFG_USE_MESSAGES</value>
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[uint32_t n;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>The messenger thread is started at an higher priority than the current thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, bmk_thread1, NULL);]]></value>
</code>
</step>
<step>
<description>
<value>Four threads are started at a lower priority than the current thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-2, bmk_thread3, NULL);
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-3, bmk_thread3, NULL);
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-4, bmk_thread3, NULL);
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-5, bmk_thread3, NULL);]]></value>
</code>
</step>
<step>
<description>
<value>The number of messages exchanged is counted in a one second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[n = msg_loop_test(threads[0]);
test_wait_threads();]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Context Switch performance.</value>
</brief>
<description>
<value>A thread is created that just performs a @p chSchGoSleepS() into a loop, the thread is awakened as fast is possible by the tester thread.&lt;br&gt;&#xD;
The Context Switch performance is calculated by measuring the number of iterations after a second of continuous operations.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[thread_t *tp;
uint32_t n;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Starting the target thread at an higher priority level.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[tp = threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1,
bmk_thread4, NULL);]]></value>
</code>
</step>
<step>
<description>
<value>Waking up the thread as fast as possible in a one second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[systime_t start, end;
n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chSysLock();
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSysUnlock();
n += 4;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));]]></value>
</code>
</step>
<step>
<description>
<value>Stopping the target thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSysLock();
chSchWakeupS(tp, MSG_TIMEOUT);
chSysUnlock();
test_wait_threads();]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n * 2);
test_println(" ctxswc/S");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Threads performance, full cycle.</value>
</brief>
<description>
<value>Threads are continuously created and terminated into a loop. A full chThdCreateStatic() / @p chThdExit() / @p chThdWait() cycle is performed in each iteration.&lt;br&gt;&#xD;
The performance is calculated by measuring the number of iterations after a second of continuous operations.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[uint32_t n;
tprio_t prio = chThdGetPriorityX() - 1;
systime_t start, end;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>A thread is created at a lower priority level and its termination detected using @p chThdWait(). The operation is repeated continuously in a one-second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chThdWait(chThdCreateStatic(wa[0], WA_SIZE, prio, bmk_thread3, NULL));
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n);
test_println(" threads/S");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Threads performance, create/exit only.</value>
</brief>
<description>
<value>Threads are continuously created and terminated into a loop. A partial @p chThdCreateStatic() / @p chThdExit() cycle is performed in each iteration, the @p chThdWait() is not necessary because the thread is created at an higher priority so there is no need to wait for it to terminate.&lt;br&gt; The performance is calculated by measuring the number of iterations after a second of continuous operations.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[uint32_t n;
tprio_t prio = chThdGetPriorityX() + 1;
systime_t start, end;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>A thread is created at an higher priority level and let terminate immediately. The operation is repeated continuously in a one-second time window.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chThdRelease(chThdCreateStatic(wa[0], WA_SIZE, prio, bmk_thread3, NULL));
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));]]></value>
</code>
</step>
<step>
<description>
<value>Score is printed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_print("--- Score : ");
test_printn(n);
test_println(" threads/S");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
</sequences>
</instance>
</instances>

View File

@ -32,6 +32,7 @@
* - @subpage test_sequence_009
* - @subpage test_sequence_010
* - @subpage test_sequence_011
* - @subpage test_sequence_012
* .
*/
@ -65,6 +66,7 @@ const testcase_t * const *test_suite[] = {
test_sequence_009,
test_sequence_010,
test_sequence_011,
test_sequence_012,
NULL
};

View File

@ -33,6 +33,7 @@
#include "test_sequence_009.h"
#include "test_sequence_010.h"
#include "test_sequence_011.h"
#include "test_sequence_012.h"
#if !defined(__DOXYGEN__)

View File

@ -67,9 +67,9 @@ static THD_FUNCTION(dyn_thread1, p) {
*
* <h2>Description</h2>
* Two threads are started by allocating the memory from the Memory
* Heap then the remaining heap space is arbitrarily allocated and a
* third tread startup is attempted.<br> The test expects the first two
* threads to successfully start and the last one to fail.
* Heap then a third thread is started with a huge stack
* requirement.<br> The test expects the first two threads to
* successfully start and the third one to fail.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
@ -80,7 +80,7 @@ static THD_FUNCTION(dyn_thread1, p) {
* <h2>Test Steps</h2>
* - [11.1.1] Getting base priority for threads.
* - [11.1.2] Getting heap info before the test.
* - [11.1.3] Creating 1, it is expected to succeed.
* - [11.1.3] Creating thread 1, it is expected to succeed.
* - [11.1.4] Creating thread 2, it is expected to succeed.
* - [11.1.5] Creating thread 3, it is expected to fail.
* - [11.1.6] Letting threads execute then checking the start order and
@ -111,7 +111,7 @@ static void test_011_001_execute(void) {
test_assert(n1 == 1, "heap fragmented");
}
/* [11.1.3] Creating 1, it is expected to succeed.*/
/* [11.1.3] Creating thread 1, it is expected to succeed.*/
test_set_step(3);
{
threads[0] = chThdCreateFromHeap(&heap1,

View File

@ -0,0 +1,516 @@
/*
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "hal.h"
#include "ch_test.h"
#include "test_root.h"
/**
* @page test_sequence_012 [12] Benchmarks
*
* File: @ref test_sequence_012.c
*
* <h2>Description</h2>
* This module implements a series of system benchmarks. The benchmarks
* are useful as a stress test and as a reference when comparing
* ChibiOS/RT with similar systems.<br> Objective of the test sequence
* is to provide a performance index for the most critical system
* subsystems. The performance numbers allow to discover performance
* regressions between successive ChibiOS/RT releases.
*
* <h2>Test Cases</h2>
* - @subpage test_012_001
* - @subpage test_012_002
* - @subpage test_012_003
* - @subpage test_012_004
* - @subpage test_012_005
* - @subpage test_012_006
* .
*/
/****************************************************************************
* Shared code.
****************************************************************************/
#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__)
static semaphore_t sem1;
#endif
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
static mutex_t mtx1;
#endif
#if CH_CFG_USE_MESSAGES
static THD_FUNCTION(bmk_thread1, p) {
thread_t *tp;
msg_t msg;
(void)p;
do {
tp = chMsgWait();
msg = chMsgGet(tp);
chMsgRelease(tp, msg);
} while (msg);
}
NOINLINE static unsigned int msg_loop_test(thread_t *tp) {
systime_t start, end;
uint32_t n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
(void)chMsgSend(tp, 1);
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));
(void)chMsgSend(tp, 0);
return n;
}
#endif
static THD_FUNCTION(bmk_thread3, p) {
chThdExit((msg_t)p);
}
static THD_FUNCTION(bmk_thread4, p) {
msg_t msg;
thread_t *self = chThdGetSelfX();
(void)p;
chSysLock();
do {
chSchGoSleepS(CH_STATE_SUSPENDED);
msg = self->u.rdymsg;
} while (msg == MSG_OK);
chSysUnlock();
}
/****************************************************************************
* Test cases.
****************************************************************************/
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
/**
* @page test_012_001 [12.1] Messages performance #1
*
* <h2>Description</h2>
* A message server thread is created with a lower priority than the
* client thread, the messages throughput per second is measured and
* the result printed on the output log.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MESSAGES
* .
*
* <h2>Test Steps</h2>
* - [12.1.1] The messenger thread is started at a lower priority than
* the current thread.
* - [12.1.2] The number of messages exchanged is counted in a one
* second time window.
* - [12.1.3] Score is printed.
* .
*/
static void test_012_001_execute(void) {
uint32_t n;
/* [12.1.1] The messenger thread is started at a lower priority than
the current thread.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, bmk_thread1, NULL);
}
/* [12.1.2] The number of messages exchanged is counted in a one
second time window.*/
test_set_step(2);
{
n = msg_loop_test(threads[0]);
test_wait_threads();
}
/* [12.1.3] Score is printed.*/
test_set_step(3);
{
test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");
}
}
static const testcase_t test_012_001 = {
"Messages performance #1",
NULL,
NULL,
test_012_001_execute
};
#endif /* CH_CFG_USE_MESSAGES */
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
/**
* @page test_012_002 [12.2] Messages performance #2
*
* <h2>Description</h2>
* A message server thread is created with an higher priority than the
* client thread, the messages throughput per second is measured and
* the result printed on the output log.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MESSAGES
* .
*
* <h2>Test Steps</h2>
* - [12.2.1] The messenger thread is started at an higher priority
* than the current thread.
* - [12.2.2] The number of messages exchanged is counted in a one
* second time window.
* - [12.2.3] Score is printed.
* .
*/
static void test_012_002_execute(void) {
uint32_t n;
/* [12.2.1] The messenger thread is started at an higher priority
than the current thread.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, bmk_thread1, NULL);
}
/* [12.2.2] The number of messages exchanged is counted in a one
second time window.*/
test_set_step(2);
{
n = msg_loop_test(threads[0]);
test_wait_threads();
}
/* [12.2.3] Score is printed.*/
test_set_step(3);
{
test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");
}
}
static const testcase_t test_012_002 = {
"Messages performance #2",
NULL,
NULL,
test_012_002_execute
};
#endif /* CH_CFG_USE_MESSAGES */
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
/**
* @page test_012_003 [12.3] Messages performance #3
*
* <h2>Description</h2>
* A message server thread is created with an higher priority than the
* client thread, four lower priority threads crowd the ready list, the
* messages throughput per second is measured while the ready list and
* the result printed on the output log.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MESSAGES
* .
*
* <h2>Test Steps</h2>
* - [12.3.1] The messenger thread is started at an higher priority
* than the current thread.
* - [12.3.2] Four threads are started at a lower priority than the
* current thread.
* - [12.3.3] The number of messages exchanged is counted in a one
* second time window.
* - [12.3.4] Score is printed.
* .
*/
static void test_012_003_execute(void) {
uint32_t n;
/* [12.3.1] The messenger thread is started at an higher priority
than the current thread.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, bmk_thread1, NULL);
}
/* [12.3.2] Four threads are started at a lower priority than the
current thread.*/
test_set_step(2);
{
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-2, bmk_thread3, NULL);
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-3, bmk_thread3, NULL);
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-4, bmk_thread3, NULL);
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-5, bmk_thread3, NULL);
}
/* [12.3.3] The number of messages exchanged is counted in a one
second time window.*/
test_set_step(3);
{
n = msg_loop_test(threads[0]);
test_wait_threads();
}
/* [12.3.4] Score is printed.*/
test_set_step(4);
{
test_print("--- Score : ");
test_printn(n);
test_print(" msgs/S, ");
test_printn(n << 1);
test_println(" ctxswc/S");
}
}
static const testcase_t test_012_003 = {
"Messages performance #3",
NULL,
NULL,
test_012_003_execute
};
#endif /* CH_CFG_USE_MESSAGES */
/**
* @page test_012_004 [12.4] Context Switch performance
*
* <h2>Description</h2>
* A thread is created that just performs a @p chSchGoSleepS() into a
* loop, the thread is awakened as fast is possible by the tester
* thread.<br> The Context Switch performance is calculated by
* measuring the number of iterations after a second of continuous
* operations.
*
* <h2>Test Steps</h2>
* - [12.4.1] Starting the target thread at an higher priority level.
* - [12.4.2] Waking up the thread as fast as possible in a one second
* time window.
* - [12.4.3] Stopping the target thread.
* - [12.4.4] Score is printed.
* .
*/
static void test_012_004_execute(void) {
thread_t *tp;
uint32_t n;
/* [12.4.1] Starting the target thread at an higher priority level.*/
test_set_step(1);
{
tp = threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1,
bmk_thread4, NULL);
}
/* [12.4.2] Waking up the thread as fast as possible in a one second
time window.*/
test_set_step(2);
{
systime_t start, end;
n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chSysLock();
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSchWakeupS(tp, MSG_OK);
chSysUnlock();
n += 4;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));
}
/* [12.4.3] Stopping the target thread.*/
test_set_step(3);
{
chSysLock();
chSchWakeupS(tp, MSG_TIMEOUT);
chSysUnlock();
test_wait_threads();
}
/* [12.4.4] Score is printed.*/
test_set_step(4);
{
test_print("--- Score : ");
test_printn(n * 2);
test_println(" ctxswc/S");
}
}
static const testcase_t test_012_004 = {
"Context Switch performance",
NULL,
NULL,
test_012_004_execute
};
/**
* @page test_012_005 [12.5] Threads performance, full cycle
*
* <h2>Description</h2>
* Threads are continuously created and terminated into a loop. A full
* chThdCreateStatic() / @p chThdExit() / @p chThdWait() cycle is
* performed in each iteration.<br> The performance is calculated by
* measuring the number of iterations after a second of continuous
* operations.
*
* <h2>Test Steps</h2>
* - [12.5.1] A thread is created at a lower priority level and its
* termination detected using @p chThdWait(). The operation is
* repeated continuously in a one-second time window.
* - [12.5.2] Score is printed.
* .
*/
static void test_012_005_execute(void) {
uint32_t n;
tprio_t prio = chThdGetPriorityX() - 1;
systime_t start, end;
/* [12.5.1] A thread is created at a lower priority level and its
termination detected using @p chThdWait(). The operation is
repeated continuously in a one-second time window.*/
test_set_step(1);
{
n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chThdWait(chThdCreateStatic(wa[0], WA_SIZE, prio, bmk_thread3, NULL));
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));
}
/* [12.5.2] Score is printed.*/
test_set_step(2);
{
test_print("--- Score : ");
test_printn(n);
test_println(" threads/S");
}
}
static const testcase_t test_012_005 = {
"Threads performance, full cycle",
NULL,
NULL,
test_012_005_execute
};
/**
* @page test_012_006 [12.6] Threads performance, create/exit only
*
* <h2>Description</h2>
* Threads are continuously created and terminated into a loop. A
* partial @p chThdCreateStatic() / @p chThdExit() cycle is performed
* in each iteration, the @p chThdWait() is not necessary because the
* thread is created at an higher priority so there is no need to wait
* for it to terminate.<br> The performance is calculated by measuring
* the number of iterations after a second of continuous operations.
*
* <h2>Test Steps</h2>
* - [12.6.1] A thread is created at an higher priority level and let
* terminate immediately. The operation is repeated continuously in a
* one-second time window.
* - [12.6.2] Score is printed.
* .
*/
static void test_012_006_execute(void) {
uint32_t n;
tprio_t prio = chThdGetPriorityX() + 1;
systime_t start, end;
/* [12.6.1] A thread is created at an higher priority level and let
terminate immediately. The operation is repeated continuously in a
one-second time window.*/
test_set_step(1);
{
n = 0;
start = test_wait_tick();
end = start + MS2ST(1000);
do {
chThdRelease(chThdCreateStatic(wa[0], WA_SIZE, prio, bmk_thread3, NULL));
n++;
#if defined(SIMULATOR)
_sim_check_for_interrupts();
#endif
} while (chVTIsSystemTimeWithinX(start, end));
}
/* [12.6.2] Score is printed.*/
test_set_step(2);
{
test_print("--- Score : ");
test_printn(n);
test_println(" threads/S");
}
}
static const testcase_t test_012_006 = {
"Threads performance, create/exit only",
NULL,
NULL,
test_012_006_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Benchmarks.
*/
const testcase_t * const test_sequence_012[] = {
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
&test_012_001,
#endif
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
&test_012_002,
#endif
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
&test_012_003,
#endif
&test_012_004,
&test_012_005,
&test_012_006,
NULL
};

View File

@ -0,0 +1,17 @@
/*
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
extern const testcase_t * const test_sequence_012[];

View File

@ -11,7 +11,8 @@ TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \
${CHIBIOS}/test/rt/source/test/test_sequence_008.c \
${CHIBIOS}/test/rt/source/test/test_sequence_009.c \
${CHIBIOS}/test/rt/source/test/test_sequence_010.c \
${CHIBIOS}/test/rt/source/test/test_sequence_011.c
${CHIBIOS}/test/rt/source/test/test_sequence_011.c \
${CHIBIOS}/test/rt/source/test/test_sequence_012.c
# Required include directories
TESTINC = ${CHIBIOS}/test/lib \