Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(bpf): Add eBPF Test Suite #1535

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

dave-tucker
Copy link
Collaborator

@dave-tucker dave-tucker commented Jun 14, 2024

This commit adds a more comprehensive eBPF test suite.
Currently it tests the operation of a number of key functions
within the eBPF code - for example the main sched_switch
tracepoint that we run. In addition, it runs a number
of micro benchmarks so we can track performance of these
key pieces of code.

Copy link

github-actions bot commented Jun 14, 2024

🤖 SeineSailor

Here is a concise summary of the pull request changes:

Summary: This pull request, titled "WIP: BPF Testing," introduces a comprehensive eBPF test suite, refactors BPF code for testing, and migrates to cilium/ebpf. The changes are grouped into three main areas:

  1. Migration to cilium/ebpf and package creation: A new pkg/bpftest package is introduced for testing BPF-related functions, facilitated by the migration to cilium/ebpf. This change extends PR chore(pkg/bpf): Replace libbpfgo with cilium/ebpf #1438.

  2. eBPF test suite and benchmarking: The pull request adds a comprehensive eBPF test suite, including tests for key functions, micro benchmarks, and new types (e.g., ExperimentCache, enumSupport, Experiment, SamplingConfig, Measurement, Ranking, Stat, StatsType, Stats, PrecisionBundle, and Stopwatch) to support benchmarking and measuring code.

  3. eBPF code refactoring and additions: The pull request refactors BPF code for testing, adding several map structures, new functions (e.g., get_on_cpu_elapsed_time_us(), get_on_cpu_cycles(), and get_on_cpu_instr()), and modifying existing ones. New global variables (e.g., TEST, HW, and SAMPLE_RATE) are introduced to configure test modes and sampling rates.

Impact: These changes significantly enhance the testing capabilities of the eBPF codebase, providing a comprehensive test suite and benchmarking support. The migration to cilium/ebpf and the introduction of the pkg/bpftest package improve the code's maintainability and testability.

Observations and suggestions:

  • The pull request is marked as "WIP," indicating that it is still a work-in-progress. It would be beneficial to break down the changes into smaller, more focused pull requests to facilitate easier review and testing.
  • The addition of new types and functions may require updates to the documentation to ensure that users are aware of the changes and can effectively utilize the new features.
  • It would be helpful to include more detailed comments and explanations within the code to facilitate understanding and maintenance of the new test suite and benchmarking features.

@dave-tucker
Copy link
Collaborator Author

dave-tucker commented Jul 5, 2024

This will fail CI (for now at least) due to needing access to hardware perf counters.
I'm going to look in to creating some software (or dummy) counters to solve this.
Suite output is as follows:

=== RUN   TestBpf
Running Suite: Bpf Suite - /home/dave/dev/kepler
================================================
Random Seed: 1720176038

Will run 6 of 6 specs
••
------------------------------
• [1.593 seconds]
BPF Exporter test should increment the page hit counter efficiently
/home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:107

  Report Entries >>
  Increment the page hit counter - /home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:109 @ 07/05/24 11:40:38.399
    Increment the page hit counter
    Name                                  | N       | Min     | Median  | Mean    | StdDev  | Max      
    ===================================================================================================
    page hit counter increment [duration] | 1000000 | 1.172µs | 1.223µs | 1.286µs | 1.125µs | 759.055µs
  << Report Entries
------------------------------
•
------------------------------
• [7.402 seconds]
BPF Exporter test efficiently collects hardware counter metrics for sched_switch events [perf_event]
/home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:217

  Report Entries >>
  sched_switch tracepoint - /home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:219 @ 07/05/24 11:40:40.035
    sched_switch tracepoint
    Name                                       | N       | Min     | Median  | Mean   | StdDev | Max      
    ======================================================================================================
    sampled sched_switch tracepoint [duration] | 1000000 | 2.124µs | 2.786µs | 2.77µs | 664ns  | 251.505µs
  << Report Entries
------------------------------
• [7.084 seconds]
BPF Exporter test uses sample rate to reduce CPU time [perf_event]
/home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:256

  Report Entries >>
  sampled sched_switch tracepoint - /home/dave/dev/kepler/pkg/bpftest/bpf_suite_test.go:258 @ 07/05/24 11:40:47.483
    sampled sched_switch tracepoint
    Name                                       | N       | Min     | Median  | Mean    | StdDev | Max      
    =======================================================================================================
    sampled sched_switch tracepoint [duration] | 1000000 | 1.863µs | 2.535µs | 2.474µs | 664ns  | 244.011µs
  << Report Entries
------------------------------

Ran 6 of 6 Specs in 16.228 seconds
SUCCESS! -- 6 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestBpf (16.23s)
PASS

@dave-tucker dave-tucker force-pushed the bpf-test branch 3 times, most recently from 636b0c3 to a9c26ae Compare July 10, 2024 10:00
@dave-tucker dave-tucker changed the title BPF Testing test(bpf): Add eBPF Test Suite Jul 10, 2024
@dave-tucker dave-tucker marked this pull request as ready for review July 10, 2024 10:02
@dave-tucker dave-tucker requested a review from sthaha July 10, 2024 10:02
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Copy link
Collaborator

@sthaha sthaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good over!
could you please resolve the unit-test failure ?

bpf/kepler.bpf.c Outdated Show resolved Hide resolved
pkg/bpf/exporter.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@sthaha sthaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Please do consider if the file descriptors must be closed before merging.

This commit adds a more comprehensive eBPF test suite.
Currently it tests the operation of a number of key functions
within the eBPF code - for example the main sched_switch
tracepoint that we run. In addition, it runs a number
of micro benchmarks so we can track performance of these
key pieces of code.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
@dave-tucker dave-tucker merged commit 15dba2a into sustainable-computing-io:main Jul 12, 2024
19 checks passed
@dave-tucker dave-tucker deleted the bpf-test branch July 12, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants