1855162e6d
Vollstaendige Demo des slohmaier Dev Process anhand einer EPB-Steuergeraet- Software. Zeigt ASPICE 4.0 / ISO 26262-konforme Entwicklung im Monorepo. Inhalte: - 5 Plaene (PID, PM-, QA-, SWE-, Test-Plan) in Word, ausgefuellt mit EPB-spezifischen Inhalten - 10 System-Anforderungen + 25 Software-Anforderungen (Doorstop-MD) - 5 System-Architektur-Elemente + 10 Software-Architektur-Elemente mit PlantUML-Diagrammen und vollstaendigem Mapping - 3 implementierte Komponenten (Apply Controller D, Actuator Driver B, Switch Debouncer QM) plus 7 Header-Stubs - 28 Unit-Tests, alle gruen, mit Coverage- und MISRA-Build-Targets - Audit-Artefakte: 1 Review-Protokoll, 1 Non-Conformity, 1 MISRA-Record - Gitea-Actions-CI-Pipeline (validate.yml) - Doorstop-Konfiguration fuer bidirektionale Traceability - Generator-Skript fuer alle 50 Reqs/Arch-Elemente aus Strukturdaten - README mit gefuehrter Tour fuer Prospects
92 lines
2.4 KiB
C
92 lines
2.4 KiB
C
/**
|
|
* @file test_switch_debouncer.c
|
|
* @brief Unit-Tests fuer den Switch-Debouncer.
|
|
*
|
|
* @reqs SWE-025
|
|
* @arch SWA-006
|
|
*/
|
|
#include "../unit_test_framework.h"
|
|
#include "../../src/switch_debouncer.h"
|
|
|
|
TestStats g_test_stats = {0, 0};
|
|
|
|
static SwitchRaw mk(bool apply, bool release)
|
|
{
|
|
SwitchRaw r = {0};
|
|
r.apply_raw = apply ? 1U : 0U;
|
|
r.release_raw = release ? 1U : 0U;
|
|
return r;
|
|
}
|
|
|
|
static void test_init_state_is_neutral(void)
|
|
{
|
|
TEST_BEGIN("init -> neutral");
|
|
(void)switch_init();
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_debounce_apply_takes_5_samples(void)
|
|
{
|
|
TEST_BEGIN("apply needs 5 stable samples (50 ms)");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 4; ++i) {
|
|
switch_step_10ms(mk(true, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
}
|
|
switch_step_10ms(mk(true, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_debounce_release_takes_5_samples(void)
|
|
{
|
|
TEST_BEGIN("release needs 5 stable samples (50 ms)");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(false, true));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_RELEASE);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_bounce_does_not_change_state(void)
|
|
{
|
|
TEST_BEGIN("bouncing input keeps current state");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(true, false));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
/* Bounce: 1 sample apply, 1 sample neutral, 1 sample release ... */
|
|
switch_step_10ms(mk(true, false));
|
|
switch_step_10ms(mk(false, false));
|
|
switch_step_10ms(mk(false, true));
|
|
switch_step_10ms(mk(true, false));
|
|
switch_step_10ms(mk(false, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_both_pressed_is_neutral(void)
|
|
{
|
|
TEST_BEGIN("both apply+release pressed -> neutral");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(true, true));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
TEST_END();
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
printf("== test_switch_debouncer ==\n");
|
|
test_init_state_is_neutral();
|
|
test_debounce_apply_takes_5_samples();
|
|
test_debounce_release_takes_5_samples();
|
|
test_bounce_does_not_change_state();
|
|
test_both_pressed_is_neutral();
|
|
TEST_SUMMARY();
|
|
}
|