Skip to content

Commit 6f6c6d8

Browse files
authored
[shell] Adds a generic, portable shell library. (project-chip#998)
* [shell] Adds a generic, portable shell library. - Command line interface (cli) registration, parsing, and dispatch. - Retargetable streamer object for input / output. - Stdio-based streamer implementation for posix platforms. - Default commands: help, echo. Other changes during review: - Build stdio streamer on UNIX only. ASF attribution. - Mark nRF5 as embedded. Reorder includes. - Add shell app to CI and VSCODE. - Add missing build script. - Fix standalone linker to use c++. Added base64 command. - Converted all sources to C++ and wrapped in namespace chip::Shell. - Fix shell_command naming consistancy. Shorten type names. - Extend shell to support hierarchical subcommands. - Added Doxygen. Plus PR comment resolution: - Moved location to `src/lib/shell`. - Use test driver pattern for TestShell - Use .cpp extension rather than .cc * [shell] Review comments -- improve tokenizer space handling and unit tests.
1 parent c35d12b commit 6f6c6d8

30 files changed

+1654
-101
lines changed

.circleci/config.yml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config/jobs/examples_standalone.yml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ steps:
1616
- run:
1717
name: Build example Standalone Echo Client
1818
command: scripts/examples/standalone_echo_client.sh
19+
- run:
20+
name: Build example Standalone Shell
21+
command: scripts/examples/standalone_shell.sh
1922
- run:
2023
name: Preserve artifacts
2124
command: |

.circleci/config/jobs/test.yml

+48-50
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
parameters:
2-
builder:
3-
type: string
4-
run_setup_payload_tests:
5-
type: boolean
6-
default: true
2+
builder:
3+
type: string
4+
run_setup_payload_tests:
5+
type: boolean
6+
default: true
77
environment:
8-
BUILD_TYPE: << parameters.builder >>
8+
BUILD_TYPE: << parameters.builder >>
99
executor: << parameters.builder >>
1010
steps:
11-
- load-built-tree:
12-
builder: << parameters.builder >>
13-
- load-build-environment:
14-
builder: << parameters.builder >>
15-
- load-persistent-ci-cache:
16-
builder: << parameters.builder >>
17-
- setup-environment:
18-
builder: << parameters.builder >>
19-
- run:
20-
name: Run mbedTLS Tests
21-
command:
22-
scripts/tools/run_if.sh "mbedtls-build" "$BUILD_TYPE"
23-
scripts/tests/mbedtls_tests.sh
24-
- run:
25-
name: Run Crypto Tests
26-
command:
27-
scripts/tools/run_if.sh "main-build mbedtls-build clang-build"
28-
"$BUILD_TYPE" scripts/tests/crypto_tests.sh
29-
- run:
30-
name: Run Setup Payload Tests
31-
command:
32-
scripts/tools/run_if.sh "main-build ubuntu-16-lts clang-build"
33-
"$BUILD_TYPE" scripts/tests/setup_payload_tests.sh
34-
- run:
35-
name: OpenSSL Tests
36-
command:
37-
scripts/tools/run_if.sh "main-build clang-build" "$BUILD_TYPE"
38-
scripts/tests/openssl_tests.sh
39-
- run:
40-
name: Run Platform Tests
41-
command:
42-
scripts/tools/run_if.sh "linux-embedded" "$BUILD_TYPE"
43-
make -C build/default/src/platform check
44-
- run:
45-
name: Run All Unit & Functional Tests
46-
command:
47-
scripts/tools/run_if.sh "main-build clang-build" "$BUILD_TYPE"
48-
scripts/tests/all_tests.sh
49-
- run:
50-
name: Save test log files
51-
command: scripts/tests/save_logs.sh /tmp/test_logs
52-
when: on_fail
53-
- store_artifacts:
54-
path: /tmp/test_logs
11+
- load-built-tree:
12+
builder: << parameters.builder >>
13+
- load-build-environment:
14+
builder: << parameters.builder >>
15+
- load-persistent-ci-cache:
16+
builder: << parameters.builder >>
17+
- setup-environment:
18+
builder: << parameters.builder >>
19+
- run:
20+
name: Run mbedTLS Tests
21+
command: scripts/tools/run_if.sh "mbedtls-build" "$BUILD_TYPE"
22+
scripts/tests/mbedtls_tests.sh
23+
- run:
24+
name: Run Crypto Tests
25+
command:
26+
scripts/tools/run_if.sh "main-build mbedtls-build clang-build"
27+
"$BUILD_TYPE" scripts/tests/crypto_tests.sh
28+
- run:
29+
name: Run Setup Payload Tests
30+
command:
31+
scripts/tools/run_if.sh "main-build ubuntu-16-lts clang-build"
32+
"$BUILD_TYPE" scripts/tests/setup_payload_tests.sh
33+
- run:
34+
name: OpenSSL Tests
35+
command:
36+
scripts/tools/run_if.sh "main-build clang-build" "$BUILD_TYPE"
37+
scripts/tests/openssl_tests.sh
38+
- run:
39+
name: Run Platform Tests
40+
command: scripts/tools/run_if.sh "linux-embedded" "$BUILD_TYPE"
41+
make -C build/default/src/platform check
42+
- run:
43+
name: Run All Unit & Functional Tests
44+
command:
45+
scripts/tools/run_if.sh "main-build clang-build" "$BUILD_TYPE"
46+
scripts/tests/all_tests.sh
47+
- run:
48+
name: Save test log files
49+
command: scripts/tests/save_logs.sh /tmp/test_logs
50+
when: on_fail
51+
- store_artifacts:
52+
path: /tmp/test_logs

.vscode/tasks.json

+25-49
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"reveal": "always",
1616
"panel": "shared"
1717
},
18-
"problemMatcher": [
19-
"$gcc"
20-
]
18+
"problemMatcher": ["$gcc"]
2119
},
2220
{
2321
"label": "Auto-enforce coding style",
@@ -30,145 +28,123 @@
3028
"reveal": "always",
3129
"panel": "shared"
3230
},
33-
"problemMatcher": [
34-
"$gcc"
35-
]
31+
"problemMatcher": ["$gcc"]
3632
},
3733
{
3834
"label": "Verify coding style conformance",
3935
"type": "shell",
4036
"command": "scripts/helpers/code_style_check.sh",
4137
"group": "none",
4238
"dependsOn": "Bootstrap",
43-
"problemMatcher": [
44-
"$gcc"
45-
]
39+
"problemMatcher": ["$gcc"]
4640
},
4741
{
4842
"label": "Run Unit and Functional Tests",
4943
"type": "shell",
5044
"command": "scripts/tests/all_tests.sh",
5145
"group": "none",
5246
"dependsOn": "Bootstrap",
53-
"problemMatcher": [
54-
"$gcc"
55-
]
47+
"problemMatcher": ["$gcc"]
5648
},
5749
{
5850
"label": "Run Distribution Generation",
5951
"type": "shell",
6052
"command": "scripts/build/distribution_check.sh",
6153
"group": "none",
6254
"dependsOn": "Bootstrap",
63-
"problemMatcher": [
64-
"$gcc"
65-
]
55+
"problemMatcher": ["$gcc"]
6656
},
6757
{
6858
"label": "Run Code Coverage",
6959
"type": "shell",
7060
"command": "scripts/tools/codecoverage.sh; code -r build/default/src/chip.info/index.html",
7161
"group": "none",
7262
"dependsOn": "Bootstrap",
73-
"problemMatcher": [
74-
"$gcc"
75-
]
63+
"problemMatcher": ["$gcc"]
7664
},
7765
{
7866
"label": "Clean",
7967
"type": "shell",
8068
"command": "scripts/helpers/clean.sh",
8169
"group": "none",
8270
"dependsOn": "Bootstrap",
83-
"problemMatcher": [
84-
"$gcc"
85-
]
71+
"problemMatcher": ["$gcc"]
8672
},
8773
{
8874
"label": "Bootstrap",
8975
"type": "shell",
9076
"command": "scripts/build/bootstrap.sh",
9177
"group": "none",
92-
"problemMatcher": [
93-
"$gcc"
94-
]
78+
"problemMatcher": ["$gcc"]
9579
},
9680
{
9781
"label": "Clean Tree",
9882
"type": "shell",
9983
"command": "scripts/helpers/clean_tree.sh",
10084
"group": "none",
101-
"problemMatcher": [
102-
"$gcc"
103-
]
85+
"problemMatcher": ["$gcc"]
10486
},
10587
{
10688
"label": "Run Setup Payload Tests",
10789
"type": "shell",
10890
"command": "scripts/tests/setup_payload_tests.sh",
10991
"group": "none",
11092
"dependsOn": "Bootstrap",
111-
"problemMatcher": [
112-
"$gcc"
113-
]
93+
"problemMatcher": ["$gcc"]
11494
},
11595
{
11696
"label": "Build QRCode Payload Tests",
11797
"type": "shell",
11898
"command": "scripts/tests/qrcode_payload_tests.sh",
11999
"group": "none",
120100
"dependsOn": "Bootstrap",
121-
"problemMatcher": [
122-
"$gcc"
123-
]
101+
"problemMatcher": ["$gcc"]
124102
},
125103
{
126104
"label": "Build & Run Crypto Tests",
127105
"type": "shell",
128106
"command": "scripts/tests/crypt_tests.sh",
129107
"group": "none",
130-
"problemMatcher": [
131-
"$gcc"
132-
]
108+
"problemMatcher": ["$gcc"]
133109
},
134110
{
135111
"label": "Build nRF5 Lock App",
136112
"type": "shell",
137113
"command": "scripts/examples/nrf_lock_app.sh",
138114
"group": "none",
139115
"dependsOn": "Clean Tree",
140-
"problemMatcher": [
141-
"$gcc"
142-
]
116+
"problemMatcher": ["$gcc"]
143117
},
144118
{
145119
"label": "Build openSSL crypto Tests",
146120
"type": "shell",
147121
"command": "scripts/tests/openssl_tests.sh",
148122
"group": "none",
149-
"problemMatcher": [
150-
"$gcc"
151-
]
123+
"problemMatcher": ["$gcc"]
152124
},
153125
{
154126
"label": "Build ESP32 Echo Example",
155127
"type": "shell",
156128
"command": "scripts/examples/esp_echo_app.sh",
157129
"group": "none",
158130
"dependsOn": "Clean Tree",
159-
"problemMatcher": [
160-
"$gcc"
161-
]
131+
"problemMatcher": ["$gcc"]
162132
},
163133
{
164134
"label": "Build Standalone Echo Client",
165135
"type": "shell",
166136
"command": "scripts/examples/standalone_echo_client.sh",
167137
"group": "none",
168138
"dependsOn": "Clean Tree",
169-
"problemMatcher": [
170-
"$gcc"
171-
]
139+
"problemMatcher": ["$gcc"]
140+
},
141+
{
142+
"label": "Build Standalone Shell",
143+
"type": "shell",
144+
"command": "scripts/examples/standalone_shell.sh",
145+
"group": "none",
146+
"dependsOn": "Clean Tree",
147+
"problemMatcher": ["$gcc"]
172148
}
173149
]
174-
}
150+
}

config/nrf5/nrf5-chip.mk

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ CHIP_CONFIGURE_OPTIONS = \
9595
--exec-prefix=$(CHIP_OUTPUT_DIR) \
9696
--host=$(CHIP_HOST_ARCH) \
9797
--build=$(CHIP_BUILD_ARCH) \
98+
--with-target-style=embedded \
9899
--with-device-layer=nrf5 \
99100
--with-network-layer=all \
100101
--with-target-network=lwip \

config/standalone/standalone-app.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ $(APP) : $(APP_EXE)
202202
# Rule to link the application executable
203203
$(APP_EXE) : $(OBJS) $(STD_LINK_PREREQUISITES) | $(OUTPUT_DIR)
204204
@echo "$$(HDR_PREFIX)LD $$@"
205-
$(NO_ECHO)$$(CC) $$(STD_LDFLAGS) $$(LDFLAGS) $$(DEBUG_FLAGS) $$(OPT_FLAGS) $$(OBJS) $$(LIBS) $$(STD_LIBS) -o $$@
205+
$(NO_ECHO)$$(CXX) $$(STD_LDFLAGS) $$(LDFLAGS) $$(DEBUG_FLAGS) $$(OPT_FLAGS) $$(OBJS) $$(LIBS) $$(STD_LIBS) -o $$@
206206
$(NO_ECHO)$$(SIZE) $$@
207207

208208
# Individual build rules for each application source file
@@ -297,4 +297,4 @@ Build options:
297297

298298
$(OptionHelp)
299299

300-
endef
300+
endef

configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ src/inet/Makefile
20932093
src/inet/tests/Makefile
20942094
src/lib/Makefile
20952095
src/lib/core/tests/Makefile
2096+
src/lib/shell/Makefile
2097+
src/lib/shell/tests/Makefile
20962098
src/lib/support/Makefile
20972099
src/lib/support/tests/Makefile
20982100
src/platform/Makefile

0 commit comments

Comments
 (0)