File: cond-start-task.sh

package info (click to toggle)
finit 4.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,216 kB
  • sloc: ansic: 17,060; sh: 6,281; makefile: 532
file content (88 lines) | stat: -rwxr-xr-x 1,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# A run/task runs once per runlevel, unless its .conf is touched
# then it will run again on initctl reload.  This test verifies
# this behavior, with the added twist of starting the task by
# asserting a condition.
set -eu

TEST_DIR=$(dirname "$0")

test_teardown()
{
    say "Running test teardown."
    run "rm -f $TEST_CONF"
}

test_one()
{
    cond=$1
    stanza=$2

    sleep 5
    say 'Enable finit debug, try to figure out what is going on ...'
    run "initctl debug"

    say "Add stanza '$stanza' to $TEST_CONF ..."
    run "echo '$stanza' > $TEST_CONF"

    run "ls -l /run/ /run/finit/"
    say 'Reload Finit'
    run "initctl ls"
    run "initctl reload"
    run "initctl status"
    run "ps"

    date
    sleep 2
    date
    run "ls -l /run/ /run/finit/"
    say 'Asserting condition'
    run "initctl cond set $cond"

    date
    sleep 2
    date
    run "ls -l /run/ /run/finit/"
    run "initctl status"
    run "ps"
    run "initctl status task.sh"

    sleep 1
    run "echo Hej; cat /run/task.state"

    assert_file_contains /run/task.state 1

    say 'Reload Finit'
    run "initctl reload"
    sleep 1
    say 'Ensure task has not run again ...'
    assert_file_contains /run/task.state 1

    say 'Switch to another runlevel ...'
    run "initctl runlevel 3"
    sleep 1
    say 'Ensure task has run again ...'
    assert_file_contains /run/task.state 2
    
    say 'Touch task.sh .conf file and reload Finit ...'
    run "touch $TEST_CONF"
    run "initctl reload"
    sleep 1
    #	run "initctl status task.sh"
    assert_file_contains /run/task.state 3

    say "Done, drop stanza from $TEST_CONF ..."
    run "rm $TEST_CONF"
    run "initctl reload"

    # Done, disable debug
    run "initctl debug"
}


# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"

TEST_CONF=$FINIT_RCSD/cond.conf

test_one "hello" "task <usr/hello> task.sh -- Hello task"