Skip to content

Commit b0c84d6

Browse files
committed
Merge branch 'master' of https://github.com/badgerloop-software/pod-embedded into hvIOX_refactor
2 parents 685e1f6 + 6b06c96 commit b0c84d6

File tree

11 files changed

+127
-11
lines changed

11 files changed

+127
-11
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
119
- uses: actions/checkout@v1
12-
- name: test
13-
run: ./deploy.sh build && ./deploy.sh clean
10+
- name: Install GTest
11+
run: ./deploy.sh gtest-setup
12+
- name: Build Executables
13+
run: ./deploy.sh build
14+
- name: Run Tests
15+
run: ./out/run_all_tests

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out)
1616

1717
set(CMAKE_CXX_STANDARD 11)
1818

19-
#add cmake projects from subdirectories
19+
# Add cmake projects from subdirectories
2020
add_subdirectory(embedded/app)
2121
add_subdirectory(embedded/data)
2222
add_subdirectory(embedded/drivers)
2323
add_subdirectory(embedded/examples)
2424
add_subdirectory(embedded/peripherals)
2525
add_subdirectory(embedded/utils)
2626
add_subdirectory(middleware)
27+
28+
# Do not compile tests when cross-compiling until we determine best way to include cross compiled GTest libs
29+
# Cross-compiled system name is "BeagleBone"
30+
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
31+
add_subdirectory(Test)
32+
endif()

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Then, to build the executable:
5656

5757
### Adding Tests
5858

59-
In order to add a test or example, put a .c or .cpp file into the respective "example" folder. Make sure that your file contains a "main" function.
59+
In order to add a test or example, put a .c or .cpp file into the respective "example" folder. Make sure that your file contains a "main" function. Be sure to add to the file to the respective CMakeLists.txt file if necessary.
6060

6161
## Directory Structure
6262
```
@@ -88,6 +88,9 @@ pod/
8888
|--autocoding/ /* Auto-coding python scripts and data.xml */
8989
| |--templates/ /* Template files to be autocoded */
9090
|
91+
|--Test/ /* GTest Unit & Component Tests */
92+
| |--example/ /* Sample GTest Test */
93+
|
9194
```
9295

9396
### Structural Conventions

Test/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
project(testlib VERSION 1.0
2+
DESCRIPTION "Tests"
3+
LANGUAGES CXX)
4+
5+
# Define sources
6+
set(dependencies example/Test_GTest.cpp)
7+
8+
set(libraries middleware
9+
data
10+
peripherals
11+
drivers
12+
Threads::Threads) #so pthreads work
13+
14+
# Configure tests library
15+
add_library(tests ${dependencies})
16+
target_link_libraries(tests PRIVATE ${libraries})
17+
18+
# Run Autocoder
19+
add_dependencies(tests autocoder)
20+
21+
export(TARGETS tests FILE TestsConfig.cmake)
22+
23+
24+
# Locate Requirements
25+
find_package(GTest REQUIRED)
26+
find_package(Threads REQUIRED)
27+
include_directories(${GTEST_INCLUDE_DIRS})
28+
29+
30+
# Run Autocoder
31+
add_dependencies(tests autocoder)
32+
33+
34+
# Add executable
35+
add_executable(run_all_tests run_all_tests.cpp ${dependencies})
36+
37+
target_link_libraries(run_all_tests ${GTEST_LIBRARIES} pthread ${libraries})
38+
target_include_directories(app PUBLIC include)
39+
40+
41+

Test/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Testing
2+
3+
4+
- Link to GTest Primer [Click here!](https://github.com/google/googletest/blob/master/googletest/docs/primer.md)
5+
6+
## Creating a Test
7+
8+
- Find the directory for the component/subsystem you would like to test, if it does not exist, create one
9+
- Create a file `Test_<Thing you would like to test>.cpp`
10+
- Add your file as a source in CMakeLists.txt
11+
- Write your tests. Follow the test template if needed
12+
13+
## Test Template
14+
15+
```c
16+
/**
17+
* Author:
18+
*/
19+
20+
#include <gtest/gtest.h>
21+
22+
TEST(ExampleTest, VerifyWorkingGTest){
23+
EXPECT_NE(1,0);
24+
EXPECT_GE(1,1);
25+
EXPECT_GE(1,0);
26+
EXPECT_LE(1,1);
27+
EXPECT_LE(0,1);
28+
29+
ASSERT_EQ(0,0);
30+
}
31+
```

Test/example/Test_GTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Author: Rohan
3+
*/
4+
5+
#include <gtest/gtest.h>
6+
7+
TEST(ExampleTest, VerifyWorkingGTest){
8+
EXPECT_NE(1,0);
9+
EXPECT_GE(1,1);
10+
EXPECT_GE(1,0);
11+
EXPECT_LE(1,1);
12+
EXPECT_LE(0,1);
13+
14+
ASSERT_EQ(0,0);
15+
}

Test/run_all_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <gtest/gtest.h>
2+
3+
// Run all GTest Tests
4+
int main(int argc, char **argv) {
5+
testing::InitGoogleTest(&argc, argv);
6+
return RUN_ALL_TESTS();
7+
}

deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ elif [ "$1" == "cross" ]; then
4949
exit 1
5050
fi
5151
echo "cross build finished"
52+
elif [ "$1" == "gtest-setup" ]; then
53+
echo "Installing Dependencies (Assumes Debian based System) - Sudo access required"
54+
sudo apt-get update
55+
sudo apt-get install -y build-essential
56+
sudo apt-get install -y cmake libgtest-dev
57+
58+
echo "Building GTest"
59+
cd /usr/src/gtest
60+
sudo cmake CMakeLists.txt
61+
sudo make
62+
sudo cp *.a /usr/lib
63+
64+
echo "GTest Install Complete"
5265
elif [ "$1" == "clean" ]; then
5366
rm -rf build
5467
rm -rf out

embedded/app/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ add_dependencies(app autocoder)
3333
#export app library so it can be used externally
3434
export(TARGETS app FILE AppLibConfig.cmake)
3535

36-
#configure HV and LV executables
36+
#configure executable
3737
find_package(Threads REQUIRED)
3838
add_executable(badgerloop main/badgerloop.cpp ${dependecies})
39-
4039
target_link_libraries(badgerloop PRIVATE ${libraries})
41-
4240
target_include_directories(badgerloop PRIVATE include)

embedded/examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ set_target_properties(bmsDisplay
5555
imu_test
5656
presTest
5757
PROPERTIES
58-
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/tests)
58+
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/tests)

0 commit comments

Comments
 (0)