intel/genxml: Add new test for subgroups.
Make sure that a <group> tag within another <group> tag work just fine. v2: rename 'halfbyte' to 'byte' to match the size (Lionel). Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
@@ -9,4 +9,12 @@
|
||||
</group>
|
||||
</struct>
|
||||
|
||||
<struct name="STRUCT_TWO_LEVELS" length="8">
|
||||
<group count="4" start="0" size="64">
|
||||
<group count="8" start="0" size="8">
|
||||
<field name="byte" start="0" end="7" type="uint"/>
|
||||
</group>
|
||||
</group>
|
||||
</struct>
|
||||
|
||||
</genxml>
|
||||
|
||||
@@ -90,6 +90,41 @@ test_struct(struct gen_spec *spec) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_two_levels(struct gen_spec *spec) {
|
||||
struct GEN9_STRUCT_TWO_LEVELS test;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
test.byte[i][j] = (i * 10 + j) % 256;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t dw[GEN9_STRUCT_TWO_LEVELS_length];
|
||||
GEN9_STRUCT_TWO_LEVELS_pack(NULL, dw, &test);
|
||||
|
||||
struct gen_group *group;
|
||||
group = gen_spec_find_struct(spec, "STRUCT_TWO_LEVELS");
|
||||
|
||||
assert(group != NULL);
|
||||
|
||||
if (!quiet) {
|
||||
printf("\nSTRUCT_TWO_LEVELS\n");
|
||||
gen_print_group(stdout, group, 0, dw, 0, false);
|
||||
}
|
||||
|
||||
struct gen_field_iterator iter;
|
||||
gen_field_iterator_init(&iter, group, dw, 0, false);
|
||||
|
||||
while (gen_field_iterator_next(&iter)) {
|
||||
int i, j;
|
||||
|
||||
assert(sscanf(iter.name, "byte[%d][%d]", &i, &j) == 2);
|
||||
uint8_t number = iter.raw_value;
|
||||
assert(number == test.byte[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct gen_spec *spec = gen_spec_load_filename(GENXML_PATH);
|
||||
@@ -98,6 +133,7 @@ int main(int argc, char **argv)
|
||||
quiet = true;
|
||||
|
||||
test_struct(spec);
|
||||
test_two_levels(spec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user