feat: Implement complete Zero OS Alpine Initramfs Builder
- Complete bash framework with strict error handling - Modular library system (docker, alpine, components, initramfs, kernel, testing) - Rust component integration (zinit, rfs, mycelium) with musl targeting - Rootless Docker/Podman support for GitHub Actions - Centralized configuration in config/build.conf - 2-stage module loading system - Strip + UPX optimization for minimal size - Complete zinit integration replacing OpenRC - GitHub Actions CI/CD pipeline - Comprehensive documentation and usage guides Components: - Latest stable kernel 6.12.44 - Alpine Linux 3.22 base - ThreeFold components: zinit, mycelium, rfs, corex - Target: ~8-12MB final initramfs.cpio.xz
This commit is contained in:
199
scripts/test.sh
Executable file
199
scripts/test.sh
Executable file
@@ -0,0 +1,199 @@
|
||||
#!/bin/bash
|
||||
# Test script for Zero OS Alpine Initramfs
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Script directory and project root detection
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Source common functions and testing library
|
||||
source "${SCRIPT_DIR}/lib/common.sh"
|
||||
source "${SCRIPT_DIR}/lib/testing.sh"
|
||||
|
||||
# Test configuration
|
||||
DEFAULT_KERNEL="${PROJECT_ROOT}/dist/vmlinuz.efi"
|
||||
TEST_TIMEOUT="${TEST_TIMEOUT:-60}"
|
||||
TEST_RUNNER="${TEST_RUNNER:-qemu}"
|
||||
|
||||
# Display usage information
|
||||
function show_usage() {
|
||||
cat << EOF
|
||||
Zero OS Test Script
|
||||
|
||||
Usage: $0 [OPTIONS]
|
||||
|
||||
Options:
|
||||
--qemu Test with QEMU (default)
|
||||
--cloud-hypervisor Test with cloud-hypervisor
|
||||
--all Test with all available runners
|
||||
--serial Use serial console test
|
||||
--interactive Interactive test session
|
||||
--timeout SECONDS Test timeout in seconds (default: 60)
|
||||
--kernel FILE Kernel file to test (default: dist/vmlinuz.efi)
|
||||
--help Show this help message
|
||||
|
||||
Examples:
|
||||
$0 # Basic QEMU test
|
||||
$0 --qemu --serial # QEMU with serial console
|
||||
$0 --cloud-hypervisor # Test with cloud-hypervisor
|
||||
$0 --all # Test with all available runners
|
||||
$0 --interactive # Interactive QEMU session
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
function parse_arguments() {
|
||||
local kernel_file="$DEFAULT_KERNEL"
|
||||
local test_type="basic"
|
||||
local runners=()
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--qemu)
|
||||
runners+=("qemu")
|
||||
shift
|
||||
;;
|
||||
--cloud-hypervisor)
|
||||
runners+=("cloud-hypervisor")
|
||||
shift
|
||||
;;
|
||||
--all)
|
||||
runners=("qemu" "cloud-hypervisor")
|
||||
shift
|
||||
;;
|
||||
--serial)
|
||||
test_type="serial"
|
||||
shift
|
||||
;;
|
||||
--interactive)
|
||||
test_type="interactive"
|
||||
shift
|
||||
;;
|
||||
--timeout)
|
||||
TEST_TIMEOUT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--kernel)
|
||||
kernel_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help|-h)
|
||||
show_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown option: $1"
|
||||
show_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Default to QEMU if no runner specified
|
||||
if [[ ${#runners[@]} -eq 0 ]]; then
|
||||
runners=("qemu")
|
||||
fi
|
||||
|
||||
# Export parsed values
|
||||
export KERNEL_FILE="$kernel_file"
|
||||
export TEST_TYPE="$test_type"
|
||||
export TEST_RUNNERS=("${runners[@]}")
|
||||
}
|
||||
|
||||
# Run tests with specified runners
|
||||
function run_tests() {
|
||||
section_header "Running Zero OS Boot Tests"
|
||||
|
||||
# Verify kernel file exists
|
||||
if [[ ! -f "$KERNEL_FILE" ]]; then
|
||||
log_error "Kernel file not found: ${KERNEL_FILE}"
|
||||
log_info "Run './scripts/build.sh' first to build the kernel"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local kernel_size=$(get_file_size "$KERNEL_FILE")
|
||||
log_info "Testing kernel: ${KERNEL_FILE} (${kernel_size})"
|
||||
log_info "Test type: ${TEST_TYPE}"
|
||||
log_info "Test timeout: ${TEST_TIMEOUT}s"
|
||||
|
||||
local test_results=()
|
||||
local overall_success=true
|
||||
|
||||
# Run tests with each specified runner
|
||||
for runner in "${TEST_RUNNERS[@]}"; do
|
||||
log_info "Testing with runner: ${runner}"
|
||||
|
||||
case "$runner" in
|
||||
"qemu")
|
||||
if testing_qemu_boot "$KERNEL_FILE" "$TEST_TYPE" "$TEST_TIMEOUT"; then
|
||||
test_results+=("QEMU-${TEST_TYPE}: PASS")
|
||||
else
|
||||
test_results+=("QEMU-${TEST_TYPE}: FAIL")
|
||||
overall_success=false
|
||||
fi
|
||||
;;
|
||||
"cloud-hypervisor")
|
||||
if command_exists "cloud-hypervisor"; then
|
||||
if testing_cloud_hypervisor_boot "$KERNEL_FILE" "$TEST_TYPE" "$TEST_TIMEOUT"; then
|
||||
test_results+=("cloud-hypervisor-${TEST_TYPE}: PASS")
|
||||
else
|
||||
test_results+=("cloud-hypervisor-${TEST_TYPE}: FAIL")
|
||||
overall_success=false
|
||||
fi
|
||||
else
|
||||
log_warn "cloud-hypervisor not available, skipping"
|
||||
test_results+=("cloud-hypervisor: SKIPPED")
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown test runner: ${runner}"
|
||||
test_results+=("${runner}: ERROR")
|
||||
overall_success=false
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Report final results
|
||||
section_header "Test Results Summary"
|
||||
|
||||
for result in "${test_results[@]}"; do
|
||||
if [[ "$result" =~ PASS ]]; then
|
||||
log_info "✓ $result"
|
||||
elif [[ "$result" =~ FAIL ]]; then
|
||||
log_error "✗ $result"
|
||||
elif [[ "$result" =~ SKIPPED ]]; then
|
||||
log_warn "⚠ $result"
|
||||
else
|
||||
log_error "✗ $result"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$overall_success" == "true" ]]; then
|
||||
log_info "All tests completed successfully"
|
||||
return 0
|
||||
else
|
||||
log_error "Some tests failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function
|
||||
function main() {
|
||||
# Parse command line arguments
|
||||
parse_arguments "$@"
|
||||
|
||||
echo ""
|
||||
echo "=================================================="
|
||||
echo "== ZERO-OS BOOT TESTING =="
|
||||
echo "=================================================="
|
||||
echo ""
|
||||
|
||||
# Run tests
|
||||
run_tests
|
||||
|
||||
section_header "Testing Complete"
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user