1 /* be-flipping.c -- Test for handling different endianness in libsframe.
3 Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "sframe-api.h"
26 /* DejaGnu should not use gnulib's vsnprintf replacement here. */
30 /* SFrame info from the following source (1 fde 5 fres):
32 extern void foo (void);
41 gcc -mbig-endian -Wa,--gsframe -c -O3 t.c
42 objcopy --dump-section .sframe=DATA-BE t.o
44 #define DATA "DATA-BE"
49 sframe_decoder_ctx
*dctx
= NULL
;
50 uint32_t nfres
, fsize
;
59 #define TEST(name, cond) \
70 fp
= fopen (DATA
, "r");
73 if (fstat (fileno (fp
), &st
) < 0)
79 sf_buf
= malloc (st
.st_size
);
85 sf_size
= fread (sf_buf
, 1, st
.st_size
, fp
);
89 fprintf (stderr
, "Decode: Read buffer failed\n");
95 /* Call to sframe_decode will endian flip the input buffer (big-endian) if
96 the host running the test is a little-endian system. This endian-flipped
97 copy of the buffer is kept internally in dctx. */
98 dctx
= sframe_decode (sf_buf
, sf_size
, &err
);
99 TEST ("be-flipping: Decoder setup", dctx
!= NULL
);
101 unsigned int fde_cnt
= sframe_decoder_get_num_fidx (dctx
);
102 TEST ("be-flipping: Decoder FDE count", fde_cnt
== 1);
104 err
= sframe_decoder_get_funcdesc (dctx
, 0, &nfres
, &fsize
, &fstart
, &finfo
);
105 TEST ("be-flipping: Decoder get FDE", err
== 0);
106 TEST ("be-flipping: Decoder FRE count", nfres
== 5);
111 sframe_decoder_free (&dctx
);
115 sframe_decoder_free (&dctx
);
116 fail ("be-flipping: Test setup");