Skip to content

Commit

Permalink
test fw
Browse files Browse the repository at this point in the history
  • Loading branch information
buhe committed Oct 4, 2021
1 parent 7524025 commit d12df3c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
67 changes: 65 additions & 2 deletions docs/插播2 测试内核.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,70 @@ fn test_runner(tests: &[&dyn Fn()]) {



```
cargo test --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]"
```makefile
# Building
TARGET := riscv64gc-unknown-none-elf
MODE := debug
KERNEL_BIN := $(KERNEL_ELF).bin

# BOARD
BOARD ?= k210
SBI ?= rustsbi
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
K210_BOOTLOADER_SIZE := 131072
LOG ?= TRACE

# Run K210
K210-SERIALPORT = /dev/tty.usbserial-35525425B50
K210-BURNER = ../tools/kflash.py

# Binutils
OBJCOPY := rust-objcopy --binary-architecture=riscv64

build: env $(KERNEL_BIN)

env:
(rustup target list | grep "riscv64gc-unknown-none-elf (installed)") || rustup target add $(TARGET)
cargo install cargo-binutils
rustup component add rust-src
rustup component add llvm-tools-preview

$(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@

kernel:
@echo Platform: $(BOARD)
@cd ../user && make build
$(eval KERNEL_ELF := $(shell cargo test --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]"))

clean:
@cargo clean

run: run-inner

run-inner: build
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)
@cp $(BOOTLOADER) $(BOOTLOADER).copy
@dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(K210_BOOTLOADER_SIZE) seek=1
@mv $(BOOTLOADER).copy $(KERNEL_BIN)
@sudo chmod 777 $(K210-SERIALPORT)
python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(KERNEL_BIN)
python3 -m serial.tools.miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210-SERIALPORT) 115200

path:
@echo $(BIN)
@echo $(INCLUDE)
@echo $(LIB)
@echo $(GDB)
@echo $(OPENOCD)

@echo
@$(BIN)/riscv64-unknown-elf-gcc --version
@echo
@$(GDB) --version
@echo
@$(OPENOCD) -f ./debug/k210.cfg

.PHONY: build env kernel clean run-inner path
```

Binary file added os/.bin
Binary file not shown.
3 changes: 1 addition & 2 deletions os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ kernel:
@echo Platform: $(BOARD)
@cd ../user && make build
$(eval KERNEL_ELF := $(shell cargo test --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]"))
@echo hi $(KERNEL_ELF)
at=human

clean:
@cargo clean

Expand Down
14 changes: 6 additions & 8 deletions os/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,26 @@ fn clear_bss() {

#[no_mangle]
extern "C" fn rust_main() -> ! {
#[cfg(test)]
test_main();

clear_bss();
heap::init();
heap::heap_test();
trap::init();
task::init();

#[cfg(test)]
test_main();

task::run();
}

#[cfg(test)]
fn test_runner(tests: &[&dyn Fn()]) {
println!("1111111Running {} tests", tests.len());
println!("Running {} tests", tests.len());
for test in tests {
test();
}
}

#[test_case]
fn trivial_assertion() {
print!("trivial assertion... ");
assert_eq!(1, 1);
println!("[ok]");
heap::heap_test();
}

0 comments on commit d12df3c

Please sign in to comment.