()
| 1183 | let (uart, exit) = run_kernel_hll(runtime_source("kernel/core/my_kernel.hll")); |
| 1184 | // When no user binary is present the kernel shuts down cleanly after |
| 1185 | // spawn_user_process returns. Verify the critical checkpoints. |
| 1186 | assert!( |
| 1187 | uart.contains("[ OK ] kernel starting\n"), |
| 1188 | "missing kernel start; uart={uart:?}" |
| 1189 | ); |
| 1190 | assert!( |
| 1191 | uart.contains("[ OK ] sv39 enabled\n"), |
| 1192 | "missing MMU enable; uart={uart:?}" |
| 1193 | ); |
| 1194 | assert!( |
| 1195 | uart.contains("[ WARN ] no user binary present"), |
| 1196 | "missing user binary skip; uart={uart:?}" |
| 1197 | ); |
| 1198 | assert_eq!(exit, Some(0), "kernel must exit with code 0; uart={uart:?}"); |
| 1199 | } |
| 1200 | |
| 1201 | // Verify that linking kernel stdlib with user code that has no `kmain` fails |
| 1202 | // at link time with an error mentioning `kmain`. |
| 1203 | #[test] |
| 1204 | fn kernel_boot_missing_kmain_is_assemble_error() { |
| 1205 | let stdlib_objs = CompilationPipeline::compile_stdlib_objects(TargetMode::Kernel) |
| 1206 | .expect("kernel stdlib compile"); |
| 1207 | |
| 1208 | // A hosted `main` program - no `kmain` defined. |
| 1209 | let mut user_pipeline = CompilationPipeline::new(); |
| 1210 | user_pipeline.set_write_artifacts(false); |
| 1211 | let user = user_pipeline |
| 1212 | .compile("main: () -> i32 { return 0 }") |
| 1213 | .expect("user compile"); |
| 1214 | let (_, user_tokens) = user_pipeline |
| 1215 | .compile_ir_to_assembly_with_tokens(&user.ir_program) |
| 1216 | .expect("valid IR layout"); |
| 1217 | let user_obj = user_pipeline.assemble(&user_tokens).expect("user assemble"); |
| 1218 | |
| 1219 | let mut modules: Vec<(&str, &AssembledOutput)> = |
| 1220 | stdlib_objs.iter().map(|(n, o)| (n.as_str(), o)).collect(); |
| 1221 | modules.push(("user", &user_obj)); |
| 1222 | let result = user_pipeline.link_assembled_objects(&modules); |
| 1223 | assert!( |
| 1224 | result.is_err(), |
| 1225 | "expected link to fail when kmain is missing" |
| 1226 | ); |
| 1227 | let err = result.unwrap_err(); |
| 1228 | assert!( |
| 1229 | err.message.contains("kmain"), |
| 1230 | "expected error to mention 'kmain', got: {}", |
| 1231 | err.message |
nothing calls this directly
no test coverage detected