Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upChanges to provide ‘npm run coverage’ #7924
Conversation
| @@ -0,0 +1,108 @@ | |||
| const config = require('../lib/config') | |||
This comment has been minimized.
This comment has been minimized.
masparrow
Jan 27, 2020
•
Author
This file coverage.js is a copy of build.js and is not strictly necessary, it just made sure I didn't break anything else whilst poking around.
The only noteworthy change compared to build.js is the utils.runCoverage step instead of utils.buildTarget
We could perhaps just have another arg for utils.buildTarget that goes on to do coverage, as the steps (as they are) require a full build I think... so it doesn't leverage any existing build of brave_unit_tests a local dev may have just done.
This comment has been minimized.
This comment has been minimized.
bridiver
Jan 28, 2020
Collaborator
missed this comment the first time, but anyway the comments should hopefully help you clean it up
This comment has been minimized.
This comment has been minimized.
masparrow
Jan 29, 2020
Author
@bridiver cheers for the feedback :) So my thinking was building with npm run test -- brave_unit_tests should provide optional flags/args to also generate coverage profile data, provided it doesn't impact/cause issues elsewhere. WDYT?
| @@ -22,7 +22,8 @@ | |||
| "lint": "node ./scripts/commands.js lint", | |||
| "test": "node ./scripts/commands.js test", | |||
| "test:scripts": "jest lib scripts", | |||
| "test-security": "npm run audit_deps && node ./scripts/commands.js start --enable_brave_update --network_log --user_data_dir_name=brave-network-test" | |||
| "test-security": "npm run audit_deps && node ./scripts/commands.js start --enable_brave_update --network_log --user_data_dir_name=brave-network-test", | |||
| "coverage": "node ./scripts/commands.js coverage" | |||
This comment has been minimized.
This comment has been minimized.
| @@ -18,6 +18,7 @@ const l10nDeleteTranslations = require('../lib/l10nDeleteTranslations') | |||
| const createDist = require('../lib/createDist') | |||
| const upload = require('../lib/upload') | |||
| const test = require('../lib/test') | |||
| const coverage = require('../lib/coverage') | |||
This comment has been minimized.
This comment has been minimized.
| .option('--ninja <opt>', 'Additional Ninja command-line options, in the form <key>:<value>', collect, []) | ||
| .option('--brave_safetynet_api_key <brave_safetynet_api_key>') | ||
| .arguments('[build_config]') | ||
| .action(coverage) |
This comment has been minimized.
This comment has been minimized.
|
Did you resolve the issue with the rust linkage? |
Noted the necessary inclusions in the description, looking for feedback on best approach for them. |
| const path = require('path') | ||
| const fs = require('fs-extra') | ||
|
|
||
| const touchOverriddenFiles = () => { |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| if (config.xcode_gen_target) { | ||
| util.generateXcodeWorkspace() |
This comment has been minimized.
This comment has been minimized.
| config.update(options) | ||
| checkVersionsMatch() | ||
|
|
||
| touchOverriddenFiles() |
This comment has been minimized.
This comment has been minimized.
bridiver
Jan 28, 2020
Collaborator
actually why are any of these here? If coverage depends on build then it should run build and the coverage
| .option('--target_os <target_os>', 'target OS') | ||
| .option('--target_arch <target_arch>', 'target architecture') | ||
| .option('--target_apk_base <target_apk_base>', 'target Android OS apk (classic, modern, mono)', 'classic') | ||
| .option('--android_override_version_name <android_override_version_name>', 'Android version number') |
This comment has been minimized.
This comment has been minimized.
| const args = util.buildArgsToString(config.buildArgs()) | ||
| // provide arg for COVERAGE_OUT_DIR | ||
| util.run('gn', ['gen', | ||
| 'out/brave/coverage', // make an arg - i.e. build with COVERAGE_OUT_DIR as 'out/COVERAGE_OUT_DIR/coverage' |
This comment has been minimized.
This comment has been minimized.
bridiver
Jan 28, 2020
Collaborator
I don't think we want to run a new build for code coverage, this doesn't seem right to me
| // provide arg for COVERAGE_OUT_DIR | ||
| util.run('gn', ['gen', | ||
| 'out/brave/coverage', // make an arg - i.e. build with COVERAGE_OUT_DIR as 'out/COVERAGE_OUT_DIR/coverage' | ||
| '--args="' + args + ' use_clang_coverage=true is_component_build=false dcheck_always_on=true"'], options) |
This comment has been minimized.
This comment has been minimized.
bridiver
Jan 28, 2020
Collaborator
this is definitely not right, these should always be handled by config.js and you shouldn't be running gn gen directly like this anyway, you should be using util.buildTarget, but I'm not sure that makes sense here either since I think we should just be running build first?
| runCoverage: (options = config.defaultOptions) => { | ||
| console.log('running coverage for ' + config.buildTarget + '...') | ||
|
|
||
| if (process.platform === 'win32') util.updateOmahaMidlFiles() |
This comment has been minimized.
This comment has been minimized.
a6dc34e
to
a7f4413
62ab5ac
to
b92e93e
masparrow commentedJan 27, 2020
•
edited
DO NOT MERGE
This PR is just to show how to utilise [Chromium Coverage]m on Mac OSX (Mojave) (https://chromium.googlesource.com/chromium/src/+/master/docs/testing/code_coverage.md) within Brave.
Warrants further discussion on how to incorporate it into dev usage, and CI/Automation with devops.
The following steps are needed, but are not production/devop platform final - we'd need to decide what/how best to fulfil the requirements.
Steps to 'be able to' run Coverage
llvm-profdata&llvm-cov-- the install 'tool link' in Chromium's web page link didn't work for me, I obtained the full LLVM tools package from LLVM, and made sure the 'bin' folder was in my local PATH
binto PATH-- may not be necessary if installed properly
src/third_party/depot_toolsto PATH-- should already be required for Brave builds?… but I had to add it
export LLVM_PROFILE_FILE='out/brave/report/brave_unit_tests.%4m.profraw'to restrict the profiles as per Chromium's 'Step 2 Create Raw Profiles'src/Libraries-- Nb. These steps could/should be better handled, but it's what I did to get this working. You may also need to have built with
npm run buildto produce these dylib's-- Locate and copy
libchallenge_bypass_ristretto.dylibtosrc/Libraries-- Locate and copy
libadblock.dylibtosrc/LibrariesUsage
npm run coverageand fingers crossed, it should build
brave_unit_testsand run coverage for the (temporarily) hardcoded folders cited inutil.jsA link is given to the report index.html at the end of the analysis stage. For me, on an iMac Pro, this takes about 30-40 mins for a clean build.
The
-farguments within theutils.jsstep simply restrict the analysis to the given folders. Providing no filters runs across the wholebrave_unit_teststarget, and for me this took about an hour, and hit ~150GB storage space in total.Suggestions
util.js- passing arguments instead of hardcoding, but otherwise it's fairly simple.coverage.jsbut I'll leave that to devops/build guru's to decide :)