Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add environ functions #3

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"crates/driver_net",
"crates/driver_pci",
"crates/driver_virtio",
"crates/dtb",
"crates/flatten_objects",
"crates/handler_table",
"crates/kernel_guard",
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# - `MODE`: Build mode: release, debug
# - `LOG:` Logging level: warn, error, info, debug, trace
# - `V`: Verbose level: (empty), 1, 2
# - `ARGS`: Command-line arguments separated by comma. Only available when feature `alloc` is enabled.
# - `ENVS`: Environment variables, separated by comma between key value pairs. Only available when feature `alloc` is enabled.
# * App options:
# - `A` or `APP`: Path to the application
# - `FEATURES`: Features os ArceOS modules to be enabled.
Expand Down Expand Up @@ -53,6 +55,10 @@ NET_DEV ?= user
IP ?= 10.0.2.15
GW ?= 10.0.2.2

# args and envs
ARGS ?=
ENVS ?=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add this two parameter to the doc in the head of this file


# App type
ifeq ($(wildcard $(APP)),)
$(error Application path "$(APP)" is not valid)
Expand Down
3 changes: 3 additions & 0 deletions api/arceos_posix_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ extern crate axruntime;
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
pub use axruntime::{environ, environ_iter, RX_ENVIRON};

#[macro_use]
mod utils;

Expand Down
22 changes: 22 additions & 0 deletions apps/c/envtest/expect_info.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
smp = 1
build_mode = release
log_level = info

Primary CPU 0 started.
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
use TLSF allocator.
Initialize kernel page table...
Initialize platform devices...
Primary CPU 0 init OK.
Running argv tests...
Argv tests run OK!
Running environ tests...
Environ tests run OK!
Shutting down...
2 changes: 2 additions & 0 deletions apps/c/envtest/features.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alloc
paging
21 changes: 21 additions & 0 deletions apps/c/envtest/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
puts("Running argv tests...");
if (argc != 3) puts("args num is wrong");
if (strcmp(argv[0], "envtest") || strcmp(argv[1], "test1") || strcmp(argv[2], "test2")) puts("argv is wrong");
if(argv[3] != NULL) puts("argv is wrong");
puts("Argv tests run OK!");

puts("Running environ tests...");
char *env1 = "env1", *ex1 = "ex1", *ex2 = "ex_2";
if(setenv(env1, ex1, 1) || strcmp(ex1, getenv(env1))) puts("set new env is wrong");
if(setenv(env1, ex2, 1) || strcmp(ex2, getenv(env1))) puts("set old env is wrong");
if(setenv(env1, ex1, 0) || strcmp(ex2, getenv(env1))) puts("override the old env is wrong");
if(strcmp("hello", getenv("world")) || strcmp("world", getenv("hello"))) puts("boot env is wrong");
puts("Environ tests run OK!");
return 0;
}


2 changes: 2 additions & 0 deletions apps/c/envtest/test_cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_one "LOG=info ARGS=envtest,test1,test2 ENVS=hello=world,world=hello" "expect_info.out"
rm -f $APP/*.o
2 changes: 1 addition & 1 deletion apps/c/memtest/expect_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ allocated addr=0x[0-9a-f]\{16\}
allocated addr=0x[0-9a-f]\{16\}
allocated addr=0x[0-9a-f]\{16\}
Memory tests run OK!
Shutting down...
Shutting down...
2 changes: 1 addition & 1 deletion apps/c/memtest/memtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>

int main()
int main(int argc, char* argv[])
{
puts("Running memory tests...");
uintptr_t *brk = (uintptr_t *)malloc(0);
Expand Down
15 changes: 13 additions & 2 deletions apps/c/redis/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@

# How to run?
- Run:
- `make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=aarch64 SMP=4 run`(for aarch64)
- `make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=x86_64 SMP=4 run`(for x86_64)

- for aarch64

```
make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=aarch64 SMP=4 ARGS="./redis-server,--bind,0.0.0.0,--port,5555,--save,\"\",--appendonly,no,--protected-mode,no,--ignore-warnings,ARM64-COW-BUG" run
```

- for x86_64

```
make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=x86_64 SMP=4 ARGS="./redis-server,--bind,0.0.0.0,--port,5555,--save,\"\",--appendonly,no,--protected-mode,no" run
```


# How to test?
- Use `redis-cli -p 5555` to connect to redis-server, and enjoy ArceOS-Redis world!
Expand Down
24 changes: 2 additions & 22 deletions apps/c/redis/redis.patch
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,10 @@ index e4f7d90..1b41e94 100644

.PHONY: clean
diff --git a/src/server.c b/src/server.c
index b170cbb..f5dfde0 100644
index b170cbb..a3960ce 100644
--- a/src/server.c
+++ b/src/server.c
@@ -6854,6 +6854,19 @@ redisTestProc *getTestProcByName(const char *name) {
#endif

int main(int argc, char **argv) {
+ const char *cmdline = "./redis-server "
+ "--bind 0.0.0.0 "
+ "--port 5555 "
+ "--save \"\" "
+ "--appendonly no "
+ "--protected-mode no "
+#if defined (__arm64__)
+ "--ignore-warnings ARM64-COW-BUG "
+#endif
+ ;
+ printf("Run Redis with: %s\n", cmdline);
+ argv = sdssplitargs(cmdline, &argc);
+
struct timeval tv;
int j;
char config_from_stdin = 0;
@@ -6900,7 +6913,7 @@ int main(int argc, char **argv) {
@@ -6900,7 +6900,7 @@ int main(int argc, char **argv) {

/* We need to initialize our libraries, and the server configuration. */
#ifdef INIT_SETPROCTITLE_REPLACEMENT
Expand Down
14 changes: 14 additions & 0 deletions crates/dtb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "dtb"
version = "0.1.0"
edition = "2021"
authors = ["Leping Wang <[email protected]>"]
description = "Device tree basic operations"
license = "GPL-3.0-or-later OR Apache-2.0"
homepage = "https://github.com/rcore-os/arceos"
repository = "https://github.com/rcore-os/arceos/tree/main/crates/dtb"
documentation = "https://rcore-os.github.io/arceos/dtb/index.html"

[dependencies]
fdt-rs = { version = "0.4.3", default-features = false }
lazy_init = { path = "../../crates/lazy_init" }
Loading
Loading