-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_simple.c
executable file
·66 lines (50 loc) · 1.39 KB
/
example_simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file simple.c
* @author Samsung R&D Poland - Mobile Security Group ([email protected])
*
*/
#include "common.h"
struct B {
unsigned char T[4];
};
struct A {
unsigned long X;
struct B *pB;
};
/********************************/
#ifdef __TESTER__
/********************************/
FUNCTION_DECLARE_FLATTEN_STRUCT(B);
FUNCTION_DECLARE_FLATTEN_STRUCT(A);
FUNCTION_DEFINE_FLATTEN_STRUCT(B);
FUNCTION_DEFINE_FLATTEN_STRUCT(A,
AGGREGATE_FLATTEN_STRUCT(B, pB);
);
static int kflat_simple_test(struct flat *flat) {
struct B b = { "ABC" };
struct A a = { 0x0000404F, &b };
struct A *pA = &a;
struct A *vpA = (struct A *)0xdeadbeefdabbad00;
FLATTEN_SETUP_TEST(flat);
FOR_ROOT_POINTER(pA,
FLATTEN_STRUCT(A, vpA);
FLATTEN_STRUCT(A, pA);
);
return FLATTEN_FINISH_TEST(flat);
}
/********************************/
#endif /* __TESTER__ */
#ifdef __VALIDATOR__
/********************************/
static int kflat_simple_validate(void *memory, size_t size, CUnflatten flatten) {
struct A *pA = (struct A *)memory;
ASSERT(pA->X == 0x0000404F);
ASSERT(!strcmp((const char *)pA->pB->T, "ABC"));
PRINT("struct A = {.X = 0x%08lx, .pB = \"%s\"}",
pA->X, pA->pB->T);
return KFLAT_TEST_SUCCESS;
}
/********************************/
#endif /* __VALIDATOR__ */
/********************************/
KFLAT_REGISTER_TEST_FLAGS("SIMPLE", kflat_simple_test, kflat_simple_validate, KFLAT_TEST_ATOMIC);