Skip to content

Commit

Permalink
Check script driver and util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
phaubertin committed Dec 6, 2024
1 parent 03e0e7b commit f0bab89
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 132 deletions.
13 changes: 6 additions & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ jinue_root = ..
include $(jinue_root)/header.mk

test_script = run-all-tests.gen.sh
check_script = check-log.sh
setup_script = setup-test.sh
check_test_script = check-test.sh
run_script = run-test.sh
setup_script = setup-test.sh
check_log_script = check-log.sh
run_log = run-test.log

deps = $(kernel_img) $(testapp_initrd)

tests = \
Expand All @@ -54,10 +56,7 @@ $(test_script): Makefile
echo "#!/bin/bash -e" > $@
echo "# Generated file - see Makefile" >> $@
echo "" >> $@; \
echo "fail () {" >> $@; \
echo " echo '*** [ FAIL ] ***' >&2" >> $@; \
echo " exit 1" >> $@; \
echo "}" >> $@; \
echo "source utils.sh" >> $@; \
echo "" >> $@; \
echo "fail_count=0" >> $@; \
for t in $(tests); do \
Expand All @@ -70,7 +69,7 @@ $(test_script): Makefile
echo "echo =============================================================" >> $@; \
echo "echo ==== CHECK $$t" >> $@; \
echo "echo =============================================================" >> $@; \
echo "./$$t/$(check_script) $$t/$(run_log) || fail_count=\$$((fail_count + 1))" >> $@; \
echo "./$(check_test_script) ./$$t/$(check_log_script) $$t/$(run_log) || fail_count=\$$((fail_count + 1))" >> $@; \
done
echo "" >> $@; \
echo "echo =============================================================" >> $@; \
Expand Down
48 changes: 48 additions & 0 deletions tests/check-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash -e
# Copyright (C) 2024 Philippe Aubertin.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author nor the names of other contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

source utils.sh

usage () {
echo "USAGE: $(basename $0) check_script log_file" >&2
exit 1
}

[[ $# -ne 2 ]] && usage

echo "* Check log file exists"
[[ -f $2 ]] || fail

CHECK_SCRIPT=$1
LOG=$2

source $CHECK_SCRIPT || exit 1

echo "[ PASS ]"
30 changes: 5 additions & 25 deletions tests/test_acpi/check-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,11 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

fail () {
echo "*** [ FAIL ] ***" >&2
exit 1
}
echo "* Check the ACPI test ran"
grep -F "Running ACPI test" $LOG || fail

usage () {
echo "USAGE: $(basename $0) log_file" >&2
exit 1
}
check_no_error

[[ $# -ne 1 ]] && usage
check_no_warning

echo "* Check log file exists"
[[ -f $1 ]] || fail

echo "* Check ACPI test ran"
grep -F "Running ACPI test" $1 || fail

echo "* Check no error occurred"
grep -E "^error:" $1 && fail

echo "* Check no warning was reported"
grep -E "^warning:" $1 && fail

echo "* Check the test application initiated the reboot"
grep -F "Rebooting." $1 || fail

echo "[ PASS ]"
check_reboot
41 changes: 10 additions & 31 deletions tests/test_boot_nopae/check-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,20 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

fail () {
echo "*** [ FAIL ] ***" >&2
exit 1
}
check_kernel_start

usage () {
echo "USAGE: $(basename $0) log_file" >&2
exit 1
}
# If check_no_panic, check_no_error would also fail, but check_no_panic provides
# more relevant context in the log.
check_no_panic

[[ $# -ne 1 ]] && usage

echo "* Check log file exists"
[[ -f $1 ]] || fail

echo "* Check kernel started"
grep -F "Jinue microkernel started." $1 || fail

echo "* Check kernel did not panic"
grep -F -A 20 "KERNEL PANIC" $1 && fail

echo "* Check no error occurred"
grep -E "^error:" $1 && fail
check_no_error

echo "* Check PAE was not enabled"
grep -F "Enabling Physical Address Extension (PAE)" $1 && fail
grep -F "warning: physical Address Extension (PAE) not enabled" $1 || fail

echo "* Check user space loader started"
grep -F "Jinue user space loader (jinue-userspace-loader) started." $1 || fail
grep -F "Enabling Physical Address Extension (PAE)" $LOG && fail
grep -F "warning: physical Address Extension (PAE) not enabled" $LOG || fail

echo "* Check test application started"
grep -F "Jinue test app (/sbin/init) started." $1 || fail
check_loader_start

echo "* Check the test application initiated the reboot"
grep -F "Rebooting." $1 || fail
check_testapp_start

echo "[ PASS ]"
check_reboot
42 changes: 10 additions & 32 deletions tests/test_boot_pae/check-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,21 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

fail () {
echo "*** [ FAIL ] ***" >&2
exit 1
}
check_kernel_start

usage () {
echo "USAGE: $(basename $0) log_file" >&2
exit 1
}
# If check_no_panic, check_no_error would also fail, but check_no_panic provides
# more relevant context in the log.
check_no_panic

[[ $# -ne 1 ]] && usage

echo "* Check log file exists"
[[ -f $1 ]] || fail

echo "* Check kernel started"
grep -F "Jinue microkernel started." $1 || fail

echo "* Check kernel did not panic"
grep -F -A 20 "KERNEL PANIC" $1 && fail

echo "* Check no error occurred"
grep -E "^error:" $1 && fail
check_no_error

echo "* Check PAE was enabled"
grep -F "Enabling Physical Address Extension (PAE)" $1 || fail

echo "* Check no warning was reported"
grep -E "^warning:" $1 && fail
grep -F "Enabling Physical Address Extension (PAE)" $LOG || fail

echo "* Check user space loader started"
grep -F "Jinue user space loader (jinue-userspace-loader) started." $1 || fail
check_no_warning

echo "* Check test application started"
grep -F "Jinue test app (/sbin/init) started." $1 || fail
check_loader_start

echo "* Check the test application initiated the reboot"
grep -F "Rebooting." $1 || fail
check_testapp_start

echo "[ PASS ]"
check_reboot
55 changes: 18 additions & 37 deletions tests/test_ipc/check-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,27 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

fail () {
echo "*** [ FAIL ] ***" >&2
exit 1
}
echo "* Check the threading and IPC test ran"
grep -F "Running threading and IPC test" $LOG || fail

usage () {
echo "USAGE: $(basename $0) log_file" >&2
exit 1
}
check_no_error

[[ $# -ne 1 ]] && usage

echo "* Check log file exists"
[[ -f $1 ]] || fail

echo "* Check threading and IPC test ran"
grep -F "Running threading and IPC test" $1 || fail

echo "* Check no error occurred"
grep -E "^error:" $1 && fail

echo "* Check no warning was reported"
grep -E "^warning:" $1 && fail
check_no_warning

echo "* Check the main thread tried to receive on the send-only descriptor"
grep -F "Attempting to call jinue_receive() on the send-only descriptor." $1 || fail
grep -F "Attempting to call jinue_receive() on the send-only descriptor." $LOG || fail

echo "* Check errno was set to JINUE_EPERM"
RESULT=`grep -F -A 1 "Attempting to call jinue_receive() on the send-only descriptor." $1`
RESULT=`grep -F -A 1 "Attempting to call jinue_receive() on the send-only descriptor." $LOG`
echo "$RESULT" | grep -F 'operation not permitted' || fail

echo "* Check client thread started and got the right argument"
grep -F "Client thread is starting with argument: 0xb01dface" $1 || fail
grep -F "Client thread is starting with argument: 0xb01dface" $LOG || fail

echo "* Check main thread received message from client thread"
grep -F "Main thread received message" $1 || fail
grep -F "Main thread received message" $LOG || fail

MESSAGE=`grep -F -A 5 "Main thread received message:" $1`
MESSAGE=`grep -F -A 5 "Main thread received message:" $LOG`

echo "* Check message data"
echo "$MESSAGE" | grep -E 'data:[ ]+"Hello World!"' || fail
Expand All @@ -80,9 +63,9 @@ echo "* Check cookie"
echo "$MESSAGE" | grep -E 'cookie:[ ]+0xca11ab1e$' || fail

echo "* Check client thread received reply from main thread"
grep -F "Client thread got reply from main thread" $1 || fail
grep -F "Client thread got reply from main thread" $LOG || fail

REPLY=`grep -F -A 2 "Client thread got reply from main thread:" $1`
REPLY=`grep -F -A 2 "Client thread got reply from main thread:" $LOG`

echo "* Check reply data"
echo "$REPLY" | grep -E 'data:[ ]+"Hi, Main Thread!"' || fail
Expand All @@ -91,24 +74,22 @@ echo "* Check message size"
echo "$REPLY" | grep -E 'size:[ ]+17$' || fail

echo "* Check client thread attempted to send the message a second time"
grep -F "Client thread is re-sending message." $1 || fail
grep -F "Client thread is re-sending message." $LOG || fail

echo "* Check main thread closed the receive descriptor while the client was send blocked"
RESULT=`grep -F -A 1 "Client thread is re-sending message." $1`
RESULT=`grep -F -A 1 "Client thread is re-sending message." $LOG`
echo "$RESULT" | grep -F 'Closing receiver descriptor.' || fail

echo "* Check closing the receive descriptor caused JINUE_EIO in the send-blocked thread"
RESULT=`grep -F -A 1 "Closing receiver descriptor." $1`
RESULT=`grep -F -A 1 "Closing receiver descriptor." $LOG`
echo "$RESULT" | grep -F 'I/O error' || fail

echo "* Check client thread exited cleanly"
grep -F "Client thread is exiting." $1 || fail
grep -F "Client thread is exiting." $LOG || fail

echo "* Check main thread joined the client thread and retrieved its exit value"
grep -F "Client thread exit value is 0xdeadbeef." $1 || fail
grep -F "Client thread exit value is 0xdeadbeef." $LOG || fail

echo "* Check the main thread initiated the reboot"
grep -F "Main thread is running." $1 || fail
grep -F "Rebooting." $1 || fail

echo "[ PASS ]"
grep -F "Main thread is running." $LOG || fail
grep -F "Rebooting." $LOG || fail
69 changes: 69 additions & 0 deletions tests/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Copyright (C) 2024 Philippe Aubertin.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author nor the names of other contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

fail () {
echo "*** [ FAIL ] ***" >&2
exit 1
}

check_no_panic () {
echo "* Check kernel did not panic"
grep -F -A 20 "KERNEL PANIC" $LOG && fail
}

check_no_error () {
echo "* Check no error occurred"
grep -E "^error:" $LOG && fail
}

check_no_warning () {
echo "* Check no warning was reported"
grep -E "^warning:" $LOG && fail
}

check_reboot () {
echo "* Check the test application initiated the reboot"
grep -F "Rebooting." $LOG || fail
}

check_kernel_start () {
echo "* Check kernel started"
grep -F "Jinue microkernel started." $LOG || fail
}

check_loader_start () {
echo "* Check user space loader started"
grep -F "Jinue user space loader (jinue-userspace-loader) started." $LOG || fail
}

check_testapp_start () {
echo "* Check test application started"
grep -F "Jinue test app (/sbin/init) started." $LOG || fail
}

0 comments on commit f0bab89

Please sign in to comment.