From: Indu Bhagat Date: Fri, 5 Dec 2025 09:29:47 +0000 (-0800) Subject: [SFrame-V3] libsframe: testsuite: add a new test for SFrame V2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cea21cf782541d16b24f05771fbd9bd22f5f588;p=thirdparty%2Fbinutils-gdb.git [SFrame-V3] libsframe: testsuite: add a new test for SFrame V2 The existing frecnt-2.c testcase reads the SFrame section from the provided DATA2 buffer. It exercises the sframe_decode (), sframe_decoder_get_num_fidx (), and sframe_decoder_get_funcdesc_v2 () APIs. Currently DATA2 file is the SFrame section created from the test input (mentioned in the comments in the file) in SFrame version 2. Moving forward, creating SFrame V2 section via GNU assembler and GNU ld will not be supported. But textual dump of SFrame V2 sections via readelf/objdump will need to be supported. Add a test similar to frecnt-2.c using SFrame version 2 binary data to the libsframe testsuite. Such a test will help ensure that sframe_decode () and related APIs remain tested for multiple supported arches till the support for V2 sections is to be maintained. Duplicate frecnt-2.c to create a frecnt-v2.c, the latter will test with a SFrame V2 input section. libsframe/ * Makefile.in: Regenerated. libsframe/testsuite/ * libsframe.decode/decode.exp: Likewise/ * libsframe.decode/local.mk: Likewise * libsframe.decode/DATA-V2: New SFrame V2 test data file. * libsframe.decode/frecnt-v2.c: New test. --- diff --git a/libsframe/Makefile.in b/libsframe/Makefile.in index c3135064754..a1a318b9e71 100644 --- a/libsframe/Makefile.in +++ b/libsframe/Makefile.in @@ -115,6 +115,7 @@ check_PROGRAMS = $(am__EXEEXT_1) @HAVE_COMPAT_DEJAGNU_TRUE@am__append_4 = testsuite/libsframe.decode/be-flipping \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-1 \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-2 \ +@HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-v2 \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.encode/encode-1 \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.find/findfre-1 \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.find/findfunc-1 \ @@ -193,6 +194,7 @@ libsframe_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ @HAVE_COMPAT_DEJAGNU_TRUE@am__EXEEXT_1 = testsuite/libsframe.decode/be-flipping$(EXEEXT) \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-1$(EXEEXT) \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-2$(EXEEXT) \ +@HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.decode/frecnt-v2$(EXEEXT) \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.encode/encode-1$(EXEEXT) \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.find/findfre-1$(EXEEXT) \ @HAVE_COMPAT_DEJAGNU_TRUE@ testsuite/libsframe.find/findfunc-1$(EXEEXT) \ @@ -212,6 +214,11 @@ am_testsuite_libsframe_decode_frecnt_2_OBJECTS = testsuite/libsframe.decode/test testsuite_libsframe_decode_frecnt_2_OBJECTS = \ $(am_testsuite_libsframe_decode_frecnt_2_OBJECTS) testsuite_libsframe_decode_frecnt_2_DEPENDENCIES = $(testsuite_LDADD) +am_testsuite_libsframe_decode_frecnt_v2_OBJECTS = testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.$(OBJEXT) +testsuite_libsframe_decode_frecnt_v2_OBJECTS = \ + $(am_testsuite_libsframe_decode_frecnt_v2_OBJECTS) +testsuite_libsframe_decode_frecnt_v2_DEPENDENCIES = \ + $(testsuite_LDADD) am_testsuite_libsframe_encode_encode_1_OBJECTS = testsuite/libsframe.encode/testsuite_libsframe_encode_encode_1-encode-1.$(OBJEXT) testsuite_libsframe_encode_encode_1_OBJECTS = \ $(am_testsuite_libsframe_encode_encode_1_OBJECTS) @@ -272,6 +279,7 @@ SOURCES = $(libsframe_la_SOURCES) \ $(testsuite_libsframe_decode_be_flipping_SOURCES) \ $(testsuite_libsframe_decode_frecnt_1_SOURCES) \ $(testsuite_libsframe_decode_frecnt_2_SOURCES) \ + $(testsuite_libsframe_decode_frecnt_v2_SOURCES) \ $(testsuite_libsframe_encode_encode_1_SOURCES) \ $(testsuite_libsframe_find_findfre_1_SOURCES) \ $(testsuite_libsframe_find_findfunc_1_SOURCES) \ @@ -281,6 +289,7 @@ DIST_SOURCES = $(libsframe_la_SOURCES) \ $(testsuite_libsframe_decode_be_flipping_SOURCES) \ $(testsuite_libsframe_decode_frecnt_1_SOURCES) \ $(testsuite_libsframe_decode_frecnt_2_SOURCES) \ + $(testsuite_libsframe_decode_frecnt_v2_SOURCES) \ $(testsuite_libsframe_encode_encode_1_SOURCES) \ $(testsuite_libsframe_find_findfre_1_SOURCES) \ $(testsuite_libsframe_find_findfunc_1_SOURCES) \ @@ -566,6 +575,9 @@ testsuite_libsframe_decode_frecnt_1_CPPFLAGS = $(testsuite_CPPFLAGS) testsuite_libsframe_decode_frecnt_2_SOURCES = testsuite/libsframe.decode/frecnt-2.c testsuite_libsframe_decode_frecnt_2_LDADD = $(testsuite_LDADD) testsuite_libsframe_decode_frecnt_2_CPPFLAGS = $(testsuite_CPPFLAGS) +testsuite_libsframe_decode_frecnt_v2_SOURCES = testsuite/libsframe.decode/frecnt-v2.c +testsuite_libsframe_decode_frecnt_v2_LDADD = $(testsuite_LDADD) +testsuite_libsframe_decode_frecnt_v2_CPPFLAGS = $(testsuite_CPPFLAGS) testsuite_libsframe_encode_encode_1_SOURCES = testsuite/libsframe.encode/encode-1.c testsuite_libsframe_encode_encode_1_LDADD = $(testsuite_LDADD) testsuite_libsframe_encode_encode_1_CPPFLAGS = $(testsuite_CPPFLAGS) @@ -720,6 +732,13 @@ testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_2-frecnt-2.$(OBJEXT testsuite/libsframe.decode/frecnt-2$(EXEEXT): $(testsuite_libsframe_decode_frecnt_2_OBJECTS) $(testsuite_libsframe_decode_frecnt_2_DEPENDENCIES) $(EXTRA_testsuite_libsframe_decode_frecnt_2_DEPENDENCIES) testsuite/libsframe.decode/$(am__dirstamp) @rm -f testsuite/libsframe.decode/frecnt-2$(EXEEXT) $(AM_V_CCLD)$(LINK) $(testsuite_libsframe_decode_frecnt_2_OBJECTS) $(testsuite_libsframe_decode_frecnt_2_LDADD) $(LIBS) +testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.$(OBJEXT): \ + testsuite/libsframe.decode/$(am__dirstamp) \ + testsuite/libsframe.decode/$(DEPDIR)/$(am__dirstamp) + +testsuite/libsframe.decode/frecnt-v2$(EXEEXT): $(testsuite_libsframe_decode_frecnt_v2_OBJECTS) $(testsuite_libsframe_decode_frecnt_v2_DEPENDENCIES) $(EXTRA_testsuite_libsframe_decode_frecnt_v2_DEPENDENCIES) testsuite/libsframe.decode/$(am__dirstamp) + @rm -f testsuite/libsframe.decode/frecnt-v2$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(testsuite_libsframe_decode_frecnt_v2_OBJECTS) $(testsuite_libsframe_decode_frecnt_v2_LDADD) $(LIBS) testsuite/libsframe.encode/$(am__dirstamp): @$(MKDIR_P) testsuite/libsframe.encode @: > testsuite/libsframe.encode/$(am__dirstamp) @@ -783,6 +802,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_be_flipping-be-flipping.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_1-frecnt-1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_2-frecnt-2.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.encode/$(DEPDIR)/testsuite_libsframe_encode_encode_1-encode-1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.find/$(DEPDIR)/testsuite_libsframe_find_findfre_1-findfre-1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@testsuite/libsframe.find/$(DEPDIR)/testsuite_libsframe_find_findfunc_1-findfunc-1.Po@am__quote@ @@ -876,6 +896,20 @@ testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_2-frecnt-2.obj: tes @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_decode_frecnt_2_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_2-frecnt-2.obj `if test -f 'testsuite/libsframe.decode/frecnt-2.c'; then $(CYGPATH_W) 'testsuite/libsframe.decode/frecnt-2.c'; else $(CYGPATH_W) '$(srcdir)/testsuite/libsframe.decode/frecnt-2.c'; fi` +testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.o: testsuite/libsframe.decode/frecnt-v2.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_decode_frecnt_v2_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.o -MD -MP -MF testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Tpo -c -o testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.o `test -f 'testsuite/libsframe.decode/frecnt-v2.c' || echo '$(srcdir)/'`testsuite/libsframe.decode/frecnt-v2.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Tpo testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testsuite/libsframe.decode/frecnt-v2.c' object='testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_decode_frecnt_v2_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.o `test -f 'testsuite/libsframe.decode/frecnt-v2.c' || echo '$(srcdir)/'`testsuite/libsframe.decode/frecnt-v2.c + +testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.obj: testsuite/libsframe.decode/frecnt-v2.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_decode_frecnt_v2_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.obj -MD -MP -MF testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Tpo -c -o testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.obj `if test -f 'testsuite/libsframe.decode/frecnt-v2.c'; then $(CYGPATH_W) 'testsuite/libsframe.decode/frecnt-v2.c'; else $(CYGPATH_W) '$(srcdir)/testsuite/libsframe.decode/frecnt-v2.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Tpo testsuite/libsframe.decode/$(DEPDIR)/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testsuite/libsframe.decode/frecnt-v2.c' object='testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_decode_frecnt_v2_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o testsuite/libsframe.decode/testsuite_libsframe_decode_frecnt_v2-frecnt-v2.obj `if test -f 'testsuite/libsframe.decode/frecnt-v2.c'; then $(CYGPATH_W) 'testsuite/libsframe.decode/frecnt-v2.c'; else $(CYGPATH_W) '$(srcdir)/testsuite/libsframe.decode/frecnt-v2.c'; fi` + testsuite/libsframe.encode/testsuite_libsframe_encode_encode_1-encode-1.o: testsuite/libsframe.encode/encode-1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(testsuite_libsframe_encode_encode_1_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT testsuite/libsframe.encode/testsuite_libsframe_encode_encode_1-encode-1.o -MD -MP -MF testsuite/libsframe.encode/$(DEPDIR)/testsuite_libsframe_encode_encode_1-encode-1.Tpo -c -o testsuite/libsframe.encode/testsuite_libsframe_encode_encode_1-encode-1.o `test -f 'testsuite/libsframe.encode/encode-1.c' || echo '$(srcdir)/'`testsuite/libsframe.encode/encode-1.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) testsuite/libsframe.encode/$(DEPDIR)/testsuite_libsframe_encode_encode_1-encode-1.Tpo testsuite/libsframe.encode/$(DEPDIR)/testsuite_libsframe_encode_encode_1-encode-1.Po diff --git a/libsframe/testsuite/libsframe.decode/DATA-V2 b/libsframe/testsuite/libsframe.decode/DATA-V2 new file mode 100644 index 00000000000..90649e27169 Binary files /dev/null and b/libsframe/testsuite/libsframe.decode/DATA-V2 differ diff --git a/libsframe/testsuite/libsframe.decode/decode.exp b/libsframe/testsuite/libsframe.decode/decode.exp index 7d8d919212f..a2ae4a30265 100644 --- a/libsframe/testsuite/libsframe.decode/decode.exp +++ b/libsframe/testsuite/libsframe.decode/decode.exp @@ -31,6 +31,7 @@ if [string equal $COMPAT_DEJAGNU "no"] { catch "exec ln -s $srcdir/libsframe.decode/DATA1 ." status catch "exec ln -s $srcdir/libsframe.decode/DATA2 ." status +catch "exec ln -s $srcdir/libsframe.decode/DATA-V2 ." status catch "exec ln -s $srcdir/libsframe.decode/DATA-BE ." status if { [host_execute "testsuite/libsframe.decode/be-flipping"] ne "" } { @@ -45,6 +46,11 @@ if { [host_execute "testsuite/libsframe.decode/frecnt-2"] ne "" } { fail "frecnt-2" } +if { [host_execute "testsuite/libsframe.decode/frecnt-v2"] ne "" } { + fail "frecnt-v2" +} + catch "exec rm DATA1" status catch "exec rm DATA2" status +catch "exec rm DATA-V2" status catch "exec rm DATA-BE" status diff --git a/libsframe/testsuite/libsframe.decode/frecnt-v2.c b/libsframe/testsuite/libsframe.decode/frecnt-v2.c new file mode 100644 index 00000000000..0360f6b47ad --- /dev/null +++ b/libsframe/testsuite/libsframe.decode/frecnt-v2.c @@ -0,0 +1,90 @@ +/* frecnt-v2.c -- Test for decoder 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 . */ + +#include "sframe-test.h" + +/* + * SFrame info from the following source (2 fde 8 fres): + * static int cnt; + * int foo() { return ++cnt; } + * int main() { return foo(); } + * + * Generate SFrame V2 section. + */ +#define DATA "DATA-V2" + +int +main (void) +{ + sframe_decoder_ctx *dctx = NULL; + uint32_t nfres, fsize; + int32_t fstart; + unsigned char finfo; + unsigned int i; + int err = 0; + FILE *fp; + struct stat st; + char *sf_buf; + size_t sf_size; + uint8_t rep_block_size; + + 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; + } + + /* Execute tests. */ + sf_size = fread (sf_buf, 1, st.st_size, fp); + fclose (fp); + TEST (sf_size != 0, "frecnt-v2: Read data"); + + dctx = sframe_decode (sf_buf, sf_size, &err); + TEST (dctx != NULL, "frecnt-v2: Decode setup"); + + unsigned int fde_cnt = sframe_decoder_get_num_fidx (dctx); + TEST (fde_cnt == 2, "frecnt-v2: Decode FDE count"); + + for (i = 0; i < fde_cnt; ++i) + { + err = sframe_decoder_get_funcdesc_v2 (dctx, i, &nfres, &fsize, &fstart, + &finfo, &rep_block_size); + TEST (err == 0, "frecnt-v2: Decode get FDE%d", i); + TEST (nfres == 4, "frecnt-v2: Decode num FREs for FDE%d", i); + } + + free (sf_buf); + sf_buf = NULL; + + sframe_decoder_free (&dctx); + return 0; + +setup_fail: + sframe_decoder_free (&dctx); + fail ("frecnt-v2: Test setup"); + return 1; +} diff --git a/libsframe/testsuite/libsframe.decode/local.mk b/libsframe/testsuite/libsframe.decode/local.mk index de34bbcfab8..aacbfdcfdd1 100644 --- a/libsframe/testsuite/libsframe.decode/local.mk +++ b/libsframe/testsuite/libsframe.decode/local.mk @@ -1,6 +1,6 @@ check_PROGRAMS = if HAVE_COMPAT_DEJAGNU - check_PROGRAMS += %D%/be-flipping %D%/frecnt-1 %D%/frecnt-2 + check_PROGRAMS += %D%/be-flipping %D%/frecnt-1 %D%/frecnt-2 %D%/frecnt-v2 endif %C%_be_flipping_SOURCES = %D%/be-flipping.c @@ -14,3 +14,7 @@ endif %C%_frecnt_2_SOURCES = %D%/frecnt-2.c %C%_frecnt_2_LDADD = $(testsuite_LDADD) %C%_frecnt_2_CPPFLAGS = $(testsuite_CPPFLAGS) + +%C%_frecnt_v2_SOURCES = %D%/frecnt-v2.c +%C%_frecnt_v2_LDADD = $(testsuite_LDADD) +%C%_frecnt_v2_CPPFLAGS = $(testsuite_CPPFLAGS)