File: tty.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (108 lines) | stat: -rw-r--r-- 2,956 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#######################################################
#
# Basic checking of 'tty' selector.
#
# The name pattern of ttys varies across operating systems.
# While the example in the documentation (e.g. "pts/[0-9]+")
# is typical and illustrative, this basic-level test needs to be
# reliably portable.
#
# The possible meta "test_skip_needs_work" would allow graceful handling
# of platforms that have not yet been tested.  But aim to minimise
# any reliance on this.
#
# It assumes that the host on which the test is being run will have at least
# one tty connection active.  This is clearly the case if it is being run
# by a human from their command line.  But it might not be true in a
# CI/CD environment; in such a case the meta/skip may be useful.
#
# Tests:
#
# 1.  Negative: using a highly unlikely name.
#
# 2.  Positive: using a known-good name pattern; allow to differ across OSes.
#
# David Lee, 2019
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

#######################################################

bundle agent init
{
  vars:
      "dummy" string => "dummy";
}

#######################################################

bundle agent test
{
  meta:
      "test_skip_needs_work" -> {"CFE-3025"}
        string => "!linux.!hpux",
        comment => "TTY-based process filtering doesn't work well on other platforms";

  vars:
    # Maintenance note: Aim to cover as many OSes as possible
    # and mimimise the ".+" catch-all.
    linux::
      "dev_pattern" string => "(pts/[0-9]+)|(ttyS?[0-9]+)";
    !linux::
      "dev_pattern" string => ".+";

  processes:
      ### Expect zero processes on a tty with a highly unlikely name.
      ".*"
        handle => "expect_none",
        process_select => test_select_tty("No-Such-Major/No-Such-Minor"),
        process_count => test_range("0", "0", "pass_bad_dev", "fail_bad_dev");

      ### Expect to find one or more processes on these ttys.
      ".*"
        handle => "expect_some",
        process_select => test_select_tty("$(dev_pattern)"),
        process_count => test_range("1", "inf", "pass_good_dev", "fail_good_dev");

}

body process_count test_range(min, max, class_good, class_bad)
{
      match_range => irange("$(min)", "$(max)");
      in_range_define => { "$(class_good)" };
      out_of_range_define => { "$(class_bad)" };
}

body process_select test_select_tty(tty_pattern)
{
      tty => "$(tty_pattern)";
      process_result => "tty";
}


#######################################################

bundle agent check
{
  classes:
      "ok" and => {
        "pass_good_dev", "pass_bad_dev",
        "!fail_good_dev", "!fail_bad_dev",
      };

  reports:
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}

### PROJECT_ID: core
### CATEGORY_ID: 30