From 5b758b93d5c8285f8e1960278682efd76cb10253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 11 Apr 2024 09:29:27 +0200 Subject: [PATCH] test: simplify ASan build checks Always use `process.config.variables.asan`. This removes the need for a special ASAN env var. PR-URL: https://github.com/nodejs/node/pull/52430 Reviewed-By: Antoine du Hamel Reviewed-By: Richard Lau Reviewed-By: Marco Ippolito Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli --- .github/workflows/test-asan.yml | 1 - test/common/index.js | 4 ++-- test/parallel/test-crypto-dh-leak.js | 4 ++-- test/parallel/test-crypto-secure-heap.js | 4 ++-- test/parallel/test-strace-openat-openssl.js | 2 +- test/parallel/test-v8-serialize-leak.js | 4 ++-- test/pummel/test-vm-memleak.js | 4 ++-- tools/test.py | 7 ++++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-asan.yml b/.github/workflows/test-asan.yml index 26284547f5bd10..495f6679d950d5 100644 --- a/.github/workflows/test-asan.yml +++ b/.github/workflows/test-asan.yml @@ -45,7 +45,6 @@ jobs: CXX: clang++ LINK: clang++ CONFIG_FLAGS: --enable-asan - ASAN: true steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: diff --git a/test/common/index.js b/test/common/index.js index 41c103be2a61d5..4aeac8293b30fa 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -128,7 +128,7 @@ const isFreeBSD = process.platform === 'freebsd'; const isOpenBSD = process.platform === 'openbsd'; const isLinux = process.platform === 'linux'; const isOSX = process.platform === 'darwin'; -const isAsan = process.env.ASAN !== undefined; +const isASan = process.config.variables.asan === 1; const isPi = (() => { try { // Normal Raspberry Pi detection is to find the `Raspberry Pi` string in @@ -960,7 +960,7 @@ const common = { hasMultiLocalhost, invalidArgTypeHelper, isAlive, - isAsan, + isASan, isDumbTerminal, isFreeBSD, isLinux, diff --git a/test/parallel/test-crypto-dh-leak.js b/test/parallel/test-crypto-dh-leak.js index fe8c138ac2c98f..85160358c8d3d8 100644 --- a/test/parallel/test-crypto-dh-leak.js +++ b/test/parallel/test-crypto-dh-leak.js @@ -4,8 +4,8 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); -if (process.config.variables.asan) - common.skip('ASAN messes with memory measurements'); +if (common.isASan) + common.skip('ASan messes with memory measurements'); const assert = require('assert'); const crypto = require('crypto'); diff --git a/test/parallel/test-crypto-secure-heap.js b/test/parallel/test-crypto-secure-heap.js index fd6a90658d129d..0e5788f00e4a44 100644 --- a/test/parallel/test-crypto-secure-heap.js +++ b/test/parallel/test-crypto-secure-heap.js @@ -7,8 +7,8 @@ if (!common.hasCrypto) if (common.isWindows) common.skip('Not supported on Windows'); -if (process.config.variables.asan) - common.skip('ASAN does not play well with secure heap allocations'); +if (common.isASan) + common.skip('ASan does not play well with secure heap allocations'); const assert = require('assert'); const { fork } = require('child_process'); diff --git a/test/parallel/test-strace-openat-openssl.js b/test/parallel/test-strace-openat-openssl.js index f5202eea8a7b24..13882e67aec0f2 100644 --- a/test/parallel/test-strace-openat-openssl.js +++ b/test/parallel/test-strace-openat-openssl.js @@ -9,7 +9,7 @@ if (!common.hasCrypto) common.skip('missing crypto'); if (!common.isLinux) common.skip('linux only'); -if (common.isAsan) +if (common.isASan) common.skip('strace does not work well with address sanitizer builds'); if (spawnSync('strace').error !== undefined) { common.skip('missing strace'); diff --git a/test/parallel/test-v8-serialize-leak.js b/test/parallel/test-v8-serialize-leak.js index 89b36c4a248dd4..ce0a06196e9fb1 100644 --- a/test/parallel/test-v8-serialize-leak.js +++ b/test/parallel/test-v8-serialize-leak.js @@ -18,8 +18,8 @@ for (let i = 0; i < 1000000; i++) { async function main() { await common.gcUntil('RSS should go down', () => { const after = process.memoryUsage.rss(); - if (process.config.variables.asan) { - console.log(`asan: before=${before} after=${after}`); + if (common.isASan) { + console.log(`ASan: before=${before} after=${after}`); return after < before * 10; } else if (process.config.variables.node_builtin_modules_path) { console.log(`node_builtin_modules_path: before=${before} after=${after}`); diff --git a/test/pummel/test-vm-memleak.js b/test/pummel/test-vm-memleak.js index be29dfe867f293..179dc3e5705c2e 100644 --- a/test/pummel/test-vm-memleak.js +++ b/test/pummel/test-vm-memleak.js @@ -24,8 +24,8 @@ const common = require('../common'); -if (process.config.variables.asan) { - common.skip('ASAN messes with memory measurements'); +if (common.isASan) { + common.skip('ASan messes with memory measurements'); } const assert = require('assert'); diff --git a/tools/test.py b/tools/test.py index 5a2bcb3b6d92ca..13ea6d12082bfc 100755 --- a/tools/test.py +++ b/tools/test.py @@ -1588,8 +1588,9 @@ def get_env_type(vm, options_type, context): return env_type -def get_asan_state(): - return "on" if os.environ.get('ASAN') is not None else "off" +def get_asan_state(vm, context): + asan = Execute([vm, '-p', 'process.config.variables.asan'], context).stdout + return "on" if asan == "1" else "off" def Main(): @@ -1684,7 +1685,7 @@ def Main(): 'system': utils.GuessOS(), 'arch': vmArch, 'type': get_env_type(vm, options.type, context), - 'asan': get_asan_state(), + 'asan': get_asan_state(vm, context), } test_list = root.ListTests([], path, context, arch, mode) unclassified_tests += test_list