forked from QMCPACK/qmcpack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_WalkerLogManager.cpp
More file actions
69 lines (58 loc) · 2.08 KB
/
test_WalkerLogManager.cpp
File metadata and controls
69 lines (58 loc) · 2.08 KB
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
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source
// License. See LICENSE file in top directory for details.
//
// Copyright (c) 2025 QMCPACK developers.
//
// File developed by: Peter W. Doak, doakpw@ornl.gov, Oak Ridge National
// Laboratory
//////////////////////////////////////////////////////////////////////////////////////
#include "OhmmsData/Libxml2Doc.h"
#include "QMCDrivers/WalkerLogManager.h"
#include "catch.hpp"
#include "Message/Communicate.h"
#include <MockGoldWalkerElements.h>
#include "ValidWalkerLogInput.h"
#include "WalkerLogInput.h"
namespace qmcplusplus
{
class CollectorHolder
{
public:
void setWalkerLogCollector(UPtr<WalkerLogCollector>&& wlc) { walker_collector_ = std::move(wlc); }
void startBlock() { walker_collector_->startBlock(); }
private:
UPtr<WalkerLogCollector> walker_collector_;
};
struct LogAndStuff
{
WalkerLogManager wlm;
CollectorHolder ch;
};
TEST_CASE("WalkerLogManager::move", "[drivers]")
{
Communicate* comm = OHMMS::Controller;
RuntimeOptions run_time_options;
auto mgwe = testing::makeGoldWalkerElementsWithEEEI(comm, run_time_options);
using WLInput = testing::WalkerLogInputSections;
Libxml2Document doc;
bool okay = doc.parseFromString(WLInput::getXml(WLInput::valid::DEFAULT));
REQUIRE(okay);
xmlNodePtr node = doc.getRoot();
WalkerLogInput walker_log_input{node};
auto make_stuff = [comm](WalkerLogInput& walker_log_input) -> LogAndStuff {
WalkerLogManager wlm{walker_log_input, true, "root_name", comm};
CollectorHolder ch;
ch.setWalkerLogCollector(wlm.makeCollector());
return {std::move(wlm), std::move(ch)};
};
auto l_and_s = make_stuff(walker_log_input);
// In the past this has resulted in a AddressSanitizer:
// stack-use-after-return
// due to access to a dead reference to
// a state object made back in moved from WalkerLogManager in
// the factory function. Seemed to work in release, caught by llvm
// asan.
l_and_s.ch.startBlock();
}
} // namespace qmcplusplus