From fb9135b9c2aebf03d19419dec5b7d23e44f69219 Mon Sep 17 00:00:00 2001 From: ichizok Date: Wed, 17 Apr 2024 03:28:27 +0900 Subject: [PATCH] Test pts/pipe bufsize --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++++++------------ pipebufsize.py | 25 +++++++++++++++++++ ptsbufsize.py | 23 +++++++++++++++++ 3 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 pipebufsize.py create mode 100644 ptsbufsize.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 631e2dc..bbcc151 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,29 +19,50 @@ on: default: github actions hello jobs: - trial-docker-buildx: - runs-on: ubuntu-latest + trial-bufsize: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-13 + - macos-14 steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Check pipebufsize + run: python3 pipebufsize.py - - name: Preparation - run: | - mkdir -p target - echo hello > target/index.txt - find -type f -not -path './.*/*' | sort + - name: Check ptsbufsize + run: python3 ptsbufsize.py - - name: Build Docker Image - uses: docker/build-push-action@v5 - with: - context: . - push: false - tags: "buildtest:latest" - outputs: type=image,oci-mediatypes=true,compression=gzip,compression-level=3,force-compression=true + # trial-docker-buildx: + # runs-on: ubuntu-latest + # + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # + # - name: Setup Docker Buildx + # uses: docker/setup-buildx-action@v3 + # + # - name: Preparation + # run: | + # mkdir -p target + # echo hello > target/index.txt + # find -type f -not -path './.*/*' | sort + # + # - name: Build Docker Image + # uses: docker/build-push-action@v5 + # with: + # context: . + # push: false + # tags: "buildtest:latest" + # outputs: type=image,oci-mediatypes=true,compression=gzip,compression-level=3,force-compression=true # trial-multiline: # runs-on: ubuntu-latest diff --git a/pipebufsize.py b/pipebufsize.py new file mode 100644 index 0000000..f94fb10 --- /dev/null +++ b/pipebufsize.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import os +from subprocess import Popen, PIPE +from fcntl import fcntl, F_GETFL, F_SETFL +from itertools import count + +def set_nonblock(fd): + flags = fcntl(fd, F_GETFL) + flags |= os.O_NONBLOCK + fcntl(fd, F_SETFL, flags) + +p = Popen(['sleep', '30'], stdin=PIPE, stdout=PIPE, stderr=PIPE) +fd = p.stdin.fileno() + +set_nonblock(fd) + +for i in count(): + try: + os.write(fd, b'a') + except BlockingIOError: + i -= 1 + p.kill() + break + +print("pipe write blocked after {} bytes ({} KiB)".format(i, i//1024)) diff --git a/ptsbufsize.py b/ptsbufsize.py new file mode 100644 index 0000000..128e65a --- /dev/null +++ b/ptsbufsize.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import os +from pty import openpty +from fcntl import fcntl, F_GETFL, F_SETFL +from itertools import count + +def set_nonblock(fd): + flags = fcntl(fd, F_GETFL) + flags |= os.O_NONBLOCK + fcntl(fd, F_SETFL, flags) + +master, slave = openpty() + +set_nonblock(slave) + +for i in count(): + try: + os.write(slave, b'a') + except BlockingIOError: + i -= 1 + break + +print("pts write blocked after {} bytes ({} KiB)".format(i, i//1024))