Skip to content

Commit

Permalink
Added cpu_count().
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Feb 4, 2025
1 parent 99749a2 commit 8e31438
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions share/ruby-install/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ function detect_downloader()
esac
}

#
# Gets the number of CPU cores.
#
function cpu_count()
{
local count

case "$os_platform" in
Darwin|*BSD)
count="$(sysctl -n hw.ncpu)"
;;
*)
count="$(getconf _NPROCESSORS_ONLN || grep -c ^processor /proc/cpuinfo)"
;;
esac

echo -n "$count"
}

detect_os
detect_sudo
detect_package_manager
Expand Down
9 changes: 9 additions & 0 deletions test/system-tests/cpu_count_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
. ./test/helper.sh
. ./share/ruby-install/system.sh

function test_cpu_count()
{
assertTrue "did not return a number > 0" '(( $(cpu_count) > 0 ))'
}

SHUNIT_PARENT=$0 . $SHUNIT2

0 comments on commit 8e31438

Please sign in to comment.