mirror of
https://github.com/meekrosoft/fff
synced 2026-01-28 10:44:27 +01:00
Migrate build to CMake and standard github workflows
Replace makefiles with CMakeLists.txt. This will allow for IDE and platform agnostic builds of FFF. Update the CI for FFF to use github workflows which don't depend on MS VC. The workflow added will verify the pull requests sent to master buy running 'buildandtest' which mirrors the developer workflow. Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
4
examples/weak_linking/test/src/bus.fake.c
Normal file
4
examples/weak_linking/test/src/bus.fake.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "bus.fake.h"
|
||||
|
||||
DEFINE_FAKE_VALUE_FUNC( bool, bus_read_write, uint8_t, uint8_t, uint8_t*, int, bool );
|
||||
DEFINE_FAKE_VALUE_FUNC( bool, bus_write, uint8_t, uint8_t, const uint8_t*, int, bool );
|
||||
4
examples/weak_linking/test/src/display.fake.c
Normal file
4
examples/weak_linking/test/src/display.fake.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "display.fake.h"
|
||||
|
||||
DEFINE_FAKE_VALUE_FUNC( bool, display_init );
|
||||
DEFINE_FAKE_VOID_FUNC( display_update, const char* );
|
||||
24
examples/weak_linking/test/src/display.test.c
Normal file
24
examples/weak_linking/test/src/display.test.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "test_common.h"
|
||||
#include "display.h"
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_tests(); // Resets common and hook errors to asserts.
|
||||
|
||||
GLOBAL_TEST_bus_read_ret[2] = 0x10;
|
||||
assert( display_init() == true );
|
||||
assert( bus_read_write_fake.call_count == 1);
|
||||
|
||||
display_update( "TEST INFO" );
|
||||
assert( bus_read_write_fake.call_count == 1 );
|
||||
assert( bus_write_fake.call_count == 1 );
|
||||
|
||||
GLOBAL_TEST_bus_read_ret[2] = 0x00;
|
||||
assert( display_init() == false );
|
||||
|
||||
printf("Test " __FILE__ " ok\n");
|
||||
return 0;
|
||||
}
|
||||
4
examples/weak_linking/test/src/error.fake.c
Normal file
4
examples/weak_linking/test/src/error.fake.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "error.fake.h"
|
||||
|
||||
DEFINE_FAKE_VOID_FUNC( runtime_error, const char* );
|
||||
DEFINE_FAKE_VALUE_FUNC( char*, runtime_error_nice_print, const char* );
|
||||
26
examples/weak_linking/test/src/main.test.c
Normal file
26
examples/weak_linking/test/src/main.test.c
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#include "display.fake.h"
|
||||
#include "sensor.fake.h"
|
||||
#include "test_common.h"
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
|
||||
int update_main( void );
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_tests(); // Resets common and hook errors to asserts.
|
||||
|
||||
sensor_init_fake.return_val = true;
|
||||
display_init_fake.return_val = true;
|
||||
|
||||
update_main();
|
||||
|
||||
assert( sensor_init_fake.call_count == 1 );
|
||||
assert( display_init_fake.call_count == 1 );
|
||||
assert( display_update_fake.call_count == 1 );
|
||||
|
||||
printf("Test " __FILE__ " ok\n");
|
||||
return 0;
|
||||
}
|
||||
11
examples/weak_linking/test/src/sensor.fake.c
Normal file
11
examples/weak_linking/test/src/sensor.fake.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "sensor.fake.h"
|
||||
|
||||
DEFINE_FAKE_VALUE_FUNC( bool, sensor_init );
|
||||
DEFINE_FAKE_VALUE_FUNC( float, sensor_read );
|
||||
|
||||
void TEST_sensor_generate_data( char* buffer, float value )
|
||||
{
|
||||
buffer[0] = 0x10;
|
||||
buffer[1] = (int)(value);
|
||||
buffer[2] = (value - buffer[1])*255;
|
||||
}
|
||||
23
examples/weak_linking/test/src/sensor.test.c
Normal file
23
examples/weak_linking/test/src/sensor.test.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include "sensor.h"
|
||||
#include "sensor.fake.h"
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_tests();
|
||||
|
||||
assert( sensor_init() == true );
|
||||
|
||||
TEST_sensor_generate_data( GLOBAL_TEST_bus_read_ret, 1.5f );
|
||||
float value = sensor_read();
|
||||
float value_error = value - 1.5f;
|
||||
assert( value_error < 0.1f && value_error > -0.1f );
|
||||
printf("Test " __FILE__ " ok\n");
|
||||
return 0;
|
||||
}
|
||||
33
examples/weak_linking/test/src/test_common.c
Normal file
33
examples/weak_linking/test/src/test_common.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "test_common.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char GLOBAL_TEST_bus_read_ret[32];
|
||||
|
||||
|
||||
void spoof_runtime_error( const char* info )
|
||||
{
|
||||
fprintf(stderr, "Runtime error: %s\n", info );
|
||||
assert(0);
|
||||
}
|
||||
|
||||
bool spoof_bus_read_write( uint8_t dev, uint8_t registry, uint8_t* buffer, int len, bool assume_echo )
|
||||
{
|
||||
memcpy( buffer, GLOBAL_TEST_bus_read_ret, len );
|
||||
fprintf(stderr, "bus spoof %d %d\n", (int)dev, (int)registry );
|
||||
return true;
|
||||
}
|
||||
|
||||
void init_tests()
|
||||
{
|
||||
memset( GLOBAL_TEST_bus_read_ret, 0x00, sizeof(GLOBAL_TEST_bus_read_ret));
|
||||
FFF_RESET_HISTORY();
|
||||
|
||||
RESET_FAKE(bus_read_write);
|
||||
RESET_FAKE(bus_write);
|
||||
RESET_FAKE(runtime_error);
|
||||
|
||||
runtime_error_fake.custom_fake = spoof_runtime_error;
|
||||
bus_read_write_fake.custom_fake = spoof_bus_read_write;
|
||||
bus_write_fake.return_val = true;
|
||||
}
|
||||
Reference in New Issue
Block a user