Skip to content

Commit

Permalink
chore: enable minil test
Browse files Browse the repository at this point in the history
  • Loading branch information
takehaya committed Sep 13, 2024
1 parent 6559b98 commit 81cf877
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[![Actions Status](https://github.com/takehaya/Sys-Ebpf/actions/workflows/test.yml/badge.svg)](https://github.com/takehaya/Sys-Ebpf/actions)
[![Actions Status](https://github.com/takehaya/perl-ebpf/actions/workflows/test.yml/badge.svg)](https://github.com/takehaya/perl-ebpf/actions)
# NAME

Sys::Ebpf - Pure-Perl interface for eBPF (extended Berkeley Packet Filter)
ebpf - Pure-Perl interface for eBPF (extended Berkeley Packet Filter)

# SYNOPSIS

use Sys::Ebpf;
use Sys::Ebpf::;

# Create a new eBPF loader
my $loader = Sys::Ebpf::loader->new();

# Load a BPF map
my $map_fd = $loader->load_bpf_map({
map_type => Sys::Ebpf::Constants::BpfMapType::BPF_MAP_TYPE_ARRAY,
map_type => Sys::Ebpf::Constants::bpf_map_type::BPF_MAP_TYPE_ARRAY,
key_size => 4,
value_size => 8,
max_entries => 1,
Expand All @@ -27,16 +27,16 @@ Sys::Ebpf - Pure-Perl interface for eBPF (extended Berkeley Packet Filter)

# DESCRIPTION

The `Sys::Ebpf` module provides a Perl interface for working with eBPF (extended Berkeley Packet Filter)
The `ebpf` module provides a Perl interface for working with eBPF (extended Berkeley Packet Filter)
on Linux systems. It allows you to load eBPF programs, create and manipulate BPF maps, and interact
with the eBPF subsystem directly from Perl.

This module includes several submodules:

- `Sys::Ebpf::Loader` - For loading eBPF programs and maps
- `Sys::Ebpf::Asm` - eBPF assembly helpers
- `Sys::Ebpf::Reader` - For reading ELF files
- `Sys::Ebpf::Elf::Parser` - For parsing ELF files
- `Sys::Ebpf::loader` - For loading eBPF programs and maps
- `Sys::Ebpf::asm` - eBPF assembly helpers
- `Sys::Ebpf::reader` - For reading ELF files
- `Sys::Ebpf::elf::parser` - For parsing ELF files

# FUNCTIONS

Expand All @@ -45,10 +45,10 @@ Refer to the documentation of individual submodules for specific functions and u

# SEE ALSO

- [Sys::Ebpf::Loader](https://metacpan.org/pod/Sys%3A%3AEbpf%3A%3Aloader)
- [Sys::Ebpf::Asm](https://metacpan.org/pod/Sys%3A%3AEbpf%3A%3Aasm)
- `Sys::Ebpf::Reader` - For reading ELF files
- `Sys::Ebpf::Elf::Parser` - For parsing ELF files
- [Sys::Ebpf::loader](https://metacpan.org/pod/Sys%3A%3AEbpf%3A%3Aloader)
- [Sys::Ebpf::asm](https://metacpan.org/pod/Sys%3A%3AEbpf%3A%3Aasm)
- `Sys::Ebpf::reader` - For reading ELF files
- `Sys::Ebpf::elf::parser` - For parsing ELF files

# AUTHOR

Expand Down
5 changes: 5 additions & 0 deletions docs/perl_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ pre-commit install
```shell
pre-commit run -a
```

## package update
```shell
sudo PERL5LIB=$PERL5LIB $(which minil) test
```
13 changes: 10 additions & 3 deletions script/gensyscall.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
ORIG_PWD=$(pwd)
echo "Original PWD: $ORIG_PWD"

PWD=$(pwd)
pushd /usr/include/x86_64-linux-gnu/sys/
h2ph -d "$PWD/lib/Ebpf/Syscall" -a -l syscall.h
popd
echo "Current directory for syscall.h: $(pwd)"

echo "Generate syscall.ph file"
echo "h2ph -d \"$ORIG_PWD/lib/Sys/Ebpf/Syscall\" -a -l syscall.h"

h2ph -d "$ORIG_PWD/lib/Sys/Ebpf/Syscall" -a -l syscall.h

popd
10 changes: 7 additions & 3 deletions t/01_ebpf_create_map.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ use warnings;
use utf8;

use Test::More import => [qw( done_testing is ok plan )];
use lib 'lib';

# Load the module you're testing
use Sys::Ebpf::Map;

use Sys::Ebpf::Constants::BpfMapType qw( BPF_MAP_TYPE_HASH );
use Sys::Ebpf::Constants::BpfMapCreateFlags
qw(BPF_F_NO_PREALLOC BPF_F_NUMA_NODE combine_flags);
use Sys::Ebpf::Constants::BpfMapType qw( BPF_MAP_TYPE_HASH );
use Sys::Ebpf::Constants::BpfMapCreateFlags qw(
BPF_F_NO_PREALLOC
BPF_F_NUMA_NODE
combine_flags
);

plan skip_all => "This test must be run as root" if $> != 0;

Expand Down
1 change: 1 addition & 0 deletions t/02_ebpf_map_serialization.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use utf8;

use Test::More import => [qw( done_testing is is_deeply subtest )];
use Data::Dumper ();
use lib 'lib';

use Sys::Ebpf::Map;

Expand Down
7 changes: 4 additions & 3 deletions t/03_ebpf_crud_map.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use utf8;

use Test::More import => [qw( done_testing is_deeply ok plan subtest )];
use Time::HiRes qw( usleep );
use lib 'lib';

use Sys::Ebpf::Map;
use Sys::Ebpf::Constants::BpfMapType qw(BPF_MAP_TYPE_HASH);
use Sys::Ebpf::Constants::BpfMapCreateFlags qw(BPF_F_NO_PREALLOC);
use Sys::Ebpf::Constants::BpfMapUpdateFlags qw(BPF_ANY BPF_NOEXIST BPF_EXIST);
use Sys::Ebpf::Constants::BpfMapType qw( BPF_MAP_TYPE_HASH );
use Sys::Ebpf::Constants::BpfMapCreateFlags qw( BPF_F_NO_PREALLOC );
use Sys::Ebpf::Constants::BpfMapUpdateFlags qw( BPF_ANY );

plan skip_all => "This test must be run as root" if $> != 0;

Expand Down
3 changes: 2 additions & 1 deletion t/04_ebpf_load_prog.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use warnings;
use utf8;

use Test::More import => [qw( done_testing ok plan )];
use lib 'lib';

use Sys::Ebpf::Asm;
use Sys::Ebpf::Asm ();
use Sys::Ebpf::Loader;

use Sys::Ebpf::Constants::BpfProgType qw( BPF_PROG_TYPE_KPROBE );
Expand Down

0 comments on commit 81cf877

Please sign in to comment.