| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "meminfo.h" |
| 24 |
#include "testutils.h" |
| 25 |
#include "units.h" |
| 26 |
|
| 27 |
typedef struct test_data |
| 28 |
{ |
| 29 |
unsigned long long memsize; |
| 30 |
unsigned long long expect_value; |
| 31 |
unit_shift shift; |
| 32 |
} test_data; |
| 33 |
|
| 34 |
static int |
| 35 |
test_memory_unit_conversion (const void *tdata) |
| 36 |
{ |
| 37 |
const struct test_data *data = tdata; |
| 38 |
int ret = 0; |
| 39 |
|
| 40 |
TEST_ASSERT_EQUAL_NUMERIC ( |
| 41 |
UNIT_CONVERT (data->memsize, data->shift), data->expect_value); |
| 42 |
return ret; |
| 43 |
} |
| 44 |
|
| 45 |
static int |
| 46 |
mymain (void) |
| 47 |
{ |
| 48 |
int ret = 0; |
| 49 |
|
| 50 |
#define KILO 1024UL |
| 51 |
#define MEGA KILO*KILO |
| 52 |
|
| 53 |
#define DO_TEST(MSG, MEMSIZE, SHIFT, EXPECT_VALUE) \ |
| 54 |
do \ |
| 55 |
{ \ |
| 56 |
test_data data = { \ |
| 57 |
.memsize = MEMSIZE, \ |
| 58 |
.shift = SHIFT, \ |
| 59 |
.expect_value = EXPECT_VALUE, \ |
| 60 |
}; \ |
| 61 |
if (test_run(MSG, test_memory_unit_conversion, &data) < 0) \ |
| 62 |
ret = -1; \ |
| 63 |
} \ |
| 64 |
while (0) |
| 65 |
|
| 66 |
|
| 67 |
DO_TEST ("check memory size conversion into kbytes", |
| 68 |
KILO, k_shift, KILO); |
| 69 |
DO_TEST ("check memory size conversion into mbytes", |
| 70 |
2*KILO, m_shift, 2UL); |
| 71 |
DO_TEST ("check memory size conversion into gbytes", |
| 72 |
4*MEGA, g_shift, 4UL); |
| 73 |
|
| 74 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 75 |
} |
| 76 |
|
| 77 |
TEST_MAIN (mymain) |