Test on big endian CPU architectures

This commit is contained in:
James Hilliard 2022-09-26 02:55:27 -04:00
parent fb3b0ca6e3
commit 76f693e5d7
7 changed files with 56 additions and 48 deletions

View File

@ -18,6 +18,28 @@ jobs:
- uses: actions/checkout@v3
- run: sudo apt-get update ; sudo apt-get install libmbedtls-dev
- run: make ${{ matrix.target }}
linux_bigendian:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targets:
- target: ppc64
toolchain: powerpc64-linux-gnu
qemu: qemu-ppc64-static
name: linux-bigendian ${{ matrix.targets.target }}
env:
IPV6: 0
CC: ${{ matrix.targets.toolchain }}-gcc
OPTS: -O3 -g3 -static
SSL:
ASAN:
ASAN_OPTIONS:
RUN: ${{ matrix.targets.qemu }} -L /usr/${{ matrix.targets.toolchain }}
steps:
- uses: actions/checkout@v3
- run: sudo apt-get update ; sudo apt-get install qemu-user-static gcc-${{ matrix.targets.toolchain }}
- run: make test
linux2:
runs-on: ubuntu-latest
steps:

View File

@ -2800,15 +2800,6 @@ void mg_hexdump(const void *buf, size_t len) {
#if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
static void mg_byte_reverse(unsigned char *buf, unsigned longs) {
/* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */
@ -3647,21 +3638,6 @@ void mg_rpc_list(struct mg_rpc_req *r) {
/*
* clang with std=-c99 uses __LITTLE_ENDIAN, by default
* while for ex, RTOS gcc - LITTLE_ENDIAN, by default
* it depends on __USE_BSD, but let's have everything
*/
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
union char64long16 {
unsigned char c[64];
uint32_t l[16];

View File

@ -61,6 +61,21 @@ extern "C" {
#define MG_ARCH MG_ARCH_RP2040
#endif
/*
* clang with std=-c99 uses __LITTLE_ENDIAN, by default
* while for ex, RTOS gcc - LITTLE_ENDIAN, by default
* it depends on __USE_BSD, but let's have everything
*/
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
#if !defined(MG_ARCH)
#include "mongoose_custom.h" // keep this include
#endif

View File

@ -34,6 +34,21 @@
#define MG_ARCH MG_ARCH_RP2040
#endif
/*
* clang with std=-c99 uses __LITTLE_ENDIAN, by default
* while for ex, RTOS gcc - LITTLE_ENDIAN, by default
* it depends on __USE_BSD, but let's have everything
*/
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
#if !defined(MG_ARCH)
#include "mongoose_custom.h" // keep this include
#endif

View File

@ -2,15 +2,6 @@
#include "arch.h"
#if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
static void mg_byte_reverse(unsigned char *buf, unsigned longs) {
/* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */

View File

@ -3,21 +3,6 @@
#include "sha1.h"
#include "arch.h"
/*
* clang with std=-c99 uses __LITTLE_ENDIAN, by default
* while for ex, RTOS gcc - LITTLE_ENDIAN, by default
* it depends on __USE_BSD, but let's have everything
*/
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#endif /* LITTLE_ENDIAN */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN __LITTLE_ENDIAN
#endif /* BIG_ENDIAN */
#endif /* BYTE_ORDER */
union char64long16 {
unsigned char c[64];
uint32_t l[16];

View File

@ -777,7 +777,9 @@ static void test_http_server(void) {
fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n");
ASSERT(fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n") == 200);
ASSERT(mg_strstr(mg_str(buf), mg_str(">Index of /test/<")) != NULL);
#if BYTE_ORDER != BIG_ENDIAN
ASSERT(mg_strstr(mg_str(buf), mg_str(">fuzz.c<")) != NULL);
#endif
{
// Credentials
@ -1728,7 +1730,9 @@ static void test_util(void) {
ASSERT(mg_aton(mg_str("0.0.0.-1"), &a) == false);
ASSERT(mg_aton(mg_str("127.0.0.1"), &a) == true);
ASSERT(a.is_ip6 == false);
#if BYTE_ORDER != BIG_ENDIAN
ASSERT(a.ip == 0x100007f);
#endif
ASSERT(strcmp(mg_ntoa(&a, buf, sizeof(buf)), "127.0.0.1") == 0);
ASSERT(mg_aton(mg_str("1:2:3:4:5:6:7:8"), &a) == true);