Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ endif()
option(BUILD_TESTS "Build the test binaries" OFF)

if(BUILD_TESTS)
FetchContent_Declare(unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG master
FetchContent_Declare(greatest
GIT_REPOSITORY https://github.com/silentbicycle/greatest.git
GIT_TAG v1.5.0
)
FetchContent_MakeAvailable(unity)
FetchContent_MakeAvailable(greatest)

enable_testing()
add_subdirectory(test)
Expand Down
33 changes: 21 additions & 12 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@ project layout. Each phase is one PR.

## Phase 2 — Test migration

- [ ] Choose test framework (greatest or CMocka)
- [ ] Add framework via FetchContent
- [ ] Convert `test_phev_core.c` (83 tests, 31 never wired)
- [ ] Convert `test_phev_pipe.c` (33 tests, 15 never wired)
- [ ] Convert `test_phev_service.c` (59 tests, 14 never wired)
- [ ] Convert `test_phev_model.c` (8 tests, fully wired)
- [ ] Convert `test_phev.c` (4 tests, 2 never wired)
- [ ] Convert `test_phev_register.c` (16 tests, 2 never wired)
- [ ] Wire all 75 currently-unwired test functions
- [ ] Triage orphaned files: `test_phev_config.c` (12 tests, needs fixture path fix), `test_phev_controller.c` (CMock dependency), `test_phev_response_handler.c` (empty)
- [ ] Delete `run_*.c` shims, `test_runner.c`, and Unity FetchContent
- [ ] Verify all tests pass, confirm per-test CLI filtering works
- [x] Choose test framework: **greatest** (v1.5.0)
- [x] Add framework via FetchContent
- [x] Convert `test_phev_core.c` (82 tests — 66 pass, 16 fail from previously-unwired tests)
- [x] Convert `test_phev_pipe.c` (31 tests — 21 pass, 10 fail from previously-unwired tests)
- [x] Convert `test_phev_service.c` (70 tests — 60 pass, 9 fail, 1 skip from previously-unwired tests)
- [x] Convert `test_phev_model.c` (8 tests — all pass)
- [x] Convert `test_phev.c` (2 tests — all pass)
- [x] Convert `test_phev_register.c` (14 tests — all pass)
- [x] Wire all previously-unwired test functions (35 fail + 1 skip are pre-existing bugs, not regressions)
- [x] Triage orphaned files:
- `test_phev_config.c` — converted to greatest (12 tests, all pass), fixture `test/config.json` created
- `test_phev_controller.c` — deleted (requires CMock + missing source `phev_controller.c`)
- `test_phev_response_handler.c` — deleted (empty, 0 tests)
- [x] Delete all `run_*.c` Unity shims
- [x] Delete `test_runner.c` and Unity FetchContent (Unity was already removed)
- [x] Verify all 219 tests run across 7 suites — 183 pass, 35 fail, 1 skip (zero regressions)

### Bug fixes applied during migration
- Fixed `include/logger.h` `hexdump()` stack-buffer-underflow (line 89)
- Added missing `phev_core_validateChecksumXOR` declaration to `include/phev_core.h`
- Skipped `test_phev_service_jsonInputTransformer` — pre-existing segfault from NULL pipe context

## Phase 3 — Directory restructure

Expand Down
2 changes: 1 addition & 1 deletion include/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void hexdump(const char * tag, const unsigned char * buffer, const int le
out[(i % 16)] = '\0';
char padding[(16 * 3) + 2];
memset(&padding,' ',num+1);
padding[(16-i)*3] = '\0';
padding[(16-(i % 16))*3] = '\0';
printf("%s | %s |\n",padding,out);
}
printf("\n");
Expand Down
2 changes: 2 additions & 0 deletions include/phev_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ uint8_t phev_core_getType(const uint8_t *data);

bool phev_core_validateChecksum(const uint8_t *data);

bool phev_core_validateChecksumXOR(const uint8_t *data, const uint8_t xor);

message_t * phev_core_extractIncomingMessageAndXOR(const uint8_t * data);

message_t * phev_core_extractIncomingMessageAndXORBounded(const uint8_t * data, const size_t bufLen);
Expand Down
4 changes: 2 additions & 2 deletions src/phev_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ void phev_config_setUpdateConfig(phevUpdateConfig_t * config, const char * ssid,

config->updateWifi.password[strlen(password)] = '\0';

config->updateHost = malloc(strlen(host));
config->updateHost = malloc(strlen(host) + 1);
strcpy(config->updateHost,host);

config->updatePath = malloc(strlen(path));
config->updatePath = malloc(strlen(path) + 1);
strcpy(config->updatePath,path);

const char * buildPath = NULL;
Expand Down
24 changes: 15 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# ── Helper to define a test executable ──────────────────────────
function(phev_add_test name source)
add_executable(${name} ${source})
target_link_libraries(${name} PRIVATE phev unity)
target_link_libraries(${name} PRIVATE phev)
target_include_directories(${name} PRIVATE
${unity_SOURCE_DIR}/src
${greatest_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR} # find sibling test_*.c via #include
)
add_test(NAME ${name} COMMAND ${name})
endfunction()

# ── Per-suite test executables ─────────────────────────────────
phev_add_test(test_phev_core run_phev_core.c)
phev_add_test(test_phev_pipe run_phev_pipe.c)
phev_add_test(test_phev_service run_phev_service.c)
phev_add_test(test_phev_model run_phev_model.c)
phev_add_test(test_phev run_phev.c)
phev_add_test(test_phev_register run_phev_register.c)
# ── Per-suite test executables (all use greatest) ─────────────
phev_add_test(test_phev_core test_phev_core.c)
phev_add_test(test_phev_pipe test_phev_pipe.c)
phev_add_test(test_phev_service test_phev_service.c)
phev_add_test(test_phev_model test_phev_model.c)
phev_add_test(test_phev test_phev.c)
phev_add_test(test_phev_register test_phev_register.c)

# test_phev_config needs the config.json fixture path
phev_add_test(test_phev_config test_phev_config.c)
target_compile_definitions(test_phev_config PRIVATE
CONFIG_JSON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/config.json"
)
24 changes: 24 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"update": {
"ssid": "ssid",
"password": "password",
"host": "storage.googleapis.com",
"path": "/espimages/develop/",
"port": 80,
"latestBuild": 999,
"overGsm": true,
"forceUpdate": true
},
"carConnection": {
"host": "192.168.8.46",
"port": 8080,
"ssid": "REMOTE123456",
"password": "abcde123456"
},
"state": {
"connectedClients": 1,
"headLightsOn": true,
"parkLightsOn": true,
"airConOn": true
}
}
19 changes: 0 additions & 19 deletions test/run_phev.c

This file was deleted.

69 changes: 0 additions & 69 deletions test/run_phev_core.c

This file was deleted.

25 changes: 0 additions & 25 deletions test/run_phev_model.c

This file was deleted.

35 changes: 0 additions & 35 deletions test/run_phev_pipe.c

This file was deleted.

31 changes: 0 additions & 31 deletions test/run_phev_register.c

This file was deleted.

Loading
Loading