Skip to content

Commit c1c44a7

Browse files
committed
feat(test_driver): implementation with a weak functions only
1 parent 01acbd8 commit c1c44a7

File tree

7 files changed

+20
-110
lines changed

7 files changed

+20
-110
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ else()
1515
endif()
1616

1717
set(srcs
18-
src/core/core.c
1918
src/flash.c
2019
src/mem_utils.c
2120
src/rom_wrappers.c

example/stub_main.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <stddef.h>
1010
#include <string.h>
1111

12-
#include <esp-stub-lib/core.h>
1312
#include <esp-stub-lib/log.h>
1413
#include <esp-stub-lib/flash.h>
1514
#include <esp-stub-lib/err.h>
@@ -137,14 +136,10 @@ int stub_main(int cmd, ...)
137136
return lib_ret;
138137
}
139138

140-
struct stub_target *target = stub_lib_new_target("esp32");
141-
if (!target) {
142-
return ESP_STUB_FAIL;
143-
}
144-
STUB_LOGD("Target created: %s\n", target->target_name);
145-
stub_lib_test_drv_init(target);
146-
stub_lib_test_drv_set(target, 147);
147-
stub_lib_test_drv_whoami(target);
139+
stub_lib_test_drv_init();
140+
stub_lib_test_drv_set(147);
141+
stub_lib_test_drv_get();
142+
stub_lib_test_drv_whoami();
148143

149144
const struct stub_cmd_handler *handler = cmd_handlers;
150145
while (handler->handler) {

include/esp-stub-lib/core.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/esp-stub-lib/test_drv.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
#pragma once
88

9-
#include <esp-stub-lib/core.h>
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif // __cplusplus
1012

11-
struct stub_test_drv_ops {
12-
int (*init)(void);
13-
int (*set)(int value);
14-
int (*get)(void);
15-
void (*whoami)(void);
16-
};
13+
int stub_lib_test_drv_init(void);
14+
int stub_lib_test_drv_set(int value);
15+
int stub_lib_test_drv_get(void);
16+
void stub_lib_test_drv_whoami(void);
1717

18-
int stub_lib_test_drv_init(struct stub_target *target);
19-
int stub_lib_test_drv_set(struct stub_target *target, int value);
20-
int stub_lib_test_drv_get(struct stub_target *target);
21-
void stub_lib_test_drv_whoami(struct stub_target *target);
18+
#ifdef __cplusplus
19+
}
20+
#endif // __cplusplus

src/core/core.c

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/target/esp32/src/test_drv.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7-
#include <esp-stub-lib/core.h>
87
#include <esp-stub-lib/log.h>
9-
#include <esp-stub-lib/test_drv.h>
8+
#include <target/test_drv.h>
109

11-
static void esp32_test_drv_whoami(void)
10+
void stub_target_common_test_drv_whoami(void)
1211
{
1312
STUB_LOGD("I am esp32 test driver\n");
1413
}
15-
16-
static const struct stub_test_drv_ops s_esp32_test_drv_ops = {
17-
.whoami = esp32_test_drv_whoami,
18-
};
19-
20-
void stub_target_test_drv_init(struct stub_target *target)
21-
{
22-
target->test_drv_ops = (void *)&s_esp32_test_drv_ops;
23-
}

src/test_drv.c

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,25 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7-
#include <esp-stub-lib/core.h>
87
#include <esp-stub-lib/test_drv.h>
98
#include <target/test_drv.h>
109

11-
int stub_lib_test_drv_init(struct stub_target *target)
10+
int stub_lib_test_drv_init(void)
1211
{
13-
struct stub_test_drv_ops *ops = target->test_drv_ops;
14-
15-
if (ops && ops->init) {
16-
return ops->init();
17-
}
18-
1912
return stub_target_common_test_drv_init();
2013
}
2114

22-
int stub_lib_test_drv_set(struct stub_target *target, int value)
15+
int stub_lib_test_drv_set(int value)
2316
{
24-
struct stub_test_drv_ops *ops = target->test_drv_ops;
25-
26-
if (ops && ops->set) {
27-
return ops->set(value);
28-
}
29-
30-
// Fallback to common implementation
3117
return stub_target_common_test_drv_set(value);
3218
}
3319

34-
int stub_lib_test_drv_get(struct stub_target *target)
20+
int stub_lib_test_drv_get(void)
3521
{
36-
struct stub_test_drv_ops *ops = target->test_drv_ops;
37-
38-
if (ops && ops->get) {
39-
return ops->get();
40-
}
41-
4222
return stub_target_common_test_drv_get();
4323
}
4424

45-
void stub_lib_test_drv_whoami(struct stub_target *target)
25+
void stub_lib_test_drv_whoami(void)
4626
{
47-
struct stub_test_drv_ops *ops = target->test_drv_ops;
48-
49-
if (ops && ops->whoami) {
50-
ops->whoami();
51-
}
52-
5327
stub_target_common_test_drv_whoami();
5428
}

0 commit comments

Comments
 (0)