#!/bin/sh

valid=1

if ! modprobe hello_world; then
	echo "could not load module!"
	exit 1
fi

dmesg | grep -i 'hello.*world'
if ! dmesg | grep -qi 'hello.*world' ; then
	valid=0
	echo "can't grep hello world!"
fi

if ! rmmod hello_world; then
	echo "could not unload module!"
	exit 1
fi


if ! modprobe hello_world_param whom=Redha howmany=3; then
	echo "could not load module!"
	exit 1
fi

dmesg | grep -i 'hello.*redha'
if ! dmesg | grep -qi 'hello.*redha'; then
	valid=0
	echo "can't grep hello world!"
fi

count=$(dmesg | grep -ic 'hello.*redha')
if [ ! "$count" -eq 3 ]; then
	echo 'failed to count 3 hello world messages'
    valid=0
fi

printf 'Jerome' > /sys/module/hello_world_param/parameters/whom

rmmod hello_world_param

dmesg | grep 'Jerome'
if ! dmesg | grep -q 'Jerome'; then
	valid=0
fi

if [ $valid -eq 0 ]; then
	echo 'Could not find the strings in dmesg!'
	exit
fi
