<commit_before>package cl11

import (
	"io"
	"testing"
)

func TestMappedBufferRead(t *testing.T) {
	allDevices := getDevices(t)
	for _, device := range allDevices {
		t.Log(device.Name, "on", device.Platform.Name)

		var toRelease []Object
		size := 1024 * 1024

		ctx, err := CreateContext([]*Device{device}, nil, nil, nil)
		if err != nil {
			t.Error(err)
			continue
		}
		toRelease = append(toRelease, ctx)

		cq, err := ctx.CreateCommandQueue(device, 0)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}
		toRelease = append(toRelease, cq)

		device0, err := ctx.CreateDeviceBuffer(int64(size), MemReadWrite)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}
		toRelease = append(toRelease, device0)

		map0, err := cq.EnqueueMapBuffer(device0, Blocking, MapRead, 0, int64(size), nil, nil)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}

		// Read nothing.
		var nothing []byte
		n, err := map0.Read(nothing)
		if n != 0 || err != nil {
			t.Error("reading nothing: want 0 <nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read everything.
		everything := make([]byte, size)
		n, err = map0.Read(everything)
		if n != size || err != nil {
			t.Error("reading everything: want", size, "<nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read past end.
		n, err = map0.Read(everything)
		if n != 0 || err != io.EOF {
			t.Error("reading past end of buffer: want 0 io.EOF, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		err = cq.EnqueueUnmapBuffer(map0, nil, nil)
		if err != nil {<commit_msg>Added mapped buffer read test.<commit_after>package cl11

import (
	"bytes"
	"io"
	"testing"
)

func TestMappedBufferRead(t *testing.T) {
	allDevices := getDevices(t)
	for _, device := range allDevices {
		t.Log(device.Name, "on", device.Platform.Name)

		var toRelease []Object
		size := 1024 * 1024

		ctx, err := CreateContext([]*Device{device}, nil, nil, nil)
		if err != nil {
			t.Error(err)
			continue
		}
		toRelease = append(toRelease, ctx)

		cq, err := ctx.CreateCommandQueue(device, 0)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}
		toRelease = append(toRelease, cq)

		device0, err := ctx.CreateDeviceBuffer(int64(size), MemReadWrite)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}
		toRelease = append(toRelease, device0)

		map0, err := cq.EnqueueMapBuffer(device0, Blocking, MapRead, 0, int64(size), nil, nil)
		if err != nil {
			t.Error(err)
			releaseAll(toRelease, t)
			continue
		}

		// Read nothing.
		var nothing []byte
		n, err := map0.Read(nothing)
		if n != 0 || err != nil {
			t.Error("reading nothing: want 0 <nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read everything.
		everything := make([]byte, size)
		n, err = map0.Read(everything)
		if n != size || err != nil {
			t.Error("reading everything: want", size, "<nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read past end.
		n, err = map0.Read(everything)
		if n != 0 || err != io.EOF {
			t.Error("reading past end of buffer: want 0 io.EOF, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Reset relative to start.
		nn, err := map0.Seek(0, 0)
		if nn != 0 || err != nil {
			t.Error("seeking: want 0 <nil>, got", nn, err)
			releaseAll(toRelease, t)
			continue
		}

		// Write to, the full buffer.
		var buf bytes.Buffer
		nn, err = map0.WriteTo(&buf)
		if nn != int64(size) || err != nil {
			t.Error("writing to: want", size, "<nil>, got", nn, err)
			releaseAll(toRelease, t)
			continue
		}

		// Write to, but buffers already consumed.
		nn, err = map0.WriteTo(&buf)
		if nn != 0 || err != nil {
			t.Error("writing to: want 0 <nil>, got", nn, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read at everything.
		n, err = map0.ReadAt(everything, 0)
		if n != size || err != nil {
			t.Error("read at 0 everything: want", size, "<nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read at running past end of buffer.
		n, err = map0.ReadAt(everything, 1)
		if n != size-1 || err != io.EOF {
			t.Error("read at 0 everything: want", size-1, "<nil>, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read at starting past the end of the buffer.
		n, err = map0.ReadAt(everything, int64(size))
		if n != 0 || err != io.EOF {
			t.Error("read at 0 everything: want 0 io.EOF, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		// Read at starting at a negative value.
		n, err = map0.ReadAt(everything, -1)
		if n != 0 || err == nil {
			t.Error("read at 0 everything: want 0 cl: MappedBuffer.ReadAt: negative offset, got", n, err)
			releaseAll(toRelease, t)
			continue
		}

		err = cq.EnqueueUnmapBuffer(map0, nil, nil)
		if err != nil {
{'fraction_non_alphanumeric': 0.15037128712871287, 'fraction_numerical': 0.01773927392739274, 'mean_word_length': 3.067953020134228, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5132884', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1753, 'n_words': 519}