From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id C39473954C6C for ; Tue, 13 Apr 2021 21:04:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C39473954C6C Received: by mail-qk1-x72d.google.com with SMTP id b139so13965858qkc.10 for ; Tue, 13 Apr 2021 14:04:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6lqIX2EFh1mJBmMqItIAxFvw4/kKQ7knR76AC1vOjRM=; b=ubWeYMo38FiWg6OHGRkIoQS7ntXwvZ4VeTYn44Qay3eqVd/R1bM+1WTBK42kOzBfPd DjGgGcQ/RZEZ0DSj6xHiNuP7rJZfmFMKYziz7dqVtFLuoU7v3UnvQAD2VZZ1fc4gOzzb mOSi5J1QOgKn3ndjIoCyc4xfrGSQjEEuhxZyLn+6rBGC8BpXsKXhMqsxKo77yIFkw4Be 7OZaimfTB97H+TnWwF+Hu+t/wC5TTBnr5n0Ft5pxaCL/gWq5zNhcUd5hQXwmGBdTUOfn ZEj/eLnbpZnkXvczxe6Z7oDzBO8aW1J73l8f9qwH0r8Pk0LJK/myHy+50vtPRQ138Shd J9HQ== X-Gm-Message-State: AOAM533Lj0H+k81cECvQ0GSJQfzzUSLSLrnDHeJ3hmQXK36Xf8wwg1SR IQcji7oCKY/QflTLUgtAFZaUtqxHw2zMG0VI X-Google-Smtp-Source: ABdhPJwch8fXqReoCnqPGSFKDnhsOiOFgRikXAKFCKj1Qkpo4su3Q/fIl+Pv4V9kaAdaRm0dFhbLLA== X-Received: by 2002:a05:620a:14ac:: with SMTP id x12mr33168410qkj.409.1618347850158; Tue, 13 Apr 2021 14:04:10 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id g8sm10003383qtm.29.2021.04.13.14.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 14:04:09 -0700 (PDT) From: Adhemerval Zanella To: libc-stable@sourceware.org Cc: Lukasz Majewski Subject: [PATCH 2.33 COMMITTED 1/6] tst: Provide test for select Date: Tue, 13 Apr 2021 18:04:00 -0300 Message-Id: <20210413210405.913196-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 21:04:12 -0000 From: Lukasz Majewski This change adds new test to assess select()'s timeout related functionality (the rdfs set provides valid fd - stderr - but during normal program operation there is no data to be read, so one just waits for timeout). To be more specific - two use cases are checked: - if select() times out immediately when passed struct timeval has zero values of tv_usec and tv_sec. - if select() times out after timeout specified in passed argument Reviewed-by: Adhemerval Zanella (cherry picked from commit bff3019afc77eb51634471827daaa1c17a6dc5bd) --- misc/Makefile | 2 +- misc/tst-select.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 misc/tst-select.c diff --git a/misc/Makefile b/misc/Makefile index b08d7c68ab..05ad034baf 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -88,7 +88,7 @@ tests := tst-dirname tst-tsearch tst-fdset tst-mntent tst-hsearch \ tst-preadvwritev tst-preadvwritev64 tst-makedev tst-empty \ tst-preadvwritev2 tst-preadvwritev64v2 tst-warn-wide \ tst-ldbl-warn tst-ldbl-error tst-dbl-efgcvt tst-ldbl-efgcvt \ - tst-mntent-autofs tst-syscalls tst-mntent-escape + tst-mntent-autofs tst-syscalls tst-mntent-escape tst-select # Tests which need libdl. ifeq (yes,$(build-shared)) diff --git a/misc/tst-select.c b/misc/tst-select.c new file mode 100644 index 0000000000..7c310256c5 --- /dev/null +++ b/misc/tst-select.c @@ -0,0 +1,71 @@ +/* Test for select timeout. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +#define TST_SELECT_TIMEOUT 1 +#define TST_SELECT_FD_ERR 2 + +static int +test_select_timeout (bool zero_tmo) +{ + const int fds = TST_SELECT_FD_ERR; + int timeout = TST_SELECT_TIMEOUT; + struct timeval to = { 0, 0 }; + struct timespec ts; + fd_set rfds; + + FD_ZERO (&rfds); + FD_SET (fds, &rfds); + + if (zero_tmo) + timeout = 0; + + to.tv_sec = timeout; + ts = xclock_now (CLOCK_REALTIME); + ts = timespec_add (ts, (struct timespec) { timeout, 0 }); + + /* Wait for timeout. */ + int ret = select (fds + 1, &rfds, NULL, NULL, &to); + if (ret == -1) + FAIL_EXIT1 ("select failed: %m\n"); + + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); + + return 0; +} + +static int +do_test (void) +{ + /* Check if select exits immediately. */ + test_select_timeout (true); + + /* Check if select exits after specified timeout. */ + test_select_timeout (false); + + return 0; +} + +#include -- 2.27.0