File: TestZombies.cpp

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (101 lines) | stat: -rw-r--r-- 5,363 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
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright 2009- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation
 * nor does it submit to any jurisdiction.
 */

#include <iostream>

#include <boost/test/unit_test.hpp>

#include "ecflow/attribute/ZombieAttr.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Suite.hpp"
#include "ecflow/node/System.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"

using namespace std;
using namespace ecf;

BOOST_AUTO_TEST_SUITE(U_Node)

BOOST_AUTO_TEST_SUITE(T_Zombies)

BOOST_AUTO_TEST_CASE(test_zombies) {
    ECF_NAME_THIS_TEST();

    Defs theDefs;
    suite_ptr s = theDefs.add_suite("s");
    task_ptr t  = s->add_family("f")->add_task("t");

    // SANITY
    {
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 0, "Expected 0 zombies but found " << s->zombies().size());
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::USER).empty(), "Expected no zombies");
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::ECF).empty(), "Expected no zombies");
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::ECF_PID).empty(), "Expected no zombies");
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::ECF_PASSWD).empty(), "Expected no zombies");
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::ECF_PID_PASSWD).empty(), "Expected no zombies");
        BOOST_REQUIRE_MESSAGE(s->findZombie(ecf::Child::PATH).empty(), "Expected no zombies");
        ZombieAttr attr;
        BOOST_REQUIRE_MESSAGE(!t->findParentZombie(ecf::Child::PATH, attr) && attr.empty(),
                              "Expected to NOT find PATH zombies on parent");
    }

    // ADD
    std::vector<ecf::Child::CmdType> child_cmds = ecf::Child::list();
    {
        s->addZombie(ZombieAttr(ecf::Child::USER, child_cmds, ecf::ZombieCtrlAction::FOB, 10));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 1, "Expected 1 zombie but found " << s->zombies().size());
        s->addZombie(ZombieAttr(ecf::Child::ECF, child_cmds, ecf::ZombieCtrlAction::FAIL, 100));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 2, "Expected 2 zombie but found " << s->zombies().size());
        s->addZombie(ZombieAttr(ecf::Child::ECF_PID, child_cmds, ecf::ZombieCtrlAction::FAIL, 100));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 3, "Expected 3 zombie but found " << s->zombies().size());
        s->addZombie(ZombieAttr(ecf::Child::ECF_PID_PASSWD, child_cmds, ecf::ZombieCtrlAction::FAIL, 100));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 4, "Expected 4 zombie but found " << s->zombies().size());
        s->addZombie(ZombieAttr(ecf::Child::ECF_PASSWD, child_cmds, ecf::ZombieCtrlAction::FAIL, 100));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 5, "Expected 5 zombie but found " << s->zombies().size());
        s->addZombie(ZombieAttr(ecf::Child::PATH, child_cmds, ecf::ZombieCtrlAction::BLOCK, 100));
        BOOST_REQUIRE_MESSAGE(s->zombies().size() == 6, "Expected 6 zombie but found " << s->zombies().size());
    }

    // FIND
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::USER).empty(), "Expected to find USER zombies");
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::ECF).empty(), "Expected to find ECF zombies");
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::ECF_PID).empty(), "Expected to find ECF_PID zombies");
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::ECF_PID_PASSWD).empty(),
                          "Expected to find ECF_PID_PASSWD zombies");
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::ECF_PASSWD).empty(), "Expected to find ECF_PASSWD zombies");
    BOOST_REQUIRE_MESSAGE(!s->findZombie(ecf::Child::PATH).empty(), "Expected to find PATH zombies");

    // FIND on parent
    {
        ZombieAttr path_z, ecf_z, ecf_pid_z, ecf_pid_passwd_z, ecf_passwd_z, user_z;
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::PATH, path_z) && !path_z.empty(),
                              "Expected to find PATH zombies on parent");
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::ECF, ecf_z) && !ecf_z.empty(),
                              "Expected to find ECF zombies on parent");
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::ECF_PID, ecf_pid_z) && !ecf_pid_z.empty(),
                              "Expected to find ECF_PID zombies on parent");
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::ECF_PID_PASSWD, ecf_pid_passwd_z) &&
                                  !ecf_pid_passwd_z.empty(),
                              "Expected to find ECF_PID_PASSWD zombies on parent");
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::ECF_PASSWD, ecf_passwd_z) && !ecf_passwd_z.empty(),
                              "Expected to find ECF_PASSWD zombies on parent");
        BOOST_REQUIRE_MESSAGE(t->findParentZombie(ecf::Child::USER, user_z) && !user_z.empty(),
                              "Expected to find USER zombies on parent");
    }

    /// Destroy System singleton to avoid valgrind from complaining
    System::destroy();
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()