From 32e25cbca210a359b09768537b6f443fe90a3070 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 20 Jun 2017 10:24:05 +0000 Subject: Separation Generator to a dedicated repo Change-Id: Id94831651c3266861435272a6e36c7884bef2c45 Signed-off-by: Romain Forlot --- CAN-binder/libs/nanopb/tests/common/SConscript | 48 ------------------- .../libs/nanopb/tests/common/malloc_wrappers.c | 54 ---------------------- .../libs/nanopb/tests/common/malloc_wrappers.h | 7 --- .../nanopb/tests/common/malloc_wrappers_syshdr.h | 15 ------ CAN-binder/libs/nanopb/tests/common/person.proto | 22 --------- CAN-binder/libs/nanopb/tests/common/test_helpers.h | 17 ------- .../libs/nanopb/tests/common/unittestproto.proto | 43 ----------------- CAN-binder/libs/nanopb/tests/common/unittests.h | 14 ------ 8 files changed, 220 deletions(-) delete mode 100644 CAN-binder/libs/nanopb/tests/common/SConscript delete mode 100644 CAN-binder/libs/nanopb/tests/common/malloc_wrappers.c delete mode 100644 CAN-binder/libs/nanopb/tests/common/malloc_wrappers.h delete mode 100644 CAN-binder/libs/nanopb/tests/common/malloc_wrappers_syshdr.h delete mode 100644 CAN-binder/libs/nanopb/tests/common/person.proto delete mode 100644 CAN-binder/libs/nanopb/tests/common/test_helpers.h delete mode 100644 CAN-binder/libs/nanopb/tests/common/unittestproto.proto delete mode 100644 CAN-binder/libs/nanopb/tests/common/unittests.h (limited to 'CAN-binder/libs/nanopb/tests/common') diff --git a/CAN-binder/libs/nanopb/tests/common/SConscript b/CAN-binder/libs/nanopb/tests/common/SConscript deleted file mode 100644 index 05e2f852..00000000 --- a/CAN-binder/libs/nanopb/tests/common/SConscript +++ /dev/null @@ -1,48 +0,0 @@ -# Build the common files needed by multiple test cases - -Import('env') - -# Protocol definitions for the encode/decode_unittests -env.NanopbProto("unittestproto") - -# Protocol definitions for basic_buffer/stream tests -env.NanopbProto("person") - -#-------------------------------------------- -# Binaries of the pb_decode.c and pb_encode.c -# These are built using more strict warning flags. -strict = env.Clone() -strict.Append(CFLAGS = strict['CORECFLAGS']) -strict.Object("pb_decode.o", "$NANOPB/pb_decode.c") -strict.Object("pb_encode.o", "$NANOPB/pb_encode.c") -strict.Object("pb_common.o", "$NANOPB/pb_common.c") - -#----------------------------------------------- -# Binaries of pb_decode etc. with malloc support -# Uses malloc_wrappers.c to count allocations. -malloc_env = env.Clone() -malloc_env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1, - 'PB_SYSTEM_HEADER': '\\"malloc_wrappers_syshdr.h\\"'}) -malloc_env.Append(CPPPATH = ["$COMMON"]) - -if 'SYSHDR' in malloc_env: - malloc_env.Append(CPPDEFINES = {'PB_OLD_SYSHDR': malloc_env['SYSHDR']}) - -# Disable libmudflap, because it will confuse valgrind -# and other memory leak detection tools. -if '-fmudflap' in env["CCFLAGS"]: - malloc_env["CCFLAGS"].remove("-fmudflap") - malloc_env["LINKFLAGS"].remove("-fmudflap") - malloc_env["LIBS"].remove("mudflap") - -malloc_strict = malloc_env.Clone() -malloc_strict.Append(CFLAGS = malloc_strict['CORECFLAGS']) -malloc_strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c") -malloc_strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c") -malloc_strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c") - -malloc_env.Object("malloc_wrappers.o", "malloc_wrappers.c") -malloc_env.Depends("$NANOPB/pb.h", ["malloc_wrappers_syshdr.h", "malloc_wrappers.h"]) - -Export("malloc_env") - diff --git a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.c b/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.c deleted file mode 100644 index ad69f1ce..00000000 --- a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "malloc_wrappers.h" -#include -#include -#include - -static size_t alloc_count = 0; - -/* Allocate memory and place check values before and after. */ -void* malloc_with_check(size_t size) -{ - size_t size32 = (size + 3) / 4 + 3; - uint32_t *buf = malloc(size32 * sizeof(uint32_t)); - buf[0] = size32; - buf[1] = 0xDEADBEEF; - buf[size32 - 1] = 0xBADBAD; - return buf + 2; -} - -/* Free memory allocated with malloc_with_check() and do the checks. */ -void free_with_check(void *mem) -{ - uint32_t *buf = (uint32_t*)mem - 2; - assert(buf[1] == 0xDEADBEEF); - assert(buf[buf[0] - 1] == 0xBADBAD); - free(buf); -} - -/* Track memory usage */ -void* counting_realloc(void *ptr, size_t size) -{ - /* Don't allocate crazy amounts of RAM when fuzzing */ - if (size > 1000000) - return NULL; - - if (!ptr && size) - alloc_count++; - - return realloc(ptr, size); -} - -void counting_free(void *ptr) -{ - if (ptr) - { - assert(alloc_count > 0); - alloc_count--; - free(ptr); - } -} - -size_t get_alloc_count() -{ - return alloc_count; -} diff --git a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.h b/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.h deleted file mode 100644 index 7eec7952..00000000 --- a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers.h +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void* malloc_with_check(size_t size); -void free_with_check(void *mem); -void* counting_realloc(void *ptr, size_t size); -void counting_free(void *ptr); -size_t get_alloc_count(); diff --git a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers_syshdr.h b/CAN-binder/libs/nanopb/tests/common/malloc_wrappers_syshdr.h deleted file mode 100644 index d295d9ed..00000000 --- a/CAN-binder/libs/nanopb/tests/common/malloc_wrappers_syshdr.h +++ /dev/null @@ -1,15 +0,0 @@ -/* This is just a wrapper in order to get our own malloc wrappers into nanopb core. */ - -#define pb_realloc(ptr,size) counting_realloc(ptr,size) -#define pb_free(ptr) counting_free(ptr) - -#ifdef PB_OLD_SYSHDR -#include PB_OLD_SYSHDR -#else -#include -#include -#include -#include -#endif - -#include diff --git a/CAN-binder/libs/nanopb/tests/common/person.proto b/CAN-binder/libs/nanopb/tests/common/person.proto deleted file mode 100644 index becefdf3..00000000 --- a/CAN-binder/libs/nanopb/tests/common/person.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto2"; - -import "nanopb.proto"; - -message Person { - required string name = 1 [(nanopb).max_size = 40]; - required int32 id = 2; - optional string email = 3 [(nanopb).max_size = 40]; - - enum PhoneType { - MOBILE = 0; - HOME = 1; - WORK = 2; - } - - message PhoneNumber { - required string number = 1 [(nanopb).max_size = 40]; - optional PhoneType type = 2 [default = HOME]; - } - - repeated PhoneNumber phone = 4 [(nanopb).max_count = 5]; -} diff --git a/CAN-binder/libs/nanopb/tests/common/test_helpers.h b/CAN-binder/libs/nanopb/tests/common/test_helpers.h deleted file mode 100644 index f77760a5..00000000 --- a/CAN-binder/libs/nanopb/tests/common/test_helpers.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Compatibility helpers for the test programs. */ - -#ifndef _TEST_HELPERS_H_ -#define _TEST_HELPERS_H_ - -#ifdef _WIN32 -#include -#include -#define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) - -#else -#define SET_BINARY_MODE(file) - -#endif - - -#endif diff --git a/CAN-binder/libs/nanopb/tests/common/unittestproto.proto b/CAN-binder/libs/nanopb/tests/common/unittestproto.proto deleted file mode 100644 index 23b5b97f..00000000 --- a/CAN-binder/libs/nanopb/tests/common/unittestproto.proto +++ /dev/null @@ -1,43 +0,0 @@ -syntax = "proto2"; - -import 'nanopb.proto'; - -message IntegerArray { - repeated int32 data = 1 [(nanopb).max_count = 10]; -} - -message FloatArray { - repeated float data = 1 [(nanopb).max_count = 10]; -} - -message StringMessage { - required string data = 1 [(nanopb).max_size = 10]; -} - -message BytesMessage { - required bytes data = 1 [(nanopb).max_size = 16]; -} - -message CallbackArray { - // We cheat a bit and use this message for testing other types, too. - // Nanopb does not care about the actual defined data type for callback - // fields. - repeated int32 data = 1; -} - -message IntegerContainer { - required IntegerArray submsg = 1; -} - -message CallbackContainer { - required CallbackArray submsg = 1; -} - -message CallbackContainerContainer { - required CallbackContainer submsg = 1; -} - -message StringPointerContainer { - repeated string rep_str = 1 [(nanopb).type = FT_POINTER]; -} - diff --git a/CAN-binder/libs/nanopb/tests/common/unittests.h b/CAN-binder/libs/nanopb/tests/common/unittests.h deleted file mode 100644 index c2b470ad..00000000 --- a/CAN-binder/libs/nanopb/tests/common/unittests.h +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#define COMMENT(x) printf("\n----" x "----\n"); -#define STR(x) #x -#define STR2(x) STR(x) -#define TEST(x) \ - if (!(x)) { \ - fprintf(stderr, "\033[31;1mFAILED:\033[22;39m " __FILE__ ":" STR2(__LINE__) " " #x "\n"); \ - status = 1; \ - } else { \ - printf("\033[32;1mOK:\033[22;39m " #x "\n"); \ - } - - -- cgit 1.2.3-korg