summaryrefslogtreecommitdiffstats
path: root/CAN-binder/libs/nanopb/tests/io_errors
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-02 18:29:37 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-02 18:29:37 +0200
commitb9e1b4435a406a8a27c078ea05dee1240e51704a (patch)
tree3bd5e75d001d0c1d57710c47375af5c8ba84c26c /CAN-binder/libs/nanopb/tests/io_errors
parent0242c26c2f5dc96387bca7efb118364c800f4ee7 (diff)
Added external libraries from openXC CMake files.
Now libraries are cleanly included and built. Change-Id: Iaa85639578b55b2da8357bc438426403e2cca8de Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/libs/nanopb/tests/io_errors')
-rw-r--r--CAN-binder/libs/nanopb/tests/io_errors/SConscript15
-rw-r--r--CAN-binder/libs/nanopb/tests/io_errors/alltypes.options3
-rw-r--r--CAN-binder/libs/nanopb/tests/io_errors/io_errors.c140
3 files changed, 0 insertions, 158 deletions
diff --git a/CAN-binder/libs/nanopb/tests/io_errors/SConscript b/CAN-binder/libs/nanopb/tests/io_errors/SConscript
deleted file mode 100644
index 60146cc0..00000000
--- a/CAN-binder/libs/nanopb/tests/io_errors/SConscript
+++ /dev/null
@@ -1,15 +0,0 @@
-# Simulate io errors when encoding and decoding
-
-Import("env")
-
-c = Copy("$TARGET", "$SOURCE")
-env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
-
-env.NanopbProto(["alltypes", "alltypes.options"])
-
-ioerr = env.Program(["io_errors.c", "alltypes.pb.c",
- "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
-
-env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"])
-
-
diff --git a/CAN-binder/libs/nanopb/tests/io_errors/alltypes.options b/CAN-binder/libs/nanopb/tests/io_errors/alltypes.options
deleted file mode 100644
index 0d5ab12b..00000000
--- a/CAN-binder/libs/nanopb/tests/io_errors/alltypes.options
+++ /dev/null
@@ -1,3 +0,0 @@
-* max_size:16
-* max_count:5
-*.*fbytes fixed_length:true max_size:4
diff --git a/CAN-binder/libs/nanopb/tests/io_errors/io_errors.c b/CAN-binder/libs/nanopb/tests/io_errors/io_errors.c
deleted file mode 100644
index 76f35b08..00000000
--- a/CAN-binder/libs/nanopb/tests/io_errors/io_errors.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Simulate IO errors after each byte in a stream.
- * Verifies proper error propagation.
- */
-
-#include <stdio.h>
-#include <pb_decode.h>
-#include <pb_encode.h>
-#include "alltypes.pb.h"
-#include "test_helpers.h"
-
-typedef struct
-{
- uint8_t *buffer;
- size_t fail_after;
-} faulty_stream_t;
-
-bool read_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
-{
- faulty_stream_t *state = stream->state;
-
- while (count--)
- {
- if (state->fail_after == 0)
- PB_RETURN_ERROR(stream, "simulated");
- state->fail_after--;
- *buf++ = *state->buffer++;
- }
-
- return true;
-}
-bool write_callback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
-{
- faulty_stream_t *state = stream->state;
-
- while (count--)
- {
- if (state->fail_after == 0)
- PB_RETURN_ERROR(stream, "simulated");
- state->fail_after--;
- *state->buffer++ = *buf++;
- }
-
- return true;
-}
-
-int main()
-{
- uint8_t buffer[2048];
- size_t msglen;
- AllTypes msg = AllTypes_init_zero;
-
- /* Get some base data to run the tests with */
- SET_BINARY_MODE(stdin);
- msglen = fread(buffer, 1, sizeof(buffer), stdin);
-
- /* Test IO errors on decoding */
- {
- bool status;
- pb_istream_t stream = {&read_callback, NULL, SIZE_MAX};
- faulty_stream_t fs;
- size_t i;
-
- for (i = 0; i < msglen; i++)
- {
- stream.bytes_left = msglen;
- stream.state = &fs;
- fs.buffer = buffer;
- fs.fail_after = i;
-
- status = pb_decode(&stream, AllTypes_fields, &msg);
- if (status != false)
- {
- fprintf(stderr, "Unexpected success in decode\n");
- return 2;
- }
- else if (strcmp(stream.errmsg, "simulated") != 0)
- {
- fprintf(stderr, "Wrong error in decode: %s\n", stream.errmsg);
- return 3;
- }
- }
-
- stream.bytes_left = msglen;
- stream.state = &fs;
- fs.buffer = buffer;
- fs.fail_after = msglen;
- status = pb_decode(&stream, AllTypes_fields, &msg);
-
- if (!status)
- {
- fprintf(stderr, "Decoding failed: %s\n", stream.errmsg);
- return 4;
- }
- }
-
- /* Test IO errors on encoding */
- {
- bool status;
- pb_ostream_t stream = {&write_callback, NULL, SIZE_MAX, 0};
- faulty_stream_t fs;
- size_t i;
-
- for (i = 0; i < msglen; i++)
- {
- stream.max_size = msglen;
- stream.bytes_written = 0;
- stream.state = &fs;
- fs.buffer = buffer;
- fs.fail_after = i;
-
- status = pb_encode(&stream, AllTypes_fields, &msg);
- if (status != false)
- {
- fprintf(stderr, "Unexpected success in encode\n");
- return 5;
- }
- else if (strcmp(stream.errmsg, "simulated") != 0)
- {
- fprintf(stderr, "Wrong error in encode: %s\n", stream.errmsg);
- return 6;
- }
- }
-
- stream.max_size = msglen;
- stream.bytes_written = 0;
- stream.state = &fs;
- fs.buffer = buffer;
- fs.fail_after = msglen;
- status = pb_encode(&stream, AllTypes_fields, &msg);
-
- if (!status)
- {
- fprintf(stderr, "Encoding failed: %s\n", stream.errmsg);
- return 7;
- }
- }
-
- return 0;
-}
-