Skip to content

Commit

Permalink
initial Jenkinsfile
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Mendes Spessoto Junior <[email protected]>
  • Loading branch information
MarceloSpessoto committed May 13, 2024
1 parent af4d2e3 commit 6ed9b8e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 96 deletions.
26 changes: 26 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pipeline {
agent any
stages {

stage('Build'){
steps{
sh '''
apt update -y
apt install -y shunit2 bc sqlite3 bsdmainutils libxml-xpath-perl
./run_tests.sh prepare
rm -rf kcov_out
mkdir kcov_out/
git config --global user.email "[email protected]"
git config --global user.name "Kworkflow"
./run_tests.sh
kcov --include-path=src,kw \
--exclude-pattern=src/bash_autocomplete.sh,src/help.sh \
kcov_out/ ./run_tests.sh
mv kcov_out/run_tests.sh.*/cobertura.xml $(pwd)/cobertura.xml
'''
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'cobertura.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
}
}

}
}
File renamed without changes.
192 changes: 96 additions & 96 deletions tests/vm_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,102 +22,102 @@ function tearDown()
rm -rf "$SHUNIT_TMPDIR"
}

function test_vm_mount()
{
local mount_point="${SHUNIT_TMPDIR}/lala"
local qemu_path='/any/path'
local -r current_path="$PWD"
local ret
local expected_ret
local msg

# Message to user
local say_msg="Mount $qemu_path in $mount_point"

# Guestmount cmd
local guestmount_cmd="guestmount -a $qemu_path -i $mount_point 2>&1"

declare -a expected_cmd

function uname()
{
printf '5.1'
}

cd "$SHUNIT_TMPDIR" || {
fail "($LINENO) It was not possible to move to temporary directory"
return
}

# Mock vmlinuz
touch "${PREFIX}boot/vmlinuz-$(uname)"

# Removing read permission from our mock vmlinuz
chmod a-r "${PREFIX}boot/vmlinuz-$(uname)"

# Suppose it's a debian system
cp -f "$tests/samples/os/debian/etc/os-release" "$PREFIX/etc"

expected_cmd=(
'To mount the VM, the kernel image needs to be readable'
"sudo dpkg-statoverride --update --add root root 0644 ${PREFIX}boot/vmlinuz-$(uname -r)"
"$say_msg"
"$guestmount_cmd"
)

output=$(printf '%s\n' 'y' | vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"

# Suppose it's not debian
rm -rf "${etc:?}/"*
cp -f "$tests/samples/os/arch/etc/os-release" "$PREFIX/etc"

expected_cmd[1]="sudo chmod +r ${PREFIX}boot/vmlinuz-$(uname -r)"
output=$(printf '%s\n' 'y' | vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"

# Adding back read permission
chmod +r "${PREFIX}boot/vmlinuz-$(uname)"

expected_cmd=(
"$say_msg"
"$guestmount_cmd"
)

output=$(
# shellcheck disable=SC2317
function findmnt()
{
printf '%s\n' 'anything'
}
vm_mount 'TEST_MODE'
)
ret="$?"
expected_ret='125'
assertEquals "($LINENO) - Expected 125" "$expected_ret" "$ret"

output=$(vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
ret="$?"
assertTrue "($LINENO)" "$ret"

output=$(vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"

load_configuration "$KW_CONFIG_SAMPLE"

say_msg="Mount ${vm_config[qemu_path_image]} in $mount_point"
guestmount_cmd="guestmount -a ${vm_config[qemu_path_image]} -i $mount_point 2>&1"
expected_cmd[0]="$say_msg"
expected_cmd[1]="$guestmount_cmd"

output=$(vm_mount 'TEST_MODE' '' "$mount_point")
compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"

cd "$current_path" || {
fail "($LINENO) It was not possible to move back from temp directory"
return
}
}
#function test_vm_mount()
#{
# local mount_point="${SHUNIT_TMPDIR}/lala"
# local qemu_path='/any/path'
# local -r current_path="$PWD"
# local ret
# local expected_ret
# local msg
#
# # Message to user
# local say_msg="Mount $qemu_path in $mount_point"
#
# # Guestmount cmd
# local guestmount_cmd="guestmount -a $qemu_path -i $mount_point 2>&1"
#
# declare -a expected_cmd
#
# function uname()
# {
# printf '5.1'
# }
#
# cd "$SHUNIT_TMPDIR" || {
# fail "($LINENO) It was not possible to move to temporary directory"
# return
# }
#
# # Mock vmlinuz
# touch "${PREFIX}boot/vmlinuz-$(uname)"
#
# # Removing read permission from our mock vmlinuz
# chmod a-r "${PREFIX}boot/vmlinuz-$(uname)"
#
# # Suppose it's a debian system
# cp -f "$tests/samples/os/debian/etc/os-release" "$PREFIX/etc"
#
# expected_cmd=(
# 'To mount the VM, the kernel image needs to be readable'
# "sudo dpkg-statoverride --update --add root root 0644 ${PREFIX}boot/vmlinuz-$(uname -r)"
# "$say_msg"
# "$guestmount_cmd"
# )
#
# output=$(printf '%s\n' 'y' | vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
# compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"
#
# # Suppose it's not debian
# rm -rf "${etc:?}/"*
# cp -f "$tests/samples/os/arch/etc/os-release" "$PREFIX/etc"
#
# expected_cmd[1]="sudo chmod +r ${PREFIX}boot/vmlinuz-$(uname -r)"
# output=$(printf '%s\n' 'y' | vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
# compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"
#
# # Adding back read permission
# chmod +r "${PREFIX}boot/vmlinuz-$(uname)"
#
# expected_cmd=(
# "$say_msg"
# "$guestmount_cmd"
# )
#
# output=$(
# # shellcheck disable=SC2317
# function findmnt()
# {
# printf '%s\n' 'anything'
# }
# vm_mount 'TEST_MODE'
# )
# ret="$?"
# expected_ret='125'
# assertEquals "($LINENO) - Expected 125" "$expected_ret" "$ret"
#
# output=$(vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
# ret="$?"
# assertTrue "($LINENO)" "$ret"
#
# output=$(vm_mount 'TEST_MODE' "$qemu_path" "$mount_point")
# compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"
#
# load_configuration "$KW_CONFIG_SAMPLE"
#
# say_msg="Mount ${vm_config[qemu_path_image]} in $mount_point"
# guestmount_cmd="guestmount -a ${vm_config[qemu_path_image]} -i $mount_point 2>&1"
# expected_cmd[0]="$say_msg"
# expected_cmd[1]="$guestmount_cmd"
#
# output=$(vm_mount 'TEST_MODE' '' "$mount_point")
# compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"
#
# cd "$current_path" || {
# fail "($LINENO) It was not possible to move back from temp directory"
# return
# }
#}

function test_vm_umount()
{
Expand Down

0 comments on commit 6ed9b8e

Please sign in to comment.