mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
2
user/apps/test_alarm/.cargo/config.toml
Normal file
2
user/apps/test_alarm/.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[build]
|
||||
target = "x86_64-unknown-linux-musl"
|
3
user/apps/test_alarm/.gitignore
vendored
Normal file
3
user/apps/test_alarm/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
/install/
|
12
user/apps/test_alarm/Cargo.toml
Normal file
12
user/apps/test_alarm/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "test_alarm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "test for alarm"
|
||||
authors = [ "smallc <2628035541@qq.com>" ]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.0"
|
||||
nix = "0.23.0"
|
56
user/apps/test_alarm/Makefile
Normal file
56
user/apps/test_alarm/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu"
|
||||
RUSTFLAGS+=""
|
||||
|
||||
ifdef DADK_CURRENT_BUILD_DIR
|
||||
# 如果是在dadk中编译,那么安装到dadk的安装目录中
|
||||
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
|
||||
else
|
||||
# 如果是在本地编译,那么安装到当前目录下的install目录中
|
||||
INSTALL_DIR = ./install
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
export RUST_TARGET=riscv64gc-unknown-linux-gnu
|
||||
else
|
||||
# 默认为x86_86,用于本地编译
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
endif
|
||||
|
||||
run:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET)
|
||||
|
||||
build:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
|
||||
|
||||
clean:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET)
|
||||
|
||||
test:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET)
|
||||
|
||||
doc:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc --target $(RUST_TARGET)
|
||||
|
||||
fmt:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
|
||||
|
||||
fmt-check:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check
|
||||
|
||||
run-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --release
|
||||
|
||||
build-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release
|
||||
|
||||
clean-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release
|
||||
|
||||
test-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET) --release
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force
|
4
user/apps/test_alarm/README.md
Normal file
4
user/apps/test_alarm/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# sysalarm调用测试
|
||||
## 测试流程
|
||||
首先测试能否正常启用sysalarm系统调用,然后测试在上一个alarm未结束时调用alarm能否取消上一个,返回剩余时间,启动下一个alarm
|
||||
|
42
user/apps/test_alarm/src/main.rs
Normal file
42
user/apps/test_alarm/src/main.rs
Normal file
@ -0,0 +1,42 @@
|
||||
extern crate libc;
|
||||
use libc::{signal, sleep, syscall, SYS_alarm, SIGALRM};
|
||||
|
||||
extern "C" fn handle_alarm(_: i32) {
|
||||
println!("Alarm ring!");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// 设置信号处理函数
|
||||
unsafe {
|
||||
signal(SIGALRM, handle_alarm as usize);
|
||||
}
|
||||
|
||||
//test1: alarm系统调用能否正常运行
|
||||
unsafe {
|
||||
syscall(SYS_alarm, 5);
|
||||
}
|
||||
println!("Alarm set for 5 seconds");
|
||||
unsafe {
|
||||
sleep(6);
|
||||
}
|
||||
println!("Test 1 complete");
|
||||
|
||||
//test2:在上一个alarm定时器未完成时重新调用alarm,查看返回值是否为上一个alarm的剩余秒数,
|
||||
//并test第三个alarm定时器能否正常运行
|
||||
|
||||
unsafe {
|
||||
let remaining = syscall(SYS_alarm, 5);
|
||||
println!("Remaining time for previous alarm: {}", remaining);
|
||||
}
|
||||
println!("Alarm set for 5 seconds");
|
||||
unsafe {
|
||||
let remaining = syscall(SYS_alarm, 3);
|
||||
println!("Remaining time for previous alarm: {}", remaining);
|
||||
}
|
||||
unsafe {
|
||||
sleep(4);
|
||||
}
|
||||
println!("Alarm set for 3 seconds");
|
||||
|
||||
println!("Test 2 complete");
|
||||
}
|
26
user/dadk/config/test_alarm_0_1_0.dadk
Normal file
26
user/dadk/config/test_alarm_0_1_0.dadk
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "test_alarm",
|
||||
"version": "0.1.0",
|
||||
"description": "test for alarm",
|
||||
"rust_target": null,
|
||||
"task_type": {
|
||||
"BuildFromSource": {
|
||||
"Local": {
|
||||
"path": "apps/test_alarm"
|
||||
}
|
||||
}
|
||||
},
|
||||
"depends": [],
|
||||
"build": {
|
||||
"build_command": "make install"
|
||||
},
|
||||
"install": {
|
||||
"in_dragonos_path": "/"
|
||||
},
|
||||
"clean": {
|
||||
"clean_command": "make clean"
|
||||
},
|
||||
"envs": [],
|
||||
"build_once": false,
|
||||
"install_once": false
|
||||
}
|
Reference in New Issue
Block a user