Skip to content

Commit 5b90614

Browse files
committed
Add PWM c++ tests
1 parent 91fb7c8 commit 5b90614

File tree

6 files changed

+393
-2
lines changed

6 files changed

+393
-2
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ install3: build3
4040
# sudo apt-get install automake
4141
# make cpp
4242
# cd build && sudo make install
43+
#
44+
# libgtest-dev is needed for UT
45+
#
46+
# sudo sh -c 'echo cape-universaln > /sys/devices/platform/bone_capemgr/slots'
47+
# sudo sh -c 'echo pwm > /sys/devices/platform/ocp/ocp\:P9_16_pinmux/state'
48+
# sudo sh -c 'echo pwm > /sys/devices/platform/ocp/ocp\:P8_19_pinmux/state'
4349
################################################################################
4450
configure: configure.ac
4551
rm -f configure && \
@@ -51,6 +57,10 @@ build/Makefile: configure
5157
../configure
5258

5359
cpp: build/Makefile
60+
cd build && \
61+
$(MAKE) build
62+
63+
cpp-check: cpp
5464
cd build && \
5565
$(MAKE) check
5666

configure.ac

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ AC_CONFIG_MACRO_DIR([m4])
99
AC_CONFIG_HEADERS([config.h])
1010
AC_CONFIG_FILES([Makefile source/Makefile])
1111

12-
AM_INIT_AUTOMAKE([1.9 dist-bzip2 dist-zip foreign subdir-objects])
12+
AM_INIT_AUTOMAKE([1.9 dist-bzip2 dist-zip foreign subdir-objects -Wall])
13+
AM_PROG_AR
14+
15+
LT_INIT
1316

1417
AC_PROG_CC
1518
AC_PROG_CXX
1619
AC_LANG([C])
1720
AC_LANG([C++])
18-
AC_PROG_LIBTOOL
21+
22+
CHECK_GTEST
23+
CHECK_KERNEL_RELEASE
1924

2025
AC_OUTPUT

m4/gtest.m4

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
AC_DEFUN([CHECK_GTEST],
2+
[
3+
AC_MSG_CHECKING([for google test])
4+
5+
AC_LANG_PUSH([C++])
6+
AC_CHECK_HEADER([gtest/gtest.h],[gtest_found=yes])
7+
AC_LANG_POP
8+
9+
#if test "x$gtest_found" = "xyes"; then
10+
# GTEST_CPPFLAGS=
11+
# AC_SUBST(GTEST_CPPFLAGS)
12+
#fi
13+
14+
AC_SUBST(HAVE_GTEST)
15+
AM_CONDITIONAL([HAVE_GTEST], [test "x$gtest_found" = "xyes"])
16+
])

m4/kernel-release.m4

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
AC_DEFUN([CHECK_KERNEL_RELEASE],
2+
[
3+
AC_MSG_CHECKING([if kernel release >= 4.1])
4+
5+
kernel_ge_41=$(python -c 'import platform; print("yes" if platform.release() >= "4.1.0" else "no")')
6+
7+
if test "x$kernel_ge_41" = "xyes"; then
8+
CPPFLAGS="$CPPFLAGS -DBBBVERSION41"
9+
AC_SUBST(CPPFLAGS)
10+
AC_MSG_RESULT(yes)
11+
else
12+
AC_MSG_RESULT(no)
13+
fi
14+
])

source/Makefile.am

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,28 @@ test_cpp_abi_new_SOURCES = test/cpp/abi.cpp
101101
test_cpp_abi_new_CXXFLAGS = $(AM_CXXFLAGS) -pthread -D_GLIBCXX_USE_CXX11_ABI=1
102102
test_cpp_abi_new_LDADD = libadafruit-bbio1.la
103103
test_cpp_abi_new_LDFLAGS = $(AM_LDFLAGS) -lpthread -static
104+
105+
if HAVE_GTEST
106+
107+
check_PROGRAMS += test/cpp/unittest
108+
109+
gtest/src/gtest-all.cc: /usr/src/gtest/src
110+
mkdir -p gtest && cp -Rvf $< gtest
111+
112+
gtest/src/gtest_main.cc: gtest/src/gtest-all.cc
113+
114+
BUILT_SOURCES = \
115+
gtest/src/gtest-all.cc \
116+
gtest/src/gtest_main.cc
117+
118+
test_cpp_unittest_SOURCES = \
119+
test/cpp/pwm.cpp \
120+
gtest/src/gtest-all.cc \
121+
gtest/src/gtest_main.cc
122+
123+
test_cpp_unittest_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_CPPFLAGS) -isystem gtest
124+
test_cpp_unittest_CXXFLAGS = $(AM_CXXFLAGS) -pthread -D_GLIBCXX_USE_CXX11_ABI=1
125+
test_cpp_unittest_LDADD = libadafruit-bbio1.la
126+
test_cpp_unittest_LDFLAGS = $(AM_LDFLAGS) -lpthread -static
127+
128+
endif # HAVE_GTEST

0 commit comments

Comments
 (0)