Skip to content

Commit af504e8

Browse files
committed
domains: refactor start and shift in sdf
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent ac0a878 commit af504e8

8 files changed

Lines changed: 26 additions & 100 deletions

tool/microkit/src/sdf.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,13 +1133,30 @@ impl DomainSchedule {
11331133

11341134
let pos = xml_sdf.doc.text_pos_at(node.range().start);
11351135

1136-
check_attributes(xml_sdf, node, &[])?;
1136+
check_attributes(xml_sdf, node, &["index_shift", "start_index"])?;
1137+
1138+
let index_shift = if let Some(xml_index_shift) = node.attribute("index_shift") {
1139+
match sdf_parse_number(xml_index_shift, node) {
1140+
Ok(val) => Some(val),
1141+
Err(_) => return Err("Error: invalid domain index shift".to_string())
1142+
}
1143+
} else {
1144+
None
1145+
};
1146+
1147+
let start_index = if let Some(xml_start_index) = node.attribute("start_index") {
1148+
match sdf_parse_number(xml_start_index, node) {
1149+
Ok(val) => val,
1150+
Err(_) => return Err("Error: invalid domain start index".to_string())
1151+
}
1152+
} else {
1153+
0
1154+
};
1155+
11371156

11381157
let mut next_domain_id = 0;
11391158
let mut domain_ids = HashMap::new();
11401159
let mut schedule = Vec::new();
1141-
let mut domain_start_idx: Option<u64> = None;
1142-
let mut domain_idx_shift: Option<u64> = None;
11431160
for child in node.children() {
11441161
if !child.is_element() {
11451162
continue;
@@ -1186,34 +1203,6 @@ impl DomainSchedule {
11861203
length: length.unwrap(),
11871204
});
11881205
}
1189-
"domain_start" => {
1190-
if let Some(domain_start_idx) = domain_start_idx {
1191-
return Err(format!(
1192-
"Error: Duplicate setting of domain start index, already set to '{}'",
1193-
domain_start_idx
1194-
));
1195-
}
1196-
check_attributes(xml_sdf, &child, &["index"])?;
1197-
let start_index = checked_lookup(xml_sdf, &child, "index")?.parse::<u64>();
1198-
if start_index.is_err() {
1199-
return Err("Error: invalid domain start index".to_string());
1200-
}
1201-
domain_start_idx = Some(start_index.unwrap());
1202-
}
1203-
"domain_idx_shift" => {
1204-
if let Some(domain_idx_shift) = domain_idx_shift {
1205-
return Err(format!(
1206-
"Error: Duplicate setting of domain index shift, already set to '{}'",
1207-
domain_idx_shift
1208-
));
1209-
}
1210-
check_attributes(xml_sdf, &child, &["shift"])?;
1211-
let index_shift = checked_lookup(xml_sdf, &child, "shift")?.parse::<u64>();
1212-
if index_shift.is_err() {
1213-
return Err("Error: invalid domain index shift".to_string());
1214-
}
1215-
domain_idx_shift = Some(index_shift.unwrap());
1216-
}
12171206
_ => {
12181207
return Err(format!(
12191208
"Error: invalid XML element '{}': {}",
@@ -1224,16 +1213,11 @@ impl DomainSchedule {
12241213
}
12251214
}
12261215

1227-
// We are defaulting the set start to 0 if none has been specified.
1228-
if domain_start_idx.is_none() {
1229-
domain_start_idx = Some(0);
1230-
}
1231-
12321216
Ok(DomainSchedule {
12331217
domain_ids,
12341218
schedule,
1235-
domain_start_idx,
1236-
domain_idx_shift,
1219+
domain_start_idx: Some(start_index),
1220+
domain_idx_shift: index_shift,
12371221
})
12381222
}
12391223
}

tool/microkit/tests/sdf/domain_duplicate_index_shift.system

Lines changed: 0 additions & 18 deletions
This file was deleted.

tool/microkit/tests/sdf/domain_duplicate_start_index.system

Lines changed: 0 additions & 18 deletions
This file was deleted.

tool/microkit/tests/sdf/domain_invalid_shift.system

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
SPDX-License-Identifier: BSD-2-Clause
66
-->
77
<system>
8-
<domain_schedule>
8+
<domain_schedule index_shift="zz">
99
<domain name="domain_1" length="1000000" />
10-
<domain_idx_shift shift="zz" />
1110
</domain_schedule>
1211

1312
<protection_domain name="test1" domain="domain_1">

tool/microkit/tests/sdf/domain_invalid_start_index.system

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
SPDX-License-Identifier: BSD-2-Clause
66
-->
77
<system>
8-
<domain_schedule>
8+
<domain_schedule start_index="zz">
99
<domain name="domain_1" length="1000000" />
10-
<domain_start index="zz" />
1110
</domain_schedule>
1211

1312
<protection_domain name="test1" domain="domain_1">

tool/microkit/tests/sdf/domain_out_of_bounds_shift.system

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
SPDX-License-Identifier: BSD-2-Clause
66
-->
77
<system>
8-
<domain_schedule>
8+
<domain_schedule index_shift="1000">
99
<domain name="domain_1" length="1000000" />
10-
<domain_idx_shift shift="1000" />
1110
</domain_schedule>
1211

1312
<protection_domain name="test1" domain="domain_1">

tool/microkit/tests/sdf/domain_out_of_bounds_start_index.system

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
SPDX-License-Identifier: BSD-2-Clause
66
-->
77
<system>
8-
<domain_schedule>
8+
<domain_schedule start_index="2">
99
<domain name="domain_1" length="1000000" />
10-
<domain_start index="2" />
1110
</domain_schedule>
1211

1312
<protection_domain name="test1" domain="domain_1">

tool/microkit/tests/test.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -863,24 +863,6 @@ mod domains {
863863
)
864864
}
865865

866-
#[test]
867-
fn test_domain_duplicate_start_index() {
868-
check_error(
869-
&DEFAULT_AARCH64_KERNEL_CONFIG,
870-
"domain_duplicate_start_index.system",
871-
"Error: Duplicate setting of domain start index, already set to '1'",
872-
)
873-
}
874-
875-
#[test]
876-
fn test_domain_duplicate_index_shift() {
877-
check_error(
878-
&DEFAULT_AARCH64_KERNEL_CONFIG,
879-
"domain_duplicate_index_shift.system",
880-
"Error: Duplicate setting of domain index shift, already set to '1'",
881-
)
882-
}
883-
884866
}
885867

886868
#[cfg(test)]

0 commit comments

Comments
 (0)