Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/logging/logTestFixture.cpp
41145 views
1
/*
2
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include "precompiled.hpp"
25
#include "jvm.h"
26
#include "logTestFixture.hpp"
27
#include "logTestUtils.inline.hpp"
28
#include "logging/logConfiguration.hpp"
29
#include "logging/logOutput.hpp"
30
#include "memory/allocation.inline.hpp"
31
#include "memory/resourceArea.hpp"
32
#include "unittest.hpp"
33
#include "utilities/ostream.hpp"
34
35
LogTestFixture::LogTestFixture() : _n_snapshots(0), _configuration_snapshot(NULL) {
36
37
// Set up TestLogFileName to include temp_dir, PID, testcase name and test name.
38
const testing::TestInfo* test_info = ::testing::UnitTest::GetInstance()->current_test_info();
39
int ret = jio_snprintf(_filename, sizeof(_filename), "%s%stestlog.pid%d.%s.%s.log",
40
os::get_temp_directory(), os::file_separator(), os::current_process_id(),
41
test_info->test_case_name(), test_info->name());
42
EXPECT_GT(ret, 0) << "_filename buffer issue";
43
TestLogFileName = _filename;
44
45
snapshot_config();
46
}
47
48
LogTestFixture::~LogTestFixture() {
49
AsyncLogWriter::flush();
50
restore_config();
51
clear_snapshot();
52
delete_file(TestLogFileName);
53
}
54
55
bool LogTestFixture::set_log_config(const char* output,
56
const char* what,
57
const char* decorators,
58
const char* options,
59
bool allow_failure) {
60
ResourceMark rm;
61
stringStream stream;
62
bool success = LogConfiguration::parse_log_arguments(output, what, decorators, options, &stream);
63
if (!allow_failure) {
64
const char* errmsg = stream.as_string();
65
EXPECT_STREQ("", errmsg) << "Unexpected error reported";
66
EXPECT_TRUE(success) << "Shouldn't cause errors";
67
}
68
return success;
69
}
70
71
void LogTestFixture::snapshot_config() {
72
clear_snapshot();
73
_n_snapshots = LogConfiguration::_n_outputs;
74
_configuration_snapshot = NEW_C_HEAP_ARRAY(char*, _n_snapshots, mtLogging);
75
for (size_t i = 0; i < _n_snapshots; i++) {
76
ResourceMark rm;
77
stringStream ss;
78
LogConfiguration::_outputs[i]->describe(&ss);
79
_configuration_snapshot[i] = os::strdup_check_oom(ss.as_string(), mtLogging);
80
}
81
}
82
83
void LogTestFixture::restore_config() {
84
LogConfiguration::disable_logging();
85
for (size_t i = 0; i < _n_snapshots; i++) {
86
// Restore the config based on the saved output description string.
87
// The string has the following format: '<name> <selection> <decorators>[ <options>]'
88
// Extract the different parameters by replacing the spaces with NULLs.
89
char* str = _configuration_snapshot[i];
90
91
char* name = str;
92
str = strchr(str, ' ');
93
*str++ = '\0';
94
95
char* selection = str;
96
str = strchr(str, ' ');
97
*str++ = '\0';
98
99
char* decorators = str;
100
101
char* options = NULL;
102
str = strchr(str, ' ');
103
if (str != NULL) {
104
*str++ = '\0';
105
options = str;
106
}
107
108
set_log_config(name, selection, decorators, options != NULL ? options : "");
109
}
110
}
111
112
void LogTestFixture::clear_snapshot() {
113
if (_configuration_snapshot == NULL) {
114
return;
115
}
116
assert(_n_snapshots > 0, "non-null array should have at least 1 element");
117
for (size_t i = 0; i < _n_snapshots; i++) {
118
os::free(_configuration_snapshot[i]);
119
}
120
FREE_C_HEAP_ARRAY(char*, _configuration_snapshot);
121
_configuration_snapshot = NULL;
122
_n_snapshots = 0;
123
}
124
125