Skip to content

Commit 49d06e0

Browse files
Andrei TrandafirAndrei Trandafir
Andrei Trandafir
authored and
Andrei Trandafir
committed
cli: Update CI test framework to sync with driver v0.5 integration
The CI framework must be updated taking into consideration that it is no longer possible to run the power-user version of the CLI while the Nitro Enclaves driver is inserted (since the latter takes exclusive ownership of the communication with the PCI device). Signed-off-by: Andrei Trandafir <[email protected]>
1 parent ea8ad39 commit 49d06e0

File tree

7 files changed

+67
-23
lines changed

7 files changed

+67
-23
lines changed

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ nitro_cli_resource_allocator: drivers/nitro_cli_resource_allocator/nitro_cli_res
106106
nitro_cli_resource_allocator-clean:
107107
PREV_DIR=$$PWD && cd drivers/nitro_cli_resource_allocator/ && make clean && cd $$PREV_DIR \
108108

109-
nitro_enclaves: drivers/virt/amazon/nitro_enclaves/ne_main.c driver-deps
110-
PREV_DIR=$$PWD && cd drivers/virt/amazon/nitro_enclaves/ && make && cd $$PREV_DIR
109+
nitro_enclaves: drivers/virt/nitro_enclaves/ne_misc_dev.c drivers/virt/nitro_enclaves/ne_pci_dev.c driver-deps
110+
PREV_DIR=$$PWD && cd drivers/virt/nitro_enclaves/ && make && cd $$PREV_DIR
111111

112112
.PHONY: nitro_enclaves-clean
113113
nitro_enclaves-clean:
114-
PREV_DIR=$$PWD && cd drivers/virt/amazon/nitro_enclaves/ && make clean && cd $$PREV_DIR
114+
PREV_DIR=$$PWD && cd drivers/virt/nitro_enclaves/ && make clean && cd $$PREV_DIR
115115

116116
.PHONY: driver-clean
117117
driver-clean: nitro_enclaves-clean nitro_cli_resource_allocator-clean
@@ -183,8 +183,9 @@ command-executer: build-setup build-container .build-command-executer
183183
--target-dir=/nitro_build/nitro_cli \
184184
--message-format json \
185185
| tee /nitro_build/nitro-tests-build.log | \
186-
jq -r "select(.profile.test == true) | .filenames[]" \
187-
> /nitro_build/test_executables.txt && \
186+
jq -r "select(.profile.test == true) | .filenames[], .package_id" | \
187+
paste -d " " - - | cut -d " " -f 1,2 \
188+
> /nitro_build/test_executables.txt && \
188189
chmod -R 777 nitro_build '
189190
touch $@
190191

@@ -277,9 +278,10 @@ install: install-tools nitro_enclaves
277278
$(INSTALL) -D -m 0755 blobs/nsm.ko ${NITRO_CLI_INSTALL_DIR}/${OPT_DIR}/nitro_cli/nsm.ko
278279
$(INSTALL) -D -m 0755 blobs/linuxkit ${NITRO_CLI_INSTALL_DIR}/${OPT_DIR}/nitro_cli/linuxkit
279280
$(MKDIR) -p ${NITRO_CLI_INSTALL_DIR}/lib/modules/$(uname -r)/extra/nitro_enclaves
280-
$(INSTALL) -D -m 0755 drivers/virt/amazon/nitro_enclaves/nitro_enclaves.ko \
281+
$(INSTALL) -D -m 0755 drivers/virt/nitro_enclaves/nitro_enclaves.ko \
281282
${NITRO_CLI_INSTALL_DIR}/lib/modules/$(uname -r)/extra/nitro_enclaves/nitro_enclaves.ko
282283
$(INSTALL) -m 0644 tools/env.sh ${NITRO_CLI_INSTALL_DIR}/${ENV_SETUP_DIR}/nitro-cli-env.sh
284+
$(INSTALL) -m 0744 tools/nitro-cli-config.sh ${NITRO_CLI_INSTALL_DIR}/${ENV_SETUP_DIR}/nitro-cli-config.sh
283285
sed -i "2 a NITRO_CLI_INSTALL_DIR=$$(readlink -f ${NITRO_CLI_INSTALL_DIR})" \
284286
${NITRO_CLI_INSTALL_DIR}/${ENV_SETUP_DIR}/nitro-cli-env.sh
285287
echo "Installation finished"
@@ -295,6 +297,7 @@ uninstall:
295297
$(RM) -rf ${NITRO_CLI_INSTALL_DIR}/lib/modules/$(uname -r)/extra/nitro_enclaves
296298
$(RM) -f ${NITRO_CLI_INSTALL_DIR}/${CONF_DIR}/vsock_proxy/config.yaml
297299
$(RM) -f ${NITRO_CLI_INSTALL_DIR}/${ENV_SETUP_DIR}/nitro-cli-env.sh
300+
$(RM) -f ${NITRO_CLI_INSTALL_DIR}/${ENV_SETUP_DIR}/nitro-cli-config.sh
298301

299302
.PHONY: clean
300303
clean:

run_tests.sh

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function register_test_fail() {
2222

2323
# Clean up and exit with the current test suite's status
2424
function clean_up_and_exit() {
25-
rmmod nitro_cli_resource_allocator || register_test_fail
26-
rmmod nitro_enclaves || register_test_fail
25+
[ "$(lsmod | grep -cw nitro_cli_resource_allocator)" -eq 0 ] || rmmod nitro_cli_resource_allocator || register_test_fail
26+
[ "$(lsmod | grep -cw nitro_enclaves)" -eq 0 ] || rmmod nitro_enclaves || register_test_fail
2727
make clean
2828
rm -rf test_images
2929

@@ -36,9 +36,23 @@ function test_failed() {
3636
clean_up_and_exit
3737
}
3838

39+
# Remove the Nitro Enclaves driver
40+
function remove_ne_driver() {
41+
[ "$(lsmod | grep -cw nitro_enclaves)" -eq 0 ] || rmmod nitro_enclaves || test_failed
42+
}
43+
44+
# Configure and insert the Nitro Enclaves driver
45+
function configure_ne_driver() {
46+
if [ "$(lsmod | grep -cw nitro_enclaves)" -eq 0 ]
47+
then
48+
# Preallocate 2048 Mb, that should be enough for all the tests
49+
source build/install/etc/profile.d/nitro-cli-env.sh || test_failed
50+
./build/install/etc/profile.d/nitro-cli-config.sh -m 2048 -p 1,3 || test_failed
51+
fi
52+
}
53+
3954
# First run the instalation test, before we change the environement
40-
pytest-3 tests/integration/test_installation.py \
41-
|| test_failed
55+
pytest-3 tests/integration/test_installation.py || test_failed
4256

4357
# Clean up build artefacts
4458
make clean
@@ -64,30 +78,40 @@ make vsock-proxy || test_failed
6478
make install || test_failed
6579
insmod drivers/nitro_cli_resource_allocator/nitro_cli_resource_allocator.ko || test_failed
6680

67-
# Preallocate 2048 Mb, that should be enough for all the tests
68-
echo 1024 > /proc/sys/vm/nr_hugepages || test_failed
69-
source build/install/etc/profile.d/nitro-cli-env.sh || test_failed
81+
# Ensure the Nitro Enclaves driver is inserted at the beginning.
82+
configure_ne_driver
7083

7184
# Create directories for enclave process sockets and logs
7285
mkdir -p /var/run/nitro_enclaves || test_failed
7386
mkdir -p /var/log/nitro_enclaves || test_failed
7487

7588
# Build EIFS for testing
7689
mkdir -p test_images
77-
nitro-cli build-enclave --docker-uri 667861386598.dkr.ecr.us-east-1.amazonaws.com/enclaves-samples:vsock-sample --output-file test_images/vsock-sample.eif
90+
nitro-cli build-enclave --docker-uri 667861386598.dkr.ecr.us-east-1.amazonaws.com/enclaves-samples:vsock-sample \
91+
--output-file test_images/vsock-sample.eif || test_failed
7892

7993
# Run all unit tests
80-
while IFS= read -r test_exec_path
94+
while IFS= read -r test_line
8195
do
8296
TEST_SUITES_TOTAL=$((TEST_SUITES_TOTAL + 1))
83-
test_exec_name=$(basename "${test_exec_path}")
84-
RUST_BACKTRACE=1 ./build/nitro_cli/x86_64-unknown-linux-musl/release/"${test_exec_name}" \
85-
--test-threads=1 --nocapture \
86-
|| test_failed
97+
test_module="$(echo ${test_line} | cut -d' ' -f2)"
98+
test_exec_name="$(basename $(echo ${test_line} | cut -d' ' -f1))"
99+
100+
if [[ $test_module == *"nitro-cli-poweruser"* ]]
101+
then
102+
remove_ne_driver
103+
else
104+
configure_ne_driver
105+
fi
106+
107+
./build/nitro_cli/x86_64-unknown-linux-musl/release/"${test_exec_name}" \
108+
--test-threads=1 --nocapture || test_failed
87109
done < <(grep -v '^ *#' < build/test_executables.txt)
88110

111+
# Ensure the Nitro Enclaves driver is inserted for the remaining integration tests.
112+
configure_ne_driver
113+
89114
# Run integration tests except the instalation test
90-
pytest-3 tests/integration/ --ignore tests/integration/test_installation.py \
91-
|| test_failed
115+
pytest-3 tests/integration/ --ignore tests/integration/test_installation.py || test_failed
92116

93117
clean_up_and_exit

tests/integration/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ def connect_console(enclave_id):
134134
"--enclave-id", enclave_id]
135135

136136
return subprocess.Popen(args, stdout = PIPE, stderr = PIPE)
137+
138+
# Get the number of CPUs in the system, both on-line and off-line.
139+
def get_cpu_count():
140+
run_lscpu = subprocess.Popen(["lscpu -a -p=cpu"], stdout=subprocess.PIPE, shell=True)
141+
(output, _) = run_lscpu.communicate()
142+
output = output.decode('UTF-8').splitlines()
143+
cpu_ids = [id for id in output if not id.startswith("#")]
144+
return len(cpu_ids)

tests/integration/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_run_invalid_cpu_count(init_resources):
6464
result = run_enclave_err(SAMPLE_EIF, "1028", "3")
6565
result = run_enclave_err(SAMPLE_EIF, "1028", "-3")
6666
result = run_enclave_err(SAMPLE_EIF, "1028", "zzz")
67-
result = run_enclave_err(SAMPLE_EIF, "1028", str(os.cpu_count()))
67+
result = run_enclave_err(SAMPLE_EIF, "1028", str(get_cpu_count()))
6868

6969
# At the end check we can still launch enclaves.
7070
result = run_enclave_ok(SAMPLE_EIF, "1028", "2")

tests/integration/test_installation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def test_install_uninstall():
3535
"/etc/profile.d//nitro-cli-env.sh && nitro-cli --help && vsock-proxy --help\""
3636
helpers.run_cmd_ok(help_cmd)
3737

38+
# Perform clean-up.
3839
uninstall_cmd = make + " uninstall"
3940
helpers.run_cmd_ok(uninstall_cmd)
4041
helpers.check_no_files(install_dir.name)
42+
43+
# Also remove the inserted driver.
44+
rmmod_cmd = "rmmod nitro_enclaves"
45+
helpers.run_cmd_ok(rmmod_cmd)

tools/env.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#!/bin/bash
12

3+
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0
25

36
if [ -z ${NITRO_CLI_INSTALL_DIR} ];
47
then

tools/nitro-cli-config.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ function print_usage {
126126
echo -e "\t-r: Remove the driver."
127127
echo -e "\t-h: Print these help messages."
128128
echo -e "\t-m: The amount of memory that will be needed for running enclaves, in megabytes."
129-
echo -e "\t-p: The CPU pool that taken from the parent instance and made available for enclaves."
129+
echo -e "\t-p: The CPU pool that is taken from the parent instance and made available for enclaves. The pool format"
130+
echo -e "\t is given in: https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html#cpu-lists"
130131
}
131132

132133
# Verify that the provided driver directory is correct.

0 commit comments

Comments
 (0)