11cb0ef41Sopenharmony_ci// Flags: --expose-gc --noconcurrent_recompilation 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ciif (!common.hasCrypto) 61cb0ef41Sopenharmony_ci common.skip('missing crypto'); 71cb0ef41Sopenharmony_ciif (process.config.variables.asan) 81cb0ef41Sopenharmony_ci common.skip('ASAN messes with memory measurements'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst assert = require('assert'); 111cb0ef41Sopenharmony_ciconst crypto = require('crypto'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst before = process.memoryUsage.rss(); 141cb0ef41Sopenharmony_ci{ 151cb0ef41Sopenharmony_ci const size = common.hasFipsCrypto || common.hasOpenSSL3 ? 1024 : 256; 161cb0ef41Sopenharmony_ci const dh = crypto.createDiffieHellman(size); 171cb0ef41Sopenharmony_ci const publicKey = dh.generateKeys(); 181cb0ef41Sopenharmony_ci const privateKey = dh.getPrivateKey(); 191cb0ef41Sopenharmony_ci for (let i = 0; i < 5e4; i += 1) { 201cb0ef41Sopenharmony_ci dh.setPublicKey(publicKey); 211cb0ef41Sopenharmony_ci dh.setPrivateKey(privateKey); 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ciglobal.gc(); 251cb0ef41Sopenharmony_ciconst after = process.memoryUsage.rss(); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci// RSS should stay the same, ceteris paribus, but allow for 281cb0ef41Sopenharmony_ci// some slop because V8 mallocs memory during execution. 291cb0ef41Sopenharmony_ciassert(after - before < 10 << 20, `before=${before} after=${after}`); 30