tests/unit/test_urcu_multiflavor_single_unit_cxx
tests/unit/test_urcu_multiflavor_single_unit_dynlink
tests/unit/test_urcu_multiflavor_single_unit_dynlink_cxx
+tests/unit/get_cpu_mask_from_sysfs
+tests/unit/get_cpu_mask_from_sysfs_cxx
+tests/unit/get_max_cpuid_from_sysfs
+tests/unit/get_max_cpuid_from_sysfs_cxx
+tests/unit/test_get_max_cpuid_from_mask
+tests/unit/test_get_max_cpuid_from_mask_cxx
+tests/unit/test_get_possible_cpus_array_len
+tests/unit/test_get_possible_cpus_array_len_cxx
tests/utils/libtap.a
tests/utils/env.sh
$(SHELL) $(top_srcdir)/tests/utils/tap-driver.sh
noinst_PROGRAMS = \
+ get_cpu_mask_from_sysfs \
+ get_cpu_mask_from_sysfs_cxx \
+ get_max_cpuid_from_sysfs \
+ get_max_cpuid_from_sysfs_cxx \
test_arch \
test_arch_cxx \
+ test_get_max_cpuid_from_mask \
+ test_get_max_cpuid_from_mask_cxx \
+ test_get_possible_cpus_array_len \
+ test_get_possible_cpus_array_len_cxx \
test_uatomic \
test_uatomic_cxx \
test_urcu_multiflavor \
test_build_dynlink \
test_build_dynlink_cxx
-TESTS = $(noinst_PROGRAMS)
+dist_noinst_SCRIPTS = \
+ test_get_cpu_mask_from_sysfs \
+ test_get_cpu_mask_from_sysfs_cxx \
+ test_get_max_cpuid_from_sysfs \
+ test_get_max_cpuid_from_sysfs_cxx
+
+TESTS = \
+ test_arch \
+ test_arch_cxx \
+ test_get_cpu_mask_from_sysfs \
+ test_get_cpu_mask_from_sysfs_cxx \
+ test_get_max_cpuid_from_mask \
+ test_get_max_cpuid_from_mask_cxx \
+ test_get_max_cpuid_from_sysfs \
+ test_get_max_cpuid_from_sysfs_cxx \
+ test_get_possible_cpus_array_len \
+ test_get_possible_cpus_array_len_cxx \
+ test_uatomic \
+ test_uatomic_cxx \
+ test_urcu_multiflavor \
+ test_urcu_multiflavor_cxx \
+ test_urcu_multiflavor_dynlink \
+ test_urcu_multiflavor_dynlink_cxx \
+ test_urcu_multiflavor_single_unit \
+ test_urcu_multiflavor_single_unit_cxx \
+ test_urcu_multiflavor_single_unit_dynlink \
+ test_urcu_multiflavor_single_unit_dynlink_cxx \
+ test_build \
+ test_build_cxx \
+ test_build_dynlink \
+ test_build_dynlink_cxx
noinst_HEADERS = test_urcu_multiflavor.h
URCU_CDS_LIB=$(top_builddir)/src/liburcu-cds.la
TAP_LIB=$(top_builddir)/tests/utils/libtap.a
+get_cpu_mask_from_sysfs_cxx_SOURCES = get_cpu_mask_from_sysfs_cxx.cpp
+get_cpu_mask_from_sysfs_SOURCES = get_cpu_mask_from_sysfs.c
+get_max_cpuid_from_sysfs_cxx_SOURCES = get_max_cpuid_from_sysfs_cxx.cpp
+get_max_cpuid_from_sysfs_SOURCES = get_max_cpuid_from_sysfs.c
+
test_arch_SOURCES = test_arch.c
test_arch_LDADD = $(URCU_COMMON_LIB) $(TAP_LIB)
test_arch_cxx_SOURCES = test_arch_cxx.cpp
test_arch_cxx_LDADD = $(URCU_COMMO_LIB) $(TAP_LIB)
+test_get_max_cpuid_from_mask_SOURCES = test_get_max_cpuid_from_mask.c
+test_get_max_cpuid_from_mask_LDADD = $(TAP_LIB)
+
+test_get_max_cpuid_from_mask_cxx_SOURCES = test_get_max_cpuid_from_mask_cxx.cpp
+test_get_max_cpuid_from_mask_cxx_LDADD = $(TAP_LIB)
+
+test_get_possible_cpus_array_len_SOURCES = test_get_possible_cpus_array_len.c
+test_get_possible_cpus_array_len_LDADD = $(TAP_LIB)
+
+test_get_possible_cpus_array_len_cxx_SOURCES = test_get_possible_cpus_array_len_cxx.cpp
+test_get_possible_cpus_array_len_cxx_LDADD = $(TAP_LIB)
+
test_uatomic_SOURCES = test_uatomic.c
test_uatomic_LDADD = $(URCU_COMMON_LIB) $(TAP_LIB)
--- /dev/null
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "compat-smp.h"
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ char buf[URCU_CPUMASK_SIZE];
+
+ if( argc < 2 ) {
+ fprintf(stderr, "Missing argument.\n");
+ return EXIT_FAILURE;
+ }
+
+ ret = get_cpu_mask_from_sysfs((char *) &buf, URCU_CPUMASK_SIZE, argv[1]);
+
+ printf("%s", buf);
+
+ if (ret >= 0)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "get_cpu_mask_from_sysfs.c"
--- /dev/null
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "compat-smp.h"
+
+int main(int argc, char *argv[])
+{
+ int ret;
+
+ if( argc < 2 ) {
+ fprintf(stderr, "Missing argument.\n");
+ return EXIT_FAILURE;
+ }
+
+ ret = _get_max_cpuid_from_sysfs(argv[1]);
+
+ printf("%d\n", ret);
+
+ if (ret >= 0)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "get_max_cpuid_from_sysfs.c"
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
+ UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
+else
+ UTILSSH="$(dirname "$0")/../utils/utils.sh"
+fi
+
+# shellcheck source=../utils/utils.sh
+source "$UTILSSH"
+
+# shellcheck source=../../utils/tap.sh
+source "$URCU_TESTS_SRCDIR/utils/tap.sh"
+
+CURDIR="${URCU_TESTS_BUILDDIR}/unit"
+
+NUM_TESTS=8
+
+TESTFILE=$(mktemp)
+
+populate_testfile() {
+ local cpumask="$1"
+
+ # shellcheck disable=SC2059
+ printf "$cpumask" > "$TESTFILE"
+}
+
+test_test_get_cpu_mask_from_sysfs() {
+ local cpumask="$1"
+ local result
+
+ # Without '\n'
+ populate_testfile "$cpumask"
+ result=$("${CURDIR}/get_cpu_mask_from_sysfs" "$TESTFILE")
+ test "$cpumask" == "$result"
+ ok $? "test_get_cpu_mask_from_sysfs - without '\n' expected: '$cpumask', result: '$result'"
+
+ # With '\n'
+ populate_testfile "$cpumask\n"
+ result=$("${CURDIR}/get_cpu_mask_from_sysfs" "$TESTFILE")
+ test "$cpumask" == "$result"
+ ok $? "test_get_cpu_mask_from_sysfs - with '\n' expected: '$cpumask', result: '$result'"
+}
+
+plan_tests $NUM_TESTS
+
+test_test_get_cpu_mask_from_sysfs ""
+test_test_get_cpu_mask_from_sysfs "0"
+test_test_get_cpu_mask_from_sysfs "0-3"
+test_test_get_cpu_mask_from_sysfs "0,3-7,9"
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
+ UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
+else
+ UTILSSH="$(dirname "$0")/../utils/utils.sh"
+fi
+
+# shellcheck source=../utils/utils.sh
+source "$UTILSSH"
+
+# shellcheck source=../../utils/tap.sh
+source "$URCU_TESTS_SRCDIR/utils/tap.sh"
+
+CURDIR="${URCU_TESTS_BUILDDIR}/unit"
+
+NUM_TESTS=8
+
+TESTFILE=$(mktemp)
+
+populate_testfile() {
+ local cpumask="$1"
+
+ # shellcheck disable=SC2059
+ printf "$cpumask" > "$TESTFILE"
+}
+
+test_test_get_cpu_mask_from_sysfs_cxx() {
+ local cpumask="$1"
+ local result
+
+ # Without '\n'
+ populate_testfile "$cpumask"
+ result=$("${CURDIR}/get_cpu_mask_from_sysfs_cxx" "$TESTFILE")
+ test "$cpumask" == "$result"
+ ok $? "test_get_cpu_mask_from_sysfs_cxx - without '\n' expected: '$cpumask', result: '$result'"
+
+ # With '\n'
+ populate_testfile "$cpumask\n"
+ result=$("${CURDIR}/get_cpu_mask_from_sysfs_cxx" "$TESTFILE")
+ test "$cpumask" == "$result"
+ ok $? "test_get_cpu_mask_from_sysfs_cxx - with '\n' expected: '$cpumask', result: '$result'"
+}
+
+plan_tests $NUM_TESTS
+
+test_test_get_cpu_mask_from_sysfs_cxx ""
+test_test_get_cpu_mask_from_sysfs_cxx "0"
+test_test_get_cpu_mask_from_sysfs_cxx "0-3"
+test_test_get_cpu_mask_from_sysfs_cxx "0,3-7,9"
--- /dev/null
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <string.h>
+
+#include "tap.h"
+
+#include "compat-smp.h"
+
+struct parse_test_data {
+ const char *buf;
+ int expected;
+};
+
+static struct parse_test_data parse_test_data[] = {
+ { "", -1 },
+ { "abc", -1 },
+ { ",,,", -1 },
+ { "--", -1 },
+ { ",", -1 },
+ { "-", -1 },
+ { "2147483647", -1 },
+ { "18446744073709551615", -1 },
+ { "0-2147483647", -1 },
+ { "0-18446744073709551615", -1 },
+ { "0", 0 },
+ { "1", 1 },
+ { "0-1", 1 },
+ { "1-3", 3 },
+ { "0,2", 2 },
+ { "1,2", 2 },
+ { "0,4-6,127", 127 },
+ { "0-4095", 4095 },
+
+ { "\n", -1 },
+ { "abc\n", -1 },
+ { ",,,\n", -1 },
+ { "--\n", -1 },
+ { ",\n", -1 },
+ { "-\n", -1 },
+ { "2147483647\n", -1 },
+ { "18446744073709551615\n", -1 },
+ { "0-2147483647\n", -1 },
+ { "0-18446744073709551615\n", -1 },
+ { "0\n", 0 },
+ { "1\n", 1 },
+ { "0-1\n", 1 },
+ { "1-3\n", 3 },
+ { "0,2\n", 2 },
+ { "1,2\n", 2 },
+ { "0,4-6,127\n", 127 },
+ { "0-4095\n", 4095 },
+};
+
+static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]);
+
+int main(void)
+{
+ int ret, i;
+
+ plan_tests(parse_test_data_len);
+
+ diag("Testing smp helpers");
+
+ for (i = 0; i < parse_test_data_len; i++) {
+ ret = get_max_cpuid_from_mask(parse_test_data[i].buf,
+ strlen(parse_test_data[i].buf));
+ ok(ret == parse_test_data[i].expected,
+ "get_max_cpuid_from_mask '%s', expected: '%d', result: '%d'",
+ parse_test_data[i].buf, parse_test_data[i].expected, ret);
+ }
+
+ return exit_status();
+}
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "test_get_max_cpuid_from_mask.c"
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
+ UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
+else
+ UTILSSH="$(dirname "$0")/../utils/utils.sh"
+fi
+
+# shellcheck source=../utils/utils.sh
+source "$UTILSSH"
+
+# shellcheck source=../../utils/tap.sh
+source "$URCU_TESTS_SRCDIR/utils/tap.sh"
+
+CURDIR="${URCU_TESTS_BUILDDIR}/unit"
+
+STD_OUTPUT="/dev/null"
+STD_ERROR="/dev/null"
+
+NUM_TESTS=13
+
+TESTDIR=$(mktemp -d)
+
+populate_testdir() {
+ local cpus=("$@")
+
+ mkdir "$TESTDIR"
+
+ for i in "${cpus[@]}"; do
+ mkdir "$TESTDIR/$i"
+ done
+}
+
+test_get_max_cpuid_from_sysfs() {
+ local num_cpus=$1
+ shift
+ local current_cpus=("$@")
+ local result
+
+ populate_testdir "${current_cpus[@]}" >"$STD_OUTPUT" 2>"$STD_ERROR"
+ result=$("${CURDIR}/get_max_cpuid_from_sysfs" "$TESTDIR")
+ is "$result" "$num_cpus" "get_max_cpuid_from_sysfs - cpu set: '${current_cpus[*]}', expected: '$num_cpus', result: '$result'"
+ rm -rf "$TESTDIR"
+}
+
+plan_tests $NUM_TESTS
+
+diag "get_max_cpuid_from_sysfs"
+
+test_data=(0 "cpu0")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(1 "cpu0" "cpu1")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(1 "cpu1" "cpu0")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(3 "cpu3")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(99 "cpu99")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(3 "cpu0" "cpu3")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(0 "cpu" "cpu0")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(5 "cpu" "cpu5")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+
+test_data=(-1 "toto")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(-1 "cpu")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(-1 "cpua" "cpud")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
+
+test_data=(-1 "cpufreq" "cpuidle")
+test_get_max_cpuid_from_sysfs "${test_data[@]}"
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
+ UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
+else
+ UTILSSH="$(dirname "$0")/../utils/utils.sh"
+fi
+
+# shellcheck source=../utils/utils.sh
+source "$UTILSSH"
+
+# shellcheck source=../../utils/tap.sh
+source "$URCU_TESTS_SRCDIR/utils/tap.sh"
+
+CURDIR="${URCU_TESTS_BUILDDIR}/unit"
+
+STD_OUTPUT="/dev/null"
+STD_ERROR="/dev/null"
+
+NUM_TESTS=13
+
+TESTDIR=$(mktemp -d)
+
+populate_testdir() {
+ local cpus=("$@")
+
+ mkdir "$TESTDIR"
+
+ for i in "${cpus[@]}"; do
+ mkdir "$TESTDIR/$i"
+ done
+}
+
+test_get_max_cpuid_from_sysfs_cxx() {
+ local num_cpus=$1
+ shift
+ local current_cpus=("$@")
+ local result
+
+ populate_testdir "${current_cpus[@]}" >"$STD_OUTPUT" 2>"$STD_ERROR"
+ result=$("${CURDIR}/get_max_cpuid_from_sysfs_cxx" "$TESTDIR")
+ is "$result" "$num_cpus" "get_max_cpuid_from_sysfs_cxx - cpu set: '${current_cpus[*]}', expected: '$num_cpus', result: '$result'"
+ rm -rf "$TESTDIR"
+}
+
+plan_tests $NUM_TESTS
+
+diag "get_max_cpuid_from_sysfs_cxx"
+
+test_data=(0 "cpu0")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(1 "cpu0" "cpu1")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(1 "cpu1" "cpu0")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(3 "cpu3")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(99 "cpu99")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(3 "cpu0" "cpu3")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(0 "cpu" "cpu0")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(5 "cpu" "cpu5")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+
+test_data=(-1 "toto")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(-1 "cpu")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(-1 "cpua" "cpud")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+
+test_data=(-1 "cpufreq" "cpuidle")
+test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
--- /dev/null
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+#include "compat-smp.h"
+
+int main(void)
+{
+ int ret;
+
+ plan_tests(2);
+
+ ret = get_possible_cpus_array_len();
+ ok(ret > 0, "get_possible_cpus_array_len (%d > 0)", ret);
+
+ ret = get_num_possible_cpus_fallback();
+ ok(ret > 0, "get_num_possible_cpus_fallback (%d > 0)", ret);
+
+ return exit_status();
+}
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "test_get_possible_cpus_array_len.c"