Skip to content

Commit 383f7be

Browse files
nordic-krchnashif
authored andcommitted
tests: misc: Add test suite for util.h with tests for COND_CODE_n
Added test suite to validate COND_CODE_0 and COND_CODE_1 macros. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 70b738f commit 383f7be

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

tests/misc/util/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.13.1)
2+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
3+
project(util)
4+
5+
FILE(GLOB app_sources src/*.c)
6+
target_sources(app PRIVATE ${app_sources})

tests/misc/util/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y

tests/misc/util/src/main.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <ztest.h>
18+
#include <misc/util.h>
19+
20+
#define TEST_DEFINE_1 1
21+
#define TEST_DEFINE_0 0
22+
23+
void test_COND_CODE_1(void)
24+
{
25+
/* Test validates that expected code has been injected. Failure would
26+
* be seen in compilation (lack of variable or ununsed variable.
27+
*/
28+
COND_CODE_1(1, (u32_t x0 = 1;), (u32_t y0;))
29+
zassert_true((x0 == 1), NULL);
30+
31+
COND_CODE_1(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;))
32+
zassert_true((y1 == 1), NULL);
33+
34+
COND_CODE_1(TEST_DEFINE_1, (u32_t x2 = 1;), (u32_t y2 = 1;))
35+
zassert_true((x2 == 1), NULL);
36+
37+
COND_CODE_1(2, (u32_t x3 = 1;), (u32_t y3 = 1;))
38+
zassert_true((y3 == 1), NULL);
39+
}
40+
41+
void test_COND_CODE_0(void)
42+
{
43+
/* Test validates that expected code has been injected. Failure would
44+
* be seen in compilation (lack of variable or ununsed variable.
45+
*/
46+
COND_CODE_0(0, (u32_t x0 = 1;), (u32_t y0;))
47+
zassert_true((x0 == 1), NULL);
48+
49+
COND_CODE_0(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;))
50+
zassert_true((y1 == 1), NULL);
51+
52+
COND_CODE_0(TEST_DEFINE_0, (u32_t x2 = 1;), (u32_t y2 = 1;))
53+
zassert_true((x2 == 1), NULL);
54+
55+
COND_CODE_0(2, (u32_t x3 = 1;), (u32_t y3 = 1;))
56+
zassert_true((y3 == 1), NULL);
57+
}
58+
59+
/*test case main entry*/
60+
void test_main(void)
61+
{
62+
ztest_test_suite(test_ringbuffer_api,
63+
ztest_unit_test(test_COND_CODE_1),
64+
ztest_unit_test(test_COND_CODE_0)
65+
);
66+
ztest_run_test_suite(test_ringbuffer_api);
67+
}

tests/misc/util/testcase.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tests:
2+
util_test:
3+
tags: util

0 commit comments

Comments
 (0)