botan icon indicating copy to clipboard operation
botan copied to clipboard

os_utils: Test failure

Open kekePower opened this issue 3 years ago • 2 comments

When trying to build on Mageia Cauldron x86_64.

os_utils:
OS::get_cpu_cycle_counter ran 1 tests all ok
OS::get_cpu_total/OS::get_cpu_available ran 1 tests 1 FAILED
Failure 1: OS::get_cpu_total/OS::get_cpu_available get_cpu_available not greater than total unexpected result 24 > 1

Build log can be found here: https://pkgsubmit.mageia.org/uploads/failure/cauldron/core/release/20211026173056.kekepower.duvel.14005/log/botan2-2.18.2-1.mga9/build.x86_64.0.20211026173205.log

kekePower avatar Oct 26 '21 17:10 kekePower

Thanks for reporting this.

Looking at the implementation of those functions (OS::get_cpu_total(), OS::get_cpu_available()): I assume that OS::get_cpu_total() falls back to the default return value (1) while OS::get_cpu_available() returns the correct ::sysconf(_SC_NPROCESSORS_ONLN) result (24 in your case).

Could you check, whether your platform provides:

  • _SC_NPROCESSORS_CONF included with unistd.h
  • _SC_NPROCESSORS_ONLN included with unistd.h

In any case, the sysconf() manpage notes that both of those "may not be standard".

As a side note: std::thread::hardware_concurrency() could return 0 under certain conditions. Hence, we should double-check this in OS::get_cpu_total() and make those implementations more resilient.

reneme avatar Oct 28 '21 13:10 reneme

Looking at it further get_cpu_total isn't something we even need or use, except for this test. We can simplify things down to just get_cpu_available, which returns a best guess at the number of CPUs (which should be at least 1!).

randombit avatar Oct 28 '21 21:10 randombit

This was resolved by #2837

randombit avatar Jan 14 '23 15:01 randombit