From d40fad4dcd73171a90cf3bfbaea85dabc342e8b0 Mon Sep 17 00:00:00 2001 From: Ying ming Date: Sat, 31 Oct 2020 21:30:31 +0800 Subject: [PATCH] test: atomic operation : add test case Add tests with negative parameters to supplement black box tests. Signed-off-by: Ying ming --- tests/kernel/common/src/atomic.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/kernel/common/src/atomic.c b/tests/kernel/common/src/atomic.c index ddc9b4082b9..7611fd0b188 100644 --- a/tests/kernel/common/src/atomic.c +++ b/tests/kernel/common/src/atomic.c @@ -24,6 +24,7 @@ * Test techniques: * - Dynamic analysis and testing * - Functional and black box testing + * - Interface testing * * Prerequisite Conditions: * - N/A @@ -114,12 +115,22 @@ void test_atomic(void) value = 2; zassert_true((atomic_add(&target, value) == 1), "atomic_add"); zassert_true((target == 3), "atomic_add"); + /* Test the atomic_add() function parameters can be negative */ + target = 2; + value = -4; + zassert_true((atomic_add(&target, value) == 2), "atomic_add"); + zassert_true((target == -2), "atomic_add"); /* atomic_sub() */ target = 10; value = 2; zassert_true((atomic_sub(&target, value) == 10), "atomic_sub"); zassert_true((target == 8), "atomic_sub"); + /* Test the atomic_sub() function parameters can be negative */ + target = 5; + value = -4; + zassert_true((atomic_sub(&target, value) == 5), "atomic_sub"); + zassert_true((target == 9), "atomic_sub"); /* atomic_inc() */ target = 5;