aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-24 12:00:20 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-24 12:00:20 -0500
commit39a420f13e8000e2dfa53777b9e51594ba03e5d4 (patch)
tree95d8a0975bf7016a71b64fea1162375a1b916985 /tests
parentbc1baf25a0844861713829c0e9e69e4a2d447cc6 (diff)
Add test cases from vi-firmware.
Diffstat (limited to 'tests')
-rw-r--r--tests/read_tests.c36
-rwxr-xr-xtests/tests.binbin24728 -> 0 bytes
-rw-r--r--tests/write_tests.c40
3 files changed, 76 insertions, 0 deletions
diff --git a/tests/read_tests.c b/tests/read_tests.c
new file mode 100644
index 0000000..f5f0f0c
--- /dev/null
+++ b/tests/read_tests.c
@@ -0,0 +1,36 @@
+#include <check.h>
+#include <stdint.h>
+#include <canutil/read.h>
+
+const uint64_t BIG_ENDIAN_TEST_DATA = __builtin_bswap64(0xEB00000000000000);
+
+START_TEST (test_parse_float)
+{
+ float result = parseFloat(BIG_ENDIAN_TEST_DATA, 2, 4, 1001.0, -30000.0);
+ float correctResult = 0xA * 1001.0 - 30000.0;
+ fail_unless(result == correctResult,
+ "parse is incorrect: %f but should be %f", result, correctResult);
+}
+END_TEST
+
+Suite* canreadSuite(void) {
+ Suite* s = suite_create("read");
+ TCase *tc_core = tcase_create("core");
+ tcase_add_checked_fixture(tc_core, NULL, NULL);
+ tcase_add_test(tc_core, test_parse_float);
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
+
+int main(void) {
+ int numberFailed;
+ Suite* s = canreadSuite();
+ 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;
+}
diff --git a/tests/tests.bin b/tests/tests.bin
deleted file mode 100755
index 5fd0916..0000000
--- a/tests/tests.bin
+++ /dev/null
Binary files differ
diff --git a/tests/write_tests.c b/tests/write_tests.c
new file mode 100644
index 0000000..da5ee89
--- /dev/null
+++ b/tests/write_tests.c
@@ -0,0 +1,40 @@
+#include <canutil/write.h>
+#include <check.h>
+#include <stdint.h>
+
+START_TEST (test_encode_can_signal)
+{
+ uint64_t value = encodeFloat(0, 1, 3, 1, 0);
+ ck_assert_int_eq(value, 0);
+}
+END_TEST
+
+START_TEST (test_encode_can_signal_rounding_precision)
+{
+ uint64_t value = encodeFloat(50, 2, 19, 0.001, 0);
+ ck_assert_int_eq(value, 0x061a800000000000LLU);
+}
+END_TEST
+
+Suite* canwriteSuite(void) {
+ Suite* s = suite_create("write");
+ TCase *tc_core = tcase_create("core");
+ tcase_add_checked_fixture(tc_core, NULL, NULL);
+ tcase_add_test(tc_core, test_encode_can_signal);
+ tcase_add_test(tc_core, test_encode_can_signal_rounding_precision);
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
+
+int main(void) {
+ int numberFailed;
+ Suite* s = canwriteSuite();
+ 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;
+}