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 <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-01-23 13:27:23 +01:00 committed by Anas Nashif
commit 383f7bec91
4 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(util)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

1
tests/misc/util/prj.conf Normal file
View file

@ -0,0 +1 @@
CONFIG_ZTEST=y

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* 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 <ztest.h>
#include <misc/util.h>
#define TEST_DEFINE_1 1
#define TEST_DEFINE_0 0
void test_COND_CODE_1(void)
{
/* Test validates that expected code has been injected. Failure would
* be seen in compilation (lack of variable or ununsed variable.
*/
COND_CODE_1(1, (u32_t x0 = 1;), (u32_t y0;))
zassert_true((x0 == 1), NULL);
COND_CODE_1(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;))
zassert_true((y1 == 1), NULL);
COND_CODE_1(TEST_DEFINE_1, (u32_t x2 = 1;), (u32_t y2 = 1;))
zassert_true((x2 == 1), NULL);
COND_CODE_1(2, (u32_t x3 = 1;), (u32_t y3 = 1;))
zassert_true((y3 == 1), NULL);
}
void test_COND_CODE_0(void)
{
/* Test validates that expected code has been injected. Failure would
* be seen in compilation (lack of variable or ununsed variable.
*/
COND_CODE_0(0, (u32_t x0 = 1;), (u32_t y0;))
zassert_true((x0 == 1), NULL);
COND_CODE_0(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;))
zassert_true((y1 == 1), NULL);
COND_CODE_0(TEST_DEFINE_0, (u32_t x2 = 1;), (u32_t y2 = 1;))
zassert_true((x2 == 1), NULL);
COND_CODE_0(2, (u32_t x3 = 1;), (u32_t y3 = 1;))
zassert_true((y3 == 1), NULL);
}
/*test case main entry*/
void test_main(void)
{
ztest_test_suite(test_ringbuffer_api,
ztest_unit_test(test_COND_CODE_1),
ztest_unit_test(test_COND_CODE_0)
);
ztest_run_test_suite(test_ringbuffer_api);
}

View file

@ -0,0 +1,3 @@
tests:
util_test:
tags: util