aboutsummaryrefslogtreecommitdiffstats
path: root/libese
diff options
context:
space:
mode:
authorWill Drewry <drewry@google.com>2017-03-10 21:44:23 +0000
committerWill Drewry <drewry@google.com>2017-03-10 21:44:23 +0000
commit4aa454a96f80ba674e3f887bc07520b5f5cfebe2 (patch)
tree7aa45326e00665faeb1711832c3989723eaa1359 /libese
parented4a7a70c0f8a69188aab74fecf65f9c31b1f57c (diff)
downloadplatform_external_libese-4aa454a96f80ba674e3f887bc07520b5f5cfebe2.tar.gz
platform_external_libese-4aa454a96f80ba674e3f887bc07520b5f5cfebe2.tar.bz2
platform_external_libese-4aa454a96f80ba674e3f887bc07520b5f5cfebe2.zip
Revert "Clean up and refactor; new hw support"
This reverts commit ed4a7a70c0f8a69188aab74fecf65f9c31b1f57c. Missed a darwin disable. Change-Id: Ifa052cb6b6686d1e6c408f64dfd9b82b362048c0
Diffstat (limited to 'libese')
-rw-r--r--libese/Android.bp10
-rw-r--r--libese/ese.c89
-rw-r--r--libese/include/ese/bit_spec.h47
-rw-r--r--libese/include/ese/ese.h19
-rw-r--r--libese/include/ese/ese_hw_api.h135
-rw-r--r--libese/include/ese/log.h4
-rw-r--r--libese/include/ese/sysdeps.h24
-rw-r--r--libese/tests/Android.bp28
-rw-r--r--libese/tests/bitspec_unittests.cpp173
-rw-r--r--libese/tests/ese_unittests.cpp14
10 files changed, 118 insertions, 425 deletions
diff --git a/libese/Android.bp b/libese/Android.bp
index 411001c..1511b3a 100644
--- a/libese/Android.bp
+++ b/libese/Android.bp
@@ -23,18 +23,16 @@ cc_library {
],
local_include_dirs: [
- "include",
+ "include",
],
// Ensure that only explicitly exported symbols are visible.
- cflags: ["-fvisibility=internal", "-std=c99"],
- // This doesn't work yet, but is good documentation for when
- // debugging is needed.
+ cflags: ["-fvisibility=internal"],
debug: {
cflags: ["-DLOG_NDEBUG=0"],
- },
+ },
- shared_libs: ["libese-sysdeps", "liblog"],
+ shared_libs: ["liblog"],
export_include_dirs: ["include"],
}
diff --git a/libese/ese.c b/libese/ese.c
index 2a0048f..1e49e22 100644
--- a/libese/ese.c
+++ b/libese/ese.c
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include "include/ese/ese.h"
-#include "include/ese/log.h"
+#include <ese/ese.h>
+#include <ese/log.h>
#include "ese_private.h"
@@ -27,91 +27,84 @@ static const char *kEseErrorMessages[] = {
};
#define ESE_MESSAGES(x) (sizeof(x) / sizeof((x)[0]))
-API const char *ese_name(const struct EseInterface *ese) {
- if (!ese) {
+/* TODO(wad): Make the default visibility on this one default default? */
+API const char *ese_name(struct EseInterface *ese) {
+ if (!ese)
return kNullEse;
- }
- if (ese->ops->name) {
+ if (ese->ops->name)
return ese->ops->name;
- }
return kUnknownHw;
}
API int ese_open(struct EseInterface *ese, void *hw_opts) {
- if (!ese) {
+ if (!ese)
return -1;
- }
ALOGV("opening interface '%s'", ese_name(ese));
- if (ese->ops->open) {
+ if (ese->ops->open)
return ese->ops->open(ese, hw_opts);
- }
return 0;
}
-API const char *ese_error_message(const struct EseInterface *ese) {
+API const char *ese_error_message(struct EseInterface *ese) {
return ese->error.message;
}
-API int ese_error_code(const struct EseInterface *ese) {
- return ese->error.code;
-}
+API int ese_error_code(struct EseInterface *ese) { return ese->error.code; }
-API bool ese_error(const struct EseInterface *ese) { return ese->error.is_err; }
+API int ese_error(struct EseInterface *ese) { return ese->error.is_err; }
API void ese_set_error(struct EseInterface *ese, int code) {
- if (!ese) {
+ if (!ese)
return;
- }
/* Negative values are reserved for API wide messages. */
ese->error.code = code;
- ese->error.is_err = true;
+ ese->error.is_err = 1;
if (code < 0) {
code = -(code + 1); /* Start at 0. */
- if ((uint32_t)(code) >= ESE_MESSAGES(kEseErrorMessages)) {
+ if ((size_t)(code) >= ESE_MESSAGES(kEseErrorMessages)) {
LOG_ALWAYS_FATAL("Unknown global error code passed to ese_set_error(%d)",
code);
}
ese->error.message = kEseErrorMessages[code];
return;
}
- if ((uint32_t)(code) >= ese->ops->errors_count) {
+ if ((size_t)(code) >= ese->errors_count) {
LOG_ALWAYS_FATAL("Unknown hw error code passed to ese_set_error(%d)", code);
}
- ese->error.message = ese->ops->errors[code];
+ ese->error.message = ese->errors[code];
}
/* Blocking. */
-API int ese_transceive(struct EseInterface *ese, const uint8_t *tx_buf,
- uint32_t tx_len, uint8_t *rx_buf, uint32_t rx_max) {
- uint32_t recvd = 0;
- if (!ese) {
+API int ese_transceive(struct EseInterface *ese, uint8_t *const tx_buf,
+ size_t tx_len, uint8_t *rx_buf, size_t rx_max) {
+ size_t recvd = 0;
+ if (!ese)
return -1;
- }
-
- if (ese->ops->transceive) {
- recvd = ese->ops->transceive(ese, tx_buf, tx_len, rx_buf, rx_max);
- return ese_error(ese) ? -1 : recvd;
- }
-
- if (ese->ops->hw_transmit && ese->ops->hw_receive) {
- ese->ops->hw_transmit(ese, tx_buf, tx_len, 1);
- if (!ese_error(ese)) {
+ while (1) {
+ if (ese->ops->transceive) {
+ recvd = ese->ops->transceive(ese, tx_buf, tx_len, rx_buf, rx_max);
+ break;
+ }
+ if (ese->ops->hw_transmit && ese->ops->hw_receive) {
+ ese->ops->hw_transmit(ese, tx_buf, tx_len, 1);
+ if (ese->error.is_err)
+ break;
recvd = ese->ops->hw_receive(ese, rx_buf, rx_max, 1);
+ break;
}
- return ese_error(ese) ? -1 : recvd;
+ ese_set_error(ese, -1);
+ break;
}
-
- ese_set_error(ese, kEseGlobalErrorNoTransceive);
- return -1;
+ if (ese->error.is_err)
+ return -1;
+ return recvd;
}
-API void ese_close(struct EseInterface *ese) {
- if (!ese) {
- return;
- }
+API int ese_close(struct EseInterface *ese) {
+ if (!ese)
+ return -1;
ALOGV("closing interface '%s'", ese_name(ese));
- if (!ese->ops->close) {
- return;
- }
- ese->ops->close(ese);
+ if (!ese->ops->close)
+ return 0;
+ return ese->ops->close(ese);
}
diff --git a/libese/include/ese/bit_spec.h b/libese/include/ese/bit_spec.h
deleted file mode 100644
index 4e6c848..0000000
--- a/libese/include/ese/bit_spec.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ESE_BIT_SPEC_H__
-#define ESE_BIT_SPEC_H__ 1
-
-struct bit_spec {
- uint8_t value;
- uint8_t shift;
-};
-
-static inline uint8_t bs_get(const struct bit_spec b, uint8_t var) {
- return (var & (b.value << b.shift)) >> b.shift;
-}
-
-static inline uint8_t bs_mask(const struct bit_spec b, uint8_t value) {
- return (value & b.value) << b.shift;
-}
-
-static inline uint8_t bs_clear(const struct bit_spec b) {
- return (((uint8_t)~0) ^ bs_mask(b, b.value));
-}
-
-static inline uint8_t bs_set(uint8_t var, const struct bit_spec b, uint8_t value) {
- return ((var) & bs_clear(b)) | bs_mask(b, value);
-}
-
-static inline void bs_assign(uint8_t *dst, const struct bit_spec b, uint8_t value) {
- *dst = bs_set(*dst, b, value);
-}
-
-
-#endif /* ESE_BIT_SPEC_H__ */
-
-
diff --git a/libese/include/ese/ese.h b/libese/include/ese/ese.h
index f12ed03..39827ed 100644
--- a/libese/include/ese/ese.h
+++ b/libese/include/ese/ese.h
@@ -17,8 +17,10 @@
#ifndef ESE_H_
#define ESE_H_ 1
+#include <stdint.h>
+#include <stdint.h>
+
#include "ese_hw_api.h"
-#include "../../../libese-sysdeps/include/ese/sysdeps.h"
#ifdef __cplusplus
extern "C" {
@@ -66,14 +68,17 @@ struct EseInterface;
#define ESE_INITIALIZER __ESE_INITIALIZER
#define ESE_INCLUDE_HW __ESE_INCLUDE_HW
-const char *ese_name(const struct EseInterface *ese);
+const char *ese_name(struct EseInterface *ese);
int ese_open(struct EseInterface *ese, void *hw_opts);
-void ese_close(struct EseInterface *ese);
-int ese_transceive(struct EseInterface *ese, const uint8_t *tx_buf, uint32_t tx_len, uint8_t *rx_buf, uint32_t rx_max);
+int ese_close(struct EseInterface *ese);
+int ese_transceive(struct EseInterface *ese, uint8_t *const tx_buf, size_t tx_len, uint8_t *rx_buf, size_t rx_max);
+
+int ese_error(struct EseInterface *ese);
+const char *ese_error_message(struct EseInterface *ese);
+int ese_error_code(struct EseInterface *ese);
-bool ese_error(const struct EseInterface *ese);
-const char *ese_error_message(const struct EseInterface *ese);
-int ese_error_code(const struct EseInterface *ese);
+/* Called by the implementations. */
+void ese_set_error(struct EseInterface *ese, int code);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/libese/include/ese/ese_hw_api.h b/libese/include/ese/ese_hw_api.h
index 1d23768..dd76391 100644
--- a/libese/include/ese/ese_hw_api.h
+++ b/libese/include/ese/ese_hw_api.h
@@ -17,7 +17,8 @@
#ifndef ESE_HW_API_H_
#define ESE_HW_API_H_ 1
-#include "../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <stddef.h>
+#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -27,109 +28,49 @@ extern "C" {
* to make use of.
*/
#define __ESE_INCLUDE_HW(name) \
- extern const struct EseOperations * name## _ops
+ extern const struct EseOperations * name## _ops; \
+ extern const char ** name##_errors; \
+ extern const size_t name##_errors_count
struct EseInterface;
-
-/* ese_hw_receive_op_t: receives a buffer from the hardware.
- * Args:
- * - struct EseInterface *: session handle.
- * - uint8_t *: pointer to the buffer to receive data into.
- * - uint32_t: maximum length of the data to receive.
- * - int: 1 or 0 indicating if it is a complete transaction. This allows the underlying
- * implementation to batch reads if needed by the underlying wire protocol or if
- * the hardware needs to be signalled explicitly.
+/* !! Note !!
+ * Receive and transmit operations on SPI buses should ensure the CS
+ * does not change between subsequent recieve (or transmit) calls unless
+ * the |complete| argument is 1.
*
- * Returns:
- * - uint32_t: bytes received.
- */
-typedef uint32_t (ese_hw_receive_op_t)(struct EseInterface *, uint8_t *, uint32_t, int);
-/* ese_hw_transmit_op_t: transmits a buffer over the hardware.
- * Args:
- * - struct EseInterface *: session handle.
- * - uint8_t *: pointer to the buffer to transmit.
- * - uint32_t: length of the data to transmit.
- * - int: 1 or 0 indicating if it is a complete transaction.
+ * In practice, this should not require additional state tracking as entry
+ * to each function can simply assert the CS state (even if unchanged) and
+ * then check whether to unassert based on |complete|.
*
- * Returns:
- * - uint32_t: bytes transmitted.
- */
-typedef uint32_t (ese_hw_transmit_op_t)(struct EseInterface *, const uint8_t *, uint32_t, int);
-/* ese_hw_reset_op_t: resets the hardware in case of communication desynchronization.
- * Args:
- * - struct EseInterface *: session handle.
+ * Other communications backends may have different needs which may be solved
+ * separately by minimally processing protocol headers.
*
- * Returns:
- * - int: -1 on error, 0 on success.
+ * The other option is having a transactional view where we have an explicit
+ * begin/end or claim/release.
*/
+typedef size_t (ese_hw_receive_op_t)(struct EseInterface *, uint8_t *, size_t, int);
+typedef size_t (ese_hw_transmit_op_t)(struct EseInterface *, const uint8_t *, size_t, int);
typedef int (ese_hw_reset_op_t)(struct EseInterface *);
-/* ese_transceive_op_t: fully contained transmission and receive operation.
- *
- * Must provide an implementation of the wire protocol necessary to transmit
- * and receive an application payload to and from the eSE. Normally, this
- * implementation is built on the hw_{receive,transmit} operations also
- * provided and often requires the poll operation below.
- *
- * Args:
- * - struct EseInterface *: session handle.
- * - const uint8_t *: pointer to the buffer to transmit.
- * - uint32_t: length of the data to transmit.
- * - uint8_t *: pointer to the buffer to receive into.
- * - uint32_t: maximum length of the data to receive.
- *
- * Returns:
- * - uint32_t: bytes received.
- */
-typedef uint32_t (ese_transceive_op_t)(struct EseInterface *, const uint8_t *, uint32_t, uint8_t *, uint32_t);
-/* ese_poll_op_t: waits for the hardware to be ready to send data.
- *
- * Args:
- * - struct EseInterface *: session handle.
- * - uint8_t: byte to wait for. E.g., a start of frame byte.
- * - float: time in seconds to wait.
- * - int: whether to complete a transaction when polling іs complete.
- *
- * Returns:
- * - int: On error or timeout, -1.
- * On success, 1 or 0 depending on if the found byte was consumed.
- */
+/* Implements wire protocol transceiving and will likely also then require locking. */
+typedef size_t (ese_transceive_op_t)(struct EseInterface *, const uint8_t *, size_t, uint8_t *, size_t);
+/* Returns 0 on timeout, 1 on byte seen, -1 on error. */
typedef int (ese_poll_op_t)(struct EseInterface *, uint8_t, float, int);
-/* ese_hw_open_op_t: prepares the hardware for use.
- *
- * This function should prepare the hardware for use and attach
- * any implementation specific state to the EseInterface handle such
- * that it is accessible in the other calls.
- *
- * Args:
- * - struct EseInterface *: freshly initialized session handle.
- * - void *: implementation specific pointer from the libese client.
- *
- * Returns:
- * - int: < 0 on error, 0 on success.
- */
typedef int (ese_open_op_t)(struct EseInterface *, void *);
-/* ese_hw_close_op_t: releases the hardware in use.
- *
- * This function should free any dynamic memory and release
- * the claimed hardware.
- *
- * Args:
- * - struct EseInterface *: freshly initialized session handle.
- *
- * Returns:
- * - Nothing.
- */
-typedef void (ese_close_op_t)(struct EseInterface *);
+typedef int (ese_close_op_t)(struct EseInterface *);
#define __ESE_INITIALIZER(TYPE) \
{ \
.ops = TYPE## _ops, \
+ .errors = TYPE## _errors, \
+ .errors_count = TYPE## _errors_count, \
.pad = { 0 }, \
}
#define __ese_init(_ptr, TYPE) {\
_ptr->ops = TYPE## _ops; \
+ _ptr->errors = TYPE## _errors; \
+ _ptr->errors_count = TYPE## _errors_count; \
_ptr->pad[0] = 0; \
}
@@ -158,10 +99,6 @@ struct EseOperations {
/* Operational options */
const void *const opts;
-
- /* Operation error messages. */
- const char **errors;
- const uint32_t errors_count;
};
/* Maximum private stack storage on the interface instance. */
@@ -169,32 +106,24 @@ struct EseOperations {
struct EseInterface {
const struct EseOperations * ops;
struct {
- bool is_err;
+ int is_err;
int code;
const char *message;
} error;
+ const char **errors;
+ size_t errors_count;
/* Reserved to avoid heap allocation requirement. */
uint8_t pad[ESE_INTERFACE_STATE_PAD];
};
-/*
- * Provided by libese to manage exposing usable errors up the stack to the
- * libese user.
- */
-void ese_set_error(struct EseInterface *ese, int code);
-/*
- * Global error enums.
- */
-enum EseGlobalError {
- kEseGlobalErrorNoTransceive = -1,
- kEseGlobalErrorPollTimedOut = -2,
-};
+#define ESE_DEFINE_HW_ERRORS(name, ary) \
+ const char ** name##_errors = (ary); \
+ const size_t name##_errors_count = (sizeof(ary) / sizeof((ary)[0]))
#define ESE_DEFINE_HW_OPS(name, obj) \
const struct EseOperations * name##_ops = &obj
-
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/libese/include/ese/log.h b/libese/include/ese/log.h
index 8eebe23..150c562 100644
--- a/libese/include/ese/log.h
+++ b/libese/include/ese/log.h
@@ -19,10 +19,6 @@
#ifndef ESE_LOG_H_
#define ESE_LOG_H_ 1
-/* Uncomment when doing bring up or other messy debugging.
- * #define LOG_NDEBUG 0
- */
-
#if defined(ESE_LOG_NONE) || defined(ESE_LOG_STDIO)
# define ESE_LOG_ANDROID 0
#endif
diff --git a/libese/include/ese/sysdeps.h b/libese/include/ese/sysdeps.h
deleted file mode 100644
index 67f91f1..0000000
--- a/libese/include/ese/sysdeps.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ESE_PLATFORM_SYSDEPS_H__
-#define ESE_PLATFORM_SYSDEPS_H__ 1
-
-#include <stdint.h> /* uint*_t */
-
-extern void *ese_memcpy(void *__dest, const void *__src, uint64_t __n);
-extern void *ese_memset(void *__s, int __c, uint64_t __n);
-
-#endif /* ESE_PLATFORM_SYSDEPS_H__ */
diff --git a/libese/tests/Android.bp b/libese/tests/Android.bp
index 1239eb2..29abee0 100644
--- a/libese/tests/Android.bp
+++ b/libese/tests/Android.bp
@@ -14,13 +14,29 @@
// limitations under the License.
//
+cc_defaults {
+ name: "libese_tests_default",
+
+ multilib: {
+ lib32: {
+ suffix: "32",
+ },
+ lib64: {
+ suffix: "64",
+ },
+ },
+}
+
+test_libraries = [
+ "libese",
+ "libese-hw-fake",
+ "liblog",
+]
+
cc_test {
name: "ese_unittests",
- srcs: ["ese_unittests.cpp", "bitspec_unittests.cpp"],
+ defaults: ["libese_tests_default"],
+ srcs: ["ese_unittests.cpp"],
host_supported: true,
- shared_libs: [
- "libese",
- "libese-hw-fake",
- "liblog",
- ],
+ shared_libs: test_libraries,
}
diff --git a/libese/tests/bitspec_unittests.cpp b/libese/tests/bitspec_unittests.cpp
deleted file mode 100644
index 1f2fc2a..0000000
--- a/libese/tests/bitspec_unittests.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdint.h>
-
-#include <ese/bit_spec.h>
-#include <gtest/gtest.h>
-
-using ::testing::Test;
-
-struct TestSpec {
- struct {
- struct bit_spec bit[8];
- } single;
- struct {
- struct bit_spec high;
- struct bit_spec mid;
- struct bit_spec low;
- } adjacent;
- struct {
- struct bit_spec all8;
- struct bit_spec upper6;
- struct bit_spec lower6;
- } overlap;
-};
-
-const struct TestSpec kTestSpec = {
- .single = {
- .bit = {
- { .value = 1, .shift = 0 },
- { .value = 1, .shift = 1 },
- { .value = 1, .shift = 2 },
- { .value = 1, .shift = 3 },
- { .value = 1, .shift = 4 },
- { .value = 1, .shift = 5 },
- { .value = 1, .shift = 6 },
- { .value = 1, .shift = 7 },
- },
- },
- .adjacent = {
- .high = { .value = 0x3, .shift = 6 },
- .mid = { .value = 0xf, .shift = 2 },
- .low = { .value = 0x3, .shift = 0 },
- },
- .overlap = {
- .all8 = { .value = 0xff, .shift = 0 },
- .upper6 = { .value = 0x3f, .shift = 2 },
- .lower6 = { .value = 0x3f, .shift = 0 },
- },
-};
-
-class BitSpecTest : public virtual Test {
- public:
- BitSpecTest() {
- }
- virtual ~BitSpecTest() { }
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(BitSpecTest, single_bits_assign_accrue) {
- uint8_t byte = 0;
- uint8_t expected_byte = 0;
- // Accrue bits.
- for (int bit = 0; bit < 8; ++bit) {
- expected_byte |= (1 << bit);
- bs_assign(&byte, kTestSpec.single.bit[bit], 1);
- EXPECT_EQ(expected_byte, byte);
- EXPECT_EQ(1, bs_get(kTestSpec.single.bit[bit], expected_byte));
- }
-}
-
-TEST_F(BitSpecTest, single_bits_assign1_individual) {
- // One bit at a time.
- for (int bit = 0; bit < 8; ++bit) {
- uint8_t expected_byte = (1 << bit);
- uint8_t byte = bs_set(0, kTestSpec.single.bit[bit], 1);
- EXPECT_EQ(expected_byte, byte);
- EXPECT_EQ(1, bs_get(kTestSpec.single.bit[bit], expected_byte));
- }
-}
-
-TEST_F(BitSpecTest, single_bits_assign0_individual) {
- // One bit at a time.
- for (int bit = 0; bit < 8; ++bit) {
- uint8_t expected_byte = 0xff ^ (1 << bit);
- uint8_t byte = bs_set(0xff, kTestSpec.single.bit[bit], 0);
- EXPECT_EQ(expected_byte, byte);
- EXPECT_EQ(0, bs_get(kTestSpec.single.bit[bit], expected_byte));
- }
-}
-
-TEST_F(BitSpecTest, single_bits_clear_individual) {
- // One bit at a time.
- for (int bit = 0; bit < 8; ++bit) {
- uint8_t byte = 0xff;
- uint8_t expected_byte = 0xff ^ (1 << bit);
- byte &= bs_clear(kTestSpec.single.bit[bit]);
- EXPECT_EQ(expected_byte, byte);
- EXPECT_EQ(0, bs_get(kTestSpec.single.bit[bit], expected_byte));
- }
-}
-
-TEST_F(BitSpecTest, adjacent_bit_assign) {
- uint8_t byte = 0;
- EXPECT_EQ(0, bs_get(kTestSpec.adjacent.high, byte));
- EXPECT_EQ(0, bs_get(kTestSpec.adjacent.mid, byte));
- EXPECT_EQ(0, bs_get(kTestSpec.adjacent.low, byte));
- byte = 0xff;
- EXPECT_EQ(0x3, bs_get(kTestSpec.adjacent.high, byte));
- EXPECT_EQ(0xf, bs_get(kTestSpec.adjacent.mid, byte));
- EXPECT_EQ(0x3, bs_get(kTestSpec.adjacent.low, byte));
- for (int i = 0; i < 0xf; ++i) {
- bs_assign(&byte, kTestSpec.adjacent.mid, i);
- EXPECT_EQ(0x3, bs_get(kTestSpec.adjacent.high, byte));
- EXPECT_EQ(i, bs_get(kTestSpec.adjacent.mid, byte));
- EXPECT_EQ(0x3, bs_get(kTestSpec.adjacent.low, byte));
- }
- byte = 0xff;
- for (int i = 0; i < 0x3; ++i) {
- bs_assign(&byte, kTestSpec.adjacent.low, i);
- bs_assign(&byte, kTestSpec.adjacent.high, i);
- EXPECT_EQ(i, bs_get(kTestSpec.adjacent.high, byte));
- EXPECT_EQ(0xf, bs_get(kTestSpec.adjacent.mid, byte));
- EXPECT_EQ(i, bs_get(kTestSpec.adjacent.low, byte));
- }
-}
-
-TEST_F(BitSpecTest, overlap_bit_assign) {
- uint8_t byte = 0;
- EXPECT_EQ(0, bs_get(kTestSpec.overlap.upper6, byte));
- EXPECT_EQ(0, bs_get(kTestSpec.overlap.lower6, byte));
- EXPECT_EQ(0, bs_get(kTestSpec.overlap.all8, byte));
- byte = 0xff;
- EXPECT_EQ(0x3f, bs_get(kTestSpec.overlap.upper6, byte));
- EXPECT_EQ(0x3f, bs_get(kTestSpec.overlap.lower6, byte));
- EXPECT_EQ(0xff, bs_get(kTestSpec.overlap.all8, byte));
-
- byte = 0;
- for (int i = 0; i < 0x3f; ++i) {
- bs_assign(&byte, kTestSpec.overlap.lower6, i);
- EXPECT_EQ((i & (0x3f << 2)) >> 2, bs_get(kTestSpec.overlap.upper6, byte));
- EXPECT_EQ(i, bs_get(kTestSpec.overlap.lower6, byte));
- EXPECT_EQ(i, bs_get(kTestSpec.overlap.all8, byte));
- }
- byte = 0;
- for (int i = 0; i < 0x3f; ++i) {
- bs_assign(&byte, kTestSpec.overlap.upper6, i);
- EXPECT_EQ(i, bs_get(kTestSpec.overlap.upper6, byte));
- EXPECT_EQ((i << 2) & 0x3f, bs_get(kTestSpec.overlap.lower6, byte));
- EXPECT_EQ(i << 2, bs_get(kTestSpec.overlap.all8, byte));
- }
- byte = 0;
- for (int i = 0; i < 0xff; ++i) {
- bs_assign(&byte, kTestSpec.overlap.all8, i);
- EXPECT_EQ(i >> 2, bs_get(kTestSpec.overlap.upper6, byte));
- EXPECT_EQ(i & 0x3f, bs_get(kTestSpec.overlap.lower6, byte));
- EXPECT_EQ(i, bs_get(kTestSpec.overlap.all8, byte));
- }
-}
diff --git a/libese/tests/ese_unittests.cpp b/libese/tests/ese_unittests.cpp
index c62b758..dcfc7f8 100644
--- a/libese/tests/ese_unittests.cpp
+++ b/libese/tests/ese_unittests.cpp
@@ -68,7 +68,7 @@ TEST_F(EseInterfaceTest, EseOpenOk) {
};
TEST_F(EseInterfaceTest, EseCloseNull) {
- ese_close(NULL);
+ EXPECT_EQ(-1, ese_close(NULL));
};
TEST_F(EseInterfaceTest, EseCloseNoOp) {
@@ -79,32 +79,32 @@ TEST_F(EseInterfaceTest, EseCloseNoOp) {
.ops = &dummy_ops
};
/* Will pass without an open first. */
- ese_close(&dummy);
+ EXPECT_EQ(0, ese_close(&dummy));
};
TEST_F(EseInterfaceTest, EseCloseOk) {
EXPECT_EQ(0, ese_open(&ese_, NULL));
- ese_close(&ese_);
+ EXPECT_EQ(0, ese_close(&ese_));
};
TEST_F(EseInterfaceTest, EseClosePending) {
EXPECT_EQ(0, ese_open(&ese_, NULL));
ese_.ops->hw_transmit(&ese_, NULL, 0, 0);
- ese_close(&ese_);
+ EXPECT_EQ(-1, ese_close(&ese_));
EXPECT_EQ(0, ese_open(&ese_, NULL));
ese_.ops->hw_transmit(&ese_, NULL, 0, 1);
ese_.ops->hw_receive(&ese_, NULL, 0, 0);
- ese_close(&ese_);
+ EXPECT_EQ(-1, ese_close(&ese_));
EXPECT_EQ(0, ese_open(&ese_, NULL));
ese_.ops->hw_receive(&ese_, NULL, 0, 1);
- ese_close(&ese_);
+ EXPECT_EQ(0, ese_close(&ese_));
};
TEST_F(EseInterfaceTest, EseTransceiveSendNothing) {
EXPECT_EQ(0, ese_open(&ese_, NULL));
EXPECT_EQ(0, ese_transceive(&ese_, NULL, 0, NULL, 0));
- ese_close(&ese_);
+ EXPECT_EQ(0, ese_close(&ese_));
};
TEST_F(EseInterfaceTest, EseTransceiveNoOps) {