From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 338E9384600B for ; Wed, 17 Apr 2024 20:21:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 338E9384600B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 338E9384600B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713385307; cv=pass; b=Ia7PP0Mhum5EMPNMsfIvgtOZ1p0b/5Gc2G6zI7s8542RmYEDE0bs/nFDsi9bq6h7xm/drNpl+N+d2LM3lms1ElYhbyEOK9+iubRPTr/g11lIt0kV3bCMFSz/LICcD3zDTcjJmFmEORzbXayFpfOH99/HvCGjIfHRJgVjNnvmu8I= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713385307; c=relaxed/simple; bh=xz2xoUQW3eI/n2/WKweDAGFAgQi1ChQBykOGF7TAXv8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=PhhXutKBgs+lLPVEj0TgJt/rUlLKQtgXtxuxM0aG00Yt/hLaHxsu7bFkWeFbD27bqMUhaO5NqlUjkLuLuIk7mmEh4pPyzucPULBWZZZ9FQtT3cMveesc9SX3zEw2b5BifunJWELHes3LU8y/2sxkG0xs921G1Ek0QXiNxfwaj+A= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43HHhqaX025880 for ; Wed, 17 Apr 2024 20:21:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=5zu8PFvnXEJ7SeNUBZwXRrBtvSP+JvZG08fZ9crgTZw=; b=Y0h9oeNMND/zRdGxsBNTlTg2opzmWpEorHLeCAvnrP+CD5snCeAcMedg2Z6VScyASMQX G5N0ekudc6Z4KjXeM632aHo9VNY1OGtUGvy9FZvP7ldeMn/v4dmug4ZSEY4GFfbShMFD FPTSY60RKpksYNn9dxZw7+ZZmW16gkCIjrtgwx7rw3bXQlMERGC6ZHS1W2EQ0WyFX8ao AeVI1GBvX+XnaMYYmi/Oxqtzt5viNGF48T/iF3DkkFywgL1/XmdbbbWPquGnG1en+ll7 2l+Ai4uv5ZgO7HQrs41uIGmcnvck0YDYzOqtNMcpMQOm4ygGQSyiIQcQcsPfFvL3a9pN KQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgffgv3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 20:21:41 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43HJJhpw012485 for ; Wed, 17 Apr 2024 20:21:40 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xgkwhfern-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 20:21:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RL02Ioyp/KaWIKXwcurSotGlAMdBJMRrWhDIATzy9zdd0EAFWIzlyUG/CjkwRYnIEaxDHUJLQThM75UIQpS034dJ0S004UtQkD6pAut7PA6Zpuw+mly25BaU59o0LX1xCeGC1adpM2VPPehFgeVy9H6RGPrEyBsswYDIiwHHXDRLGxHih0a7HQ8J91jkLQPNmy8F5chpWYYzCn/GVbuW08xQ6tPA9Cnyj7bxI07e0QrcCfWVORHqrEZDmHQGY1yl+/wFz1HerS5AsMqxFclicEUxCemq6zlqsC1c/LTiaMAQ7UKJfjsUwD/7AM6EiJNB0fJJ3fE7CgrGBcRKcxn5Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5zu8PFvnXEJ7SeNUBZwXRrBtvSP+JvZG08fZ9crgTZw=; b=KpiVn9fEHQCKP3tGJX1spdLsYUBt5riwvEa5MMDsXdZZHIxsclP/G4b3AxzCgFDzm81+APFsx3cA+pxwOlXXprnUg0MALkSydeM5Q609NRkLz3itEIC/7Wy+vw09EQY3luI615PFaYrY5b9wLtOT9pus3U7K50UxocpNjtEGRDnyE1ORftAi/X5ixxAYaLBZA9+/vDUbuCVyZ3t0/8Y3E5+uRzDNDwczaJpG0Yuinm0FNF+8hLcj7zmiySncwUrDVO0kITwcpO7ErH6Sy0cLfTJlaRRhPC5S/IVK9jFZafWHqm2WmNfgdMd368qc3J4CIEZAj3xr6x+ZBuQ4hDySzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5zu8PFvnXEJ7SeNUBZwXRrBtvSP+JvZG08fZ9crgTZw=; b=zATDCmGhd2jdAkq951iXCNoW4sYySMYwxZR7dfy0hetxyoCbpOg8FrXV5uigSjDh37eqE4UFyHmUSoav2FvkZo98hLILTC62/7EHjTJuwiDk1xAIqufTtVfGrilq8Lxnaf19f/jknmcsnK366hK8nf/pz3uw3+sn13efYtglORo= Received: from MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) by LV8PR10MB7966.namprd10.prod.outlook.com (2603:10b6:408:202::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Wed, 17 Apr 2024 20:21:37 +0000 Received: from MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::67a4:9544:7249:7751]) by MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::67a4:9544:7249:7751%7]) with mapi id 15.20.7472.037; Wed, 17 Apr 2024 20:21:37 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 18/22] libctf: add rewriting tests Date: Wed, 17 Apr 2024 21:20:14 +0100 Message-ID: <20240417202018.34966-19-nick.alcock@oracle.com> X-Mailer: git-send-email 2.44.0.273.ge0bd14271f In-Reply-To: <20240417202018.34966-1-nick.alcock@oracle.com> References: <20240417202018.34966-1-nick.alcock@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P265CA0082.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bd::15) To MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR10MB6608:EE_|LV8PR10MB7966:EE_ X-MS-Office365-Filtering-Correlation-Id: 6afa9cdf-c4c2-44d6-f2d2-08dc5f1bfb8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UqG6DDsutoHspYANpuK7Hxs2hFzHcZdmI3WmE+1KoJ2xpPZ3XKIxGJHbdrc191CvPBSXnpC6yRR4ZAUji6Gw21VHsUl8rzbAfa94P5yw8kby+niyFQciiw41kRnCN3ntOq+Jo6DfV1mJGh7ELMY+kP0c/eD0I0xmB9CKVPsovOJGMvealocHd/F6KTok/KvMw8bSOwYXec8A4aTE3xh8UxRlx+69ysIdl5XJLYidUVCJhhXLNgCgjwakckjv+mL2jc9wucp5NT33FWiaVyRD9SSxAw9LDPkTO+sQTU6VhaD56yqC4cXaz1xaQGBsClM9jgYVWXRVslI85xv4jby6yVY1e4lD49ocT+SQQleznEx0dUZTbK2CYowfAqSNQIckNU7eJcywI1RDmsapI0OklI0SZUy7RAjA/D4VuD0JMJti+6nkhTIwGbtyNepGxA+XD+o6ckyDeOxiSBTGGbEKAt6RjuajWVV67kuQe+aDXtP7DP9dy5i/c7gwJ82Mi/pmgMpLU4ejXzaADxFcnJ8peKECg/vf1GtAX0lvt9vdzESZMumc3TBE5Fomk9rHvi2ylFozuxMyy/R0anoW1pSdmomvGsbmEskXXyDBAJy9sZ4h6XdWZ3flcuG7KNpvDlATEPhCjU/szJIIiI/FeNd6HG4n5nISdlecXtU2z/e02eU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR10MB6608.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ubPtLX8nHsenoB/v3lMbgL5l5QNRaKRye7/b0gi3aTQkCheAd9bZagnHA/NT?= =?us-ascii?Q?0Z+GHnD0eC3CJ3sakva5ZsSt6qbbuffXf1Tc2QEIbzf7WWhNO3FAxiPSm8xt?= =?us-ascii?Q?YvaSywlIkakIMbftp6QcC+KCwe06aPct4DsAVTJWmmqsarUFGZzD10rkUcVg?= =?us-ascii?Q?2DlawSQ70j5lOZQhEFfp8hGdsuHhRTT1oe7vMaTIJpz+if9TV3x9iSIwIPXU?= =?us-ascii?Q?R9GL7bfU8LBGxQOIgeHnQMwGmKeHV6+fUXp23ShoDOTV7ab/5Bg+um699U0X?= =?us-ascii?Q?EO6Wo9z5N3G0R+Aac64I7PRaac96OYbzsmLhyIE4MDVOmhD+lc/inNTpXve6?= =?us-ascii?Q?gDcG+HdPJGAFNVAI5+AtTF1j3NlCeqJFFFsyEje07YnYz7mXFhdPxmKbLpgZ?= =?us-ascii?Q?MYtZgoL+pCuFyNcA78y5i08ToRPPMPhnAQ7Ycpt2OgTD68z+7lfs4RkWFnjB?= =?us-ascii?Q?oMs/UcptbQnbLiRVBxRnrIgVNqRhAPvuQCoXiAFD42xEtNFg6dgnub/QWFCv?= =?us-ascii?Q?NkEiSvParZUFEdWXe9WdfHD0UR+XXEpbQZ5fGWoF4UnMQEZrSJZtjp3Mq77Q?= =?us-ascii?Q?qwpmTlW2kxwicy9Fux4oBcPTiMS8MPcs0Z5tMkGA4CRfUaA4xoDF+XYxTYc0?= =?us-ascii?Q?3xizvV89prBOs3/TPyamkNIoJSFDq0wCwLwn0MrzJEHb0DMXusWghqxbpiaq?= =?us-ascii?Q?TBlLDs6pbdEuxG3c2B0zS8/soxSXt0PG0QIj4Xcn10RhbY34bQm39JPPYPZJ?= =?us-ascii?Q?c526yMas2tWfLsAdVEU2gSSqEDCzuGbsWZ8g6Av5xBeO88jN6w7fYxojePZP?= =?us-ascii?Q?xzfI3p0X2rpdQr+z/igqbwJdWsu0fjV8/NsnwUDlg7opwHlDKK73qphf08zB?= =?us-ascii?Q?jcU8E0QK8sM5svAXkwUwVgUHFbBD3Wr6wDs41Ov3UyUBPo0j6rKHkptG8qUB?= =?us-ascii?Q?V+RniyGYYn4JMPD1kqAdbRyPCy/Nna/SrWRwIoDR8ZkUBS4wsF5E3zisuZNP?= =?us-ascii?Q?DZTG24SALKE1P0HpWnAXbmdizX0CKbEZwlssesP0aORaXUo47rqcK90e5s9v?= =?us-ascii?Q?EaqcnP0Ls2dhZhz8vCLhL5Rq1uTQLYN9r/u1Bv3ywAH7IDTBR0xRKIWemGl9?= =?us-ascii?Q?rDCE7ug8YNPw46XoCWC1OvcY70iCeQ/gjPKYy12DhZFe9wePM/0NXWOo8kpX?= =?us-ascii?Q?BMbKouB01kT5i0NM0TStGFmDPoeEtxig4oAB6YqBE9TOpN/YNB2Al4+dQQre?= =?us-ascii?Q?21dIFILqjFnTRok3jIXf9BnUuiPB+9S0i3wsV5TciBxNAny3xwTBd2uxQEbh?= =?us-ascii?Q?akdA3tSfI1e8re5RHKl20LKAlGqmcIbcf4EMZu+Z0+MPfJFlbzjpxS1svyPW?= =?us-ascii?Q?oY9LCe06A8oa5AGk5gOkL0eoKYg4L1FmNyVdNzNQEmIxnE8moN6RfF5Z2cfx?= =?us-ascii?Q?Eef4tQiQzBJz/NRiX+GZWz2kHkdPfbembSesNGTnXn6saNSG7M8kmm1CrDHe?= =?us-ascii?Q?yeExjwCmn2i8MPUbcJH+UbA9avfPh51k6UDXl3ZphtPnEWcWXEcGoh2FI1+G?= =?us-ascii?Q?hGjuLI2wGRDttwNRFe69n24i8dIN7vaQaYhFpll567krkrBmlls7uWaGlOBL?= =?us-ascii?Q?lw=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6QjCKBJF2QFwjF8uS5aEoDcLTrW6KR19SyxutiieUkEyrXIGDS8Y7dA4ajB/6GD46u5XicuqY2sj03Gn4W6mi/cSe+wjmWvSmCXmksYNT0tLwWAJYKXnMDVy/AVMR7k3f6XIergTQRmkF5Fw9mNNgxPCbxqAJ5MMPv8wuPEao5lpnDUw9xyALH9Wwl4SEtRicz0HZpF76auU7jMrGHqoY6m8SvAON8hDwtTSVcmFeI1oHtTBx5KyyxVtlRB0pjv/VRs9gjrxckcfmCtKD9XlPiuNhdywTuoy+69PgXwnmY6N9Z0xS6fQzBc3SZt1v6M03jvYAz581roS60J/ecPIH1qbAl/R2TbckP1jJbe8e/GfOU7koWvpAkbCdKbqdalyHGDvOETe9gHqV3CeHNkZbb2g69bhjDBHjgyj1DgvIMfNDJMilRh+2CuSu7eisO/p/dxSiU7MNkIQ2/D3DsZNZElTO1I1kZvxbTqUOsAHnfowl/td7uRgtsfu5082Nll727Z4J/oQh3euQh5NczPLqk+rg4rLnRIoFquahpWwHBZbEV9Bo1c0NEdS+fS0ZgdTsa3nnrbIvNZy3UPkS3QTD7k/RFOSiyUIWgS/N+26Dk4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6afa9cdf-c4c2-44d6-f2d2-08dc5f1bfb8f X-MS-Exchange-CrossTenant-AuthSource: MW4PR10MB6608.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 20:21:37.1270 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Gdpjt3KA9gdtQIC1EVGmhKZpuhTpyhNl7PxD8Vqd8VayxaGmY9ujD65JuZ0/q7RC5kjcVQVAjejpC3RYGkwF+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR10MB7966 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_17,2024-04-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=927 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170143 X-Proofpoint-ORIG-GUID: _8tI7Gm7uHWuecLBNliFPQxxOEeD1IDJ X-Proofpoint-GUID: _8tI7Gm7uHWuecLBNliFPQxxOEeD1IDJ X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,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 List-Id: Now there's a chance of it actually working, we can add more tests for the long-broken dict read-and-rewrite cases. This is the first ever test for the (rarely-used, unpleasant, and until recently completely broken) ctf_gzwrite function. libctf/ * testsuite/libctf-regression/gzrewrite*: New test. * testsuite/libctf-regression/zrewrite*: Likewise. --- .../libctf-regression/gzrewrite-ctf.c | 19 ++ .../testsuite/libctf-regression/gzrewrite.c | 165 ++++++++++++++++++ .../testsuite/libctf-regression/gzrewrite.lk | 3 + libctf/testsuite/libctf-regression/zrewrite.c | 156 +++++++++++++++++ .../testsuite/libctf-regression/zrewrite.lk | 3 + 5 files changed, 346 insertions(+) create mode 100644 libctf/testsuite/libctf-regression/gzrewrite-ctf.c create mode 100644 libctf/testsuite/libctf-regression/gzrewrite.c create mode 100644 libctf/testsuite/libctf-regression/gzrewrite.lk create mode 100644 libctf/testsuite/libctf-regression/zrewrite.c create mode 100644 libctf/testsuite/libctf-regression/zrewrite.lk diff --git a/libctf/testsuite/libctf-regression/gzrewrite-ctf.c b/libctf/testsuite/libctf-regression/gzrewrite-ctf.c new file mode 100644 index 00000000000..b5d483ea1cb --- /dev/null +++ b/libctf/testsuite/libctf-regression/gzrewrite-ctf.c @@ -0,0 +1,19 @@ +int an_int; +char *a_char_ptr; +typedef int (*a_typedef) (int main); +struct struct_forward; +enum enum_forward; +union union_forward; +typedef int an_array[50]; +struct a_struct { int foo; }; +union a_union { int bar; }; +enum an_enum { FOO }; + +a_typedef a; +struct struct_forward *x; +union union_forward *y; +enum enum_forward *z; +struct a_struct *xx; +union a_union *yy; +enum an_enum *zz; +an_array ar; diff --git a/libctf/testsuite/libctf-regression/gzrewrite.c b/libctf/testsuite/libctf-regression/gzrewrite.c new file mode 100644 index 00000000000..8e279ca3fac --- /dev/null +++ b/libctf/testsuite/libctf-regression/gzrewrite.c @@ -0,0 +1,165 @@ +/* Make sure that you can modify then ctf_gzwrite() a dict + and it changes after modification. */ + +#include +#include +#include +#include +#include +#include +#include + +char *read_gz(const char *path, size_t *len) +{ + char *in = NULL; + char buf[4096]; + gzFile foo; + size_t ret; + + if ((foo = gzopen (path, "rb")) == NULL) + return NULL; + + *len = 0; + while ((ret = gzread (foo, buf, 4096)) > 0) + { + if ((in = realloc (in, *len + ret)) == NULL) + { + fprintf (stderr, "Out of memory\n"); + exit (1); + } + + memcpy (&in[*len], buf, ret); + *len += ret; + } + if (ret < 0) + { + int errnum; + const char *err; + err = gzerror (foo, &errnum); + if (errnum != Z_ERRNO) + fprintf (stderr, "error reading %s: %s\n", path, err); + else + fprintf (stderr, "error reading %s: %s\n", path, strerror(errno)); + exit (1); + } + gzclose (foo); + return in; +} + +int +main (int argc, char *argv[]) +{ + ctf_dict_t *fp, *fp_b; + ctf_archive_t *ctf; + gzFile foo; + char *a, *b; + size_t a_len, b_len; + ctf_id_t type, ptrtype; + int err; + + if (argc != 2) + { + fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]); + exit(1); + } + + if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) + goto open_err; + if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) + goto open_err; + + if ((foo = gzopen ("tmpdir/one.gz", "wb")) == NULL) + goto write_gzerr; + if (ctf_gzwrite (fp, foo) < 0) + goto write_err; + gzclose (foo); + + if ((foo = gzopen ("tmpdir/two.gz", "wb")) == NULL) + goto write_gzerr; + if (ctf_gzwrite (fp, foo) < 0) + goto write_err; + gzclose (foo); + + if ((a = read_gz ("tmpdir/one.gz", &a_len)) == NULL) + goto read_err; + + if ((b = read_gz ("tmpdir/two.gz", &b_len)) == NULL) + goto read_err; + + if (a_len != b_len || memcmp (a, b, a_len) != 0) + { + fprintf (stderr, "consecutive gzwrites are different: lengths %i and %i\n", a_len, b_len); + return 1; + } + + free (b); + + /* Add some new types to the dict and write it out, then read it back in and + make sure they're still there, and that at least some of the + originally-present data objects are still there too. */ + + if ((type = ctf_lookup_by_name (fp, "struct a_struct")) == CTF_ERR) + fprintf (stderr, "Lookup of struct a_struct failed: %s\n", ctf_errmsg (ctf_errno (fp))); + + if ((ptrtype = ctf_add_pointer (fp, CTF_ADD_ROOT, type)) == CTF_ERR) + fprintf (stderr, "Cannot add pointer to ctf_opened dict: %s\n", ctf_errmsg (ctf_errno (fp))); + + unlink ("tmpdir/two.gz"); + if ((foo = gzopen ("tmpdir/two.gz", "wb")) == NULL) + goto write_gzerr; + if (ctf_gzwrite (fp, foo) < 0) + goto write_err; + gzclose (foo); + + if ((b = read_gz ("tmpdir/two.gz", &b_len)) == NULL) + goto read_err; + + if (memcmp (a, b, b_len) == 0) + { + fprintf (stderr, "gzwrites after adding types does not change the dict\n"); + return 1; + } + + free (a); + if ((fp_b = ctf_simple_open (b, b_len, NULL, 0, 0, NULL, 0, &err)) == NULL) + goto open_err; + + if (ctf_type_reference (fp_b, ptrtype) == CTF_ERR) + fprintf (stderr, "Lookup of pointer preserved across writeout failed: %s\n", ctf_errmsg (ctf_errno (fp_b))); + + if (ctf_type_reference (fp_b, ptrtype) != type) + fprintf (stderr, "Look up of newly-added type in serialized dict yields ID %lx, expected %lx\n", ctf_type_reference (fp_b, ptrtype), type); + + if (ctf_lookup_by_symbol_name (fp_b, "an_int") == CTF_ERR) + fprintf (stderr, "Lookup of symbol an_int failed: %s\n", ctf_errmsg (ctf_errno (fp_b))); + + free (b); + ctf_dict_close (fp); + ctf_dict_close (fp_b); + ctf_close (ctf); + + printf ("All done.\n"); + return 0; + + open_err: + fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); + return 1; + write_err: + fprintf (stderr, "%s: cannot write: %s\n", argv[0], ctf_errmsg (ctf_errno (fp))); + return 1; + write_gzerr: + { + int errnum; + const char *err; + + err = gzerror (foo, &errnum); + if (errnum != Z_ERRNO) + fprintf (stderr, "error gzwriting: %s\n", err); + else + fprintf (stderr, "error gzwriting: %s\n", strerror(errno)); + return 1; + } + read_err: + fprintf (stderr, "%s: cannot read\n", argv[0]); + return 1; +} diff --git a/libctf/testsuite/libctf-regression/gzrewrite.lk b/libctf/testsuite/libctf-regression/gzrewrite.lk new file mode 100644 index 00000000000..2d0de3dc464 --- /dev/null +++ b/libctf/testsuite/libctf-regression/gzrewrite.lk @@ -0,0 +1,3 @@ +# source: gzrewrite-ctf.c +# lookup: gzrewrite.c +All done. diff --git a/libctf/testsuite/libctf-regression/zrewrite.c b/libctf/testsuite/libctf-regression/zrewrite.c new file mode 100644 index 00000000000..4d5d15e7985 --- /dev/null +++ b/libctf/testsuite/libctf-regression/zrewrite.c @@ -0,0 +1,156 @@ +/* Make sure that you can modify then ctf_compress_write() a dict + and it changes after modification. */ + +#include +#include +#include +#include +#include +#include +#include + +char *read_file(const char *path, size_t *len) +{ + char *in = NULL; + char buf[4096]; + int foo; + size_t ret; + + if ((foo = open (path, O_RDONLY)) < 0) + { + fprintf (stderr, "error opening %s: %s\n", path, strerror(errno)); + exit (1); + } + + *len = 0; + while ((ret = read (foo, buf, 4096)) > 0) + { + if ((in = realloc (in, *len + ret)) == NULL) + { + fprintf (stderr, "Out of memory\n"); + exit (1); + } + + memcpy (&in[*len], buf, ret); + *len += ret; + } + + if (ret < 0) + { + fprintf (stderr, "error reading %s: %s\n", path, strerror(errno)); + exit (1); + } + close (foo); + return in; +} + +int +main (int argc, char *argv[]) +{ + ctf_dict_t *fp, *fp_b; + ctf_archive_t *ctf, *ctf_b; + int foo; + char *a, *b; + size_t a_len, b_len; + ctf_id_t type, ptrtype; + int err; + + if (argc != 2) + { + fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]); + exit(1); + } + + if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) + goto open_err; + if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) + goto open_err; + + if ((foo = open ("tmpdir/one", O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) + goto write_stderr; + if (ctf_compress_write (fp, foo) < 0) + goto write_err; + close (foo); + + if ((foo = open ("tmpdir/two", O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) + goto write_stderr; + if (ctf_compress_write (fp, foo) < 0) + goto write_err; + close (foo); + + a = read_file ("tmpdir/one", &a_len); + b = read_file ("tmpdir/two", &b_len); + + if (a_len != b_len || memcmp (a, b, a_len) != 0) + { + fprintf (stderr, "consecutive compress_writes are different: lengths %i and %i\n", a_len, b_len); + return 1; + } + + free (b); + + /* Add some new types to the dict and write it out, then read it back in and + make sure they're still there, and that at least some of the + originally-present data objects are still there too. */ + + if ((type = ctf_lookup_by_name (fp, "struct a_struct")) == CTF_ERR) + fprintf (stderr, "Lookup of struct a_struct failed: %s\n", ctf_errmsg (ctf_errno (fp))); + + if ((ptrtype = ctf_add_pointer (fp, CTF_ADD_ROOT, type)) == CTF_ERR) + fprintf (stderr, "Cannot add pointer to ctf_opened dict: %s\n", ctf_errmsg (ctf_errno (fp))); + + unlink ("tmpdir/two"); + + if ((foo = open ("tmpdir/two", O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) + goto write_stderr; + if (ctf_compress_write (fp, foo) < 0) + goto write_err; + close (foo); + + b = read_file ("tmpdir/two", &b_len); + + if (memcmp (a, b, b_len) == 0) + { + fprintf (stderr, "compress_writes after adding types does not change the dict\n"); + return 1; + } + + free (a); + free (b); + + if ((ctf_b = ctf_open ("tmpdir/two", NULL, &err)) == NULL) + goto open_err; + if ((fp_b = ctf_dict_open (ctf_b, NULL, &err)) == NULL) + goto open_err; + + if (ctf_type_reference (fp_b, ptrtype) == CTF_ERR) + fprintf (stderr, "Lookup of pointer preserved across writeout failed: %s\n", ctf_errmsg (ctf_errno (fp_b))); + + if (ctf_type_reference (fp_b, ptrtype) != type) + fprintf (stderr, "Look up of newly-added type in serialized dict yields ID %lx, expected %lx\n", ctf_type_reference (fp_b, ptrtype), type); + + if (ctf_lookup_by_symbol_name (fp_b, "an_int") == CTF_ERR) + fprintf (stderr, "Lookup of symbol an_int failed: %s\n", ctf_errmsg (ctf_errno (fp_b))); + + ctf_dict_close (fp); + ctf_close (ctf); + + ctf_dict_close (fp_b); + ctf_close (ctf_b); + + printf ("All done.\n"); + return 0; + + open_err: + fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); + return 1; + write_err: + fprintf (stderr, "%s: cannot write: %s\n", argv[0], ctf_errmsg (ctf_errno (fp))); + return 1; + write_stderr: + fprintf (stderr, "%s: cannot open for writing: %s\n", argv[0], strerror (errno)); + return 1; + read_err: + fprintf (stderr, "%s: cannot read\n", argv[0]); + return 1; +} diff --git a/libctf/testsuite/libctf-regression/zrewrite.lk b/libctf/testsuite/libctf-regression/zrewrite.lk new file mode 100644 index 00000000000..a0a53d91a04 --- /dev/null +++ b/libctf/testsuite/libctf-regression/zrewrite.lk @@ -0,0 +1,3 @@ +# source: gzrewrite-ctf.c +# lookup: zrewrite.c +All done. -- 2.44.0.273.ge0bd14271f