From 06f31c13df6aaf92124f10b8cb5eee96b75c4f73 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Mon, 30 Dec 2013 15:25:32 -0500 Subject: [PATCH] Initial commit. --- .gitignore | 4 ++++ .gitmodules | 6 ++++++ .travis.yml | 11 +++++++++++ CHANGELOG.mkd | 5 +++++ LICENSE | 24 ++++++++++++++++++++++++ Makefile | 39 +++++++++++++++++++++++++++++++++++++++ README.mkd | 20 ++++++++++++++++++++ deps/bitfield-c | 1 + deps/isotp-c | 1 + runtests.sh | 17 +++++++++++++++++ tests/tests.c | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 165 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .travis.yml create mode 100644 CHANGELOG.mkd create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.mkd create mode 160000 deps/bitfield-c create mode 160000 deps/isotp-c create mode 100644 runtests.sh create mode 100644 tests/tests.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b4225c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +.DS_Store +*~ +*.bin diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..d9c0194b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "deps/bitfield-c"] + path = deps/bitfield-c + url = https://github.com/openxc/bitfield-c +[submodule "deps/isotp-c"] + path = deps/isotp-c + url = https://github.com/openxc/isotp-c diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..22b1a91a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: c +compiler: + - gcc +script: make test +before_install: + - git submodule update --init + - sudo apt-get update -qq + - sudo apt-get install check +notifications: + hipchat: + - secure: "ZO/hEAoOTZ4FJytMW0m4LZrsdFVM1/V0Hu13zfj8mdcHkf2MyfxthPDecnn5\naZVn4P8mSSwpp39EnAfa9fBcWcDESnKM1YQKPPGkoxZZHIOd2rYhRv34XfpE\n5qNLkQ/lEPQCBEmvIQ5ZJxsiZjGhO7KxWvdNdruH6cdVCYSh4Xo=" diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd new file mode 100644 index 00000000..edf7f7d5 --- /dev/null +++ b/CHANGELOG.mkd @@ -0,0 +1,5 @@ +# OBD-II Support Library in C + +## v0.1 + +* Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..330d61f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2013 Ford Motor Company +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..98730380 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +CC = gcc +INCLUDES = -Isrc -Ideps/bitfield-c/src -Ideps/isotp-c/src +CFLAGS = $(INCLUDES) -c -w -Wall -Werror -g -ggdb -std=c99 +LDFLAGS = +LDLIBS = -lcheck + +TEST_DIR = tests + +# Guard against \r\n line endings only in Cygwin +OSTYPE := $(shell uname) +ifneq ($(OSTYPE),Darwin) + OSTYPE := $(shell uname -o) + ifeq ($(OSTYPE),Cygwin) + TEST_SET_OPTS = igncr + endif +endif + +SRC = $(wildcard src/**/*.c) +SRC += $(wildcard deps/bitfield-c/src/**/*.c) +SRC += $(wildcard deps/isotp-c/src/**/*.c) +OBJS = $(SRC:.c=.o) +TEST_SRC = $(wildcard $(TEST_DIR)/test_*.c) +TESTS=$(patsubst %.c,%.bin,$(TEST_SRC)) +TEST_SUPPORT_SRC = $(TEST_DIR)/common.c +TEST_SUPPORT_OBJS = $(TEST_SUPPORT_SRC:.c=.o) + +all: $(OBJS) + +test: $(TESTS) + @set -o $(TEST_SET_OPTS) >/dev/null 2>&1 + @export SHELLOPTS + @sh runtests.sh $(TEST_DIR) + +$(TEST_DIR)/%.bin: $(TEST_DIR)/%.o $(OBJS) $(TEST_SUPPORT_OBJS) + @mkdir -p $(dir $@) + $(CC) $(LDFLAGS) $(CC_SYMBOLS) $(INCLUDES) -o $@ $^ $(LDLIBS) + +clean: + rm -rf **/*.o $(TEST_DIR)/*.bin diff --git a/README.mkd b/README.mkd new file mode 100644 index 00000000..485f2cc5 --- /dev/null +++ b/README.mkd @@ -0,0 +1,20 @@ +OBD-II Support Library in C +============================= + +## API + +## Testing + +The library includes a test suite that uses the `check` C unit test library. + + $ make test + +## Authors + +Chris Peplin cpeplin@ford.com + +## License + +Copyright (c) 2013 Ford Motor Company + +Licensed under the BSD license. diff --git a/deps/bitfield-c b/deps/bitfield-c new file mode 160000 index 00000000..cd74b884 --- /dev/null +++ b/deps/bitfield-c @@ -0,0 +1 @@ +Subproject commit cd74b88432054107c439c4e565bea14840dd9ea5 diff --git a/deps/isotp-c b/deps/isotp-c new file mode 160000 index 00000000..368d36cc --- /dev/null +++ b/deps/isotp-c @@ -0,0 +1 @@ +Subproject commit 368d36cc15b69882e9d21803f3b8aa7a1c97736e diff --git a/runtests.sh b/runtests.sh new file mode 100644 index 00000000..4781636b --- /dev/null +++ b/runtests.sh @@ -0,0 +1,17 @@ +echo "Running unit tests:" + +for i in $1/*.bin +do + if test -f $i + then + if ./$i + then + echo $i PASS + else + echo "ERROR in test $i:" + exit 1 + fi + fi +done + +echo "${txtbld}$(tput setaf 2)All unit tests passed.$(tput sgr0)" diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 00000000..68745652 --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +void setup() { + +} + +START_TEST (test_fail) +{ + fail_unless(false); +} +END_TEST + +Suite* testSuite(void) { + Suite* s = suite_create("obd2"); + TCase *tc_core = tcase_create("core"); + tcase_add_checked_fixture(tc_core, setup, NULL); + tcase_add_test(tc_core, test_fail); + suite_add_tcase(s, tc_core); + + return s; +} + +int main(void) { + int numberFailed; + Suite* s = testSuite(); + SRunner *sr = srunner_create(s); + // Don't fork so we can actually use gdb + srunner_set_fork_status(sr, CK_NOFORK); + srunner_run_all(sr, CK_NORMAL); + numberFailed = srunner_ntests_failed(sr); + srunner_free(sr); + return (numberFailed == 0) ? 0 : 1; +} -- 2.16.6