Merge pull request #2151 from angelapwen/fix-cpu-group-bug
Account for existing but empty `cpus` file
This commit is contained in:
commit
592977e6ae
7 changed files with 68 additions and 7 deletions
|
|
@ -6,7 +6,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
|
|||
|
||||
## [UNRELEASED]
|
||||
|
||||
No user facing changes.
|
||||
- Fix an issue where an existing, but empty, `/sys/fs/cgroup/cpuset.cpus` file always resulted in a single-threaded run. [#2151](https://github.com/github/codeql-action/pull/2151)
|
||||
|
||||
## 3.24.3 - 15 Feb 2024
|
||||
|
||||
|
|
|
|||
8
lib/util.js
generated
8
lib/util.js
generated
|
|
@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.checkActionVersion = exports.checkDiskUsage = exports.prettyPrintPack = exports.getErrorMessage = exports.wrapError = exports.fixInvalidNotificationsInFile = exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.isInTestMode = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.ConfigurationError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.getMemoryFlagValueForPlatform = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
|
||||
exports.checkActionVersion = exports.checkDiskUsage = exports.prettyPrintPack = exports.getErrorMessage = exports.wrapError = exports.fixInvalidNotificationsInFile = exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.isInTestMode = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.ConfigurationError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getCgroupCpuCountFromCpus = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.getMemoryFlagValueForPlatform = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
|
|
@ -316,7 +316,10 @@ function getCgroupCpuCountFromCpus(cpusFile, logger) {
|
|||
}
|
||||
let cpuCount = 0;
|
||||
// Comma-separated numbers and ranges, for eg. 0-1,3
|
||||
const cpusString = fs.readFileSync(cpusFile, "utf-8");
|
||||
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();
|
||||
if (cpusString.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
for (const token of cpusString.split(",")) {
|
||||
if (!token.includes("-")) {
|
||||
// Not a range
|
||||
|
|
@ -331,6 +334,7 @@ function getCgroupCpuCountFromCpus(cpusFile, logger) {
|
|||
logger.info(`While resolving threads, found a cgroup CPUs file with ${cpuCount} CPUs in ${cpusFile}.`);
|
||||
return cpuCount;
|
||||
}
|
||||
exports.getCgroupCpuCountFromCpus = getCgroupCpuCountFromCpus;
|
||||
/**
|
||||
* Get the codeql `--threads` flag specified for the `threads` input.
|
||||
* If no value was specified, all available threads will be used.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
21
lib/util.test.js
generated
21
lib/util.test.js
generated
|
|
@ -354,4 +354,25 @@ for (const [version, githubVersion, shouldReportWarning,] of CHECK_ACTION_VERSIO
|
|||
versionStub.restore();
|
||||
});
|
||||
}
|
||||
(0, ava_1.default)("getCgroupCpuCountFromCpus calculates the number of CPUs correctly", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
fs.writeFileSync(testCpuFile, "1, 9-10\n", "utf-8");
|
||||
t.deepEqual(util.getCgroupCpuCountFromCpus(testCpuFile, (0, logging_1.getRunnerLogger)(true)), 3);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("getCgroupCpuCountFromCpus returns undefined if the CPU file doesn't exist", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
t.false(fs.existsSync(testCpuFile));
|
||||
t.deepEqual(util.getCgroupCpuCountFromCpus(testCpuFile, (0, logging_1.getRunnerLogger)(true)), undefined);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("getCgroupCpuCountFromCpus returns undefined if the CPU file exists but is empty", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
fs.writeFileSync(testCpuFile, "\n", "utf-8");
|
||||
t.deepEqual(util.getCgroupCpuCountFromCpus(testCpuFile, (0, logging_1.getRunnerLogger)(true)), undefined);
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=util.test.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -449,3 +449,36 @@ for (const [
|
|||
versionStub.restore();
|
||||
});
|
||||
}
|
||||
|
||||
test("getCgroupCpuCountFromCpus calculates the number of CPUs correctly", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir: string) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
fs.writeFileSync(testCpuFile, "1, 9-10\n", "utf-8");
|
||||
t.deepEqual(
|
||||
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
|
||||
3,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("getCgroupCpuCountFromCpus returns undefined if the CPU file doesn't exist", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir: string) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
t.false(fs.existsSync(testCpuFile));
|
||||
t.deepEqual(
|
||||
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("getCgroupCpuCountFromCpus returns undefined if the CPU file exists but is empty", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir: string) => {
|
||||
const testCpuFile = `${tmpDir}/cpus-file`;
|
||||
fs.writeFileSync(testCpuFile, "\n", "utf-8");
|
||||
t.deepEqual(
|
||||
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -440,7 +440,7 @@ function getCgroupCpuCountFromCpuMax(
|
|||
/**
|
||||
* Gets the number of available cores listed in the cgroup cpuset.cpus file at the given path.
|
||||
*/
|
||||
function getCgroupCpuCountFromCpus(
|
||||
export function getCgroupCpuCountFromCpus(
|
||||
cpusFile: string,
|
||||
logger: Logger,
|
||||
): number | undefined {
|
||||
|
|
@ -453,7 +453,10 @@ function getCgroupCpuCountFromCpus(
|
|||
|
||||
let cpuCount = 0;
|
||||
// Comma-separated numbers and ranges, for eg. 0-1,3
|
||||
const cpusString = fs.readFileSync(cpusFile, "utf-8");
|
||||
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();
|
||||
if (cpusString.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
for (const token of cpusString.split(",")) {
|
||||
if (!token.includes("-")) {
|
||||
// Not a range
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue