Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/ngp/NgpDebugFieldSync_Fixtures.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include "NgpDebugFieldSync_Fixtures.hpp"
36 #include <gtest/gtest.h>
37 #include "stk_util/stk_kokkos_macros.h"
38 #include "stk_mesh/base/FieldSyncDebugging.hpp"
39 #include <string>
40 #include <sstream>
41 #include <vector>
42
43 template <typename Out>
44 void split_lines(const std::string &s, Out result) {
45 std::istringstream iss(s);
46 std::string item;
47 while (std::getline(iss, item)) {
48 *result++ = item;
49 }
50 }
51
52 std::vector<std::string> split_lines(const std::string &s) {
53 std::vector<std::string> elems;
54 split_lines(s, std::back_inserter(elems));
55 return elems;
56 }
57
58 void extract_warning(std::string & stdoutString, [[maybe_unused]] int numExpectedOccurrences, const std::string & warningString)
59 {
60 std::vector<std::string> warningLines = split_lines(stdoutString);
61 std::string newStdoutString;
62 #if defined(STK_USE_DEVICE_MESH)
63 int numFound = 0;
64 #endif
65
66 for (const std::string & line : warningLines) {
67 const size_t loc = line.find(warningString);
68 if (loc != std::string::npos) {
69 #if defined(STK_USE_DEVICE_MESH)
70 ++numFound;
71 #endif
72 }
73 else {
74 newStdoutString += line + "\n";
75 }
76 }
77
78 #if defined(STK_USE_DEVICE_MESH)
79 if (numFound != numExpectedOccurrences) {
80 std::cout << "Warning string found " << numFound << " times when expecting " << numExpectedOccurrences << " occurrences: \""
81 << warningString << "\"" << std::endl;
82 ADD_FAILURE();
83 }
84 #endif
85
86 stdoutString = newStdoutString;
87 }
88
89 void check_no_warnings(const std::string & stdoutString)
90 {
91 std::vector<std::string> warningLines = split_lines(stdoutString);
92
93 for (const std::string & line : warningLines) {
94 if (!line.empty()) {
95 std::cout << "Found unexpected warning: \"" << line << "\"" << std::endl;
96 ADD_FAILURE();
97 }
98 }
99 }
100
101 void check_contains_file_name([[maybe_unused]] const std::string & stdoutString, [[maybe_unused]] const std::string & fileName)
102 {
103 #if defined(STK_USE_DEVICE_MESH) && defined(HOST_USE_LOCATION_BUILTINS)
104 const size_t fileNameLoc = stdoutString.find(fileName);
105 EXPECT_NE(fileNameLoc, std::string::npos) << "Could not find fileName '" << fileName
106 << "' in stdoutString '" << stdoutString << "'" << std::endl;
107 #endif
108 }
109
110 void check_contains_a_line_number([[maybe_unused]] const std::string & stdoutString)
111 {
112 #if defined(STK_USE_DEVICE_MESH) && defined(HOST_USE_LOCATION_BUILTINS)
113 const size_t colonLoc = stdoutString.find(":");
114 ASSERT_NE(colonLoc, std::string::npos);
115 const size_t lineNumberLoc = colonLoc + 1;
116 int lineNumber = std::stoi(stdoutString.data()+lineNumberLoc);
117 EXPECT_GT(lineNumber, 0);
118 #endif
119 }