xref: /freebsd/tests/ci/tools/freebsdci (revision 54521a2ff93ae06c95c31f79f89dc23c9b51c20b)
1#!/bin/sh
2#
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2024 The FreeBSD Foundation
6#
7# This software was developed by Cybermancer Infosec <bofh@FreeBSD.org>
8# under sponsorship from the FreeBSD Foundation.
9#
10# PROVIDE: freebsdci
11# REQUIRE: LOGIN FILESYSTEMS
12# KEYWORD: firstboot
13
14# This script is used to run the firstboot CI tests on the first boot of a
15# FreeBSD image. It is automatically disabled after the first boot.
16#
17# The script will run the firstboot CI tests and then shut down the system.
18# The tests are run in the foreground so that the system can shut down
19# immediately after the tests are finished.
20#
21# Default test types are full and smoke.  To run only the smoke tests, set
22# freebsdci_type="smoke" in /etc/rc.conf.local or /etc/rc.conf.
23# To run only the full tests, set freebsdci_type="full" in
24# /etc/rc.conf.local or /etc/rc.conf.
25
26. /etc/rc.subr
27
28: ${freebsdci_enable:="NO"}
29
30name="freebsdci"
31desc="Run FreeBSD CI"
32rcvar=freebsdci_enable
33start_cmd="firstboot_ci_run"
34stop_cmd=":"
35os_arch=$(uname -p)
36
37auto_shutdown()
38{
39	# XXX: Currently RISC-V kernels lack the ability to
40	#      make qemu exit on shutdown. Reboot instead;
41	#      it makes qemu exit too.
42	case "$os_arch" in
43		riscv64)
44			shutdown -r now
45		;;
46		*)
47			shutdown -p now
48		;;
49	esac
50}
51
52smoke_tests()
53{
54	echo
55	echo "--------------------------------------------------------------"
56	echo "BUILD sequence COMPLETED"
57	echo "IMAGE sequence COMPLETED"
58	echo "BOOT sequence COMPLETED"
59	echo "INITIATING system SHUTDOWN"
60	echo "--------------------------------------------------------------"
61}
62
63full_tests()
64{
65	# Currently this is a placeholder.
66	# This will be used to add the full tests scenario those are run in
67	# the CI system
68	echo
69	echo "--------------------------------------------------------------"
70	echo "BUILD sequence COMPLETED"
71	echo "IMAGE sequence COMPLETED"
72	echo "BOOT sequence COMPLETED"
73	echo "TEST sequence STARTED"
74	echo "TEST sequence COMPLETED"
75	echo "INITIATING system SHUTDOWN"
76	echo "--------------------------------------------------------------"
77}
78
79firstboot_ci_run()
80{
81	if [ "$freebsdci_type" = "smoke" ]; then
82		smoke_tests
83	elif [ "$freebsdci_type" = "full" ]; then
84		full_tests
85	fi
86	auto_shutdown
87}
88
89load_rc_config $name
90run_rc_command "$1"
91