Skip to content

Commit f82c5a7

Browse files
authored
Merge pull request #1186 from en-sc/en-sc/from_upstream
Merge up to 133dd9d from upstream
2 parents cf9963a + 4b9fb19 commit f82c5a7

Some content is hidden

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

47 files changed

+212
-194
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*.la
1212
*.in
1313

14-
# generated source files
15-
src/jtag/minidriver_imp.h
16-
src/jtag/jtag_minidriver.h
14+
# coverage files (gcov)
15+
*.gcda
16+
*.gcno
1717

1818
# OpenULINK driver files generated by SDCC
1919
src/jtag/drivers/OpenULINK/*.rel

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "tools/git2cl"]
2-
path = tools/git2cl
3-
url = https://git.savannah.nongnu.org/git/git2cl.git
41
[submodule "jimtcl"]
52
path = jimtcl
63
url = https://github.com/msteveb/jimtcl.git

HACKING

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ patch:
118118
make
119119
@endcode
120120

121+
- Code coverage analysis
122+
123+
By inspecting the code coverage, you can identify potential gaps in your testing
124+
and use that information to improve your test scenarios.
125+
126+
Example usage:
127+
@code
128+
mkdir build-gcov; cd build-gcov
129+
../configure --enable-gcov [...]
130+
make
131+
# ... Now execute your test scenarios to collect OpenOCD code coverage ...
132+
lcov --capture --directory ./src --output-file openocd-coverage.info
133+
genhtml openocd-coverage.info --output-directory coverage_report
134+
# ... Open coverage_report/index.html in a web browser ...
135+
@endcode
136+
121137
Please consider performing these additional checks where appropriate
122138
(especially Clang Static Analyzer for big portions of new code) and
123139
mention the results (e.g. "Valgrind-clean, no new Clang analyzer

Makefile.am

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ endif
3838

3939
# common flags used in openocd build
4040
AM_CFLAGS = $(GCC_WARNINGS)
41+
AM_LDFLAGS =
4142

4243
AM_CPPFLAGS = $(HOST_CPPFLAGS)\
4344
-I$(top_srcdir)/src \
@@ -51,6 +52,12 @@ AM_CPPFLAGS += -I$(top_srcdir)/jimtcl \
5152
else
5253
AM_CPPFLAGS += $(JIMTCL_CFLAGS)
5354
endif
55+
56+
if USE_GCOV
57+
AM_CFLAGS += --coverage
58+
AM_LDFLAGS += --coverage
59+
endif
60+
5461
EXTRA_DIST += \
5562
BUGS \
5663
HACKING \
@@ -116,14 +123,13 @@ TCL_PATH = tcl
116123
TCL_FILES = find $(srcdir)/$(TCL_PATH) -name '*.cfg' -o -name '*.tcl' -o -name '*.txt' | \
117124
sed -e 's,^$(srcdir)/$(TCL_PATH),,'
118125

119-
# Without the PERL_UNICODE="IO" workaround below when running git2cl, you get several
120-
# "Wide character" warnings and you also risk an invalid character encoding in
121-
# the generated ChangeLog file. For more information, see this bug report:
122-
# Warning "Wide character in print"
123-
# https://savannah.nongnu.org/bugs/?65689
126+
# The git log command below generates many empty text lines with only some space characters
127+
# for indentation purposes, so use sed to trim all trailing whitespace.
124128
dist-hook:
125129
if test -d $(srcdir)/.git -a \( ! -e $(distdir)/ChangeLog -o -w $(distdir)/ChangeLog \) ; then \
126-
git --git-dir $(srcdir)/.git log | PERL_UNICODE="IO" $(srcdir)/tools/git2cl/git2cl > $(distdir)/ChangeLog ; \
130+
git --git-dir $(srcdir)/.git log --date=short --pretty="format:%ad %aN <%aE>%n%n%w(0,4,6)* %B" \
131+
| sed 's/[[:space:]]*$$//' > $(distdir)/ChangeLog.tmp && \
132+
mv $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \
127133
fi
128134
for i in $$($(TCL_FILES)); do \
129135
j="$(distdir)/$(TCL_PATH)/$$i" && \

bootstrap

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
# Run the autotools bootstrap sequence to create the configure script
55

6-
# Abort execution on error
7-
set -e
6+
set -e # Abort execution on error.
7+
set -u # Abort if you reference an undefined variable.
88

99
if which libtoolize > /dev/null; then
1010
libtoolize="libtoolize"
@@ -15,13 +15,21 @@ else
1515
exit 1
1616
fi
1717

18-
if [ "$1" = "nosubmodule" ]; then
19-
SKIP_SUBMODULE=1
20-
elif [ -n "$1" ]; then
21-
echo "$0: Illegal argument $1"
22-
echo "USAGE: $0 [nosubmodule]"
23-
exit 1
24-
fi
18+
SKIP_SUBMODULE=0
19+
20+
case "$#" in
21+
0) ;;
22+
1) if [ "$1" = "nosubmodule" ]; then
23+
SKIP_SUBMODULE=1
24+
else
25+
echo "$0: Illegal argument $1" >&2
26+
echo "USAGE: $0 [nosubmodule]" >&2
27+
exit 1
28+
fi;;
29+
*) echo "$0: Wrong number of command-line arguments." >&2
30+
echo "USAGE: $0 [nosubmodule]" >&2
31+
exit 1;;
32+
esac
2533

2634
# bootstrap the autotools
2735
(
@@ -34,7 +42,7 @@ autoheader --warnings=all
3442
automake --warnings=all --gnu --add-missing --copy
3543
)
3644

37-
if [ -n "$SKIP_SUBMODULE" ]; then
45+
if [ "$SKIP_SUBMODULE" -ne 0 ]; then
3846
echo "Skipping submodule setup"
3947
else
4048
echo "Setting up submodules"

configure.ac

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ m4_define([DUMMY_ADAPTER],
172172
m4_define([OPTIONAL_LIBRARIES],
173173
[[[capstone], [Use Capstone disassembly framework], []]])
174174

175+
m4_define([COVERAGE],
176+
[[[gcov], [Collect coverage using gcov], []]])
177+
175178
AC_ARG_ENABLE([doxygen-html],
176179
AS_HELP_STRING([--disable-doxygen-html],
177180
[Disable building Doxygen manual as HTML.]),
@@ -200,6 +203,19 @@ AC_ARG_ENABLE([werror],
200203
AS_HELP_STRING([--disable-werror], [Do not treat warnings as errors]),
201204
[gcc_werror=$enableval], [gcc_werror=$gcc_warnings])
202205

206+
AC_ARG_ENABLE([gcov],
207+
AS_HELP_STRING([--enable-gcov], [Enable runtime coverage collection via gcov]),
208+
[enable_gcov=$enableval], [enable_gcov=no])
209+
210+
AS_IF([test "x$enable_gcov" = "xyes"], [
211+
AC_DEFINE([USE_GCOV], [1], [1 to enable coverage collection using gcov.])
212+
dnl When collecting coverage, disable optimizations.
213+
dnl This overrides the "-O2" that autoconf uses by default:
214+
CFLAGS+=" -O0"
215+
], [
216+
AC_DEFINE([USE_GCOV], [0], [0 to leave coverage collection disabled.])
217+
])
218+
203219
# set default verbose options, overridden by following options
204220
debug_usb_io=no
205221
debug_usb_comms=no
@@ -257,9 +273,13 @@ AC_ARG_ENABLE([dmem],
257273
m4_define([AC_ARG_ADAPTERS], [
258274
m4_foreach([adapter], [$1],
259275
[AC_ARG_ENABLE(ADAPTER_OPT([adapter]),
260-
AS_HELP_STRING([--enable-ADAPTER_OPT([adapter])],
276+
AS_HELP_STRING([--enable-ADAPTER_OPT([adapter])[[[=yes/no/auto]]]],
261277
[Enable building support for the ]ADAPTER_DESC([adapter])[ (default is $2)]),
262-
[], [ADAPTER_VAR([adapter])=$2])
278+
[case "${enableval}" in
279+
yes|no|auto) ;;
280+
*) AC_MSG_ERROR([Option --enable-ADAPTER_OPT([adapter]) has invalid value "${enableval}".]) ;;
281+
esac],
282+
[ADAPTER_VAR([adapter])=$2])
263283
])
264284
])
265285

@@ -268,7 +288,7 @@ AC_ARG_ADAPTERS([
268288
HIDAPI_ADAPTERS,
269289
HIDAPI_USB1_ADAPTERS,
270290
LIBFTDI_ADAPTERS,
271-
LIBFTDI_USB1_ADAPTERS
291+
LIBFTDI_USB1_ADAPTERS,
272292
LIBGPIOD_ADAPTERS,
273293
SERIAL_PORT_ADAPTERS,
274294
PCIE_ADAPTERS,
@@ -357,10 +377,6 @@ AS_CASE([$host_os],
357377
AC_MSG_ERROR([sysfsgpio is only available on linux])
358378
])
359379
360-
AS_IF([test "x$enable_linuxgpiod" = "xyes"], [
361-
AC_MSG_ERROR([linuxgpiod is only available on linux])
362-
])
363-
364380
AS_CASE([$host_os], [freebsd*], [],
365381
[
366382
AS_IF([test "x$build_rshim" = "xyes"], [
@@ -399,6 +415,8 @@ AS_CASE(["${host_cpu}"],
399415
parport_use_ppdev=yes
400416
])
401417

418+
can_build_buspirate=yes
419+
402420
AS_CASE([$host],
403421
[*-cygwin*], [
404422
is_win32=yes
@@ -430,12 +448,12 @@ AS_CASE([$host],
430448
])
431449
parport_use_giveio=yes
432450
433-
AS_IF([test "x$enable_buspirate" = "xyes"], [
434-
AC_MSG_ERROR([buspirate currently not supported by MinGW32 hosts])
451+
AS_IF([test "x$ADAPTER_VAR([buspirate])" = "xyes"], [
452+
AC_MSG_ERROR([The Bus Pirate adapter is currently not supported by MinGW32 hosts.])
435453
])
436454
437455
# In case enable_buspirate=auto, make sure it will not be built.
438-
enable_buspirate=no
456+
can_build_buspirate=no
439457
440458
AC_SUBST([HOST_CPPFLAGS], ["-D__USE_MINGW_ANSI_STDIO -DFD_SETSIZE=128"])
441459
],
@@ -579,12 +597,6 @@ AS_IF([test "x$build_gw16012" = "xyes"], [
579597
AC_DEFINE([BUILD_GW16012], [0], [0 if you don't want the Gateworks GW16012 driver.])
580598
])
581599

582-
AS_IF([test "x$enable_buspirate" != "xno"], [
583-
AC_DEFINE([BUILD_BUSPIRATE], [1], [1 if you want the Buspirate JTAG driver.])
584-
], [
585-
AC_DEFINE([BUILD_BUSPIRATE], [0], [0 if you don't want the Buspirate JTAG driver.])
586-
])
587-
588600
AS_IF([test "x$use_internal_jimtcl" = "xyes"], [
589601
AS_IF([test -f "$srcdir/jimtcl/configure"], [
590602
AS_IF([test "x$use_internal_jimtcl_maintainer" = "xyes"], [
@@ -697,7 +709,7 @@ m4_define([PROCESS_ADAPTERS], [
697709
])
698710
], [
699711
AS_IF([test "x$ADAPTER_VAR([adapter])" = "xyes"], [
700-
AC_MSG_ERROR([$3 is required for [adapter] ADAPTER_DESC([adapter]).])
712+
AC_MSG_ERROR([$3 is required for [adapter] "ADAPTER_DESC([adapter])".])
701713
])
702714
ADAPTER_VAR([adapter])=no
703715
AC_DEFINE([BUILD_]ADAPTER_SYM([adapter]), [0], [0 if you do not want the ]ADAPTER_DESC([adapter]).)
@@ -711,9 +723,11 @@ PROCESS_ADAPTERS([HIDAPI_ADAPTERS], ["x$use_hidapi" = "xyes"], [hidapi])
711723
PROCESS_ADAPTERS([HIDAPI_USB1_ADAPTERS], ["x$use_hidapi" = "xyes" -a "x$use_libusb1" = "xyes"], [hidapi and libusb-1.x])
712724
PROCESS_ADAPTERS([LIBFTDI_ADAPTERS], ["x$use_libftdi" = "xyes"], [libftdi])
713725
PROCESS_ADAPTERS([LIBFTDI_USB1_ADAPTERS], ["x$use_libftdi" = "xyes" -a "x$use_libusb1" = "xyes"], [libftdi and libusb-1.x])
714-
PROCESS_ADAPTERS([LIBGPIOD_ADAPTERS], ["x$use_libgpiod" = "xyes"], [libgpiod])
726+
PROCESS_ADAPTERS([LIBGPIOD_ADAPTERS], ["x$use_libgpiod" = "xyes"], [Linux libgpiod])
715727
PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o "x$use_libjaylink" = "xyes"], [libjaylink-0.2])
716728
PROCESS_ADAPTERS([PCIE_ADAPTERS], ["x$is_linux" = "xyes"], [Linux build])
729+
PROCESS_ADAPTERS([SERIAL_PORT_ADAPTERS], ["x$can_build_buspirate" = "xyes"],
730+
[internal error: validation should happen beforehand])
717731
PROCESS_ADAPTERS([DUMMY_ADAPTER], [true], [unused])
718732

719733
AS_IF([test "x$enable_linuxgpiod" != "xno"], [
@@ -768,7 +782,6 @@ AM_CONDITIONAL([USB_BLASTER_DRIVER], [test "x$enable_usb_blaster" != "xno" -o "x
768782
AM_CONDITIONAL([AMTJTAGACCEL], [test "x$build_amtjtagaccel" = "xyes"])
769783
AM_CONDITIONAL([GW16012], [test "x$build_gw16012" = "xyes"])
770784
AM_CONDITIONAL([REMOTE_BITBANG], [test "x$build_remote_bitbang" = "xyes"])
771-
AM_CONDITIONAL([BUSPIRATE], [test "x$enable_buspirate" != "xno"])
772785
AM_CONDITIONAL([SYSFSGPIO], [test "x$build_sysfsgpio" = "xyes"])
773786
AM_CONDITIONAL([USE_LIBUSB1], [test "x$use_libusb1" = "xyes"])
774787
AM_CONDITIONAL([IS_CYGWIN], [test "x$is_cygwin" = "xyes"])
@@ -788,6 +801,8 @@ AM_CONDITIONAL([INTERNAL_JIMTCL], [test "x$use_internal_jimtcl" = "xyes"])
788801
AM_CONDITIONAL([HAVE_JIMTCL_PKG_CONFIG], [test "x$have_jimtcl_pkg_config" = "xyes"])
789802
AM_CONDITIONAL([INTERNAL_LIBJAYLINK], [test "x$use_internal_libjaylink" = "xyes"])
790803

804+
AM_CONDITIONAL([USE_GCOV], [test "x$enable_gcov" = "xyes"])
805+
791806
# Look for environ alternatives. Possibility #1: is environ in unistd.h or stdlib.h?
792807
AC_MSG_CHECKING([for environ in unistd.h and stdlib.h])
793808
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@@ -863,7 +878,8 @@ m4_foreach([adapter], [USB1_ADAPTERS,
863878
LIBGPIOD_ADAPTERS,
864879
LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS, SERIAL_PORT_ADAPTERS,
865880
DUMMY_ADAPTER,
866-
OPTIONAL_LIBRARIES],
881+
OPTIONAL_LIBRARIES,
882+
COVERAGE],
867883
[s=m4_format(["%-40s"], ADAPTER_DESC([adapter]))
868884
AS_CASE([$ADAPTER_VAR([adapter])],
869885
[auto], [
@@ -874,6 +890,11 @@ m4_foreach([adapter], [USB1_ADAPTERS,
874890
],
875891
[no], [
876892
echo "$s"no
893+
],
894+
[
895+
AC_MSG_ERROR(m4_normalize([
896+
Error in [adapter] "ADAPTER_ARG([adapter])": Variable "ADAPTER_VAR([adapter])"
897+
has invalid value "$ADAPTER_VAR([adapter])".]))
877898
])
878899
])
879900
echo

src/helper/jim-nvp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef OPENOCD_HELPER_JIM_NVP_H
2020
#define OPENOCD_HELPER_JIM_NVP_H
2121

22+
#include <stdbool.h>
2223
#include <jim.h>
2324

2425
/** Name Value Pairs, aka: NVP
@@ -136,7 +137,7 @@ struct jim_getopt_info {
136137
Jim_Interp *interp;
137138
int argc;
138139
Jim_Obj *const *argv;
139-
int isconfigure; /* non-zero if configure */
140+
bool is_configure;
140141
};
141142

142143
/** GetOpt - how to.

src/jtag/adapter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static const struct gpio_map {
6666
[ADAPTER_GPIO_IDX_LED] = { "led", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
6767
};
6868

69+
static int adapter_config_khz(unsigned int khz);
70+
6971
bool is_adapter_initialized(void)
7072
{
7173
return adapter_config.adapter_initialized;
@@ -245,7 +247,8 @@ static int adapter_set_speed(int speed)
245247
return is_adapter_initialized() ? adapter_driver->speed(speed) : ERROR_OK;
246248
}
247249

248-
int adapter_config_khz(unsigned int khz)
250+
/** Attempt to configure the adapter for the specified kHz. */
251+
static int adapter_config_khz(unsigned int khz)
249252
{
250253
LOG_DEBUG("handle adapter khz");
251254
adapter_config.clock_mode = CLOCK_MODE_KHZ;

src/jtag/adapter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ int adapter_get_speed(int *speed);
9797
*/
9898
int adapter_get_speed_readable(int *speed);
9999

100-
/** Attempt to configure the adapter for the specified kHz. */
101-
int adapter_config_khz(unsigned int khz);
102-
103100
/**
104101
* Attempt to enable RTCK/RCLK. If that fails, fallback to the
105102
* specified frequency.

src/jtag/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static void jtag_add_scan_check(struct jtag_tap *active,
5151
tap_state_t state),
5252
int in_num_fields, struct scan_field *in_fields, tap_state_t state);
5353

54+
static int jtag_error_clear(void);
55+
5456
/**
5557
* The jtag_error variable is set when an error occurs while executing
5658
* the queue. Application code may set this using jtag_set_error(),
@@ -127,7 +129,11 @@ void jtag_set_error(int error)
127129
jtag_error = error;
128130
}
129131

130-
int jtag_error_clear(void)
132+
/**
133+
* Resets jtag_error to ERROR_OK, returning its previous value.
134+
* @returns The previous value of @c jtag_error.
135+
*/
136+
static int jtag_error_clear(void)
131137
{
132138
int temp = jtag_error;
133139
jtag_error = ERROR_OK;
@@ -186,7 +192,7 @@ struct jtag_tap *jtag_all_taps(void)
186192
return __jtag_all_taps;
187193
};
188194

189-
unsigned int jtag_tap_count(void)
195+
static unsigned int jtag_tap_count(void)
190196
{
191197
struct jtag_tap *t = jtag_all_taps();
192198
unsigned int n = 0;

0 commit comments

Comments
 (0)