Skip to content

Commit e646126

Browse files
authored
Merge pull request #7448 from sylvestre/selinux2
selinux: run the GNU test too
2 parents 49c52eb + 2bd7ee9 commit e646126

File tree

9 files changed

+408
-109
lines changed

9 files changed

+408
-109
lines changed

.github/workflows/CICD.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ jobs:
267267
- uses: dtolnay/rust-toolchain@stable
268268
- uses: taiki-e/install-action@nextest
269269
- uses: Swatinem/rust-cache@v2
270+
- name: Install/setup prerequisites
271+
shell: bash
272+
run: |
273+
sudo apt-get -y update ; sudo apt-get -y install libselinux1-dev
270274
- name: Run sccache-cache
271275
uses: mozilla-actions/[email protected]
272276
- name: "`make build`"
@@ -402,7 +406,7 @@ jobs:
402406
run: |
403407
## Install dependencies
404408
sudo apt-get update
405-
sudo apt-get install jq
409+
sudo apt-get install jq libselinux1-dev
406410
- name: "`make install`"
407411
shell: bash
408412
run: |
@@ -847,6 +851,7 @@ jobs:
847851
- name: Install/setup prerequisites
848852
shell: bash
849853
run: |
854+
sudo apt-get -y update ; sudo apt-get -y install libselinux1-dev
850855
## Install/setup prerequisites
851856
make prepare-busytest
852857
- name: Run BusyBox test suite
@@ -930,16 +935,19 @@ jobs:
930935
- uses: Swatinem/rust-cache@v2
931936
- name: Run sccache-cache
932937
uses: mozilla-actions/[email protected]
938+
- name: Install/setup prerequisites
939+
shell: bash
940+
run: |
941+
sudo apt-get -y update ; sudo apt-get -y install libselinux1-dev
933942
- name: Build coreutils as multiple binaries
934943
shell: bash
935944
run: |
936945
## Build individual uutil binaries
937946
set -v
938947
make
939-
- name: Install/setup prerequisites
948+
- name: Run toybox src
940949
shell: bash
941950
run: |
942-
## Install/setup prerequisites
943951
make toybox-src
944952
- name: Run Toybox test suite
945953
id: summary

.github/workflows/GnuTests.yml

Lines changed: 152 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ jobs:
5555
#
5656
SUITE_LOG_FILE="${path_GNU_tests}/test-suite.log"
5757
ROOT_SUITE_LOG_FILE="${path_GNU_tests}/test-suite-root.log"
58+
SELINUX_SUITE_LOG_FILE="${path_GNU_tests}/selinux-test-suite.log"
59+
SELINUX_ROOT_SUITE_LOG_FILE="${path_GNU_tests}/selinux-test-suite-root.log"
5860
TEST_LOGS_GLOB="${path_GNU_tests}/**/*.log" ## note: not usable at bash CLI; [why] double globstar not enabled by default b/c MacOS includes only bash v3 which doesn't have double globstar support
5961
TEST_FILESET_PREFIX='test-fileset-IDs.sha1#'
6062
TEST_FILESET_SUFFIX='.txt'
6163
TEST_SUMMARY_FILE='gnu-result.json'
6264
TEST_FULL_SUMMARY_FILE='gnu-full-result.json'
63-
outputs SUITE_LOG_FILE ROOT_SUITE_LOG_FILE TEST_FILESET_PREFIX TEST_FILESET_SUFFIX TEST_LOGS_GLOB TEST_SUMMARY_FILE TEST_FULL_SUMMARY_FILE
65+
TEST_ROOT_FULL_SUMMARY_FILE='gnu-root-full-result.json'
66+
TEST_SELINUX_FULL_SUMMARY_FILE='selinux-gnu-full-result.json'
67+
TEST_SELINUX_ROOT_FULL_SUMMARY_FILE='selinux-root-gnu-full-result.json'
68+
AGGREGATED_SUMMARY_FILE='aggregated-result.json'
69+
70+
outputs SUITE_LOG_FILE ROOT_SUITE_LOG_FILE SELINUX_SUITE_LOG_FILE SELINUX_ROOT_SUITE_LOG_FILE TEST_FILESET_PREFIX TEST_FILESET_SUFFIX TEST_LOGS_GLOB TEST_SUMMARY_FILE TEST_FULL_SUMMARY_FILE TEST_ROOT_FULL_SUMMARY_FILE TEST_SELINUX_FULL_SUMMARY_FILE TEST_SELINUX_ROOT_FULL_SUMMARY_FILE AGGREGATED_SUMMARY_FILE
6471
- name: Checkout code (uutil)
6572
uses: actions/checkout@v4
6673
with:
@@ -82,6 +89,44 @@ jobs:
8289
submodules: false
8390
persist-credentials: false
8491

92+
- name: Selinux - Setup Lima
93+
uses: lima-vm/lima-actions/setup@v1
94+
id: lima-actions-setup
95+
96+
- name: Selinux - Cache ~/.cache/lima
97+
uses: actions/cache@v4
98+
with:
99+
path: ~/.cache/lima
100+
key: lima-${{ steps.lima-actions-setup.outputs.version }}
101+
102+
- name: Selinux - Start Fedora VM with SELinux
103+
run: limactl start --plain --name=default --cpus=4 --disk=40 --memory=8 --network=lima:user-v2 template://fedora
104+
105+
- name: Selinux - Setup SSH
106+
uses: lima-vm/lima-actions/ssh@v1
107+
108+
- name: Selinux - Verify SELinux Status and Configuration
109+
run: |
110+
lima getenforce
111+
lima ls -laZ /etc/selinux
112+
lima sudo sestatus
113+
114+
# Ensure we're running in enforcing mode
115+
lima sudo setenforce 1
116+
lima getenforce
117+
118+
# Create test files with SELinux contexts for testing
119+
lima sudo mkdir -p /var/test_selinux
120+
lima sudo touch /var/test_selinux/test_file
121+
lima sudo chcon -t etc_t /var/test_selinux/test_file
122+
lima ls -Z /var/test_selinux/test_file # Verify context
123+
124+
- name: Selinux - Install dependencies in VM
125+
run: |
126+
lima sudo dnf -y update
127+
lima sudo dnf -y install git autoconf autopoint bison texinfo gperf gcc g++ gdb jq libacl-devel libattr-devel libcap-devel libselinux-devel attr rustup clang-devel texinfo-tex wget automake patch quilt
128+
lima rustup-init -y --default-toolchain stable
129+
85130
- name: Override submodule URL and initialize submodules
86131
# Use github instead of upstream git server
87132
run: |
@@ -125,55 +170,123 @@ jobs:
125170
sudo update-locale
126171
echo "After:"
127172
locale -a
173+
174+
- name: Selinux - Copy the sources to VM
175+
run: |
176+
rsync -a -e ssh . lima-default:~/work/
177+
128178
- name: Build binaries
129179
shell: bash
130180
run: |
131181
## Build binaries
132182
cd '${{ steps.vars.outputs.path_UUTILS }}'
133183
bash util/build-gnu.sh --release-build
184+
185+
- name: Selinux - Generate selinux tests list
186+
run: |
187+
# Find and list all tests that require SELinux
188+
lima bash -c "cd ~/work/gnu/ && grep -l 'require_selinux_' -r tests/ > ~/work/uutils/selinux-tests.txt"
189+
lima bash -c "cd ~/work/uutils/ && cat selinux-tests.txt"
190+
191+
# Count the tests
192+
lima bash -c "cd ~/work/uutils/ && echo 'Found SELinux tests:'; wc -l selinux-tests.txt"
193+
194+
- name: Selinux - Build for selinux tests
195+
run: |
196+
lima bash -c "cd ~/work/uutils/ && bash util/build-gnu.sh"
197+
lima bash -c "mkdir -p ~/work/gnu/tests-selinux/"
198+
199+
- name: Selinux - Run selinux tests
200+
run: |
201+
lima sudo setenforce 1
202+
lima getenforce
203+
lima cat /proc/filesystems
204+
lima bash -c "cd ~/work/uutils/ && bash util/run-gnu-test.sh \$(cat selinux-tests.txt)"
205+
206+
- name: Selinux - Extract testing info from individual logs into JSON
207+
shell: bash
208+
run : |
209+
lima bash -c "cd ~/work/gnu/ && python3 ../uutils/util/gnu-json-result.py tests > ~/work/gnu/tests-selinux/${{ steps.vars.outputs.TEST_SELINUX_FULL_SUMMARY_FILE }}"
210+
211+
- name: Selinux/root - Run selinux tests
212+
run: |
213+
lima bash -c "cd ~/work/uutils/ && CI=1 bash util/run-gnu-test.sh run-root \$(cat selinux-tests.txt)"
214+
215+
- name: Selinux/root - Extract testing info from individual logs into JSON
216+
shell: bash
217+
run : |
218+
lima bash -c "cd ~/work/gnu/ && python3 ../uutils/util/gnu-json-result.py tests > ~/work/gnu/tests-selinux/${{ steps.vars.outputs.TEST_SELINUX_ROOT_FULL_SUMMARY_FILE }}"
219+
220+
- name: Selinux - Collect test logs and test results
221+
run: |
222+
mkdir -p ${{ steps.vars.outputs.path_GNU_tests }}-selinux
223+
224+
# Copy the test logs from the Lima VM to the host
225+
lima bash -c "cp ~/work/gnu/tests/test-suite.log ~/work/gnu/tests-selinux/ || echo 'No test-suite.log found'"
226+
lima bash -c "cp ~/work/gnu/tests/test-suite-root.log ~/work/gnu/tests-selinux/ || echo 'No test-suite-root.log found'"
227+
rsync -v -a -e ssh lima-default:~/work/gnu/tests-selinux/ ./${{ steps.vars.outputs.path_GNU_tests }}-selinux/
228+
229+
# Copy SELinux logs to the main test directory for integrated processing
230+
cp -f ${{ steps.vars.outputs.path_GNU_tests }}-selinux/test-suite.log ${{ steps.vars.outputs.path_GNU_tests }}/selinux-test-suite.log
231+
cp -f ${{ steps.vars.outputs.path_GNU_tests }}-selinux/test-suite-root.log ${{ steps.vars.outputs.path_GNU_tests }}/selinux-test-suite-root.log
232+
cp -f ${{ steps.vars.outputs.path_GNU_tests }}-selinux/${{ steps.vars.outputs.TEST_SELINUX_FULL_SUMMARY_FILE }} .
233+
cp -f ${{ steps.vars.outputs.path_GNU_tests }}-selinux/${{ steps.vars.outputs.TEST_SELINUX_ROOT_FULL_SUMMARY_FILE }} .
234+
134235
- name: Run GNU tests
135236
shell: bash
136237
run: |
137238
## Run GNU tests
138239
path_GNU='${{ steps.vars.outputs.path_GNU }}'
139240
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
140241
bash "${path_UUTILS}/util/run-gnu-test.sh"
242+
243+
- name: Extract testing info from individual logs into JSON
244+
shell: bash
245+
run : |
246+
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
247+
python ${path_UUTILS}/util/gnu-json-result.py ${{ steps.vars.outputs.path_GNU_tests }} > ${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}
248+
141249
- name: Run GNU root tests
142250
shell: bash
143251
run: |
144252
## Run GNU root tests
145253
path_GNU='${{ steps.vars.outputs.path_GNU }}'
146254
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
147255
bash "${path_UUTILS}/util/run-gnu-test.sh" run-root
148-
- name: Extract testing info into JSON
256+
257+
- name: Extract testing info from individual logs (run as root) into JSON
149258
shell: bash
150259
run : |
151-
## Extract testing info into JSON
152260
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
153-
python ${path_UUTILS}/util/gnu-json-result.py ${{ steps.vars.outputs.path_GNU_tests }} > ${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}
261+
python ${path_UUTILS}/util/gnu-json-result.py ${{ steps.vars.outputs.path_GNU_tests }} > ${{ steps.vars.outputs.TEST_ROOT_FULL_SUMMARY_FILE }}
262+
154263
- name: Extract/summarize testing info
155264
id: summary
156265
shell: bash
157266
run: |
158267
## Extract/summarize testing info
159268
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
160-
#
269+
161270
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
162-
#
163-
SUITE_LOG_FILE='${{ steps.vars.outputs.SUITE_LOG_FILE }}'
164-
ROOT_SUITE_LOG_FILE='${{ steps.vars.outputs.ROOT_SUITE_LOG_FILE }}'
165-
ls -al ${SUITE_LOG_FILE} ${ROOT_SUITE_LOG_FILE}
166271
167-
if test -f "${SUITE_LOG_FILE}"
272+
# Check if the file exists
273+
if test -f "${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}"
168274
then
169-
source ${path_UUTILS}/util/analyze-gnu-results.sh ${SUITE_LOG_FILE} ${ROOT_SUITE_LOG_FILE}
275+
# Look at all individual results and summarize
276+
eval $(python3 ${path_UUTILS}/util/analyze-gnu-results.py -o=${{ steps.vars.outputs.AGGREGATED_SUMMARY_FILE }} ${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }} ${{ steps.vars.outputs.TEST_ROOT_FULL_SUMMARY_FILE }} ${{ steps.vars.outputs.TEST_SELINUX_FULL_SUMMARY_FILE }} ${{ steps.vars.outputs.TEST_SELINUX_ROOT_FULL_SUMMARY_FILE }})
277+
170278
if [[ "$TOTAL" -eq 0 || "$TOTAL" -eq 1 ]]; then
171-
echo "::error ::Failed to parse test results from '${SUITE_LOG_FILE}'; failing early"
279+
echo "::error ::Failed to parse test results from '${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}'; failing early"
172280
exit 1
173281
fi
282+
174283
output="GNU tests summary = TOTAL: $TOTAL / PASS: $PASS / FAIL: $FAIL / ERROR: $ERROR / SKIP: $SKIP"
175284
echo "${output}"
176-
if [[ "$FAIL" -gt 0 || "$ERROR" -gt 0 ]]; then echo "::warning ::${output}" ; fi
285+
286+
if [[ "$FAIL" -gt 0 || "$ERROR" -gt 0 ]]; then
287+
echo "::warning ::${output}"
288+
fi
289+
177290
jq -n \
178291
--arg date "$(date --rfc-email)" \
179292
--arg sha "$GITHUB_SHA" \
@@ -187,9 +300,10 @@ jobs:
187300
HASH=$(sha1sum '${{ steps.vars.outputs.TEST_SUMMARY_FILE }}' | cut --delim=" " -f 1)
188301
outputs HASH
189302
else
190-
echo "::error ::Failed to find summary of test results (missing '${SUITE_LOG_FILE}'); failing early"
303+
echo "::error ::Failed to find summary of test results (missing '${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}'); failing early"
191304
exit 1
192305
fi
306+
193307
# Compress logs before upload (fails otherwise)
194308
gzip ${{ steps.vars.outputs.TEST_LOGS_GLOB }}
195309
- name: Reserve SHA1/ID of 'test-summary'
@@ -212,14 +326,38 @@ jobs:
212326
with:
213327
name: gnu-full-result.json
214328
path: ${{ steps.vars.outputs.TEST_FULL_SUMMARY_FILE }}
329+
- name: Upload root json results
330+
uses: actions/upload-artifact@v4
331+
with:
332+
name: gnu-root-full-result.json
333+
path: ${{ steps.vars.outputs.TEST_ROOT_FULL_SUMMARY_FILE }}
334+
- name: Upload selinux json results
335+
uses: actions/upload-artifact@v4
336+
with:
337+
name: selinux-gnu-full-result.json
338+
path: ${{ steps.vars.outputs.TEST_SELINUX_FULL_SUMMARY_FILE }}
339+
- name: Upload selinux root json results
340+
uses: actions/upload-artifact@v4
341+
with:
342+
name: selinux-root-gnu-full-result.json
343+
path: ${{ steps.vars.outputs.TEST_SELINUX_ROOT_FULL_SUMMARY_FILE }}
344+
- name: Upload aggregated json results
345+
uses: actions/upload-artifact@v4
346+
with:
347+
name: aggregated-result.json
348+
path: ${{ steps.vars.outputs.AGGREGATED_SUMMARY_FILE }}
215349
- name: Compare test failures VS reference
216350
shell: bash
217351
run: |
218352
## Compare test failures VS reference
219353
have_new_failures=""
220354
REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/test-suite.log'
221355
ROOT_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/test-suite-root.log'
356+
SELINUX_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/selinux-test-suite.log'
357+
SELINUX_ROOT_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/selinux-test-suite-root.log'
222358
REF_SUMMARY_FILE='${{ steps.vars.outputs.path_reference }}/test-summary/gnu-result.json'
359+
360+
223361
REPO_DEFAULT_BRANCH='${{ steps.vars.outputs.repo_default_branch }}'
224362
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
225363
# https://github.com/uutils/coreutils/issues/4294

.vscode/cspell.dictionaries/jargon.wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ whitespace
143143
wordlist
144144
wordlists
145145
xattrs
146+
xpass
146147

147148
# * abbreviations
148149
consts

GNUmakefile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ TOYBOX_ROOT := $(BASEDIR)/tmp
5757
TOYBOX_VER := 0.8.12
5858
TOYBOX_SRC := $(TOYBOX_ROOT)/toybox-$(TOYBOX_VER)
5959

60-
ifeq ($(SELINUX_ENABLED),)
61-
SELINUX_ENABLED := 0
60+
61+
ifdef SELINUX_ENABLED
62+
override SELINUX_ENABLED := 0
63+
# Now check if we should enable it (only on non-Windows)
6264
ifneq ($(OS),Windows_NT)
63-
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
64-
SELINUX_ENABLED := 1
65+
ifeq ($(shell if [ -x /sbin/selinuxenabled ] && /sbin/selinuxenabled 2>/dev/null; then echo 0; else echo 1; fi),0)
66+
override SELINUX_ENABLED := 1
67+
$(info /sbin/selinuxenabled successful)
68+
else
69+
$(info SELINUX_ENABLED=1 but /sbin/selinuxenabled failed)
6570
endif
6671
endif
6772
endif
@@ -176,9 +181,7 @@ SELINUX_PROGS := \
176181

177182
ifneq ($(OS),Windows_NT)
178183
PROGS := $(PROGS) $(UNIX_PROGS)
179-
endif
180-
181-
ifeq ($(SELINUX_ENABLED),1)
184+
# Build the selinux command even if not on the system
182185
PROGS := $(PROGS) $(SELINUX_PROGS)
183186
endif
184187

@@ -265,6 +268,7 @@ TEST_SPEC_FEATURE := test_unimplemented
265268
else ifeq ($(SELINUX_ENABLED),1)
266269
TEST_NO_FAIL_FAST :=
267270
TEST_SPEC_FEATURE := feat_selinux
271+
BUILD_SPEC_FEATURE := feat_selinux
268272
endif
269273

270274
define TEST_BUSYBOX
@@ -288,11 +292,15 @@ use_default := 1
288292

289293
build-pkgs:
290294
ifneq (${MULTICALL}, y)
295+
ifdef BUILD_SPEC_FEATURE
296+
${CARGO} build ${CARGOFLAGS} --features "$(BUILD_SPEC_FEATURE)" ${PROFILE_CMD} $(foreach pkg,$(EXES),-p uu_$(pkg))
297+
else
291298
${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} $(foreach pkg,$(EXES),-p uu_$(pkg))
292299
endif
300+
endif
293301

294302
build-coreutils:
295-
${CARGO} build ${CARGOFLAGS} --features "${EXES}" ${PROFILE_CMD} --no-default-features
303+
${CARGO} build ${CARGOFLAGS} --features "${EXES} $(BUILD_SPEC_FEATURE)" ${PROFILE_CMD} --no-default-features
296304

297305
build: build-coreutils build-pkgs
298306

0 commit comments

Comments
 (0)