From 7cd85c1134efb0c35ff6e9a831af9ac000402481 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 21 Nov 2019 12:09:43 +0000 Subject: [PATCH] Add integration test for basic dinitcheck functionality --- .gitignore | 2 ++ src/Makefile | 2 +- src/igr-tests/Makefile | 1 + src/igr-tests/check-basic/expected.txt | 5 +++++ src/igr-tests/check-basic/run-test.sh | 11 +++++++++++ src/igr-tests/check-basic/sd/boot | 3 +++ src/igr-tests/igr-runner.cc | 3 ++- 7 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/igr-tests/check-basic/expected.txt create mode 100755 src/igr-tests/check-basic/run-test.sh create mode 100644 src/igr-tests/check-basic/sd/boot diff --git a/.gitignore b/.gitignore index ccf983e..24a87a4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /src/**/*.d /src/dinit /src/dinitctl +/src/dinitcheck /src/shutdown /src/mconfig-gen /src/includes/mconfig.h @@ -23,6 +24,7 @@ /src/igr-tests/ps-environ/env-record /src/igr-tests/chain-to/recorded-output /src/igr-tests/restart/basic-ran +/src/igr-tests/check-basic/output.txt # Generated man pages: /doc/manpages/*.5 diff --git a/src/Makefile b/src/Makefile index 8d96318..6bc6b2f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -53,7 +53,7 @@ $(objects): %.o: %.cc check: $(MAKE) -C tests check -check-igr: dinit dinitctl +check-igr: dinit dinitctl dinitcheck $(MAKE) -C igr-tests check-igr run-cppcheck: diff --git a/src/igr-tests/Makefile b/src/igr-tests/Makefile index ad73728..b148fb1 100644 --- a/src/igr-tests/Makefile +++ b/src/igr-tests/Makefile @@ -9,3 +9,4 @@ igr-runner: igr-runner.cc clean: rm -f igr-runner basic/basic-ran environ/env-record ps-environ/env-record chain-to/recorded-output rm -f restart/basic-ran + rm -f check-basic/output.txt diff --git a/src/igr-tests/check-basic/expected.txt b/src/igr-tests/check-basic/expected.txt new file mode 100644 index 0000000..a25578f --- /dev/null +++ b/src/igr-tests/check-basic/expected.txt @@ -0,0 +1,5 @@ +Checking service: boot... +Service 'boot': Unknown setting: 'not-valid'. +Service 'boot': run-as: Specified user id contains invalid numeric characters or is outside allowed range. +Checking service: test1... +Unable to load service 'test1': Service description not found. diff --git a/src/igr-tests/check-basic/run-test.sh b/src/igr-tests/check-basic/run-test.sh new file mode 100755 index 0000000..d75048c --- /dev/null +++ b/src/igr-tests/check-basic/run-test.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +../../dinitcheck -d sd > output.txt 2>&1 + +STATUS=FAIL +if cmp -s expected.txt output.txt; then + STATUS=PASS +fi + +if [ $STATUS = PASS ]; then exit 0; fi +exit 1 diff --git a/src/igr-tests/check-basic/sd/boot b/src/igr-tests/check-basic/sd/boot new file mode 100644 index 0000000..2bbb5c9 --- /dev/null +++ b/src/igr-tests/check-basic/sd/boot @@ -0,0 +1,3 @@ +depends-on=test1 +not-valid=some value +run-as=9notanumber diff --git a/src/igr-tests/igr-runner.cc b/src/igr-tests/igr-runner.cc index 7843557..3d53e9b 100644 --- a/src/igr-tests/igr-runner.cc +++ b/src/igr-tests/igr-runner.cc @@ -12,7 +12,8 @@ extern char **environ; int main(int argc, char **argv) { - const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart" }; + const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart", + "check-basic" }; constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]); int passed = 0; -- 2.25.1