blob: bf67410741c70c66671f6250af09fd81bddcfc59 [file] [log] [blame]
Tomáš Pecka55f64f82020-12-10 19:03:30 +01001#include "trompeloeil_doctest.h"
2#include "pretty_printers.h"
3#include "test_log_setup.h"
4#include "test_sysrepo_helpers.h"
5
6/* This is a generic test for the following use-case in the ietf-hardware model
7 * - Process #1 starts and uses sr_set_item to set some data in the "/ietf-hardware:hardware/component" subtree
8 * - Process #2 starts and implements sr_oper_get_items_subscribe for the data in the same subtree
9 * - Process #3 should see all of the data.
10 *
11 * Processes #1 and #2 are started (and stopped) by ctest wrapper script (sysrepo_test_merge_fixture.sh) and their code can be found in sysrepo_test_merge_daemon.cpp
12 * The wrapper script ŕeturns *after* both processes report that sysrepo is initialised (ie., callback is added in #2, items are set in #1).
13 * This is implemented simply via some checks whether file exists (see the sh file).
14 */
15
16using namespace std::chrono_literals;
17
18TEST_CASE("HardwareState with two daemons")
19{
20 TEST_SYSREPO_INIT;
21 TEST_SYSREPO_INIT_LOGS;
22
23 SECTION("Test when both processes are running")
24 {
25 srSess->session_switch_ds(SR_DS_OPERATIONAL);
26 REQUIRE(dataFromSysrepo(srSess, "/ietf-hardware:hardware") == std::map<std::string, std::string> {
27 {"/component[name='ne']", ""},
28 {"/component[name='ne']/name", "ne"},
29 {"/component[name='ne']/class", "iana-hardware:module"},
30 {"/component[name='ne']/description", "This data was brought to you by process 2 (subscr)."},
31 {"/component[name='ne']/sensor-data", ""},
32 {"/component[name='ne:edfa']", ""},
33 {"/component[name='ne:edfa']/name", "ne:edfa"},
34 {"/component[name='ne:edfa']/class", "iana-hardware:module"},
35 {"/component[name='ne:edfa']/sensor-data", ""},
36 {"/component[name='ne:ctrl']", ""},
37 {"/component[name='ne:ctrl']/name", "ne:ctrl"},
38 {"/component[name='ne:ctrl']/class", "iana-hardware:module"},
39 {"/component[name='ne:ctrl']/sensor-data", ""},
40 });
41 srSess->session_switch_ds(SR_DS_RUNNING);
42 }
43}