mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
2
user/apps/test-blockcache/.cargo/config.toml
Normal file
2
user/apps/test-blockcache/.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[build]
|
||||
target = "x86_64-unknown-linux-musl"
|
3
user/apps/test-blockcache/.gitignore
vendored
Normal file
3
user/apps/test-blockcache/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
/install/
|
10
user/apps/test-blockcache/Cargo.toml
Normal file
10
user/apps/test-blockcache/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "test-blockcache"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "用于测试blockcac小程序"
|
||||
authors = [ "ZZJJWarth <2678328250@qq.com>" ]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
41
user/apps/test-blockcache/Makefile
Normal file
41
user/apps/test-blockcache/Makefile
Normal file
@ -0,0 +1,41 @@
|
||||
# The toolchain we use.
|
||||
# You can get it by running DragonOS' `tools/bootstrap.sh`
|
||||
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux_dragonos-gnu"
|
||||
RUSTFLAGS+="-C target-feature=+crt-static -C link-arg=-no-pie"
|
||||
|
||||
# 如果是在dadk中编译,那么安装到dadk的安装目录中
|
||||
INSTALL_DIR?=$(DADK_CURRENT_BUILD_DIR)
|
||||
# 如果是在本地编译,那么安装到当前目录下的install目录中
|
||||
INSTALL_DIR?=./install
|
||||
|
||||
|
||||
run:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run
|
||||
|
||||
build:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build
|
||||
|
||||
clean:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean
|
||||
|
||||
test:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test
|
||||
|
||||
doc:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc
|
||||
|
||||
run-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --release
|
||||
|
||||
build-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --release
|
||||
|
||||
clean-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --release
|
||||
|
||||
test-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --release
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --path . --no-track --root $(INSTALL_DIR) --force
|
8
user/apps/test-blockcache/README.md
Normal file
8
user/apps/test-blockcache/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
## 程序说明
|
||||
用于测试BlockCache的测试程序
|
||||
本程序生成一个文件,并开始对这个文件进行单纯的读操作(共读10000次)
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 打开系统的/bin目录
|
||||
2. 输入指令exec test-blockcache即可开始测试
|
22
user/apps/test-blockcache/src/main.rs
Normal file
22
user/apps/test-blockcache/src/main.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read, Seek, SeekFrom, Write};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let file_size_bytes: u64 = 512;
|
||||
let mut file = File::create("large_file")?;
|
||||
file.seek(std::io::SeekFrom::Start(file_size_bytes - 1))?;
|
||||
file.write_all(&[0])?;
|
||||
let mut file = File::open("large_file")?;
|
||||
// let mut reader = BufReader::new(file);
|
||||
let mut buffer = [0; 512];
|
||||
let mut count = 0;
|
||||
loop {
|
||||
count += 1;
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
let bytes_read = file.read_exact(&mut buffer)?;
|
||||
if count > 10000 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user