From patchwork Mon Aug 5 09:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1968983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IWst4Rrv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wcs9g6pjkz1yZb for ; Mon, 5 Aug 2024 19:49:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3AF8385DDDC for ; Mon, 5 Aug 2024 09:49:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 1BBDF3858294 for ; Mon, 5 Aug 2024 09:49:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BBDF3858294 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1BBDF3858294 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722851377; cv=none; b=EthzlzJWk4GOcKzju0UfeLThdQ6bkNjxZRHdkoSj4jmmNXFqSpDLCWNhXicWRb/+mq9JH77M9756vXHYOpOuTe4l1h84Glcq2+tMFzQmIckSNIXKHYPO5io/ZmLRTpgLldmce0Vh4ddZtErwREFx+WW3+5GEjOhwH8lCxoqh0pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722851377; c=relaxed/simple; bh=4mEay03wvpaTuPnVj421ZGw4yEsg7P7MQjLFE7rBCPg=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=aPsrbLm7k41qtbB+TLM0Wshq8pONVntZcGhn0V/n6reDwxUZi5pKEGpffViSbXZQCJs+ZD2P6j7w0eLa+raxm9SOgWsRwclSparWmR2TuRQ/gNgJ3mhTPW6Gb+5N19fi7oDDg9zRhUqKlXsg5OWE+yjcIeT75lMqSPxK59Teasg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722851374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uzxz+lwQsdFOFXw6y3zIWLko/KEVyNpPkBUn+77y3Iw=; b=IWst4RrvNxPoK4PdRKWvTztZxl2XVdKtE6py+nhpwiS2rImh+eRb6jusDF7Bp545qA88d/ L+9GHWQa6odBL4VD19CRBj9fVHEj7nINUNRa8dXyFmJ/wtT4LotA5lA2kThB7wbKQbEimQ D+JbwSHSDetAyjec3EHaBxdLzG13/84= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-vLmakRISM_um3hDbLy7UTw-1; Mon, 05 Aug 2024 05:49:31 -0400 X-MC-Unique: vLmakRISM_um3hDbLy7UTw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 487451955F49 for ; Mon, 5 Aug 2024 09:49:30 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.16]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 55576300019F for ; Mon, 5 Aug 2024 09:49:29 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 1/7] iconv: Base tests for buffer management In-Reply-To: Message-ID: <71b9f0cd0e96de609b4ac93c4ea40361d8ff6e2a.1722851053.git.fweimer@redhat.com> References: X-From-Line: 71b9f0cd0e96de609b4ac93c4ea40361d8ff6e2a Mon Sep 17 00:00:00 2001 Date: Mon, 05 Aug 2024 11:49:26 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org --- iconv/Makefile | 10 +- iconv/tst-iconv_prog-buffer.sh | 177 +++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 iconv/tst-iconv_prog-buffer.sh diff --git a/iconv/Makefile b/iconv/Makefile index 63afc853ff..2e9ce26573 100644 --- a/iconv/Makefile +++ b/iconv/Makefile @@ -72,7 +72,10 @@ include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left)) ifeq ($(run-built-tests),yes) xtests-special += $(objpfx)test-iconvconfig.out -tests-special += $(objpfx)tst-iconv_prog.out +tests-special += \ + $(objpfx)tst-iconv_prog-buffer.out \ + $(objpfx)tst-iconv_prog.out \ + # tests-special endif # Make a copy of the file because gconv module names are constructed @@ -126,3 +129,8 @@ $(objpfx)tst-iconv_prog.out: tst-iconv_prog.sh $(objpfx)iconv_prog $(BASH) $< $(common-objdir) '$(test-wrapper-env)' \ '$(run-program-env)' > $@; \ $(evaluate-test) + +$(objpfx)tst-iconv_prog-buffer.out: \ + tst-iconv_prog-buffer.sh $(objpfx)iconv_prog + $(BASH) $< $(common-objdir) '$(test-program-prefix)' > $@; \ + $(evaluate-test) diff --git a/iconv/tst-iconv_prog-buffer.sh b/iconv/tst-iconv_prog-buffer.sh new file mode 100644 index 0000000000..a27107f02b --- /dev/null +++ b/iconv/tst-iconv_prog-buffer.sh @@ -0,0 +1,177 @@ +#!/bin/bash +# Test for iconv (the program) buffer management. +# Copyright (C) 2024 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 +# . + +exec 2>&1 +set -e + +exec {logfd}>&1 + +codir=$1 +test_program_prefix="$2" + +# Use internal converters to avoid issues with module loading. +iconv_args="-f ASCII -t UTF-8" + +failure=false + +tmp=`mktemp -d` +trap 'rm -rf "$tmp"' 0 +echo ABC > "$tmp/abc" +echo DEF > "$tmp/def" +echo GGG > "$tmp/ggg" +echo HH > "$tmp/hh" +echo XY > "$tmp/xy" +echo ZT > "$tmp/zt" +echo OUT > "$tmp/out-template" +printf '\xff' > "$tmp/0xff" +cat "$tmp/xy" "$tmp/0xff" "$tmp/zt" > "$tmp/0xff-wrapped" + +run_iconv () { + local c=0 + if test "${FUNCNAME[2]}" = main; then + c=1 + fi + echo "${BASH_SOURCE[$c]}:${BASH_LINENO[$c]}: iconv $iconv_args $@" >&$logfd + $test_program_prefix $codir/iconv/iconv_prog $iconv_args "$@" +} + +check_out_expected () { + if ! cmp -s "$tmp/out" "$tmp/expected" ; then + echo "error: iconv output difference" >&$logfd + echo "*** expected ***" >&$logfd + cat "$tmp/expected" >&$logfd + echo "*** actual ***" >&$logfd + cat "$tmp/out" >&$logfd + failure=true + fi +} + +expect_files () { + local f + ! test -z "$1" + cp "$tmp/$1" "$tmp/expected" + shift + for f in "$@" ; do + cat "$tmp/$f" >> "$tmp/expected" + done + check_out_expected +} + +check_out () { + cat > "$tmp/expected" + check_out_expected +} + +expect_exit () { + local expected=$1 + shift + # Prevent failure for stopping the script. + if "$@" ; then + actual=$? + else + actual=$? + fi + if test "$actual" -ne "$expected"; then + echo "error: expected exit status $expected, not $actual" >&$logfd + exit 1 + fi +} + +ignore_failure () { + set +e + "$@" + status=$? + set -e +} + +# Concatentation test. +run_iconv -o "$tmp/out" "$tmp/abc" "$tmp/def" +expect_files abc def + +# Single-file in-place conversion. +run_iconv -o "$tmp/out" "$tmp/out" +expect_files abc def + +# Multiple input files with in-place conversion. + +run_iconv -o "$tmp/out" "$tmp/out" "$tmp/abc" +expect_files abc def abc + +# But not if we are writing to standard output. + +cp "$tmp/out-template" "$tmp/out" +run_iconv >"$tmp/out" +expect_files out-template + +cp "$tmp/out-template" "$tmp/out" +run_iconv - >"$tmp/out" +expect_files out-template + +cp "$tmp/out-template" "$tmp/out" +run_iconv /dev/null >>"$tmp/out" +expect_files out-template + +# Conversion errors should avoid clobbering an existing file if +# it is also an input file. + +cp "$tmp/0xff" "$tmp/out" +expect_exit 1 run_iconv -o "$tmp/out" "$tmp/out" +expect_files 0xff + +cp "$tmp/0xff" "$tmp/out" +expect_exit 1 run_iconv -o "$tmp/out" < "$tmp/out" +expect_files 0xff + +cp "$tmp/0xff" "$tmp/out" +expect_exit 1 run_iconv -o "$tmp/out" - < "$tmp/out" +expect_files 0xff + +# If errors are ignored, the file should be overwritten. + +cp "$tmp/out-template" "$tmp/out" +expect_exit 1 \ + run_iconv -c -o "$tmp/out" "$tmp/abc" "$tmp/0xff" "$tmp/def" 2>"$tmp/err" +! test -s "$tmp/err" +expect_files abc def + +# FIXME: This is not correct, -c should not change the exit status. +cp "$tmp/out-template" "$tmp/out" +run_iconv -c -o "$tmp/out" \ + "$tmp/abc" "$tmp/0xff-wrapped" "$tmp/def" 2>"$tmp/err" +! test -s "$tmp/err" +expect_files abc xy zt def + +# If the file does not exist yet, it should not be created on error. + +rm "$tmp/out" +expect_exit 1 run_iconv -o "$tmp/out" "$tmp/0xff" +! test -e "$tmp/out" + +expect_exit 1 run_iconv -o "$tmp/out" < "$tmp/0xff" +! test -e "$tmp/out" + +expect_exit 1 run_iconv -o "$tmp/out" "$tmp/abc" "$tmp/0xff" "$tmp/def" +! test -e "$tmp/out" + +expect_exit 1 run_iconv -o "$tmp/out" "$tmp/abc" - < "$tmp/0xff" "$tmp/def" +! test -e "$tmp/out" + +if $failure ; then + exit 1 +fi