@@ -132,6 +132,30 @@ install: $(BIN)
132132 install -m 755 -d $(DESTDIR )$(MANDIR )
133133 install -m 644 nsjail.1 $(DESTDIR )$(MANDIR )
134134
135+ define run_test
136+ @echo "Testing: $(1 ) (expecting exit code $(2 ) )"; \
137+ ($(1 ) ); ret=$$? ; \
138+ if [ "$$ret" -ne "$(2 ) " ]; then \
139+ echo "❌ FAIL: '$(1 ) ' returned $$ret, expected $(2 ) "; \
140+ exit 1; \
141+ else \
142+ echo "✅ PASS: '$(1 ) ' returned $$ret"; \
143+ fi
144+ endef
145+
146+ .PHONY : test
147+ test : $(BIN )
148+ $(call run_test, ./nsjail -q -Mo --rw --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME ) /nsjail_test && exit 77', 77)
149+ $(call run_test, ./nsjail -q -Mo --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME ) /nsjail_test || exit 77', 77)
150+ $(call run_test, rm -f $(HOME ) /nsjail_test, 0)
151+ $(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.cfg -q -t 1, 137)
152+ $(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.json -q -t 1, 137)
153+ $(call run_test, ./nsjail --config configs/static-busybox-with-execveat.cfg -q -t 1, 137)
154+ $(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/true, 0)
155+ $(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/false, 1)
156+ $(call run_test, ./nsjail --config configs/firefox-with-net-wayland.cfg -q -t 3, 137)
157+ $(call run_test, ./nsjail --config configs/chromium-with-net-wayland.cfg -q -t 3, 137)
158+
135159# Dependencies (Generated by makedepend)
136160# DO NOT DELETE THIS LINE -- make depend depends on it.
137161
@@ -150,7 +174,7 @@ mnt.o: mnt.h nsjail.h config.pb.h logs.h macros.h mnt_legacy.h mnt_newapi.h
150174mnt.o : subproc.h util.h
151175mnt_legacy.o : mnt_legacy.h mnt.h nsjail.h config.pb.h logs.h macros.h util.h
152176mnt_newapi.o : mnt_newapi.h mnt.h nsjail.h config.pb.h logs.h util.h
153- net.o : net.h nsjail.h config.pb.h logs.h util.h
177+ net.o : net.h nsjail.h config.pb.h logs.h macros.h util.h
154178nsjail.o : nsjail.h config.pb.h cgroup2.h cmdline.h logs.h macros.h net.h
155179nsjail.o : sandbox.h subproc.h util.h
156180pid.o : pid.h nsjail.h config.pb.h logs.h subproc.h
0 commit comments