failed approach

This commit is contained in:
2020-11-19 18:24:03 +01:00
parent e25fd2f9b9
commit dd4cacb538
324 changed files with 57839 additions and 11 deletions

View File

@ -0,0 +1,136 @@
#ifndef GS_UTIL_TEST_CMOCKA_H
#define GS_UTIL_TEST_CMOCKA_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
Cmocka extensions.
Official site for cmocka https://cmocka.org.
*/
#include <gs/util/string.h>
// cmocka
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !(__DOXYGEN__)
// internal helpers - use macros
void _gs_assert_int_equal(const intptr_t a, const intptr_t b, bool equal, const char * const file, const int line);
void _gs_assert_uint_equal(const uintptr_t a, const uintptr_t b, bool equal, bool hex, const char * const file, const int line);
void _gs_assert_error_equal(const int a, const int b, bool equal, const char * const file, const int line);
void _gs_assert_float_equal(const float a, const float b, const float diff, bool equal, const char * const file, const int line);
void _gs_assert_double_equal(const double a, const double b, const double diff, bool equal, const char * const file, const int line);
#endif
/**
Assert int (print value as signed).
*/
#define GS_ASSERT_INT_EQUAL(a,b) _gs_assert_int_equal((intptr_t) (a), (intptr_t) (b), true, __FILE__, __LINE__)
/**
Assert unsigned int (print value as unsigned).
*/
#define GS_ASSERT_UINT_EQUAL(a,b) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), true, false, __FILE__, __LINE__)
/**
Assert int (print value as hex).
*/
#define GS_ASSERT_XINT_EQUAL(a,b) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), true, true, __FILE__, __LINE__)
/**
Assert #gs_error_t (print value and error text).
*/
#define GS_ASSERT_ERROR_EQUAL(a,b) _gs_assert_error_equal(a, b, true, __FILE__, __LINE__)
/**
Assert #GS_OK (print value and error text).
*/
#define GS_ASSERT_ERROR_OK(a) _gs_assert_error_equal(a, GS_OK, true, __FILE__, __LINE__)
/**
Assert float (print value as signed).
*/
#define GS_ASSERT_FLOAT_EQUAL(a,b,diff) _gs_assert_float_equal(a, b, diff, true, __FILE__, __LINE__)
/**
Assert double (print value as signed).
*/
#define GS_ASSERT_DOUBLE_EQUAL(a,b,diff) _gs_assert_double_equal(a, b, diff, true, __FILE__, __LINE__)
/**
Assert int (print value as signed).
*/
#define GS_ASSERT_INT_NOT_EQUAL(a,b) _gs_assert_int_equal((intptr_t) (a), (intptr_t) (b), false, __FILE__, __LINE__)
/**
Assert unsigned int (print value as unsigned).
*/
#define GS_ASSERT_UINT_NOT_EQUAL(a,b) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), false, false, __FILE__, __LINE__)
/**
Assert int (print value as hex).
*/
#define GS_ASSERT_XINT_NOT_EQUAL(a,b) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), false, true, __FILE__, __LINE__)
/**
Assert #GS_OK (print value and error text).
*/
#define GS_ASSERT_ERROR_NOT_EQUAL(a,b) _gs_assert_error_equal(a, b, false, __FILE__, __LINE__)
/**
Code reference.
*/
#define GS_REF() __FILE__,__LINE__
/**
Assert int with code reference (print value as signed).
*/
#define GS_ASSERT_INT_EQUAL_REF(a,b,file,line) _gs_assert_int_equal((intptr_t) (a), (intptr_t) (b), true, file, file, line)
/**
Assert unsigned int with code reference (print value as unsigned).
*/
#define GS_ASSERT_UINT_EQUAL_REF(a,b,file,line) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), true, false, file, line)
/**
Assert int with code reference (print value as hex).
*/
#define GS_ASSERT_XINT_EQUAL_REF(a,b,file,line) _gs_assert_uint_equal((uintptr_t) (a), (uintptr_t) (b), true, true, file, line)
/**
Assert #gs_error_t with code reference (print value and error text).
*/
#define GS_ASSERT_ERROR_EQUAL_REF(a,b,file,line) _gs_assert_error_equal(a, b, true, file, line)
/**
Assert #GS_OK with code reference (print value and error text).
*/
#define GS_ASSERT_ERROR_OK_REF(a,file,line) _gs_assert_error_equal(a, GS_OK, true, file, line)
/**
Run \a cmocka test group.
@param[in] name name of test. If name is \a tests and GS_TEST_NAME is set, GS_TEST_NAME will be used instead.
@param[in] tests array of tests.
@param[in] num_tests number of tests.
@param[in] setup setup function, can be NULL.
@param[in] teardown teardown function, can be NULL.
@return 0 on success.
*/
static inline int gs_cmocka_run_group_tests(const char *name,
const struct CMUnitTest * const tests,
const size_t num_tests,
CMFixtureFunction setup,
CMFixtureFunction teardown)
{
#ifdef GS_TEST_NAME // set by buildtools::gs_test_cmocka.py
if (strcasecmp(name, "tests") == 0) {
name = GS_DEF2STRING(GS_TEST_NAME);
}
#endif
return _cmocka_run_group_tests(name, tests, num_tests, setup, teardown);
}
#ifdef GS_TEST_NAME
// hi-jack cmocka's macro
#undef cmocka_run_group_tests
#define cmocka_run_group_tests(tests, setup, teardown) gs_cmocka_run_group_tests(GS_DEF2STRING(tests), tests, GS_ARRAY_SIZE(tests), setup, teardown)
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,80 @@
#ifndef GS_UTIL_TEST_COMMAND_H
#define GS_UTIL_TEST_COMMAND_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Command Test framework.
Provides a simple way of unit-testing/validating commands.
*/
#include <gs/util/gosh/command.h>
#include <gs/util/test/cmocka.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Validate command execution.
Runs a commands and validates the output/results agains the inputs.
Asserts if the results does not match.
@param[in] cmd command (including arguments) to execute.
@param[in] ret expected return code from the command execution framework.
@param[in] cmd_ret expected return code from the commands handler. This is only validated if (ret = GS_OK).
@param[in] std_in string with expected command input.
@param[in] std_out string with expected command output. Wildcards (*\/?) are supported.
@param[in] file string with file name.
@param[in] line string with line no.
@return void
*/
void _gs_assert_command_validate(const char *cmd, gs_error_t ret, gs_error_t cmd_ret, const char *std_in, const char *std_out, const char * const file, const int line);
/**
Validate command results returned from last command execution.
Asserts if the results does not match.
@param[in] no the result no to verify.
@param[in] group string with expected group id. Wildcards (*\/?) are supported.
@param[in] key string with expected key. Wildcards (*\/?) are supported.
@param[in] value string with expected value. Wildcards (*\/?) are supported.
@param[in] file string with file name.
@param[in] line string with line no.
@return void
*/
void _gs_assert_command_validate_last_result(unsigned int no, const char *group, const char *key, const char *value, const char * const file, const int line);
/**
Validate command execution.
Runs a commands and validates the output/results agains the inputs.
Asserts if the results does not match.
@param[in] cmd command (including arguments) to execute.
@param[in] ret expected return code from the command execution framework.
@param[in] cmd_ret expected return code from the commands handler. This is only validated if (ret = GS_OK).
@param[in] std_in string with expected command input.
@param[in] std_out string with expected command output. Wildcards (*\/?) are supported.
@return void
*/
#define GS_ASSERT_COMMAND(cmd,ret,cmd_ret,std_in,std_out) _gs_assert_command_validate(cmd,ret,cmd_ret,std_in,std_out, __FILE__, __LINE__);
/**
Validate command results returned from last command execution.
Asserts if the results does not match.
@param[in] no the result no to verify.
@param[in] group string with expected group id. Wildcards (*\/?) are supported.
@param[in] key string with expected key. Wildcards (*\/?) are supported.
@param[in] value string with expected value. Wildcards (*\/?) are supported.
@return void
*/
#define GS_ASSERT_COMMAND_RESULT(no,group,key,value) _gs_assert_command_validate_last_result(no,group,key,value, __FILE__, __LINE__);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,88 @@
#ifndef GS_UTIL_TEST_LOG_H
#define GS_UTIL_TEST_LOG_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Log Test framework.
Provides a simple way of veriyfing logs generated during unit-testing.
*/
#include <gs/util/log/log.h>
#include <gs/util/test/cmocka.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Assert log count - internal helper function.
*/
void gs_assert_log_count(int level, unsigned int count, const char * file, int line);
/**
Assert log messag and count - internal helper function.
*/
void gs_assert_log(unsigned int stack_index, unsigned int count, gs_log_level_t level, const char * pattern, const char * file, int line);
/**
Initialize framework, by installing a callback for \a print.
@param[in] verbose of \a true, logs will be printed on stdout.
*/
void gs_test_log_init(bool verbose);
/**
Clear log stats.
*/
void gs_test_log_clear(void);
/**
Assert number of error logs.
*/
#define GS_ASSERT_LOG_ERROR(cnt) gs_assert_log_count(LOG_ERROR, cnt, __FILE__, __LINE__);
/**
Assert number of warning logs.
*/
#define GS_ASSERT_LOG_WARNING(cnt) gs_assert_log_count(LOG_WARNING, cnt, __FILE__, __LINE__);
/**
Assert number of notice logs.
*/
#define GS_ASSERT_LOG_NOTICE(cnt) gs_assert_log_count(LOG_NOTICE, cnt, __FILE__, __LINE__);
/**
Assert number of info logs.
*/
#define GS_ASSERT_LOG_INFO(cnt) gs_assert_log_count(LOG_INFO, cnt, __FILE__, __LINE__);
/**
Assert number of debug logs.
*/
#define GS_ASSERT_LOG_DEBUG(cnt) gs_assert_log_count(LOG_DEBUG, cnt, __FILE__, __LINE__);
/**
Assert number of trace logs.
*/
#define GS_ASSERT_LOG_TRACE(cnt) gs_assert_log_count(LOG_TRACE, cnt, __FILE__, __LINE__);
/**
Assert number of all logs.
*/
#define GS_ASSERT_LOG_ALL(cnt) gs_assert_log_count(-1, cnt, __FILE__, __LINE__);
/**
Assert/find number of entries matching level and pattern.
*/
#define GS_ASSERT_LOG(count,level,pattern) gs_assert_log(-1, count, level, pattern, __FILE__, __LINE__)
/**
Assert log at stack index against matching level and pattern.
*/
#define GS_ASSERT_LOG_AT(stack_index,level,pattern) gs_assert_log(stack_index, 1, level, pattern, __FILE__, __LINE__)
#ifdef __cplusplus
}
#endif
#endif