1 /*
2 * Copyright (c) 2016, 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 */
78 delete_file(name);
79 #endif
80 }
81
82 static inline void init_log_file(const char* filename, const char* options = "") {
83 LogStreamHandle(Error, logging) stream;
84 bool success = LogConfiguration::parse_log_arguments(filename, "logging=trace", "", options, &stream);
85 guarantee(success, "Failed to initialize log file '%s' with options '%s'", filename, options);
86 log_debug(logging)("%s", LOG_TEST_STRING_LITERAL);
87 success = LogConfiguration::parse_log_arguments(filename, "all=off", "", "", &stream);
88 guarantee(success, "Failed to disable logging to file '%s'", filename);
89 }
90
91 // Read a complete line from fp and return it as a resource allocated string.
92 // Returns NULL on EOF.
93 static inline char* read_line(FILE* fp) {
94 assert(fp != NULL, "invalid fp");
95 int buflen = 512;
96 char* buf = NEW_RESOURCE_ARRAY(char, buflen);
97 long pos = ftell(fp);
98
99 char* ret = fgets(buf, buflen, fp);
100 while (ret != NULL && buf[strlen(buf) - 1] != '\n' && !feof(fp)) {
101 // retry with a larger buffer
102 buf = REALLOC_RESOURCE_ARRAY(char, buf, buflen, buflen * 2);
103 buflen *= 2;
104 // rewind to beginning of line
105 fseek(fp, pos, SEEK_SET);
106 // retry read with new buffer
107 ret = fgets(buf, buflen, fp);
108 }
109 return ret;
110 }
111
112 static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) {
113 FILE* fp = fopen(filename, "r");
114 assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno));
115
116 size_t idx = 0;
117 while (substrs[idx] != NULL) {
|
1 /*
2 * Copyright (c) 2016, 2018, 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 */
78 delete_file(name);
79 #endif
80 }
81
82 static inline void init_log_file(const char* filename, const char* options = "") {
83 LogStreamHandle(Error, logging) stream;
84 bool success = LogConfiguration::parse_log_arguments(filename, "logging=trace", "", options, &stream);
85 guarantee(success, "Failed to initialize log file '%s' with options '%s'", filename, options);
86 log_debug(logging)("%s", LOG_TEST_STRING_LITERAL);
87 success = LogConfiguration::parse_log_arguments(filename, "all=off", "", "", &stream);
88 guarantee(success, "Failed to disable logging to file '%s'", filename);
89 }
90
91 // Read a complete line from fp and return it as a resource allocated string.
92 // Returns NULL on EOF.
93 static inline char* read_line(FILE* fp) {
94 assert(fp != NULL, "invalid fp");
95 int buflen = 512;
96 char* buf = NEW_RESOURCE_ARRAY(char, buflen);
97 long pos = ftell(fp);
98 if (pos < 0) return NULL;
99
100 char* ret = fgets(buf, buflen, fp);
101 while (ret != NULL && buf[strlen(buf) - 1] != '\n' && !feof(fp)) {
102 // retry with a larger buffer
103 buf = REALLOC_RESOURCE_ARRAY(char, buf, buflen, buflen * 2);
104 buflen *= 2;
105 // rewind to beginning of line
106 fseek(fp, pos, SEEK_SET);
107 // retry read with new buffer
108 ret = fgets(buf, buflen, fp);
109 }
110 return ret;
111 }
112
113 static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) {
114 FILE* fp = fopen(filename, "r");
115 assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno));
116
117 size_t idx = 0;
118 while (substrs[idx] != NULL) {
|