fix: ifdef linux specific cpu count compat
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 15 Aug 2022 15:11:54 +0000 (11:11 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Aug 2022 14:57:05 +0000 (10:57 -0400)
Expand the '#ifdef __linux__' block in src/compat-cpu.h to all static
inline functions related to sysfs since they are only useful on Linux
and fail to build on some non-Linux platforms. This issue was reported
on QNX.

The corresponding unit tests have to be skipped on non-Linux platforms.

Thanks to Elad Lahav <e2lahav@gmail.com> for reporting this issue.

Change-Id: I17c88a9a2fb5b9be6cf5325234a18ff40788cd09
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/compat-smp.h
tests/unit/get_cpu_mask_from_sysfs.c
tests/unit/get_max_cpuid_from_sysfs.c
tests/unit/test_get_cpu_mask_from_sysfs
tests/unit/test_get_cpu_mask_from_sysfs_cxx
tests/unit/test_get_max_cpuid_from_mask.c
tests/unit/test_get_max_cpuid_from_sysfs
tests/unit/test_get_max_cpuid_from_sysfs_cxx
tests/unit/test_get_possible_cpus_array_len.c

index 7240d2f66b3c8af059338df28bc032192abdcd20..31fa979a7040736999823a49ca1f01b7a4d92c48 100644 (file)
@@ -36,6 +36,7 @@ static inline int get_num_possible_cpus_sysconf(void)
 }
 #endif
 
+#ifdef __linux__
 /*
  * Get the highest CPU id from sysfs.
  *
@@ -235,7 +236,6 @@ error:
        return -1;
 }
 
-#ifdef __linux__
 /*
  * On Linux try sysfs first and fallback to sysconf.
  */
index 91f2ebf2b31ce48a0dd2e1f32506a6f55e2fbbdf..7938f234bc8e042cf52ec4a7a90769e9ddc8b07c 100644 (file)
@@ -7,6 +7,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifdef __linux__
+
 #include "compat-smp.h"
 
 int main(int argc, char *argv[])
@@ -28,3 +30,11 @@ int main(int argc, char *argv[])
        else
                return EXIT_FAILURE;
 }
+
+#else
+
+int main(void)
+{
+       return EXIT_SUCCESS;
+}
+#endif
index a948a22e51367496743517ab3105ed8bd15558d2..37c4b3d4851e9b410cac37046752819f9c8ba6f5 100644 (file)
@@ -7,6 +7,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifdef __linux__
+
 #include "compat-smp.h"
 
 int main(int argc, char *argv[])
@@ -27,3 +29,11 @@ int main(int argc, char *argv[])
        else
                return EXIT_FAILURE;
 }
+
+#else
+
+int main(void)
+{
+       return EXIT_SUCCESS;
+}
+#endif
index fff561f5dd56e1d1ac0a4b3f7806459ef08c98be..2a6acc1bfb38dadf73aff8a89ba89b3c7d861edf 100755 (executable)
@@ -43,9 +43,13 @@ test_test_get_cpu_mask_from_sysfs() {
        ok $? "test_get_cpu_mask_from_sysfs - with '\n' expected: '$cpumask', result: '$result'"
 }
 
-plan_tests $NUM_TESTS
+if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
+       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"
+       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"
+else
+       plan_skip_all "Linux specific tests."
+fi
index 6b80e534e749f027d6e7d2560b03446acf81cdd2..ffddbf9c27f96507d33bc4759bab33c43381f12e 100755 (executable)
@@ -43,9 +43,13 @@ test_test_get_cpu_mask_from_sysfs_cxx() {
        ok $? "test_get_cpu_mask_from_sysfs_cxx - with '\n' expected: '$cpumask', result: '$result'"
 }
 
-plan_tests $NUM_TESTS
+if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
+       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"
+       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"
+else
+       plan_skip_all "Linux specific tests."
+fi
index 435bb5c6fda55fdfd28d079359ff50050fc5ffc2..25a2417f4947c91d530adcdb92e7d176840f9877 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "compat-smp.h"
 
+#ifdef __linux__
 struct parse_test_data {
        const char *buf;
        int expected;
@@ -75,3 +76,13 @@ int main(void)
 
        return exit_status();
 }
+
+#else
+
+int main(void)
+{
+       plan_skip_all("Linux specific tests.");
+
+       return exit_status();
+}
+#endif
index 230a51cd5c5f9c4ec3b60c4af9fd9739db5a789b..cd646a16ecd35ec1e0fa38283b1ef37d2ea595b1 100755 (executable)
@@ -44,46 +44,50 @@ test_get_max_cpuid_from_sysfs() {
        rm -rf "$TESTDIR"
 }
 
-plan_tests $NUM_TESTS
+if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
+       plan_tests $NUM_TESTS
 
-diag "get_max_cpuid_from_sysfs"
+       diag "get_max_cpuid_from_sysfs"
 
-test_data=(0 "cpu0")
-test_get_max_cpuid_from_sysfs "${test_data[@]}"
+       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 "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=(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=(3 "cpu3")
+       test_get_max_cpuid_from_sysfs "${test_data[@]}"
 
-test_data=(99 "cpu99")
-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 "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=(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=(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=(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 "toto")
+       test_get_max_cpuid_from_sysfs "${test_data[@]}"
 
-test_data=(-1 "cpu")
-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 "cpua" "cpud")
+       test_get_max_cpuid_from_sysfs "${test_data[@]}"
 
-test_data=(-1 "cpufreq" "cpuidle")
-test_get_max_cpuid_from_sysfs "${test_data[@]}"
+       test_data=(-1 "cpufreq" "cpuidle")
+       test_get_max_cpuid_from_sysfs "${test_data[@]}"
+else
+       plan_skip_all "Linux specific tests."
+fi
index 886c065bef8db682f93f01e7fa8785579eaf55c2..db99094f7157702a3d2331b35cce8d7e4da8fb9e 100755 (executable)
@@ -44,46 +44,50 @@ test_get_max_cpuid_from_sysfs_cxx() {
        rm -rf "$TESTDIR"
 }
 
-plan_tests $NUM_TESTS
+if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
+       plan_tests $NUM_TESTS
 
-diag "get_max_cpuid_from_sysfs_cxx"
+       diag "get_max_cpuid_from_sysfs_cxx"
 
-test_data=(0 "cpu0")
-test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+       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 "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=(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=(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=(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 "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=(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=(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=(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 "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 "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 "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[@]}"
+       test_data=(-1 "cpufreq" "cpuidle")
+       test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
+else
+       plan_skip_all "Linux specific tests."
+fi
index ab64d9dbf7fa3e42f95f239ab75f179391fddea0..c5ab2b4b68c7cbc6652f4093d1e425ea6465853d 100644 (file)
@@ -19,8 +19,12 @@ int main(void)
        ret = get_possible_cpus_array_len();
        ok(ret > 0, "get_possible_cpus_array_len (%d > 0)", ret);
 
+#ifdef __linux__
        ret = get_num_possible_cpus_fallback();
        ok(ret > 0, "get_num_possible_cpus_fallback (%d > 0)", ret);
+#else
+       skip(1, "Linux specific test.");
+#endif
 
        return exit_status();
 }
This page took 0.033051 seconds and 4 git commands to generate.