From 2bab5c9d2c0d15661327817dbf75ecc79496b8cd Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Wed, 3 Jan 2024 19:09:17 +0100 Subject: [PATCH] add env script, and (stupid) draft tests --- scripts/env.sh | 30 ++++++++++++++++++++++++++++++ test/bitops-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/pool-test.c | 7 +++++-- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100755 scripts/env.sh create mode 100644 test/bitops-test.c diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100755 index 0000000..eab931b --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# env.sh - set environment for brchess developer. +# +# Copyright (C) 2023 Bruno Raoult ("br") +# Licensed under the GNU General Public License v3.0 or later. +# Some rights reserved. See COPYING. +# +# You should have received a copy of the GNU General Public License along with this +# program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# USAGE: source env.sh [arg] +# +# This file will actually be sourced if it was never sourced in current bash +# environment. + +if [[ ! -v _BRLIB_ENV_ ]]; then + export _BRLIB_ENV_=1 BRLIB_ROOT LD_LIBRARY_PATH + BRLIB_SCRIPTDIR=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")") + BRLIB_ROOT=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")/..") + BRLIB_LIBDIR="$BRLIB_ROOT/lib" + BRLIB_BINDIR="$BRLIB_ROOT/bin" + LD_LIBRARY_PATH="${BRLIB_LIBDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + PATH="$PATH:$BRLIB_BINDIR:$BRLIB_SCRIPTDIR" + #printf "R=%s L=%s LD=%s\n" "$BRLIB_ROOT" "$BRLIB_DIR" "$LD_LIBRARY_PATH" + unset BRLIB_LIBDIR BRLIB_BINDIR BRLIB_SCRIPTDIR + printf "brlib environment complete.\n" +fi diff --git a/test/bitops-test.c b/test/bitops-test.c new file mode 100644 index 0000000..d78b6ad --- /dev/null +++ b/test/bitops-test.c @@ -0,0 +1,46 @@ +/* bits.c - bitops testing. + * + * Copyright (C) 2024 Bruno Raoult ("br") + * Licensed under the GNU General Public License v3.0 or later. + * Some rights reserved. See COPYING. + * + * You should have received a copy of the GNU General Public License along with this + * program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include +#include + +#include "br.h" +#include "bitops.h" +// #include "cutest/CuTest.h" + +static void test_popcount() +{ + u32 t32[] = { 0x0, 0x88000101, 0xffffffff }; + u64 t64[] = { 0x0ll, 0x8880000000000101LL, 0xffffffffffffffffll }; + + for (uint i = 0; i < sizeof(t32); ++i) { + printf("popcount 32 (%#x): ", t32[i]); +# ifdef ___popcount32_native + printf("native:%d ", ___popcount32_native(t32[i])); +# endif + printf("emulated:%d\n", ___popcount_emulated(t32[i])); + } + for (uint i = 0; i < sizeof(t64); ++i) { + printf("popcount 64 (%#lx): ", t64[i]); +# ifdef ___popcount64_native + printf("native:%d ", ___popcount64_native(t64[i])); +# endif + printf("emulated:%d\n", ___popcount_emulated(t64[i])); + } +} + +int main() +{ + test_popcount(); + exit(0); +} diff --git a/test/pool-test.c b/test/pool-test.c index 14ce9f7..66209c7 100644 --- a/test/pool-test.c +++ b/test/pool-test.c @@ -1,6 +1,9 @@ #include -#include "bits.h" +#include + +#include "br.h" #include "pool.h" +#include "debug.h" struct d { u16 data1; @@ -19,7 +22,7 @@ int main(int ac, char**av) char ccur='z'; struct d *elt; - debug_init(3); + debug_init(3, stderr, true); log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt), sizeof(*elt), offsetof(struct d, list));