Пример
golang.org/x/sys v0.31.0: unix.Eventfd, unix.Pipe2, unix.Sysinfo
Проверенный пример — golang golang.org/x/sys v0.31.0: unix.Eventfd, unix.Pipe2, unix.Sysinfo. Контракт выполнен на go 1.26 · linux alpine/x64 · docker и…
sha256:de25fc2ddaccd391333f5ce63c4e1c26c012950282d2a3ea08ade8ee2ebb77c6
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-27 |
Кейс
HOW- Цель
- verify pkg:golang/golang.org/x/sys@v0.31.0
- Пакеты
- Символы
-
- unix.Eventfd
- unix.Pipe2
- unix.Sysinfo
- Создан
- 2026-08-27T12:15:18Z
Контракт
- unix.Sysinfo returns system statistics including positive uptime, totalram, and process count without error
- unix.Eventfd creates a non-blocking event file descriptor that records initial counter value and accumulates writes
- unix.Pipe2 creates a non-blocking pipe pair with close-on-exec enabled for inter-process communication
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/golang.org/x/sys@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sys@v0.31.0
Demonstrate these symbols/APIs:
- unix.Eventfd
- unix.Pipe2
- unix.Sysinfo
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:202826a7158e540ce94ce7eb594b88c300f16f3bd96e41f13986c4f332c8132e","contract":["unix.Sysinfo returns system statistics including positive uptime, totalram, and process count without error","unix.Eventfd creates a non-blocking event file descriptor that records initial counter value and accumulates writes","unix.Pipe2 creates a non-blocking pipe pair with close-on-exec enabled for inter-process communication"],"goal":"verify pkg:golang/golang.org/x/sys@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"symbols":["unix.Eventfd","unix.Pipe2","unix.Sysinfo"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.31.0","symbols":["unix.Eventfd","unix.Pipe2","unix.Sysinfo"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require golang.org/x/sys v0.31.0
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
package main
import (
"encoding/binary"
"fmt"
"os"
"golang.org/x/sys/unix"
)
// GetSystemStatistics retrieves system info using unix.Sysinfo.
func GetSystemStatistics() (*unix.Sysinfo_t, error) {
var info unix.Sysinfo_t
if err := unix.Sysinfo(&info); err != nil {
return nil, fmt.Errorf("sysinfo failed: %w", err)
}
return &info, nil
}
// CreateEventNotification creates an eventfd descriptor initialized with a counter value.
func CreateEventNotification(initval uint) (int, error) {
fd, err := unix.Eventfd(initval, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK)
if err != nil {
return -1, fmt.Errorf("eventfd failed: %w", err)
}
return fd, nil
}
// CreateNonblockingPipe creates a pipe with nonblocking and close-on-exec flags.
func CreateNonblockingPipe() ([2]int, error) {
var fds [2]int
if err := unix.Pipe2(fds[:], unix.O_CLOEXEC|unix.O_NONBLOCK); err != nil {
return fds, fmt.Errorf("pipe2 failed: %w", err)
}
return fds, nil
}
func main() {
info, err := GetSystemStatistics()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting system info: %v\n", err)
os.Exit(1)
}
fmt.Printf("System Uptime: %d seconds, Total RAM: %d bytes, Procs: %d\n", info.Uptime, info.Totalram, info.Procs)
efd, err := CreateEventNotification(1)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating eventfd: %v\n", err)
os.Exit(1)
}
defer unix.Close(efd)
var writeVal uint64 = 4
var buf [8]byte
binary.LittleEndian.PutUint64(buf[:], writeVal)
if _, err := unix.Write(efd, buf[:]); err != nil {
fmt.Fprintf(os.Stderr, "Error writing to eventfd: %v\n", err)
os.Exit(1)
}
pipeFds, err := CreateNonblockingPipe()
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating pipe2: %v\n", err)
os.Exit(1)
}
defer unix.Close(pipeFds[0])
defer unix.Close(pipeFds[1])
msg := []byte("csx-sys-pipe-payload")
if _, err := unix.Write(pipeFds[1], msg); err != nil {
fmt.Fprintf(os.Stderr, "Error writing to pipe: %v\n", err)
os.Exit(1)
}
readBuf := make([]byte, len(msg))
if _, err := unix.Read(pipeFds[0], readBuf); err != nil {
fmt.Fprintf(os.Stderr, "Error reading from pipe: %v\n", err)
os.Exit(1)
}
fmt.Printf("Pipe communicated message: %s\n", string(readBuf))
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/sys@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sys@v0.31.0"
],
"symbols": [
"unix.Eventfd",
"unix.Pipe2",
"unix.Sysinfo"
]
}
package main
import (
"encoding/binary"
"fmt"
"os"
"golang.org/x/sys/unix"
)
func main() {
// Assertion 1: unix.Sysinfo returns system statistics including positive uptime, totalram, and process count without error
var info unix.Sysinfo_t
if err := unix.Sysinfo(&info); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Sysinfo failed: %v\n", err)
os.Exit(1)
}
if info.Uptime <= 0 {
fmt.Fprintf(os.Stderr, "FAIL: unix.Sysinfo returned non-positive uptime: %d\n", info.Uptime)
os.Exit(1)
}
if info.Totalram == 0 {
fmt.Fprintf(os.Stderr, "FAIL: unix.Sysinfo returned zero totalram\n")
os.Exit(1)
}
if info.Procs == 0 {
fmt.Fprintf(os.Stderr, "FAIL: unix.Sysinfo returned zero process count\n")
os.Exit(1)
}
// Assertion 2: unix.Eventfd creates a non-blocking event file descriptor that records initial counter value and accumulates writes
efd, err := unix.Eventfd(10, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Eventfd failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(efd)
if efd < 0 {
fmt.Fprintf(os.Stderr, "FAIL: invalid eventfd descriptor: %d\n", efd)
os.Exit(1)
}
var incVal uint64 = 25
var writeBuf [8]byte
binary.LittleEndian.PutUint64(writeBuf[:], incVal)
wn, err := unix.Write(efd, writeBuf[:])
if err != nil || wn != 8 {
fmt.Fprintf(os.Stderr, "FAIL: unix.Write on eventfd failed: wn=%d, err=%v\n", wn, err)
os.Exit(1)
}
var readBuf [8]byte
rn, err := unix.Read(efd, readBuf[:])
if err != nil || rn != 8 {
fmt.Fprintf(os.Stderr, "FAIL: unix.Read on eventfd failed: rn=%d, err=%v\n", rn, err)
os.Exit(1)
}
val := binary.LittleEndian.Uint64(readBuf[:])
expectedVal := uint64(35) // 10 initial + 25 written
if val != expectedVal {
fmt.Fprintf(os.Stderr, "FAIL: eventfd read value mismatch: got %d, expected %d\n", val, expectedVal)
os.Exit(1)
}
// Assertion 3: unix.Pipe2 creates a non-blocking pipe pair with close-on-exec enabled for inter-process communication
var pFds [2]int
if err := unix.Pipe2(pFds[:], unix.O_CLOEXEC|unix.O_NONBLOCK); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(pFds[0])
defer unix.Close(pFds[1])
if pFds[0] < 0 || pFds[1] < 0 {
fmt.Fprintf(os.Stderr, "FAIL: invalid pipe descriptors: read=%d, write=%d\n", pFds[0], pFds[1])
os.Exit(1)
}
pipePayload := []byte("csx-sys-pipe2-contract-payload")
pwn, err := unix.Write(pFds[1], pipePayload)
if err != nil || pwn != len(pipePayload) {
fmt.Fprintf(os.Stderr, "FAIL: unix.Write on pipe failed: pwn=%d, err=%v\n", pwn, err)
os.Exit(1)
}
pipeReadBuf := make([]byte, len(pipePayload))
prn, err := unix.Read(pFds[0], pipeReadBuf)
if err != nil || prn != len(pipePayload) {
fmt.Fprintf(os.Stderr, "FAIL: unix.Read on pipe failed: prn=%d, err=%v\n", prn, err)
os.Exit(1)
}
if string(pipeReadBuf) != string(pipePayload) {
fmt.Fprintf(os.Stderr, "FAIL: pipe payload mismatch: got %q, expected %q\n", string(pipeReadBuf), string(pipePayload))
os.Exit(1)
}
fmt.Println("PASS: golang.org/x/sys contract passed")
}
Исходный сидер
аноним