Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2e9c84

Browse files
committed
Added Initial Unit_Testing_Meson example
1 parent 26c0801 commit d2e9c84

File tree

100 files changed

+69987
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+69987
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: All
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: None
22+
AlwaysBreakAfterReturnType: None
23+
AlwaysBreakBeforeMultilineStrings: false
24+
AlwaysBreakTemplateDeclarations: MultiLine
25+
BinPackArguments: true
26+
BinPackParameters: true
27+
BraceWrapping:
28+
AfterCaseLabel: false
29+
AfterClass: false
30+
AfterControlStatement: false
31+
AfterEnum: false
32+
AfterFunction: false
33+
AfterNamespace: false
34+
AfterObjCDeclaration: false
35+
AfterStruct: false
36+
AfterUnion: false
37+
AfterExternBlock: false
38+
BeforeCatch: false
39+
BeforeElse: false
40+
IndentBraces: false
41+
SplitEmptyFunction: true
42+
SplitEmptyRecord: true
43+
SplitEmptyNamespace: true
44+
BreakBeforeBinaryOperators: None
45+
BreakBeforeBraces: Attach
46+
BreakBeforeInheritanceComma: false
47+
BreakInheritanceList: BeforeColon
48+
BreakBeforeTernaryOperators: true
49+
BreakConstructorInitializersBeforeComma: false
50+
BreakConstructorInitializers: BeforeColon
51+
BreakAfterJavaFieldAnnotations: false
52+
BreakStringLiterals: true
53+
ColumnLimit: 80
54+
CommentPragmas: '^ IWYU pragma:'
55+
CompactNamespaces: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
57+
ConstructorInitializerIndentWidth: 4
58+
ContinuationIndentWidth: 4
59+
Cpp11BracedListStyle: true
60+
DeriveLineEnding: true
61+
DerivePointerAlignment: false
62+
DisableFormat: false
63+
ExperimentalAutoDetectBinPacking: false
64+
FixNamespaceComments: true
65+
ForEachMacros:
66+
- foreach
67+
- Q_FOREACH
68+
- BOOST_FOREACH
69+
IncludeBlocks: Preserve
70+
IncludeCategories:
71+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
72+
Priority: 2
73+
SortPriority: 0
74+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
75+
Priority: 3
76+
SortPriority: 0
77+
- Regex: '.*'
78+
Priority: 1
79+
SortPriority: 0
80+
IncludeIsMainRegex: '(Test)?$'
81+
IncludeIsMainSourceRegex: ''
82+
IndentCaseLabels: false
83+
IndentGotoLabels: true
84+
IndentPPDirectives: None
85+
IndentWidth: 2
86+
IndentWrappedFunctionNames: false
87+
JavaScriptQuotes: Leave
88+
JavaScriptWrapImports: true
89+
KeepEmptyLinesAtTheStartOfBlocks: true
90+
MacroBlockBegin: ''
91+
MacroBlockEnd: ''
92+
MaxEmptyLinesToKeep: 1
93+
NamespaceIndentation: None
94+
ObjCBinPackProtocolList: Auto
95+
ObjCBlockIndentWidth: 2
96+
ObjCSpaceAfterProperty: false
97+
ObjCSpaceBeforeProtocolList: true
98+
PenaltyBreakAssignment: 2
99+
PenaltyBreakBeforeFirstCallParameter: 19
100+
PenaltyBreakComment: 300
101+
PenaltyBreakFirstLessLess: 120
102+
PenaltyBreakString: 1000
103+
PenaltyBreakTemplateDeclaration: 10
104+
PenaltyExcessCharacter: 1000000
105+
PenaltyReturnTypeOnItsOwnLine: 60
106+
PointerAlignment: Right
107+
ReflowComments: true
108+
SortIncludes: true
109+
SortUsingDeclarations: true
110+
SpaceAfterCStyleCast: false
111+
SpaceAfterLogicalNot: false
112+
SpaceAfterTemplateKeyword: true
113+
SpaceBeforeAssignmentOperators: true
114+
SpaceBeforeCpp11BracedList: false
115+
SpaceBeforeCtorInitializerColon: true
116+
SpaceBeforeInheritanceColon: true
117+
SpaceBeforeParens: ControlStatements
118+
SpaceBeforeRangeBasedForLoopColon: true
119+
SpaceInEmptyBlock: false
120+
SpaceInEmptyParentheses: false
121+
SpacesBeforeTrailingComments: 1
122+
SpacesInAngles: false
123+
SpacesInConditionalStatement: false
124+
SpacesInContainerLiterals: true
125+
SpacesInCStyleCastParentheses: false
126+
SpacesInParentheses: false
127+
SpacesInSquareBrackets: false
128+
SpaceBeforeSquareBrackets: false
129+
Standard: Latest
130+
StatementMacros:
131+
- Q_UNUSED
132+
- QT_REQUIRE_VERSION
133+
TabWidth: 8
134+
UseCRLF: false
135+
UseTab: Never
136+
...
137+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Exclude these files from root level .gitignore
2+
build
3+
4+
# Files
5+
!stm32l4discovery.cfg
6+
7+
# Remove everything
8+
.vscode/*.DB*
9+
.vscode/*.json
10+
11+
# Keep these for reference
12+
!.vscode/launch.json
13+
!.vscode/c_cpp_properties.json
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"_DEBUG",
10+
"UNICODE",
11+
"_UNICODE"
12+
],
13+
"configurationProvider": "ms-vscode.cmake-tools",
14+
"intelliSenseMode": "gcc-arm",
15+
"browse": {
16+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
17+
},
18+
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
19+
}
20+
],
21+
"version": 4
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"cwd": "${workspaceFolder}",
5+
"executable": "build/Minimal_Unit_Testing.elf",
6+
"configFiles": [
7+
"stm32l4discovery.cfg"
8+
],
9+
"postLaunchCommands": [
10+
"monitor arm semihosting enable",
11+
],
12+
"name": "Debug Microcontroller",
13+
"request": "launch",
14+
"type": "cortex-debug",
15+
"servertype": "openocd"
16+
}
17+
]
18+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
# Set your constants here
4+
# NOTE, These should be options
5+
set(PROJECT_NAME "Minimal_Unit_Testing_Meson")
6+
set(CONTROLLER_NAME "STM32L475xx")
7+
set(USE_SEMIHOSTING OFF)
8+
set(TESTING OFF)
9+
10+
if(TESTING)
11+
message("Configuring Testing")
12+
13+
project(${PROJECT_NAME})
14+
15+
include(CTest)
16+
enable_testing()
17+
18+
include(cmake/testing.cmake)
19+
20+
# TODO, Add more here
21+
set(TEST_INCLUDE_DIRECTORIES
22+
${CMAKE_SOURCE_DIR}/driver
23+
${CMAKE_SOURCE_DIR}/l0_lowlevel/arm/cmsis/core
24+
${CMAKE_SOURCE_DIR}/l0_lowlevel/device/stm32
25+
)
26+
27+
# TODO, Add more mocks here
28+
add_subdirectory(driver/gpio/mock)
29+
add_subdirectory(driver/rcc/mock)
30+
31+
# TODO, Add more tests here
32+
add_subdirectory(HAL/output_gpio/test)
33+
add_subdirectory(HAL/input_gpio/test)
34+
35+
else()
36+
message("Configuring ARM Project")
37+
38+
# Project start
39+
set(CMAKE_TOOLCHAIN_FILE "cmake/toolchain.cmake")
40+
project(${PROJECT_NAME})
41+
42+
set(USER_PROJECT_TARGET "${PROJECT_NAME}.elf")
43+
add_executable(${USER_PROJECT_TARGET} application/main.c)
44+
45+
target_compile_definitions(${USER_PROJECT_TARGET} PRIVATE ${CONTROLLER_NAME})
46+
target_compile_options(${USER_PROJECT_TARGET} PRIVATE ${COMMON_C_FLAGS}
47+
${USER_C_FLAGS})
48+
49+
if(USE_SEMIHOSTING)
50+
message("Configuring Project with Semihosting")
51+
target_link_options(${USER_PROJECT_TARGET} PRIVATE
52+
${COMMON_C_FLAGS}
53+
${USER_SEMIHOSTING_FLAGS}
54+
${USER_LINK_FLAGS}
55+
)
56+
target_compile_definitions(${USER_PROJECT_TARGET} PRIVATE SEMIHOSTING=1)
57+
else()
58+
message("Turning Semihosting off")
59+
target_link_options(${USER_PROJECT_TARGET} PRIVATE
60+
${COMMON_C_FLAGS}
61+
${USER_NO_SEMIHOSTING_FLAGS}
62+
${USER_LINK_FLAGS}
63+
)
64+
endif()
65+
66+
# TODO, Add more subdirectories here
67+
add_subdirectory(l0_lowlevel)
68+
add_subdirectory(driver)
69+
add_subdirectory(modules)
70+
add_subdirectory(HAL)
71+
add_subdirectory(third_party/FreeRTOS)
72+
73+
# Tools
74+
include(cmake/compile.cmake)
75+
76+
endif()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(output_gpio_files output_gpio/output_gpio.c)
2+
set(input_gpio_files input_gpio/input_gpio.c)
3+
4+
target_sources(${USER_PROJECT_TARGET} PRIVATE
5+
${output_gpio_files}
6+
${input_gpio_files}
7+
)
8+
target_include_directories(${USER_PROJECT_TARGET} PRIVATE .)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "input_gpio.h"
2+
3+
#include "rcc/rcc.h"
4+
5+
void input_gpio__init(GPIO_s *input_config, GPIO_TypeDef *port, uint32_t pin,
6+
uint32_t rcc_config) {
7+
rcc__set_ahb2_peripheral_clock_enable(rcc_config);
8+
9+
input_config->mode = GPIO_mode_INPUT;
10+
input_config->type = GPIO_type_PUSH_PULL;
11+
input_config->speed = GPIO_speed_LOW_SPEED;
12+
input_config->pull = GPIO_pull_NO_PULLUP_OR_PULLDOWN;
13+
gpio__init(input_config, port, pin);
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef HAL_INPUT_GPIO_INPUT_GPIO_H_
2+
#define HAL_INPUT_GPIO_INPUT_GPIO_H_
3+
4+
#include <gpio/gpio.h>
5+
6+
void input_gpio__init(GPIO_s *input_config, GPIO_TypeDef *port, uint32_t pin,
7+
uint32_t rcc_config);
8+
9+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
add_executable(input_gpio_test input_gpio_test.c)
2+
3+
target_sources(input_gpio_test PRIVATE
4+
../input_gpio.c
5+
)
6+
7+
# TODO, Make this better
8+
target_include_directories(input_gpio_test PRIVATE
9+
../
10+
)
11+
target_compile_definitions(input_gpio_test PRIVATE "STM32L475xx")
12+
13+
target_link_libraries(input_gpio_test PRIVATE mock_rcc mock_gpio)
14+
target_link_libraries(input_gpio_test PRIVATE unity fff)
15+
# These warnings are hit due to the CMSIS files
16+
target_compile_options(input_gpio_test PRIVATE -Wno-int-to-pointer-cast)
17+
add_test(NAME input_gpio_test COMMAND input_gpio_test)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "fff.h"
2+
#include "unity.h"
3+
4+
#include "mock_gpio.h"
5+
#include "mock_rcc.h"
6+
7+
#include "input_gpio.h"
8+
9+
DEFINE_FFF_GLOBALS;
10+
11+
void setUp() {
12+
RESET_FAKE(rcc__set_ahb2_peripheral_clock_enable);
13+
RESET_FAKE(gpio__init);
14+
15+
FFF_RESET_HISTORY();
16+
}
17+
18+
void tearDown() {}
19+
20+
void gpio_input_init_test(void) {
21+
GPIO_s input_config;
22+
input_gpio__init(&input_config, GPIOC, 13, RCC_AHB2ENR_GPIOCEN);
23+
24+
TEST_ASSERT_EQUAL_UINT16(
25+
rcc__set_ahb2_peripheral_clock_enable_fake.call_count, 1);
26+
TEST_ASSERT_EQUAL_UINT16(gpio__init_fake.call_count, 1);
27+
}
28+
29+
int main() {
30+
UNITY_BEGIN();
31+
RUN_TEST(gpio_input_init_test);
32+
return UNITY_END();
33+
}

0 commit comments

Comments
 (0)