11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst start = process.cpuUsage(); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Run a busy-loop for specified # of milliseconds. 81cb0ef41Sopenharmony_ciconst RUN_FOR_MS = 500; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Define slop factor for checking maximum expected diff values. 111cb0ef41Sopenharmony_ciconst SLOP_FACTOR = 2; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// Run a busy loop. 141cb0ef41Sopenharmony_ciconst now = Date.now(); 151cb0ef41Sopenharmony_ciwhile (Date.now() - now < RUN_FOR_MS); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// Get a diff reading from when we started. 181cb0ef41Sopenharmony_ciconst diff = process.cpuUsage(start); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst MICROSECONDS_PER_MILLISECOND = 1000; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci// Diff usages should be >= 0, <= ~RUN_FOR_MS millis. 231cb0ef41Sopenharmony_ci// Let's be generous with the slop factor, defined above, in case other things 241cb0ef41Sopenharmony_ci// are happening on this CPU. The <= check may be invalid if the node process 251cb0ef41Sopenharmony_ci// is making use of multiple CPUs, in which case, just remove it. 261cb0ef41Sopenharmony_ciassert(diff.user >= 0); 271cb0ef41Sopenharmony_ciassert(diff.user <= SLOP_FACTOR * RUN_FOR_MS * MICROSECONDS_PER_MILLISECOND); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciassert(diff.system >= 0); 301cb0ef41Sopenharmony_ciassert(diff.system <= SLOP_FACTOR * RUN_FOR_MS * MICROSECONDS_PER_MILLISECOND); 31