Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 123 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
options: "-DENABLE_TESTS=ON",
packager: "sudo apt-get",
# no expect because stdout seems to be redirected
packages: "libcmocka-dev libxxhash-dev shunit2",
packages: "libcmocka-dev libxxhash-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -36,7 +36,7 @@ jobs:
cc: "clang",
options: "-DENABLE_TESTS=ON",
packager: "sudo apt-get",
packages: "libcmocka-dev libxxhash-dev shunit2",
packages: "libcmocka-dev libxxhash-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -47,7 +47,7 @@ jobs:
cc: "gcc",
options: "",
packager: "sudo apt-get",
packages: "libcmocka-dev libxxhash-dev valgrind shunit2",
packages: "libcmocka-dev libxxhash-dev valgrind",
snaps: "",
build-cmd: "make"
}
Expand All @@ -59,7 +59,7 @@ jobs:
options: "",
packager: "sudo apt-get",
# no valgrind because it does not support DWARF5 yet generated by clang 14
packages: "libcmocka-dev libxxhash-dev shunit2",
packages: "libcmocka-dev libxxhash-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -70,7 +70,7 @@ jobs:
cc: "clang",
options: "-DENABLE_TESTS=ON -DPATH_EXPECT=",
packager: "brew",
packages: "cmocka xxhash shunit2 tcl-tk",
packages: "cmocka xxhash tcl-tk",
snaps: "",
build-cmd: "make"
}
Expand Down Expand Up @@ -241,3 +241,121 @@ jobs:
- name: Install
working-directory: '${{ github.workspace }}/../build'
run: cmake --install . --strip

build-solaris:
name: Release, Solaris, gcc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Build and test
uses: vmactions/solaris-vm@main
with:
release: '11.4-gcc'
usesh: true

prepare: |
echo "Installing dependencies..."
export PATH=/opt/csw/bin:$PATH

pkgutil -y -i git cmake libpcre2_dev

# build cmocka from source
git clone --depth 1 https://github.com/clibs/cmocka.git
cd cmocka
mkdir build-cmocka
cd build-cmocka
cmake -DCMAKE_BUILD_TYPE=Release ..
gmake
gmake install
cd ../..

run: |
set -e
echo "Starting build..."
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON ..
gmake
ctest --output-on-failure

build-freebsd:
name: Release, FreeBSD, clang
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Release, FreeBSD, clang
uses: vmactions/freebsd-vm@main
with:
usesh: true

prepare: |
echo "Installing dependencies..."
pkg update -f
pkg install -y cmake cmocka xxhash bash git pcre2

run: |
set -e
echo "Starting build..."
mkdir build
cd build

cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON ..
make
ctest --output-on-failure

build-linux-32bit:
name: Release, Linux 32-bit, gcc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Build in 32-bit container
run: |
docker run --rm \
-v ${{ github.workspace }}:${{ github.workspace }} \
-w ${{ github.workspace }} \
i386/ubuntu \
/bin/bash -c " \
apt-get update -q && \
apt-get install -y -q git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON .. && \
make && \
ctest --output-on-failure \
"

build-big-endian:
name: Release, Big-endian, s390x
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Build and test
# use QEMU user-static emulation to run non-x86 Linux
uses: uraimo/run-on-arch-action@master
with:
arch: s390x
distro: ubuntu22.04

# speeds up build by caching Docker images in GitHub Packages
githubToken: ${{ github.token }}

# map the build directory to the container
dockerRunArgs: |
--volume "${PWD}:/workspace"

# install dependencies inside the emulated container
install: |
apt-get update -q -y
apt-get install -q -y git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev

# run the build
run: |
set -e
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON ..
make
ctest --output-on-failure
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ endif()
# link compat
use_compat()

if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
# required for some extensions on Solaris (e.g. strndup), see man 7 standards, section "Feature Test Macros"
# https://docs.oracle.com/cd/E88353_01/html/E37853/posix-7.html
add_compile_definitions(__EXTENSIONS__)
endif()

# create static libyang library
if(NOT BUILD_SHARED_LIBS)
add_definitions(-DSTATIC)
Expand Down Expand Up @@ -418,6 +424,10 @@ if(XXHASH_FOUND)
include_directories(${XXHASH_INCLUDE_DIR})
target_link_libraries(yang ${XXHASH_LIBRARY})
message(STATUS "Hash algorithm: xxhash")
if (HAVE_XXH3_64BITS_WITHSEED)
# for 32-bit system compatibility, this may not be available there, so use XXH32 instead
add_definitions(-DLY_XXH3_64BITS_WITHSEED)
endif()
else()
message(STATUS "Hash algorithm: internal Jenkin's one-at-a-time")
endif()
Expand Down
3 changes: 3 additions & 0 deletions CMakeModules/FindXXHash.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ find_library(XXHASH_LIBRARY
${CMAKE_INSTALL_PREFIX}/lib
)

# for 32-bit system compatibility
check_symbol_exists(XXH3_64bits_withSeed ${XXHASH_INCLUDE_DIR}/xxhash.h HAVE_XXH3_64BITS_WITHSEED)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XXHash FOUND_VAR XXHASH_FOUND REQUIRED_VARS XXHASH_INCLUDE_DIR XXHASH_LIBRARY)
5 changes: 5 additions & 0 deletions CMakeModules/UseCompat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(TestBigEndian)
include(CheckStructHasMember)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
Expand Down Expand Up @@ -61,6 +62,10 @@ macro(USE_COMPAT)

check_include_file("alloca.h" HAVE_ALLOCA_H)

check_include_file("byteswap.h" HAVE_BYTESWAP_H)

check_struct_has_member("struct dirent" d_type "dirent.h" HAVE_DIRENT_D_TYPE)

list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
Expand Down
8 changes: 5 additions & 3 deletions compat/compat.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
# include <alloca.h>
#endif

#if defined (__APPLE__) || defined (_WIN32)
#cmakedefine HAVE_BYTESWAP_H
#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#else
# define bswap_32 __builtin_bswap32
# define bswap64 __builtin_bswap64
#else
# include <byteswap.h>
#endif

#include <limits.h>
Expand Down Expand Up @@ -85,6 +86,7 @@
#cmakedefine HAVE_MMAP
#cmakedefine HAVE_STRCASECMP
#cmakedefine HAVE_SETENV
#cmakedefine HAVE_DIRENT_D_TYPE

#ifndef bswap64
#define bswap64(val) \
Expand Down
13 changes: 12 additions & 1 deletion src/hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ lyht_hash_multi(uint32_t hash, const char *key_part, size_t len)
{
#ifdef LY_XXHASH_SUPPORT
if (key_part && len) {
# ifdef LY_XXH3_64BITS_WITHSEED
return XXH3_64bits_withSeed(key_part, len, hash);
# else
return XXH32(key_part, len, hash);
# endif
}

# ifdef LY_XXH3_64BITS_WITHSEED
return XXH3_64bits_withSeed(NULL, 0, hash);
# else
return XXH32(NULL, 0, hash);
# endif
#else
uint32_t i;

Expand All @@ -62,7 +69,11 @@ LIBYANG_API_DEF uint32_t
lyht_hash(const char *key, size_t len)
{
#ifdef LY_XXHASH_SUPPORT
# ifdef LY_XXH3_64BITS_WITHSEED
return XXH3_64bits(key, len);
# else
return XXH32(key, len, 0);
# endif
#else
uint32_t hash;

Expand Down
2 changes: 1 addition & 1 deletion src/parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ lydjson_parse_attribute(struct lyd_json_ctx *lydctx, struct lyd_node *attr_node,
{
LY_ERR r;
const char *opaq_name, *mod_name, *attr_mod = NULL;
size_t opaq_name_len, attr_mod_len;
size_t opaq_name_len, attr_mod_len = 0;

if (!attr_node) {
/* learn the attribute module name */
Expand Down
27 changes: 18 additions & 9 deletions src/tree_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -2349,13 +2349,28 @@ lys_search_localfile_file_type(const struct dirent *file, const char *wd, struct
{
LY_ERR rc = LY_SUCCESS;
char *str = NULL;
ly_bool is_dir = 0, is_reg = 0;
ly_bool is_dir = 0, is_reg = 0, need_stat = 1;
struct stat st;

*skip = 0;

if ((file->d_type == DT_UNKNOWN) || (file->d_type == DT_LNK)) {
/* FS does not support this field or its a symbolic link, need to call stat */
#ifdef HAVE_DIRENT_D_TYPE
if (file->d_type == DT_DIR) {
/* dirent - dir */
is_dir = 1;
need_stat = 0;
} else if (file->d_type == DT_REG) {
/* dirent - file */
is_reg = 1;
need_stat = 0;
} else if ((file->d_type != DT_UNKNOWN) && (file->d_type != DT_LNK)) {
/* it is a known type, but not dir or regular file, so trust d_type and just skip it */
need_stat = 0;
}
#endif // HAVE_DIRENT_D_TYPE

if (need_stat) {
/* need to use stat to determine the file type */
if (asprintf(&str, "%s/%s", wd, file->d_name) == -1) {
LOGMEM(NULL);
rc = LY_EMEM;
Expand All @@ -2371,12 +2386,6 @@ lys_search_localfile_file_type(const struct dirent *file, const char *wd, struct
/* stat - file */
is_reg = 1;
}
} else if (file->d_type == DT_DIR) {
/* dirent - dir */
is_dir = 1;
} else if (file->d_type == DT_REG) {
/* dirent - file */
is_reg = 1;
}

if (is_dir && (dirs->count || !implicit_cwd)) {
Expand Down
22 changes: 15 additions & 7 deletions tests/yanglint/interactive/all.tcl
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package require tcltest
package require Expect

# Save current terminal size
set stty_output [exec stty size]
scan $stty_output "%d %d" orig_lines orig_columns
# setting some large terminal width
stty columns 720
# Save current terminal size, but only if we are in an environtment with a tty (i.g. may not be present in a CI)
set has_tty 0
if {![catch {exec stty size} stty_output]} {
scan $stty_output "%d %d" orig_lines orig_columns
set has_tty 1
}

if {$has_tty} {
# setting some large terminal width
stty columns 720
}

# Hook to determine if any of the tests failed.
# Sets a global variable exitCode to 1 if any test fails otherwise it is set to 0.
Expand All @@ -21,7 +27,9 @@ if {[info exists ::env(TESTS_DIR)]} {
# run all interactive tests
tcltest::runAllTests

# Restore original terminal size
exec stty rows $orig_lines cols $orig_columns
if {$has_tty} {
# Restore original terminal size
exec stty rows $orig_lines cols $orig_columns
}

exit $exitCode
4 changes: 2 additions & 2 deletions tools/lint/linenoise/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ static size_t utf8BytesToCodePoint(const char* buf, size_t len, int* cp) {
*/
size_t linenoiseUtf8NextCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len) {
size_t beg = pos;
int cp;
int cp = 0;
size_t len = utf8BytesToCodePoint(buf + pos, buf_len - pos, &cp);
if (isCombiningChar(cp)) {
/* NOTREACHED */
Expand All @@ -423,7 +423,7 @@ size_t linenoiseUtf8PrevCharLen(const char* buf, size_t UNUSED(buf_len), size_t
while (pos > 0) {
size_t len = prevUtf8CharLen(buf, pos);
pos -= len;
int cp;
int cp = 0;
utf8BytesToCodePoint(buf + pos, len, &cp);
if (!isCombiningChar(cp)) {
if (col_len != NULL) *col_len = isWideChar(cp) ? 2 : 1;
Expand Down