#!/bin/sh # # $OpenBSD: statemachine,v 1.6 2018/02/05 18:28:15 anton Exp $ #/* # * Copyright (c) Rob Pierce # * # * Permission to use, copy, modify, and distribute this software for any # * purpose with or without fee is hereby granted, provided that the above # * copyright notice and this permission notice appear in all copies. # * # * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # */ # Basic ifstated regression script to test the finite state machine. # # NOTE: Increase LSLEEP as required when adding additional test states. # # Ensure OBJDIR is defined : ${OBJDIR?} || exit 1 export OBJDIR # Global variables FILE1="truth1.test" FILE2="truth2.test" EVERY=2 SLEEP=5 LSLEEP=35 cleanup() { rm ${OBJDIR}/$FILE1 >/dev/null 2>&1 rm ${OBJDIR}/$FILE2 >/dev/null 2>&1 rm ${OBJDIR}/ifstated.conf >/dev/null 2>&1 rm ${OBJDIR}/ifstated.log >/dev/null 2>&1 rm ${OBJDIR}/output.test >/dev/null 2>&1 rm ${OBJDIR}/output.new >/dev/null 2>&1 rm ${OBJDIR}/nohup.out >/dev/null 2>&1 } fail() { echo FAILED cleanup exit 1 } skip() { echo SKIPPED cleanup exit 0 } trap 'skip' INT if [ "$(pgrep ifstated)" ] then echo "The ifstated daemon is already running." echo SKIPPED exit 0 fi rm -f ${OBJDIR}/${FILE1} rm -f ${OBJDIR}/${FILE2} cat > ${OBJDIR}/ifstated.conf < ${OBJDIR}/output.test < ifstated.log 2>&1) & sleep ${LSLEEP} grep ^changing ${OBJDIR}/ifstated.log > ${OBJDIR}/output.new kill $(pgrep ifstated) >/dev/null 2>&1 diff ${OBJDIR}/output.test ${OBJDIR}/output.new case $? in 0) echo PASSED cleanup exit 0 ;; 1) fail ;; esac