2 |
3 | int add(int x, int y) {
4 | return x + y;
5 | }
6 |
7 | void printTest(int x) {
8 | printf("begin\n");
9 | if ( x > 100) {
10 | printf("input > 100 \n");
11 | }
12 | else if ( x > 60) {
13 | printf(" 60 < input <= 100\n");
14 | }
15 | else if ( x > 0) {
16 | printf(" 0 < input <= 60\n");
17 | }
18 | else {
19 | printf(" input <= 0\n");
20 | }
21 | printf("end\n");
22 | }
23 |
24 | int main(void) {
25 |
26 | printTest(12);
27 | printTest(8);
28 | printTest(0);
29 |
30 | int r = add(1, 2);
31 | printf("result: %d\n", r);
32 |
33 |
34 | return 0;
35 | }
36 |
37 |
38 | /*
39 | // 覆盖率编译
40 | clang -fprofile-instr-generate -fcoverage-mapping bar.m -o bar_coverage
41 | // 正常编译
42 | clang bar.m -o bar_no_coverage
43 |
44 | // 执行代码,会在当前目录得到 default.profraw
45 | ./bar_coverage
46 |
47 | // 生成执行的代码数据
48 | xcrun llvm-profdata merge -sparse default.profraw -o bar_coverage.profdata
49 |
50 | # 查看profdata数据
51 | xcrun llvm-profdata show -all-functions -instr bar_coverage.profdata > bar_coverage_profdata.text
52 |
53 | # 导出为html
54 | xcrun llvm-cov show ./bar_coverage -instr-profile=bar_coverage.profdata -use-color -format=html -output-dir bar_coverage_html
55 |
56 | # 生成汇编
57 | xcrun -sdk iphonesimulator clang -S -fobjc-arc bar.m -o main.s
58 |
59 | */
60 |
61 |
--------------------------------------------------------------------------------
/Source-based/bar_oc/bar_coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_oc/bar_coverage
--------------------------------------------------------------------------------
/Source-based/bar_oc/bar_coverage.profdata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_oc/bar_coverage.profdata
--------------------------------------------------------------------------------
/Source-based/bar_oc/bar_coverage_html/index.html:
--------------------------------------------------------------------------------
1 | Coverage Report
Created: 2021-11-04 22:38
Click here for information about interpreting this report.
Generated by llvm-cov -- llvm version 12.0.0
--------------------------------------------------------------------------------
/Source-based/bar_oc/bar_coverage_profdata.text:
--------------------------------------------------------------------------------
1 | Counters:
2 | main:
3 | Hash: 0x0000000000000018
4 | Counters: 1
5 | Function count: 1
6 | printTest:
7 | Hash: 0x03e0e16a652906a0
8 | Counters: 4
9 | Function count: 3
10 | add:
11 | Hash: 0x0000000000000018
12 | Counters: 1
13 | Function count: 1
14 | Instrumentation level: Front-end
15 | Functions shown: 3
16 | Total functions: 3
17 | Maximum function count: 3
18 | Maximum internal block count: 2
19 |
--------------------------------------------------------------------------------
/Source-based/bar_oc/bar_no_coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_oc/bar_no_coverage
--------------------------------------------------------------------------------
/Source-based/bar_oc/default.profraw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_oc/default.profraw
--------------------------------------------------------------------------------
/Source-based/bar_swift/bar_coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_swift/bar_coverage
--------------------------------------------------------------------------------
/Source-based/bar_swift/bar_coverage.profdata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_swift/bar_coverage.profdata
--------------------------------------------------------------------------------
/Source-based/bar_swift/bar_coverage_html/index.html:
--------------------------------------------------------------------------------
1 | Coverage Report
Created: 2022-04-16 23:19
Click here for information about interpreting this report.
Generated by llvm-cov -- llvm version 13.0.0
--------------------------------------------------------------------------------
/Source-based/bar_swift/bar_coverage_profdata.text:
--------------------------------------------------------------------------------
1 | Counters:
2 | bar.swift:$s12bar_coverage3addyS2i_SitF:
3 | Hash: 0x0000000000000000
4 | Counters: 1
5 | Function count: 1
6 | bar.swift:__tlcd_line:24:1:
7 | Hash: 0x0000000000000000
8 | Counters: 1
9 | Function count: 1
10 | bar.swift:__tlcd_line:23:1:
11 | Hash: 0x0000000000000000
12 | Counters: 1
13 | Function count: 1
14 | bar.swift:$s12bar_coverage4mainyySiF:
15 | Hash: 0x0000000000000000
16 | Counters: 4
17 | Function count: 3
18 | bar.swift:__tlcd_line:25:1:
19 | Hash: 0x0000000000000000
20 | Counters: 1
21 | Function count: 1
22 | bar.swift:__tlcd_line:26:1:
23 | Hash: 0x0000000000000000
24 | Counters: 1
25 | Function count: 1
26 | Instrumentation level: Front-end
27 | Functions shown: 6
28 | Total functions: 6
29 | Maximum function count: 3
30 | Maximum internal block count: 2
31 |
--------------------------------------------------------------------------------
/Source-based/bar_swift/bar_no_coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_swift/bar_no_coverage
--------------------------------------------------------------------------------
/Source-based/bar_swift/bars.swift:
--------------------------------------------------------------------------------
1 | func add(_ x: Int, _ y: Int) -> Int {
2 | return x + y
3 | }
4 |
5 | func main(_ x: Int) {
6 | print("begin")
7 | if ( x > 100) {
8 | print("input > 100")
9 | }
10 | else if ( x > 60) {
11 | print(" 60 < input <= 100")
12 | }
13 | else if ( x > 0) {
14 | print(" 0 < input <= 60")
15 | }
16 | else {
17 | print(" input <= 0")
18 | }
19 | print("end")
20 | }
21 |
22 |
23 | main(12)
24 | main(8)
25 | main(0)
26 | print("\(add(1, 2))")
27 |
28 |
29 | /*
30 | // 覆盖率编译
31 | swiftc -profile-generate -profile-coverage-mapping barswift -o bar_coverage
32 | // 正常编译
33 | swiftc barswift -o bar_no_coverage
34 |
35 | // 执行代码,会在当前目录得到 defaultprofraw
36 | /bar_coverage
37 |
38 | // 生成执行的代码数据
39 | xcrun llvm-profdata merge -sparse default.profraw -o bar_coverage.profdata
40 |
41 | # 查看profdata数据
42 | xcrun llvm-profdata show -all-functions -instr bar_coverageprofdata > bar_coverage_profdatatext
43 |
44 | # 导出为html
45 | xcrun llvm-cov show ./bar_coverage -instr-profile=bar_coverage.profdata -use-color -format=html -output-dir bar_coverage_html
46 |
47 | # -path-equivalence 解决多台设备生成具体覆盖率为0的问题
48 | xcrun llvm-cov show -instr-profile=bar_coverage.profdata -use-color -format=html bar_coverage -output-dir=bar_coverage_html -path-equivalence=/Users/denglibing/HDProject/HarryProject/iOS/hdcoverage/Source-based/bar_swift/,/Users/denglibing/HDProject/HarryProject/iOS/hdcoverage/Source-based/bar_swift/bars/
49 | */
50 |
51 |
--------------------------------------------------------------------------------
/Source-based/bar_swift/bars/bar.swift:
--------------------------------------------------------------------------------
1 | func add(_ x: Int, _ y: Int) -> Int {
2 | return x + y
3 | }
4 |
5 | func main(_ x: Int) {
6 | print("begin")
7 | if ( x > 100) {
8 | print("input > 100")
9 | }
10 | else if ( x > 60) {
11 | print(" 60 < input <= 100")
12 | }
13 | else if ( x > 0) {
14 | print(" 0 < input <= 60")
15 | }
16 | else {
17 | print(" input <= 0")
18 | }
19 | print("end")
20 | }
21 |
22 |
23 | main(12)
24 | main(8)
25 | main(0)
26 | print("\(add(1, 2))")
27 |
28 |
29 | /*
30 | // 覆盖率编译
31 | swiftc -profile-generate -profile-coverage-mapping barswift -o bar_coverage
32 | // 正常编译
33 | swiftc barswift -o bar_no_coverage
34 |
35 | // 执行代码,会在当前目录得到 defaultprofraw
36 | /bar_coverage
37 |
38 | // 生成执行的代码数据
39 | xcrun llvm-profdata merge -sparse default.profraw -o bar_coverage.profdata
40 |
41 | # 查看profdata数据
42 | xcrun llvm-profdata show -all-functions -instr bar_coverageprofdata > bar_coverage_profdatatext
43 |
44 | # 导出为html
45 | xcrun llvm-cov show ./bar_coverage -instr-profile=bar_coverage.profdata -use-color -format=html -output-dir bar_coverage_html
46 | */
47 |
48 |
--------------------------------------------------------------------------------
/Source-based/bar_swift/default.profraw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/bar_swift/default.profraw
--------------------------------------------------------------------------------
/Source-based/bar_swift/default.txt:
--------------------------------------------------------------------------------
1 | 1|func add(_ x: Int, _ y: Int) -> Int {
2 | 2| return x + y
3 | 3|}
4 | 4|
5 | 5|func main(_ x: Int) {
6 | 6| print("begin")
7 | 7| if ( x > 100) {
8 | 8| print("input > 100")
9 | 9| }
10 | 10| else if ( x > 60) {
11 | 11| print(" 60 < input <= 100")
12 | 12| }
13 | 13| else if ( x > 0) {
14 | 14| print(" 0 < input <= 60")
15 | 15| }
16 | 16| else {
17 | 17| print(" input <= 0")
18 | 18| }
19 | 19| print("end")
20 | 20|}
21 | 21|
22 | 22|
23 | 23|main(12)
24 | 24|main(8)
25 | 25|main(0)
26 | 26|print("\(add(1, 2))")
27 |
28 |
--------------------------------------------------------------------------------
/Source-based/foo_c/foo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/foo_c/foo
--------------------------------------------------------------------------------
/Source-based/foo_c/foo.cc:
--------------------------------------------------------------------------------
1 | #define BAR(x) ((x) || (x))
2 | template void foo(T x) {
3 | for (unsigned I = 0; I < 10; ++I) { BAR(I); }
4 | }
5 |
6 | int main() {
7 | foo(0);
8 | foo(0);
9 | return 0;
10 | }
11 |
12 | // xcrun llvm-cov report ./foo -instr-profile=foo.profdata
13 | //xcrun llvm-cov report ./foo -instr-profile=foo.profdata
14 |
--------------------------------------------------------------------------------
/Source-based/foo_c/foo.profdata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/foo_c/foo.profdata
--------------------------------------------------------------------------------
/Source-based/foo_c/foo.profraw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/foo_c/foo.profraw
--------------------------------------------------------------------------------
/Source-based/foo_c/no_coverage_foo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/Source-based/foo_c/no_coverage_foo
--------------------------------------------------------------------------------
/_Pods.xcodeproj:
--------------------------------------------------------------------------------
1 | Example/Pods/Pods.xcodeproj
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | pkg
3 | .idea/
4 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # Specify your gem's dependencies in cocoapods-hdcoverage.gemspec
4 | gemspec
5 |
6 | group :development do
7 | gem 'cocoapods'
8 |
9 | gem 'mocha'
10 | gem 'bacon'
11 | gem 'mocha-on-bacon'
12 | gem 'prettybacon'
13 | end
14 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2021 denglibing
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/README.md:
--------------------------------------------------------------------------------
1 | # cocoapods-hdcoverage
2 |
3 | A description of cocoapods-hdcoverage.
4 |
5 | ## Installation
6 |
7 | $ gem install cocoapods-hdcoverage
8 |
9 | ## Usage
10 |
11 | $ pod spec hdcoverage POD_NAME
12 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/Rakefile:
--------------------------------------------------------------------------------
1 | require 'bundler/gem_tasks'
2 |
3 | def specs(dir)
4 | FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5 | end
6 |
7 | desc 'Runs all the specs'
8 | task :specs do
9 | sh "bundle exec bacon #{specs('**')}"
10 | end
11 |
12 | task :default => :specs
13 |
14 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/cocoapods-hdcoverage-0.0.1.gem:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erduoniba/hdcoverage/a91b3981638db3451458d45e9f829a2f687e529f/cocoapods-coverage/cocoapods-hdcoverage/cocoapods-hdcoverage-0.0.1.gem
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/cocoapods-hdcoverage.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path('../lib', __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require 'cocoapods-hdcoverage/gem_version.rb'
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = 'cocoapods-hdcoverage'
8 | spec.version = CocoapodsHdcoverage::VERSION
9 | spec.authors = ['denglibing']
10 | spec.email = ['denglibing3@jd.com']
11 | spec.description = %q{A short description of cocoapods-hdcoverage.}
12 | spec.summary = %q{A longer description of cocoapods-hdcoverage.}
13 | spec.homepage = 'https://github.com/EXAMPLE/cocoapods-hdcoverage'
14 | spec.license = 'MIT'
15 |
16 | spec.files = Dir['lib/**/*']
17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19 | spec.require_paths = ['lib']
20 |
21 | spec.add_development_dependency 'bundler', '~> 1.3'
22 | spec.add_development_dependency 'rake'
23 | end
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/lib/cocoapods-hdcoverage.rb:
--------------------------------------------------------------------------------
1 | require 'cocoapods-hdcoverage/gem_version'
2 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/lib/cocoapods-hdcoverage/command.rb:
--------------------------------------------------------------------------------
1 | require 'cocoapods-hdcoverage/command/hdcoverage'
2 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/lib/cocoapods-hdcoverage/command/hdcoverage.rb:
--------------------------------------------------------------------------------
1 | module Pod
2 | class Command
3 | # This is an example of a cocoapods plugin adding a top-level subcommand
4 | # to the 'pod' command.
5 | #
6 | # You can also create subcommands of existing or new commands. Say you
7 | # wanted to add a subcommand to `list` to show newly deprecated pods,
8 | # (e.g. `pod list deprecated`), there are a few things that would need
9 | # to change.
10 | #
11 | # - move this file to `lib/pod/command/list/deprecated.rb` and update
12 | # the class to exist in the the Pod::Command::List namespace
13 | # - change this class to extend from `List` instead of `Command`. This
14 | # tells the plugin system that it is a subcommand of `list`.
15 | # - edit `lib/cocoapods_plugins.rb` to require this file
16 | #
17 | # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18 | # in the `plugins.json` file, once your plugin is released.
19 | #
20 | class Hdcoverage < Command
21 | self.summary = 'Short description of cocoapods-hdcoverage.'
22 |
23 | self.description = <<-DESC
24 | Longer description of cocoapods-hdcoverage.
25 | DESC
26 |
27 | self.arguments = 'NAME'
28 |
29 | def initialize(argv)
30 | @name = argv.shift_argument
31 | super
32 | end
33 |
34 | def validate!
35 | super
36 | help! 'A Pod name is required.' unless @name
37 | end
38 |
39 | def run
40 | UI.puts "Add your implementation for the cocoapods-hdcoverage plugin in #{__FILE__}"
41 | end
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/lib/cocoapods-hdcoverage/gem_version.rb:
--------------------------------------------------------------------------------
1 | module CocoapodsHdcoverage
2 | VERSION = "0.0.1"
3 | end
4 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/lib/cocoapods_plugin.rb:
--------------------------------------------------------------------------------
1 | require 'cocoapods-hdcoverage/command'
2 | # 引用 cocoapods 包
3 | require 'cocoapods'
4 |
5 | module CocoapodsHdcoverage
6 | # 注册 pod install 钩子
7 | Pod::HooksManager.register('cocoapods-hdcoverage', :post_install) do |context|
8 | p "cocoapods-hdcoverage hook post_install"
9 | end
10 |
11 | def method_name
12 |
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/spec/command/hdcoverage_spec.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../../spec_helper', __FILE__)
2 |
3 | module Pod
4 | describe Command::Hdcoverage do
5 | describe 'CLAide' do
6 | it 'registers it self' do
7 | Command.parse(%w{ hdcoverage }).should.be.instance_of Command::Hdcoverage
8 | end
9 | end
10 | end
11 | end
12 |
13 |
--------------------------------------------------------------------------------
/cocoapods-coverage/cocoapods-hdcoverage/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'pathname'
2 | ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3 | $:.unshift((ROOT + 'lib').to_s)
4 | $:.unshift((ROOT + 'spec').to_s)
5 |
6 | require 'bundler/setup'
7 | require 'bacon'
8 | require 'mocha-on-bacon'
9 | require 'pretty_bacon'
10 | require 'pathname'
11 | require 'cocoapods'
12 |
13 | Mocha::Configuration.prevent(:stubbing_non_existent_method)
14 |
15 | require 'cocoapods_plugin'
16 |
17 | #-----------------------------------------------------------------------------#
18 |
19 | module Pod
20 |
21 | # Disable the wrapping so the output is deterministic in the tests.
22 | #
23 | UI.disable_wrap = true
24 |
25 | # Redirects the messages to an internal store.
26 | #
27 | module UI
28 | @output = ''
29 | @warnings = ''
30 |
31 | class << self
32 | attr_accessor :output
33 | attr_accessor :warnings
34 |
35 | def puts(message = '')
36 | @output << "#{message}\n"
37 | end
38 |
39 | def warn(message = '', actions = [])
40 | @warnings << "#{message}\n"
41 | end
42 |
43 | def print(message)
44 | @output << message
45 | end
46 | end
47 | end
48 | end
49 |
50 | #-----------------------------------------------------------------------------#
51 |
--------------------------------------------------------------------------------
/pod_release.sh:
--------------------------------------------------------------------------------
1 | function pushTagAndPodTrunk {
2 | git tag -m $1 $2
3 | git push orgin $2
4 |
5 | pod trunk push HDCoverage.podspec --allow-warnings
6 | }
7 |
8 | function main {
9 | echo "git commit msg: $1, tag: $2"
10 |
11 | git add .
12 | git commit -m $1
13 | git push -u orgin master
14 |
15 | if [ $? -eq 0 ]; then
16 | echo "git push success"
17 | pushTagAndPodTrunk $1 $2
18 | else
19 | echo "git push faild"
20 | pushTagAndPodTrunk $1 $2
21 | fi
22 |
23 | }
24 |
25 | main $1 $2
26 |
--------------------------------------------------------------------------------