File: TestSimulator.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 (99 lines) | stat: -rw-r--r-- 3,342 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
/*
 * 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 <string>

#include <boost/test/unit_test.hpp>

#include "ecflow/core/File.hpp"
#include "ecflow/node/System.hpp"
#include "ecflow/simulator/Simulator.hpp"

using namespace std;
using namespace ecf;

BOOST_AUTO_TEST_SUITE(S_Simulator)

BOOST_AUTO_TEST_SUITE(T_Simulator)

void simulate(const std::string& directory, bool pass) {
    auto full_path = fs::absolute(directory);

    BOOST_CHECK(fs::exists(full_path));
    BOOST_CHECK(fs::is_directory(full_path));

    // std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n";
    fs::directory_iterator end_iter;
    for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr) {

        try {
            fs::path relPath(directory + "/" + dir_itr->path().filename().string());

            // recurse down directories
            if (is_directory(dir_itr->status())) {
                simulate(relPath.string(), pass);
                continue;
            }

            // Only simulate file with .def file extension, i.e. ignore log files.
            // cout << "path = " << relPath << "\n";
            if (File::getExt(relPath.filename().string()) != "def" &&
                File::getExt(relPath.filename().string()) != "got") {
                continue;
            }

            // std::cout << "...............Simulating file " << relPath.string() << "\n";
            Simulator simulator;
            std::string errorMsg;
            bool simPass = simulator.run(relPath.string(), errorMsg);
            if (pass) {
                // Test expected to pass
                BOOST_CHECK_MESSAGE(simPass, "Simulator expected to pass for " << relPath << "\n" << errorMsg);
            }
            else {
                // test expected to fail
                BOOST_CHECK_MESSAGE(!simPass, "Simulator expected to fail for " << relPath << "\n" << errorMsg);
            }

            // remove generated log file. Comment out to debug
            std::string logFileName = relPath.string() + ".log";
            fs::remove(logFileName);
        }
        catch (const std::exception& ex) {
            std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
        }
    }
}

BOOST_AUTO_TEST_CASE(test_simulate_good_defs) {
    cout << "Simulator:: ...test_simulate_good_defs\n";

    std::string path = File::test_data("libs/simulator/test/data/good_defs", "libs/simulator");

    // All the defs in this directory are expected to pass
    simulate(path, true);
}

BOOST_AUTO_TEST_CASE(test_simulate_bad_defs) {
    cout << "Simulator:: ...test_simulate_bad_defs\n";

    std::string path = File::test_data("libs/simulator/test/data/bad_defs", "libs/simulator");

    // All the defs in this directory are expected to fail
    simulate(path, false);

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

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()