add env script, and (stupid) draft tests

This commit is contained in:
2024-01-03 19:09:17 +01:00
parent a41ca50404
commit 2bab5c9d2c
3 changed files with 81 additions and 2 deletions

30
scripts/env.sh Executable file
View File

@@ -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 <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
#
# SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
#
# 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

46
test/bitops-test.c Normal file
View File

@@ -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 <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
*
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
*
*/
#include <stdio.h>
#include <stdlib.h>
#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);
}

View File

@@ -1,6 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "bits.h" #include <stdlib.h>
#include "br.h"
#include "pool.h" #include "pool.h"
#include "debug.h"
struct d { struct d {
u16 data1; u16 data1;
@@ -19,7 +22,7 @@ int main(int ac, char**av)
char ccur='z'; char ccur='z';
struct d *elt; 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), log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt),
sizeof(*elt), offsetof(struct d, list)); sizeof(*elt), offsetof(struct d, list));