-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QA-536: move san file handling in its own class (#20898)
* move san file handling in its own class, and also deploy it for launched subprocesses * move this function as well. * use san file handler * fix import * fix name clash * don't shadow param * fix binary name * Update js/client/modules/@arangodb/testutils/instance.js Co-authored-by: Manuel Pöter <[email protected]> * Update js/client/modules/@arangodb/testutils/process-utils.js Co-authored-by: Manuel Pöter <[email protected]> * fix constructing parameters * debug * remove spooky chars * remove spooky chars * no debug * Update js/client/modules/@arangodb/testutils/san-file-handler.js Co-authored-by: Manuel Pöter <[email protected]> * preserve any crash * backwards compatibility * backwards compatibility --------- Co-authored-by: Manuel Pöter <[email protected]> Co-authored-by: Vadim Kondratev <[email protected]>
- Loading branch information
1 parent
adf9d99
commit 25c89db
Showing
3 changed files
with
145 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
js/client/modules/@arangodb/testutils/san-file-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* jshint strict: false, sub: true */ | ||
/* global print, arango */ | ||
'use strict'; | ||
|
||
// ////////////////////////////////////////////////////////////////////////////// | ||
// / DISCLAIMER | ||
// / | ||
// / Copyright 2014-2024 ArangoDB GmbH, Cologne, Germany | ||
// / Copyright 2004-2014 triAGENS GmbH, Cologne, Germany | ||
// / | ||
// / Licensed under the Business Source License 1.1 (the "License"); | ||
// / you may not use this file except in compliance with the License. | ||
// / You may obtain a copy of the License at | ||
// / | ||
// / https://github.com/arangodb/arangodb/blob/devel/LICENSE | ||
// / | ||
// / Unless required by applicable law or agreed to in writing, software | ||
// / distributed under the License is distributed on an "AS IS" BASIS, | ||
// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// / See the License for the specific language governing permissions and | ||
// / limitations under the License. | ||
// / | ||
// / Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// / | ||
// / @author Wilfried Goesgens | ||
// ////////////////////////////////////////////////////////////////////////////// | ||
|
||
const _ = require('lodash'); | ||
const fs = require('fs'); | ||
const crashUtils = require('@arangodb/testutils/crash-utils'); | ||
|
||
var regex = /[^\u0000-\u00ff]/; // Small performance gain from pre-compiling the regex | ||
function containsDoubleByte(str) { | ||
if (!str.length) return false; | ||
if (str.charCodeAt(0) > 255) return true; | ||
return regex.test(str); | ||
} | ||
|
||
class sanHandler { | ||
constructor(binaryName, sanOptions, isSan, extremeVerbosity) { | ||
this.binaryName = binaryName; | ||
this.sanOptions = _.clone(sanOptions); | ||
this.enabled = isSan; | ||
this.extremeVerbosity = extremeVerbosity; | ||
this.sanitizerLogPaths = {}; | ||
this.backup = {}; | ||
} | ||
detectLogfiles(rootDir, tmpDir) { | ||
if (this.enabled) { | ||
if (containsDoubleByte(rootDir)) { | ||
rootDir = tmpDir; | ||
} | ||
for (const [key, value] of Object.entries(this.sanOptions)) { | ||
let oneLogFile = fs.join(rootDir, key.toLowerCase().split('_')[0] + '.log'); | ||
// we need the log files to contain the exe name, otherwise our code to pick them up won't find them | ||
this.sanOptions[key]['log_exe_name'] = "true"; | ||
const origPath = this.sanOptions[key]['log_path']; | ||
this.sanOptions[key]['log_path'] = oneLogFile; | ||
this.sanitizerLogPaths[key] = { upstream: origPath, local: oneLogFile }; | ||
} | ||
} | ||
} | ||
setSanOptions() { | ||
if (this.enabled) { | ||
print("Using sanOptions ", this.sanOptions); | ||
for (const [key, value] of Object.entries(this.sanOptions)) { | ||
let oneSet = ""; | ||
for (const [keyOne, valueOne] of Object.entries(value)) { | ||
if (oneSet.length > 0) { | ||
oneSet += ":"; | ||
} | ||
let val = valueOne.replace(/,/g, '_'); | ||
oneSet += `${keyOne}=${val}`; | ||
} | ||
this.backup[key] = process.env[key]; | ||
process.env[key] = oneSet; | ||
} | ||
} | ||
} | ||
resetSanOptions() { | ||
if (this.enabled) { | ||
for (const [key, value] of Object.entries(this.backup)) { | ||
process.env[key] = value; | ||
} | ||
} | ||
} | ||
|
||
fetchSanFileAfterExit(pid) { | ||
if (!this.enabled) { | ||
return false; | ||
} | ||
let ret = false; | ||
for (const [key, value] of Object.entries(this.sanitizerLogPaths)) { | ||
print("processing ", value); | ||
const { upstream, local } = value; | ||
let fn = `${local}.${this.binaryname}.${pid}`; | ||
if (this.extremeVerbosity) { | ||
print(`checking for ${fn}: ${fs.exists(fn)}`); | ||
} | ||
if (fs.exists(fn)) { | ||
let content = fs.read(fn); | ||
if (upstream) { | ||
print("found file ", fn, " - writing file ", `${upstream}.${this.binaryName}.${this.pid}`); | ||
fs.write(`${upstream}.${this.binaryName}.${this.pid}`, content); | ||
} | ||
if (content.length > 10) { | ||
crashUtils.GDB_OUTPUT += `Report of '${this.name}' in ${fn} contains: \n`; | ||
crashUtils.GDB_OUTPUT += content; | ||
ret = true; | ||
} | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
} | ||
|
||
exports.sanHandler = sanHandler; |