nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cilium/ebpf
Pull request #42 (2020-01-06 15:50:25)

CI: test on 5.4 instead of 5.3
5.4 is the current LTS, while 5.3 is going to be unsupported soon.
Move testing to 5.4 and run the BTF tests against the new kernel's
builtin BTF.


Patch:
diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml
index 1a9ba16..ba5d2a5 100644
--- a/.semaphore/semaphore.yml
+++ b/.semaphore/semaphore.yml
@@ -24,9 +24,9 @@ blocks:
           - GOOS=darwin go build ./...
           - GOARCH=arm GOARM=6 go build ./...
           - GOARCH=arm64 go build ./...
-      - name: Test on 5.3.8
+      - name: Test on 5.4.5
         commands:
-          - timeout -s KILL 60s ./run-tests.sh 5.3.8
+          - timeout -s KILL 60s ./run-tests.sh 5.4.5
       - name: Test on 4.19.81
         commands:
           - timeout -s KILL 60s ./run-tests.sh 4.19.81


Test patch:
diff --git a/internal/btf/btf_test.go b/internal/btf/btf_test.go
index e6e1777..31c79ad 100644
--- a/internal/btf/btf_test.go
+++ b/internal/btf/btf_test.go
@@ -44,6 +44,32 @@ func TestParseVmlinux(t *testing.T) {
 	}
 }
 
+func TestParseCurrentKernelBTF(t *testing.T) {
+	if _, err := os.Stat("/sys/kernel/btf/vmlinux"); os.IsNotExist(err) {
+		t.Skip("/sys/kernel/btf/vmlinux is not available")
+	}
+
+	fh, err := os.Open("/sys/kernel/btf/vmlinux")
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer fh.Close()
+
+	s, err := parseBTF(fh, binary.LittleEndian)
+	if err != nil {
+		t.Fatal("Can't load BTF:", err)
+	}
+
+	var bpfAttr Union
+	if err := s.FindType("bpf_attr", &bpfAttr); err != nil {
+		t.Fatal("Can't find btf_attr:", err)
+	}
+
+	if name := bpfAttr.Name; name != "bpf_attr" {
+		t.Error("struct bpf_attr has incorrect name:", name)
+	}
+}
+
 func TestLoadSpecFromElf(t *testing.T) {
 	fh, err := os.Open("../../testdata/loader-clang-9.elf")
 	if err != nil {
Repository: cilium/ebpf
Pull request #48 (2020-01-27 11:29:32)

map: allow creating PerfEventArray with key or value size four
libbpf based tooling expects map definitions for PerfEventArrays to
have a key and value size of four, while this package has traditionally
required a size of zero. Accept key or value size of four to be
compatible with libbpf.

lmb: cc @hamburgerbun

Patch:
diff --git a/map.go b/map.go
index 86eff1a..586cfff 100644
--- a/map.go
+++ b/map.go
@@ -129,11 +129,11 @@ func createMap(spec *MapSpec, inner *internal.FD, handle *btf.Handle) (*Map, err
 		spec.ValueSize = 4
 
 	case PerfEventArray:
-		if spec.KeySize != 0 {
-			return nil, errors.Errorf("KeySize must be zero for perf event array")
+		if spec.KeySize != 0 && spec.KeySize != 4 {
+			return nil, errors.Errorf("KeySize must be zero or four for perf event array")
 		}
-		if spec.ValueSize != 0 {
-			return nil, errors.Errorf("ValueSize must be zero for perf event array")
+		if spec.ValueSize != 0 && spec.ValueSize != 4 {
+			return nil, errors.Errorf("ValueSize must be zero or four for perf event array")
 		}
 		if spec.MaxEntries == 0 {
 			n, err := internal.OnlineCPUs()


Test patch:
diff --git a/map_test.go b/map_test.go
index e71dd1c..0b86349 100644
--- a/map_test.go
+++ b/map_test.go
@@ -292,13 +292,20 @@ func TestNewMapInMapFromFD(t *testing.T) {
 }
 
 func TestPerfEventArray(t *testing.T) {
-	m, err := NewMap(&MapSpec{
-		Type: PerfEventArray,
-	})
-	if err != nil {
-		t.Fatal("Can't create perf event array:", err)
+	specs := []*MapSpec{
+		{Type: PerfEventArray},
+		{Type: PerfEventArray, KeySize: 4},
+		{Type: PerfEventArray, ValueSize: 4},
+	}
+
+	for _, spec := range specs {
+		m, err := NewMap(spec)
+		if err != nil {
+			t.Errorf("Can't create perf event array from %v: %s", spec, err)
+		} else {
+			m.Close()
+		}
 	}
-	m.Close()
 }
 
 func createMapInMap(t *testing.T, typ MapType) *Map {
Repository: cilium/ebpf
Pull request #59 (2020-02-05 13:46:41)

Make CI runs a bit faster
I'm trying to trim some time from our CI builds, without much luck it seems. I've managed to avoid fetching packages over and over, but I suspect that something is messing with the Go build cache. Since we still have plenty of credit on CI this isn't super pressing, so I'm not investigating further.


Patch:
diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml
index f8b775c..3b5848c 100644
--- a/.semaphore/semaphore.yml
+++ b/.semaphore/semaphore.yml
@@ -13,7 +13,6 @@ blocks:
         commands:
           - checkout
           - sem-version go 1.13
-          - go get -d ./...
           - go build ./...
           - sudo pip3 install https://github.com/amluto/virtme/archive/538f1e756139a6b57a4780e7ceb3ac6bcaa4fe6f.zip
           - sudo apt-get install -y qemu-system-x86
@@ -25,10 +24,10 @@ blocks:
           - GOARCH=arm64 go build ./...
       - name: Test on 5.4.5
         commands:
-          - timeout -s KILL 60s ./run-tests.sh 5.4.5
+          - timeout -s KILL 90s ./run-tests.sh 5.4.5
       - name: Test on 4.19.81
         commands:
-          - timeout -s KILL 60s ./run-tests.sh 4.19.81
+          - timeout -s KILL 90s ./run-tests.sh 4.19.81
       - name: Test on 4.9.198
         commands:
-          - timeout -s KILL 60s ./run-tests.sh 4.9.198
+          - timeout -s KILL 90s ./run-tests.sh 4.9.198


Test patch:
diff --git a/run-tests.sh b/run-tests.sh
index 30f9744..7eb8dd6 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -8,14 +8,12 @@ set -o pipefail
 if [[ "${1:-}" = "--in-vm" ]]; then
   shift
 
-  readonly home="$(mktemp --directory)"
-
   mount -t bpf bpf /sys/fs/bpf
   export CGO_ENABLED=0
   export GOFLAGS=-mod=readonly
-  export GOPROXY=file:///run/go-proxy
+  export GOPATH=/run/go-path
+  export GOPROXY=file:///run/go-root/pkg/mod/cache/download
   export GOCACHE=/run/go-cache
-  export HOME="$home"
 
   echo Running tests...
   /usr/local/bin/go test -coverprofile="$1/coverage.txt" -covermode=atomic -v ./...
@@ -23,9 +21,6 @@ if [[ "${1:-}" = "--in-vm" ]]; then
   exit 0
 fi
 
-# Force Go modules, so that vendoring and building are easier.
-export GO111MODULE=on
-
 # Pull all dependencies, so that we can run tests without the
 # vm having network access.
 go mod download
@@ -53,11 +48,11 @@ test -e "${tmp_dir}/${kernel}" || {
 }
 
 echo Testing on ${kernel_version}
-$sudo virtme-run --kimg "${tmp_dir}/${kernel}" --memory 256M --pwd \
+$sudo virtme-run --kimg "${tmp_dir}/${kernel}" --memory 512M --pwd \
   --rwdir=/run/output="${output}" \
-  --rodir=/run/go-proxy="$(go env GOPATH)/pkg/mod/cache/download" \
+  --rodir=/run/go-path="$(go env GOPATH)" \
   --rwdir=/run/go-cache="$(go env GOCACHE)" \
-  --script-sh "$(realpath "$0") --in-vm /run/output" --qemu-opts -smp 2
+  --script-sh "$(realpath "$0") --in-vm /run/output"
 
 if [[ ! -e "${output}/success" ]]; then
   echo "Test failed on ${kernel_version}"
Repository: cilium/ebpf
Pull request #79 (2020-03-10 20:34:20)

Don't ignore kernelVersion
Signed-off-by: Lehner Florian <dev@der-flo.net>

If specified in `ProgramSpec` so far `kenelVersion` was just ignored. This attribute is around since 4.1  [2541517c32be](https://github.com/torvalds/linux/commit/2541517c32be). 

florianl: True, this field was declared deprecated with commit [6c4fc209fcf9d27efbaa48368773e4d2bfbd59aa](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6c4fc209fcf9d27efbaa48368773e4d2bfbd59aa). As kernel version 4.9 and 4.19 are supported at the moment, this attribute is checked for BPF_PROG_TYPE_KPROBE.
I don't have a test in mind, but will think about it.
florianl: I've added a test. Let me know, what you think about it.
florianl: 0 is already a bogus kernel version. The test fails on 4.9 and 4.19, if you comment out `	testutils.SkipOnOldKernel(...)`
florianl: I've updated the test to use 42 instead of 0 as the kernel version.
lmb: Sorry for the late reply, `0` would have been fine. Thanks again!

Patch:
diff --git a/prog.go b/prog.go
index 5306475..60860a2 100644
--- a/prog.go
+++ b/prog.go
@@ -202,6 +202,7 @@ func convertProgramSpec(spec *ProgramSpec, handle *btf.Handle) (*bpfProgLoadAttr
 		insCount:           insCount,
 		instructions:       internal.NewSlicePointer(bytecode),
 		license:            internal.NewStringPointer(spec.License),
+		kernelVersion:      spec.KernelVersion,
 	}
 
 	if haveObjName() == nil {


Test patch:
diff --git a/prog_test.go b/prog_test.go
index 9c1e334..faef237 100644
--- a/prog_test.go
+++ b/prog_test.go
@@ -224,6 +224,23 @@ func TestProgramVerifierOutputOnError(t *testing.T) {
 	}
 }
 
+func TestProgramKernelVersion(t *testing.T) {
+	testutils.SkipOnOldKernel(t, "4.20", "KernelVersion")
+	prog, err := NewProgram(&ProgramSpec{
+		Type: Kprobe,
+		Instructions: asm.Instructions{
+			asm.LoadImm(asm.R0, 0, asm.DWord),
+			asm.Return(),
+		},
+		KernelVersion: 42,
+		License:       "MIT",
+	})
+	if err != nil {
+		t.Fatal("Could not load Kprobe program")
+	}
+	defer prog.Close()
+}
+
 func TestProgramVerifierOutput(t *testing.T) {
 	prog, err := NewProgramWithOptions(socketFilterSpec, ProgramOptions{
 		LogLevel: 2,
Repository: cilium/ebpf
Pull request #89 (2020-04-28 11:42:32)

Use RLIMIT_MEMLOCK and RLIM_INFINITY consts from x/sys/unix
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

lmb: Can you rebase on top of master?

Patch:
diff --git a/internal/unix/types_linux.go b/internal/unix/types_linux.go
index 7efbbd7..89baae2 100644
--- a/internal/unix/types_linux.go
+++ b/internal/unix/types_linux.go
@@ -36,6 +36,7 @@ const (
 	PERF_SAMPLE_RAW          = linux.PERF_SAMPLE_RAW
 	PERF_FLAG_FD_CLOEXEC     = linux.PERF_FLAG_FD_CLOEXEC
 	RLIM_INFINITY            = linux.RLIM_INFINITY
+	RLIMIT_MEMLOCK           = linux.RLIMIT_MEMLOCK
 )
 
 // Statfs_t is a wrapper
diff --git a/internal/unix/types_other.go b/internal/unix/types_other.go
index 7961b35..8fc8e77 100644
--- a/internal/unix/types_other.go
+++ b/internal/unix/types_other.go
@@ -38,6 +38,7 @@ const (
 	PERF_SAMPLE_RAW          = 0x400
 	PERF_FLAG_FD_CLOEXEC     = 0x8
 	RLIM_INFINITY            = 0x7fffffffffffffff
+	RLIMIT_MEMLOCK           = 8
 )
 
 // Statfs_t is a wrapper


Test patch:
diff --git a/map_test.go b/map_test.go
index d0b43be..b7f7204 100644
--- a/map_test.go
+++ b/map_test.go
@@ -19,9 +19,9 @@ import (
 )
 
 func TestMain(m *testing.M) {
-	err := unix.Setrlimit(8, &unix.Rlimit{
-		Cur: math.MaxUint64,
-		Max: math.MaxUint64,
+	err := unix.Setrlimit(unix.RLIMIT_MEMLOCK, &unix.Rlimit{
+		Cur: unix.RLIM_INFINITY,
+		Max: unix.RLIM_INFINITY,
 	})
 	if err != nil {
 		fmt.Println("WARNING: Failed to adjust rlimit, tests may fail")
Repository: cilium/ebpf
Pull request #98 (2020-05-21 18:02:46)

Expose EEXIST
Signed-off-by: Lehner Florian <dev@der-flo.net>

If you update a hash map with the flag `UpdateNoExist` you expect an error if the key already exists. This PR exposes this error and let the user of the package handle it properly.

florianl: Thanks for the review. I also added a test.

Patch:
diff --git a/internal/unix/types_linux.go b/internal/unix/types_linux.go
index 89baae2..0545fe9 100644
--- a/internal/unix/types_linux.go
+++ b/internal/unix/types_linux.go
@@ -10,6 +10,7 @@ import (
 
 const (
 	ENOENT                   = linux.ENOENT
+	EEXIST                   = linux.EEXIST
 	EAGAIN                   = linux.EAGAIN
 	ENOSPC                   = linux.ENOSPC
 	EINVAL                   = linux.EINVAL
diff --git a/internal/unix/types_other.go b/internal/unix/types_other.go
index 8fc8e77..555a5ce 100644
--- a/internal/unix/types_other.go
+++ b/internal/unix/types_other.go
@@ -12,6 +12,7 @@ var errNonLinux = fmt.Errorf("unsupported platform %s/%s", runtime.GOOS, runtime
 
 const (
 	ENOENT                   = syscall.ENOENT
+	EEXIST                   = syscall.EEXIST
 	EAGAIN                   = syscall.EAGAIN
 	ENOSPC                   = syscall.ENOSPC
 	EINVAL                   = syscall.EINVAL
diff --git a/map.go b/map.go
index ddb8054..5350513 100644
--- a/map.go
+++ b/map.go
@@ -14,6 +14,7 @@ import (
 // Errors returned by Map and MapIterator methods.
 var (
 	ErrKeyNotExist      = xerrors.New("key does not exist")
+	ErrKeyExist         = xerrors.New("key already exists")
 	ErrIterationAborted = xerrors.New("iteration aborted")
 )
 
diff --git a/syscalls.go b/syscalls.go
index 20de356..4a244f0 100644
--- a/syscalls.go
+++ b/syscalls.go
@@ -340,6 +340,10 @@ func wrapMapError(err error) error {
 		return ErrKeyNotExist
 	}
 
+	if xerrors.Is(err, unix.EEXIST) {
+		return ErrKeyExist
+	}
+
 	return xerrors.New(err.Error())
 }
 


Test patch:
diff --git a/map_test.go b/map_test.go
index b7f7204..c4a2a00 100644
--- a/map_test.go
+++ b/map_test.go
@@ -456,6 +456,19 @@ func TestNotExist(t *testing.T) {
 	}
 }
 
+func TestExist(t *testing.T) {
+	hash := createHash()
+	defer hash.Close()
+
+	if err := hash.Put("hello", uint32(21)); err != nil {
+		t.Errorf("Failed to put key/value pair into hash: %v", err)
+	}
+
+	if err := hash.Update("hello", uint32(42), UpdateNoExist); !xerrors.Is(err, ErrKeyExist) {
+		t.Error("Updating existing key doesn't return ErrKeyExist")
+	}
+}
+
 func TestIterateMapInMap(t *testing.T) {
 	const idx = uint32(1)
Repository: miurahr/aqtinstall
Pull request #159 (2020-09-09 19:57:09)

Add check on packages name to download
When we start an installation, all packages are downloaded whatever the specified platform.

Gamso: For more details, 

i used this command line "aqt install --outputdir c:\Qt windows desktop win32_msvc2019 -m all".
Like explained in the documentation, i use "-m all" to get all extra modules. 

Into class "QtArchive", if self.all_extra = True, the method "_parse_update_xml()" accept all packages ...
Gamso: I hope that the test is enough strong. I was a bit confused about test syntax x) (first time i did a python test).
miurahr: @Gamso Thank you for you help, but... could you add test data to repository?
You may forget to run `git add ...` command.

Patch:
diff --git a/aqt/archives.py b/aqt/archives.py
index 70f18b7..66f0053 100644
--- a/aqt/archives.py
+++ b/aqt/archives.py
@@ -25,6 +25,8 @@ from logging import getLogger
 
 import requests
 
+from aqt.settings import Settings
+
 
 class ArchiveListError(Exception):
     pass
@@ -67,6 +69,7 @@ class QtArchives:
         self.mirror = mirror
         self.os_name = os_name
         self.all_extra = all_extra
+        self.arch_list = [item.get('arch') for item in Settings().qt_combinations]
         all_archives = (subarchives is None)
         if mirror is not None:
             self.has_mirror = True
@@ -131,6 +134,9 @@ class QtArchives:
         else:
             for packageupdate in self.update_xml.iter("PackageUpdate"):
                 name = packageupdate.find("Name").text
+                name_last_section = name.split(".")[-1]
+                if name_last_section in self.arch_list and self.arch != name_last_section:
+                    continue
                 if self.all_extra or name in target_packages:
                     if packageupdate.find("DownloadableArchives").text is not None:
                         downloadable_archives = packageupdate.find("DownloadableArchives").text.split(", ")


Test patch:
diff --git a/tests/test_archives.py b/tests/test_archives.py
index 846b933..3753da1 100644
--- a/tests/test_archives.py
+++ b/tests/test_archives.py
@@ -20,3 +20,18 @@ def test_parse_update_xml(monkeypatch, os_name, version, target, datafile):
 
     qt_archives = QtArchives(os_name, 'desktop', version, target)
     assert qt_archives.archives is not None
+
+    # Get packages with all extra modules
+    qt_archives_all_modules = QtArchives(os_name, 'desktop', version, target, None, ['all'], None, None, True)
+    assert qt_archives_all_modules.archives is not None
+
+    # Extract all urls
+    url_list = [item.url for item in qt_archives.archives]
+    url_all_modules_list = [item.url for item in qt_archives_all_modules.archives]
+
+    # Check the difference list contains only extra modules urls for target specified
+    list_diff = [item for item in url_all_modules_list if item not in url_list]
+    unwanted_targets = [item for item in list_diff if target not in item]
+
+    # Assert if list_diff contains urls without target specified
+    assert unwanted_targets == []
Repository: miurahr/aqtinstall
Pull request #323 (2021-07-16 22:25:00)

Add `aqt.metadata.Versions.flattened()`
This adds a function to Versions that returns a flattened list of Version objects. This is a spinoff from #318 that I needed for that feature, but I think it's outside the scope of that PR.

This also adds test coverage for the whole Versions class.


Patch:
diff --git a/aqt/metadata.py b/aqt/metadata.py
index 1aa9b2b..965601a 100644
--- a/aqt/metadata.py
+++ b/aqt/metadata.py
@@ -160,10 +160,14 @@ class Versions:
             return None
         return self.versions[-1][-1]
 
-    def __iter__(self) -> List[Version]:
+    def __iter__(self) -> Generator[List[Version], None, None]:
         for item in self.versions:
             yield item
 
+    def flattened(self) -> List[Version]:
+        """Return a flattened list of all versions"""
+        return [version for row in self for version in row]
+
 
 def get_semantic_version(qt_ver: str, is_preview: bool) -> Optional[Version]:
     """Converts a Qt version string (596, 512, 5132, etc) into a semantic version.


Test patch:
diff --git a/tests/test_list.py b/tests/test_list.py
index a012ecf..2014c0c 100644
--- a/tests/test_list.py
+++ b/tests/test_list.py
@@ -2,11 +2,57 @@ import json
 import re
 import sys
 from pathlib import Path
+from typing import Generator
 
 import pytest
 
 from aqt.installer import Cli
-from aqt.metadata import ArchiveId, MetadataFactory, SimpleSpec, Version
+from aqt.metadata import ArchiveId, MetadataFactory, SimpleSpec, Version, Versions
+
+
+def test_versions():
+    versions = Versions(
+        [
+            (1, [Version("1.1.1"), Version("1.1.2")]),
+            (2, [Version("1.2.1"), Version("1.2.2")]),
+        ]
+    )
+    assert (
+        str(versions)
+        == "[[Version('1.1.1'), Version('1.1.2')], [Version('1.2.1'), Version('1.2.2')]]"
+    )
+    assert format(versions) == "1.1.1 1.1.2\n1.2.1 1.2.2"
+    assert format(versions, "s") == str(versions)
+    assert versions.flattened() == [
+        Version("1.1.1"),
+        Version("1.1.2"),
+        Version("1.2.1"),
+        Version("1.2.2"),
+    ]
+    assert isinstance(versions.__iter__(), Generator)
+    assert versions.latest() == Version("1.2.2")
+    assert versions
+
+    empty_versions = Versions(None)
+    assert str(empty_versions) == "[]"
+    assert format(empty_versions) == ""
+    assert empty_versions.flattened() == []
+    assert isinstance(empty_versions.__iter__(), Generator)
+    assert empty_versions.latest() is None
+    assert not empty_versions
+
+    one_version = Versions(Version("1.2.3"))
+    assert str(one_version) == "[[Version('1.2.3')]]"
+    assert format(one_version) == "1.2.3"
+    assert one_version.flattened() == [Version("1.2.3")]
+    assert isinstance(one_version.__iter__(), Generator)
+    assert one_version.latest() == Version("1.2.3")
+    assert one_version
+
+    with pytest.raises(TypeError) as pytest_wrapped_e:
+        format(versions, "x")
+    assert pytest_wrapped_e.type == TypeError
+
 
 MINOR_REGEX = re.compile(r"^\d+\.(\d+)")