Skip to content

Commit b428727

Browse files
committed
fake: screen: fix fake screen impl
the kernel will not issue an upcall if the command returns an error.
1 parent e964e2e commit b428727

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

unittest/src/fake/screen/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ impl crate::fake::SyscallDriver for Screen {
163163
}
164164

165165
GET_RESOLUTION_WIDTH_HEIGHT => {
166-
self.share_ref
167-
.schedule_upcall(0, (0, 0, 0))
168-
.expect("Unable to schedule upcall {}");
169166
if argument0 < self.screen_resolution_width_height.len() as u32 {
170167
if Option::is_some(&self.screen_setup) {
168+
self.share_ref
169+
.schedule_upcall(0, (0, 0, 0))
170+
.expect("Unable to schedule upcall {}");
171171
crate::command_return::success_2_u32(
172172
self.screen_resolution_width_height[argument0 as usize]
173173
.unwrap()
@@ -193,11 +193,11 @@ impl crate::fake::SyscallDriver for Screen {
193193
}
194194

195195
PIXEL_FORMAT => {
196-
self.share_ref
197-
.schedule_upcall(0, (0, 0, 0))
198-
.expect("Unable to schedule upcall {}");
199196
if argument0 < self.screen_pixel_format.len() as u32 {
200197
if Option::is_some(&self.screen_setup) {
198+
self.share_ref
199+
.schedule_upcall(0, (0, 0, 0))
200+
.expect("Unable to schedule upcall {}");
201201
crate::command_return::success_u32(
202202
self.screen_pixel_format[argument0 as usize] as u32,
203203
)
@@ -217,13 +217,13 @@ impl crate::fake::SyscallDriver for Screen {
217217
}
218218

219219
SET_ROTATION => {
220-
self.share_ref
221-
.schedule_upcall(0, (0, 0, 0))
222-
.expect("Unable to schedule upcall {}");
223220
if argument0 > 359 {
224221
command_return::failure(ErrorCode::Invalid)
225222
} else {
226223
self.rotation.set(argument0 as u16);
224+
self.share_ref
225+
.schedule_upcall(0, (0, 0, 0))
226+
.expect("Unable to schedule upcall {}");
227227
command_return::success()
228228
}
229229
}
@@ -245,11 +245,11 @@ impl crate::fake::SyscallDriver for Screen {
245245
GET_PIXEL_FORMAT => command_return::success_u32(self.pixel_format.get()),
246246

247247
SET_PIXEL_FORMAT => {
248-
self.share_ref
249-
.schedule_upcall(0, (0, 0, 0))
250-
.expect("Unable to schedule upcall {}");
251248
if argument0 < self.pixel_modes.unwrap() as u32 {
252249
self.pixel_format.set(argument0);
250+
self.share_ref
251+
.schedule_upcall(0, (0, 0, 0))
252+
.expect("Unable to schedule upcall {}");
253253
command_return::success()
254254
} else {
255255
command_return::failure(ErrorCode::Invalid)

unittest/src/fake/screen/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ fn command() {
6969
// Set and validate pixel format
7070
assert!(screen.command(SET_PIXEL_FORMAT, 1, 0).is_success());
7171

72+
// Ensure that an invalid pixel format returns an error.
73+
assert!(screen.command(SET_PIXEL_FORMAT, 99999, 0).is_failure());
74+
7275
// Kernel setup for screen and buffer simulation
7376
let kernel = fake::Kernel::new();
7477
kernel.add_driver(&screen);

0 commit comments

Comments
 (0)