1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-29 21:47:30 +03:00

ctdb-tests: Add test templates for various data types

These test templates will use new style of len/push/pull functions.
The differences in the new style of marshalling functions are:

1. len/push functions will be passed pointer to a value instead of the value
2. push/pull functions will additionally return the number of bytes consumed

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-27 17:38:47 +10:00 committed by Martin Schwenke
parent c16d2585bc
commit 62229f4c93

@ -58,6 +58,87 @@ static void TEST_FUNC(NAME)(void) \
talloc_free(mem_ctx); \
}
/*
* Test for basic data types that do not need memory allocation
* For example - int32_t, uint32_t, uint64_t
*/
#define PROTOCOL_TYPE1_TEST(TYPE, NAME) \
static void TEST_FUNC(NAME)(void) \
{ \
TYPE p1; \
TYPE p2; \
size_t buflen, np = 0; \
int ret; \
\
FILL_FUNC(NAME)(&p1); \
buflen = LEN_FUNC(NAME)(&p1); \
assert(buflen < sizeof(BUFFER)); \
PUSH_FUNC(NAME)(&p1, BUFFER, &np); \
assert(np == buflen); \
np = 0; \
ret = PULL_FUNC(NAME)(BUFFER, buflen, &p2, &np); \
assert(ret == 0); \
assert(np == buflen); \
VERIFY_FUNC(NAME)(&p1, &p2); \
}
/*
* Test for container data types that need memory allocation for sub-elements
* For example - TDB_DATA
*/
#define PROTOCOL_TYPE2_TEST(TYPE, NAME) \
static void TEST_FUNC(NAME)(void) \
{ \
TALLOC_CTX *mem_ctx; \
TYPE p1; \
TYPE p2; \
size_t buflen, np = 0; \
int ret; \
\
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
FILL_FUNC(NAME)(mem_ctx, &p1); \
buflen = LEN_FUNC(NAME)(&p1); \
assert(buflen < sizeof(BUFFER)); \
PUSH_FUNC(NAME)(&p1, BUFFER, &np); \
assert(np == buflen); \
np = 0; \
ret = PULL_FUNC(NAME)(BUFFER, buflen, mem_ctx, &p2, &np); \
assert(ret == 0); \
assert(np == buflen); \
VERIFY_FUNC(NAME)(&p1, &p2); \
talloc_free(mem_ctx); \
}
/*
* Test for derived data types that need memory allocation
* For example - most ctdb structures
*/
#define PROTOCOL_TYPE3_TEST(TYPE, NAME) \
static void TEST_FUNC(NAME)(void) \
{ \
TALLOC_CTX *mem_ctx; \
TYPE *p1, *p2; \
size_t buflen, np = 0; \
int ret; \
\
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
p1 = talloc_zero(mem_ctx, TYPE); \
assert(p1 != NULL); \
FILL_FUNC(NAME)(p1, p1); \
buflen = LEN_FUNC(NAME)(p1); \
assert(buflen < sizeof(BUFFER)); \
PUSH_FUNC(NAME)(p1, BUFFER, &np); \
assert(np == buflen); \
np = 0; \
ret = PULL_FUNC(NAME)(BUFFER, buflen, mem_ctx, &p2, &np); \
assert(ret == 0); \
assert(np == buflen); \
VERIFY_FUNC(NAME)(p1, p2); \
talloc_free(mem_ctx); \
}
extern uint8_t BUFFER[1024*1024];
int rand_int(int max);