Improved test suite for Nil.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12653 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
Giovanni Di Sirio 2019-02-10 12:36:00 +00:00
parent a3f7f78983
commit d6fa7fed19
7 changed files with 270 additions and 2 deletions

View File

@ -5,7 +5,7 @@
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).

View File

@ -1354,6 +1354,100 @@ test_assert(!chEvtIsListeningI(&es2), "stuck listener");]]></value>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Synchronous Messages.</value>
</brief>
<description>
<value>This module implements the test sequence for the Synchronous Messages subsystem.</value>
</description>
<condition>
<value>CH_CFG_USE_MESSAGES</value>
</condition>
<shared_code>
<value><![CDATA[/*
* Messager thread.
*/
static THD_WORKING_AREA(wa_messager, 128);
static THD_FUNCTION(messager, p) {
chMsgSend(p, 'A');
chMsgSend(p, 'B');
chMsgSend(p, 'C');
chMsgSend(p, 'D');
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Messages Server loop.</value>
</brief>
<description>
<value>A messenger thread is spawned that sends four messages back to the tester thread.&lt;br&gt;&#xD;
The test expect to receive the messages in the correct sequence and to not find a fifth message waiting.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[thread_t *tp, *tp1;
msg_t msg;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Starting the messenger thread.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[thread_config_t tc = {
chThdGetPriorityX() - 1,
"messager",
wa_messager,
THD_WORKING_AREA_END(wa_messager),
messager,
chThdGetSelfX()
};
tp1 = chThdCreate(&tc);]]></value>
</code>
</step>
<step>
<description>
<value>Waiting for four messages then testing the receive order.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[unsigned i;
for (i = 0; i < 4; i++) {
tp = chMsgWait();
msg = chMsgGet(tp);
chMsgRelease(tp, msg);
test_emit_token(msg);
}
chThdWait(tp1);
test_assert_sequence("ABCD", "invalid sequence");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
</sequences>
</instance>
</instances>

View File

@ -4,7 +4,8 @@ TESTSRC += ${CHIBIOS}/test/nil/source/test/nil_test_root.c \
${CHIBIOS}/test/nil/source/test/nil_test_sequence_002.c \
${CHIBIOS}/test/nil/source/test/nil_test_sequence_003.c \
${CHIBIOS}/test/nil/source/test/nil_test_sequence_004.c \
${CHIBIOS}/test/nil/source/test/nil_test_sequence_005.c
${CHIBIOS}/test/nil/source/test/nil_test_sequence_005.c \
${CHIBIOS}/test/nil/source/test/nil_test_sequence_006.c
# Required include directories
TESTINC += ${CHIBIOS}/test/nil/source/test

View File

@ -26,6 +26,7 @@
* - @subpage nil_test_sequence_003
* - @subpage nil_test_sequence_004
* - @subpage nil_test_sequence_005
* - @subpage nil_test_sequence_006
* .
*/
@ -55,6 +56,9 @@ const testsequence_t * const nil_test_suite_array[] = {
&nil_test_sequence_004,
#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__)
&nil_test_sequence_005,
#endif
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
&nil_test_sequence_006,
#endif
NULL
};

View File

@ -29,6 +29,7 @@
#include "nil_test_sequence_003.h"
#include "nil_test_sequence_004.h"
#include "nil_test_sequence_005.h"
#include "nil_test_sequence_006.h"
#if !defined(__DOXYGEN__)

View File

@ -0,0 +1,141 @@
/*
ChibiOS - Copyright (C) 2006..2018 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 "nil_test_root.h"
/**
* @file nil_test_sequence_006.c
* @brief Test Sequence 006 code.
*
* @page nil_test_sequence_006 [6] Synchronous Messages
*
* File: @ref nil_test_sequence_006.c
*
* <h2>Description</h2>
* This module implements the test sequence for the Synchronous
* Messages subsystem.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MESSAGES
* .
*
* <h2>Test Cases</h2>
* - @subpage nil_test_006_001
* .
*/
#if (CH_CFG_USE_MESSAGES) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
/*
* Messager thread.
*/
static THD_WORKING_AREA(wa_messager, 128);
static THD_FUNCTION(messager, p) {
chMsgSend(p, 'A');
chMsgSend(p, 'B');
chMsgSend(p, 'C');
chMsgSend(p, 'D');
}
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page nil_test_006_001 [6.1] Messages Server loop
*
* <h2>Description</h2>
* A messenger thread is spawned that sends four messages back to the
* tester thread.<br> The test expect to receive the messages in the
* correct sequence and to not find a fifth message waiting.
*
* <h2>Test Steps</h2>
* - [6.1.1] Starting the messenger thread.
* - [6.1.2] Waiting for four messages then testing the receive order.
* .
*/
static void nil_test_006_001_execute(void) {
thread_t *tp, *tp1;
msg_t msg;
/* [6.1.1] Starting the messenger thread.*/
test_set_step(1);
{
thread_config_t tc = {
chThdGetPriorityX() - 1,
"messager",
wa_messager,
THD_WORKING_AREA_END(wa_messager),
messager,
chThdGetSelfX()
};
tp1 = chThdCreate(&tc);
}
/* [6.1.2] Waiting for four messages then testing the receive
order.*/
test_set_step(2);
{
unsigned i;
for (i = 0; i < 4; i++) {
tp = chMsgWait();
msg = chMsgGet(tp);
chMsgRelease(tp, msg);
test_emit_token(msg);
}
chThdWait(tp1);
test_assert_sequence("ABCD", "invalid sequence");
}
}
static const testcase_t nil_test_006_001 = {
"Messages Server loop",
NULL,
NULL,
nil_test_006_001_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Array of test cases.
*/
const testcase_t * const nil_test_sequence_006_array[] = {
&nil_test_006_001,
NULL
};
/**
* @brief Synchronous Messages.
*/
const testsequence_t nil_test_sequence_006 = {
"Synchronous Messages",
nil_test_sequence_006_array
};
#endif /* CH_CFG_USE_MESSAGES */

View File

@ -0,0 +1,27 @@
/*
ChibiOS - Copyright (C) 2006..2018 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.
*/
/**
* @file nil_test_sequence_006.h
* @brief Test Sequence 006 header.
*/
#ifndef NIL_TEST_SEQUENCE_006_H
#define NIL_TEST_SEQUENCE_006_H
extern const testsequence_t nil_test_sequence_006;
#endif /* NIL_TEST_SEQUENCE_006_H */