aboutsummaryrefslogtreecommitdiff
path: root/tests/libsqfs/abi.c
blob: 04bbc30a01188e01fe2f31ebf1112ed87f3c2ffe (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * abi.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"

#include "sqfs/block_processor.h"
#include "sqfs/compressor.h"
#include "sqfs/block.h"
#include "../test.h"

#include <stddef.h>

static void test_compressor_opt_struct(void)
{
	sqfs_compressor_config_t cfg;

	TEST_EQUAL_UI(sizeof(cfg.id), sizeof(sqfs_u16));
	TEST_EQUAL_UI(sizeof(cfg.flags), sizeof(sqfs_u16));
	TEST_EQUAL_UI(sizeof(cfg.block_size), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(cfg.level), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(cfg.opt), (2 * sizeof(sqfs_u64)));

	TEST_EQUAL_UI(sizeof(cfg.opt.gzip), sizeof(cfg.opt));
	TEST_EQUAL_UI(sizeof(cfg.opt.lzo), sizeof(cfg.opt));
	TEST_EQUAL_UI(sizeof(cfg.opt.xz), sizeof(cfg.opt));
	TEST_EQUAL_UI(sizeof(cfg.opt.padd0), sizeof(cfg.opt));

	TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, id), 0);
	TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, flags),
		      sizeof(sqfs_u16));
	TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, block_size),
		      sizeof(sqfs_u32));
	TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, level),
		      (2 * sizeof(sqfs_u32)));
	TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, opt),
		      (4 * sizeof(sqfs_u32)));
}

static const char *names[] = {
	[SQFS_COMP_GZIP] = "gzip",
	[SQFS_COMP_LZMA] = "lzma",
	[SQFS_COMP_LZO] = "lzo",
	[SQFS_COMP_XZ] = "xz",
	[SQFS_COMP_LZ4] = "lz4",
	[SQFS_COMP_ZSTD] = "zstd",
};

static void test_compressor_names(void)
{
	const char *str;
	int i, id;

	for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) {
		str = sqfs_compressor_name_from_id(i);
		TEST_STR_EQUAL(str, names[i]);

		id = sqfs_compressor_id_from_name(str);
		TEST_EQUAL_I(id, i);
	}
}

static void test_blockproc_stats(void)
{
	sqfs_block_processor_stats_t stats;

	TEST_ASSERT(sizeof(stats) >= (8 * sizeof(sqfs_u64)));

	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t, size), 0);
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       input_bytes_read), sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       output_bytes_generated), 2 * sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       data_block_count), 3 * sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       frag_block_count), 4 * sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       sparse_block_count), 5 * sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       total_frag_count), 6 * sizeof(sqfs_u64));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
			       actual_frag_count), 7 * sizeof(sqfs_u64));

	TEST_EQUAL_UI(sizeof(stats.size), sizeof(size_t));
	TEST_EQUAL_UI(sizeof(stats.input_bytes_read), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.output_bytes_generated), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.data_block_count), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.frag_block_count), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.sparse_block_count), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.total_frag_count), sizeof(sqfs_u64));
	TEST_EQUAL_UI(sizeof(stats.actual_frag_count), sizeof(sqfs_u64));
}

static void test_blockproc_desc(void)
{
	sqfs_block_processor_desc_t desc;

	TEST_ASSERT(sizeof(desc) >= (4 * sizeof(sqfs_u32) +
				     5 * sizeof(void *)));

	TEST_EQUAL_UI(sizeof(desc.size), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(desc.max_block_size), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(desc.num_workers), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(desc.max_backlog), sizeof(sqfs_u32));
	TEST_EQUAL_UI(sizeof(desc.cmp), sizeof(void *));
	TEST_EQUAL_UI(sizeof(desc.wr), sizeof(void *));
	TEST_EQUAL_UI(sizeof(desc.tbl), sizeof(void *));
	TEST_EQUAL_UI(sizeof(desc.file), sizeof(void *));
	TEST_EQUAL_UI(sizeof(desc.uncmp), sizeof(void *));

	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, size), 0);
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, max_block_size),
		      sizeof(sqfs_u32));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, num_workers),
		      (2 * sizeof(sqfs_u32)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, max_backlog),
		      (3 * sizeof(sqfs_u32)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, cmp),
		      (4 * sizeof(sqfs_u32)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, wr),
		      (4 * sizeof(sqfs_u32) + sizeof(void *)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, tbl),
		      (4 * sizeof(sqfs_u32) + 2 * sizeof(void *)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, file),
		      (4 * sizeof(sqfs_u32) + 3 * sizeof(void *)));
	TEST_EQUAL_UI(offsetof(sqfs_block_processor_desc_t, uncmp),
		      (4 * sizeof(sqfs_u32) + 4 * sizeof(void *)));
}

int main(void)
{
	test_compressor_opt_struct();
	test_compressor_names();
	test_blockproc_stats();
	test_blockproc_desc();
	return EXIT_SUCCESS;
}