Files
binutils-gdb/libsframe/testsuite/libsframe.decode/be-flipping.c
Indu Bhagat 4dc07bf60c libsframe: testsuite: make test names unique
Fix PR libsframe/33437 - libsframe test names are not unique

The TEST () macro definition originally in plt-findfre-2.c, was being
used to differentiate between multiple runs of the testcases.  Adapt
that definition a bit to allow for a variable number of arguments following
the test condition: A test name format string may be used by macro
users, such that the name of the tests are unique.

Move the new variadic TEST macro definition in the testsuite's common
header sframe-test.h, and use it throughout the testsuite.

Reviewed-by: Jens Remus <jremus@linux.ibm.com>

libsframe/testsuite/
	PR libsframe/33437
	* libsframe.decode/be-flipping.c: Use new TEST macro with
	suffix.
	* libsframe.decode/frecnt-1.c: Likewise.
	* libsframe.decode/frecnt-2.c: Likewise.
	* libsframe.encode/encode-1.c: Likewise.
	* libsframe.find/findfre-1.c: Likewise.
	* libsframe.find/findfunc-1.c: Likewise.
	* libsframe.find/plt-findfre-1.c: Likewise.
	* libsframe.find/plt-findfre-2.c: Likewise.
	* sframe-test.h: Move the TEST macro definition to this
	testsuite header.
2025-10-02 15:26:10 -07:00

101 lines
2.6 KiB
C

/* be-flipping.c -- Test for handling different endianness in libsframe.
Copyright (C) 2022-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "sframe-test.h"
/* SFrame info from the following source (1 fde 5 fres):
static int cnt;
extern void foo (void);
int bar()
{
cnt++;
if (cnt == 3)
foo();
return (cnt);
}
gcc -mbig-endian -Wa,--gsframe -c -O3 t.c
objcopy --dump-section .sframe=DATA-BE t.o
*/
#define DATA "DATA-BE"
int
main (void)
{
sframe_decoder_ctx *dctx = NULL;
uint32_t nfres, fsize;
int32_t fstart;
unsigned char finfo;
int err = 0;
FILE *fp;
struct stat st;
char *sf_buf;
size_t sf_size;
uint8_t rep_block_size;
/* Test setup. */
fp = fopen (DATA, "r");
if (fp == NULL)
goto setup_fail;
if (fstat (fileno (fp), &st) < 0)
{
perror ("fstat");
fclose (fp);
goto setup_fail;
}
sf_buf = malloc (st.st_size);
if (sf_buf == NULL)
{
perror ("malloc");
goto setup_fail;
}
sf_size = fread (sf_buf, 1, st.st_size, fp);
fclose (fp);
if (sf_size == 0)
{
fprintf (stderr, "Decode: Read buffer failed\n");
goto setup_fail;
}
/* Execute tests. */
/* Call to sframe_decode will endian flip the input buffer (big-endian) if
the host running the test is a little-endian system. This endian-flipped
copy of the buffer is kept internally in dctx. */
dctx = sframe_decode (sf_buf, sf_size, &err);
TEST (dctx != NULL, "be-flipping-1: Decoder setup");
unsigned int fde_cnt = sframe_decoder_get_num_fidx (dctx);
TEST (fde_cnt == 1, "be-flipping-1: Decoder FDE count");
err = sframe_decoder_get_funcdesc_v2 (dctx, 0, &nfres, &fsize, &fstart,
&finfo, &rep_block_size);
TEST (err == 0, "be-flipping-1: Decoder get FDE");
TEST (nfres == 5, "be-flipping-1: Decoder FRE count");
free (sf_buf);
sf_buf = NULL;
sframe_decoder_free (&dctx);
return 0;
setup_fail:
sframe_decoder_free (&dctx);
fail ("be-flipping-1: Test setup");
return 1;
}