summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am16
-rw-r--r--SConstruct5
-rw-r--r--libgps_core.c105
-rwxr-xr-xregress-driver4
-rw-r--r--test_libgps.c108
6 files changed, 122 insertions, 117 deletions
diff --git a/.gitignore b/.gitignore
index ea8ba1c4..a6b79d63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,6 +49,7 @@ srec.html
*.sum
*.i
*.o
+*.os
*.a
*.lo
*.la
diff --git a/Makefile.am b/Makefile.am
index 5cb6fd08..334261b7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,7 +43,7 @@ bin_PROGRAMS = $(CURSESPROGS) gpsdecode gpsctl gpspipe gpxlogger lcdgps
sbin_PROGRAMS = gpsd
# to-do: Add programs to TESTS if not already used.
-check_PROGRAMS = test_float test_trig test_bits test_packet test_mkgmtime test_geoid test_json
+check_PROGRAMS = test_float test_trig test_bits test_packet test_mkgmtime test_geoid test_json test_libgps
if LIBGPSMM_ENABLE
check_PROGRAMS += test_gpsmm
endif
@@ -465,6 +465,11 @@ test_mkgmtime_LDADD = $(LIBC) libgps.la $(LIBM)
test_json_SOURCES = test_json.c
test_json_LDADD = $(LIBC) libgps.la $(LIBM)
+#
+# Build libgps tester
+test_libgps_SOURCES = test_libgps.c
+test_libgps_LDADD = $(LIBC) libgps.la $(LIBM)
+
MANPAGES_BASE = \
gpsd.8 \
gpsd_json.5 \
@@ -632,11 +637,6 @@ CLEANFILES += $(BUILT_SOURCES) *.core $(PYEXTENSIONS) $(BUILT_MANPAGES)
pkgconfig_DATA = libgps.pc libgpsd.pc
pkgconfigdir = $(libdir)/pkgconfig
-# These are not distributed
-libgps: libgps_core.c gps.h .libs/libgps.a
- $(CC) $(CFLAGS) -o libgps $(LIBM) -DTESTMAIN $(LIBPTHREAD) -g libgps_core.c .libs/libgps.a
-
-
# Report splint warnings
# Note: test_bits.c is unsplintable because of the PRI64 macros.
SPLINTOPTS = -I/usr/include/dbus-1.0/ -DSYSCONFDIR=\"$(sysconfdir)\" $(LIBUSB_CFLAGS) +quiet
@@ -823,12 +823,12 @@ time-regress: test_mkgmtime
$(srcdir)/test_mkgmtime
# Regression test the unpacking code in libgps
-unpack-regress: libgps
+unpack-regress: test_libgps
@echo "Testing the client-library sentence decoder..."
$(run_regress_driver) -c $(srcdir)/test/clientlib/*.log
# Build the regression test for the sentence unpacker
-unpack-makeregress: libgps
+unpack-makeregress: test_libgps
@echo "Rebuilding the client sentence-unpacker tests..."
$(run_regress_driver) -c -b $(srcdir)/test/clientlib/*.log
diff --git a/SConstruct b/SConstruct
index 95e262c8..28dff2fb 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,7 +1,6 @@
### SCons build recipe for the GPSD project
# Unfinished items:
-# * Check for Python development libraries
# * Python module build
# * Qt binding
# * Utility and test productions
@@ -19,7 +18,6 @@ EnsureSConsVersion(1,2,0)
import os, sys, commands, glob
-
#
# Build-control options
#
@@ -427,8 +425,9 @@ test_trig = env.Program('test_trig', ['test_trig.c'], LIBS=["m"])
test_packet = env.Program('test_packet', ['test_packet.c'], LIBS=gpsdlibs)
test_bits = env.Program('test_bits', ['test_bits.c', "bits.c"])
test_gpsmm = env.Program('test_gpsmm', ['test_gpsmm.cpp'], LIBS=gpslibs)
+test_libgps = env.Program('test_libgps', ['test_libgps.c'], LIBS=gpslibs)
testprogs = [test_float, test_trig, test_bits, test_packet,
- test_mkgmtime, test_geoid, test_json]
+ test_mkgmtime, test_geoid, test_json, test_libgps]
if cxx:
testprogs.append(test_gpsmm)
diff --git a/libgps_core.c b/libgps_core.c
index 243c4f86..91b613e5 100644
--- a/libgps_core.c
+++ b/libgps_core.c
@@ -245,107 +245,4 @@ void libgps_dump_state(struct gps_data_t *collect)
}
#endif /* LIBGPS_DEBUG */
-#ifdef TESTMAIN
-/*
- * A simple command-line exerciser for the library.
- * Not really useful for anything but debugging.
- */
-
-#ifndef S_SPLINT_S
-#include <unistd.h>
-#endif /* S_SPLINT_S */
-#include <getopt.h>
-#include <signal.h>
-
-static void onsig(int sig)
-{
- (void)fprintf(stderr, "libgps: died with signal %d\n", sig);
- exit(1);
-}
-
-/* must start zeroed, otherwise the unit test will try to chase garbage pointer fields. */
-static struct gps_data_t gpsdata;
-
-int main(int argc, char *argv[])
-{
- struct gps_data_t collect;
- char buf[BUFSIZ];
- int option;
- bool batchmode = false;
- int debug = 0;
-
- (void)signal(SIGSEGV, onsig);
- (void)signal(SIGBUS, onsig);
-
- while ((option = getopt(argc, argv, "bhsD:?")) != -1) {
- switch (option) {
- case 'b':
- batchmode = true;
- break;
- case 's':
- (void)
- printf
- ("Sizes: fix=%zd gpsdata=%zd rtcm2=%zd rtcm3=%zd ais=%zd compass=%zd raw=%zd devices=%zd policy=%zd version=%zd, noise=%zd\n",
- sizeof(struct gps_fix_t),
- sizeof(struct gps_data_t), sizeof(struct rtcm2_t),
- sizeof(struct rtcm3_t), sizeof(struct ais_t),
- sizeof(struct attitude_t), sizeof(struct rawdata_t),
- sizeof(collect.devices), sizeof(struct policy_t),
- sizeof(struct version_t), sizeof(struct gst_t));
- exit(0);
- case 'D':
- debug = atoi(optarg);
- break;
- case '?':
- case 'h':
- default:
- (void)fputs("usage: libgps [-b] [-d lvl] [-s]\n", stderr);
- exit(1);
- }
- }
-
- gps_enable_debug(debug, stdout);
- if (batchmode) {
- while (fgets(buf, sizeof(buf), stdin) != NULL) {
- if (buf[0] == '{' || isalpha(buf[0])) {
- gps_unpack(buf, &gpsdata);
- libgps_dump_state(&gpsdata);
- }
- }
- } else if (gps_open(NULL, 0, &collect) <= 0) {
- (void)fputs("Daemon is not running.\n", stdout);
- exit(1);
- } else if (optind < argc) {
- (void)strlcpy(buf, argv[optind], BUFSIZ);
- (void)strlcat(buf, "\n", BUFSIZ);
- (void)gps_send(&collect, buf);
- (void)gps_read(&collect);
- libgps_dump_state(&collect);
- (void)gps_close(&collect);
- } else {
- int tty = isatty(0);
-
- if (tty)
- (void)fputs("This is the gpsd exerciser.\n", stdout);
- for (;;) {
- if (tty)
- (void)fputs("> ", stdout);
- if (fgets(buf, sizeof(buf), stdin) == NULL) {
- if (tty)
- putchar('\n');
- break;
- }
- collect.set = 0;
- (void)gps_send(&collect, buf);
- (void)gps_read(&collect);
- libgps_dump_state(&collect);
- }
- (void)gps_close(&collect);
- }
-
- return 0;
-}
-
-/*@-nullderef@*/
-
-#endif /* TESTMAIN */
+// end
diff --git a/regress-driver b/regress-driver
index 3b981855..fe080e38 100755
--- a/regress-driver
+++ b/regress-driver
@@ -106,7 +106,7 @@ case $mode in
trap 'rm -f ${TMP}/test-$$.chk; exit $errors' EXIT HUP INT TERM
case $testing in
daemon) ${PYTHON} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ${ALTFILTER} >${TMP}/test-$$.chk ;;
- clientlib) ${GPSD_HOME}/libgps -b <${f} >${TMP}/test-$$.chk ;;
+ clientlib) ${GPSD_HOME}/test_libgps -b <${f} >${TMP}/test-$$.chk ;;
esac
if [ "${ALTFILTER}" ]
then
@@ -163,7 +163,7 @@ case $mode in
for f in $*; do
case $testing in
daemon) ${PYTHON} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} >${f}.chk;;
- clientlib) ${GPSD_HOME}/libgps -b <${f} >${f}.chk ;;
+ clientlib) ${GPSD_HOME}/test_libgps -b <${f} >${f}.chk ;;
esac
done
status=0
diff --git a/test_libgps.c b/test_libgps.c
new file mode 100644
index 00000000..43c72647
--- /dev/null
+++ b/test_libgps.c
@@ -0,0 +1,108 @@
+/*
+ * A simple command-line exerciser for the library.
+ * Not really useful for anything but debugging.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include "gpsd.h"
+
+#ifndef S_SPLINT_S
+#include <unistd.h>
+#endif /* S_SPLINT_S */
+#include <getopt.h>
+#include <signal.h>
+
+static void onsig(int sig)
+{
+ (void)fprintf(stderr, "libgps: died with signal %d\n", sig);
+ exit(1);
+}
+
+/* must start zeroed, otherwise the unit test will try to chase garbage pointer fields. */
+static struct gps_data_t gpsdata;
+
+int main(int argc, char *argv[])
+{
+ struct gps_data_t collect;
+ char buf[BUFSIZ];
+ int option;
+ bool batchmode = false;
+ int debug = 0;
+
+ (void)signal(SIGSEGV, onsig);
+ (void)signal(SIGBUS, onsig);
+
+ while ((option = getopt(argc, argv, "bhsD:?")) != -1) {
+ switch (option) {
+ case 'b':
+ batchmode = true;
+ break;
+ case 's':
+ (void)
+ printf
+ ("Sizes: fix=%zd gpsdata=%zd rtcm2=%zd rtcm3=%zd ais=%zd compass=%zd raw=%zd devices=%zd policy=%zd version=%zd, noise=%zd\n",
+ sizeof(struct gps_fix_t),
+ sizeof(struct gps_data_t), sizeof(struct rtcm2_t),
+ sizeof(struct rtcm3_t), sizeof(struct ais_t),
+ sizeof(struct attitude_t), sizeof(struct rawdata_t),
+ sizeof(collect.devices), sizeof(struct policy_t),
+ sizeof(struct version_t), sizeof(struct gst_t));
+ exit(0);
+ case 'D':
+ debug = atoi(optarg);
+ break;
+ case '?':
+ case 'h':
+ default:
+ (void)fputs("usage: libgps [-b] [-d lvl] [-s]\n", stderr);
+ exit(1);
+ }
+ }
+
+ gps_enable_debug(debug, stdout);
+ if (batchmode) {
+ while (fgets(buf, sizeof(buf), stdin) != NULL) {
+ if (buf[0] == '{' || isalpha(buf[0])) {
+ gps_unpack(buf, &gpsdata);
+ libgps_dump_state(&gpsdata);
+ }
+ }
+ } else if (gps_open(NULL, 0, &collect) <= 0) {
+ (void)fputs("Daemon is not running.\n", stdout);
+ exit(1);
+ } else if (optind < argc) {
+ (void)strlcpy(buf, argv[optind], BUFSIZ);
+ (void)strlcat(buf, "\n", BUFSIZ);
+ (void)gps_send(&collect, buf);
+ (void)gps_read(&collect);
+ libgps_dump_state(&collect);
+ (void)gps_close(&collect);
+ } else {
+ int tty = isatty(0);
+
+ if (tty)
+ (void)fputs("This is the gpsd exerciser.\n", stdout);
+ for (;;) {
+ if (tty)
+ (void)fputs("> ", stdout);
+ if (fgets(buf, sizeof(buf), stdin) == NULL) {
+ if (tty)
+ putchar('\n');
+ break;
+ }
+ collect.set = 0;
+ (void)gps_send(&collect, buf);
+ (void)gps_read(&collect);
+ libgps_dump_state(&collect);
+ }
+ (void)gps_close(&collect);
+ }
+
+ return 0;
+}
+
+/*@-nullderef@*/