Skip to content

Commit

Permalink
Support FreeBSD 14.0 + NetBSD 10.0 + add testing (#74)
Browse files Browse the repository at this point in the history
* Adds support for FreeBSD and NetBSD.
* Adds GitHub Actions for 2 new workflows (which internally download an image for a VM and runs it in qemu emulator on Ubuntu host) to test that library builds and unit tests run properly on FreeBSD 14.0 and NetBSD 10.0.
* Works around problems with CITRUS iconv implementation on modern FreeBSD and NetBSD by disabling one test (bytes_to_str_invalid_seq_gb2312_two_bytes).
  • Loading branch information
GreyCat authored Jun 6, 2024
1 parent 2831b0e commit a05cfed
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,57 @@ jobs:
run: .build\build.ps1 -GTestPath C:\vcpkg\installed\x64-windows
- name: unittest
run: .build\run-unittest.ps1
freebsd_14_0:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run in FreeBSD
uses: vmactions/freebsd-vm@v1
with:
release: "14.0"
usesh: true
prepare: |
pkg install -y cmake googletest
run: |
echo '#### System information'
whoami
env
freebsd-version
c++ --version
gcc --version
clang++ --version
pkg info
echo '#### Building'
.build/build -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF
echo '#### Testing'
.build/run-unittest
netbsd_10_0:
runs-on: ubuntu-latest
# Doesn't use clang, has gcc:
# c++ (nb3 20231008) 10.5.0
# Copyright (C) 2020 Free Software Foundation, Inc.
steps:
- uses: actions/checkout@v4
- name: Run in NetBSD
uses: vmactions/netbsd-vm@v1
with:
release: "10.0"
usesh: true
prepare: |
/usr/sbin/pkg_add cmake googletest
run: |
echo '#### System information'
whoami
env
c++ --version
gcc --version
echo '#### Building'
.build/build -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF
echo '#### Testing'
.build/run-unittest
17 changes: 16 additions & 1 deletion kaitai/kaitaistream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#else // !__APPLE__ or !_MSC_VER or !__QNX__
#else
// At this point it's either Linux or BSD. Both have "sys/param.h", so it's safe to include
#include <sys/param.h>
#if defined(BSD)
// Supposed to work on FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=bswap16&manpath=FreeBSD+14.0-RELEASE
// Supposed to work on NetBSD: https://man.netbsd.org/NetBSD-10.0/bswap16.3
#include <sys/endian.h>
#include <sys/types.h>
#define bswap_16(x) bswap16(x)
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#else // !__APPLE__ or !_MSC_VER or !__QNX__ or !BSD
#include <endian.h>
#include <byteswap.h>
#endif
#endif

#include <cstring> // std::memcpy
#include <iostream>
Expand Down
11 changes: 10 additions & 1 deletion tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <gtest/gtest.h>
#endif

// Necessary for proper detection of *BSD
#if !defined(_MSC_VER)
#include <sys/param.h>
#endif

#include "kaitai/kaitaistream.h"
#include "kaitai/exceptions.h"
#include <sstream>
Expand Down Expand Up @@ -359,7 +364,6 @@ TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_euc_jp_too_short)
}
}


TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_too_short)
{
try {
Expand All @@ -376,8 +380,12 @@ TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_too_short)
}
}

#if !defined(__FreeBSD__) && !defined(__NetBSD__)
TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_two_bytes)
{
// 0xB0 0x30 is illegal sequence in GB2312: 0xB0 must be followed by [0xA1..0xFE].
// However, some iconv engines, namely CITRUS integrated with modern FreeBSD (10+) and NetBSD,
// are not considering this as error and thus not returning EILSEQ.
try {
std::string res = kaitai::kstream::bytes_to_str("\xb0\x30", "GB2312");
FAIL() << "Expected illegal_seq_in_encoding exception";
Expand All @@ -391,6 +399,7 @@ TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_two_bytes)
#endif
}
}
#endif

TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_utf_16le_odd_bytes)
{
Expand Down

0 comments on commit a05cfed

Please sign in to comment.