spinel_test-unit 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2341cde71f3bee22ab32ced8d1a7db330bfbbc77dccec006bb9acfc7965c2cb
4
- data.tar.gz: dd0e9c94e0839a62409c8406999bcf11fa60f6b3aec7e2d04ada67e537cc59a3
3
+ metadata.gz: ca6a33c6a80b2a6dfb7797f0adb7c006c9c009e6f128ca39db4c8421976d6aed
4
+ data.tar.gz: b06d4664914659ff8da18e21ba1f5b3d0e88110c3fb15a5356c5a3ebb55aeedc
5
5
  SHA512:
6
- metadata.gz: bec8fd80b6355b89a98d4972390468639e7e2cb93a6e7643dd323cb8ffe0b9c006d537d428f62a2b60ecfafb2fd892e56b5047fa7c6c6778fb2fa900285effb3
7
- data.tar.gz: 561053edd31dc9783b69afadefaea5299b0d74d8765f2597a8dde7bd42f404f5afb83c640e401d9ce49e048df2dfee7a0b4d16093fe881221e7748f521cb80c3
6
+ metadata.gz: ee8a0ff148142c1bd42c4a9daf8b177b9c5c003be001079624dc225420e3094e7797dd89f9c6adc927118955725671dd60dface231ba6b3d220e997fdec8b10e
7
+ data.tar.gz: 4f8202617c173710a9a0d1da60e4204223e88fd44d410fdcdbec4a223a9ea881dfc19ebff5f1144913391f555039a647832e850afc821716a67c84020e62802b
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Unreleased
2
+
3
+ ## 0.1.1
4
+
5
+ * Allow to configure Spinel compile options
6
+
7
+ ## 0.1.0
8
+
9
+ * Initial release
data/README.md CHANGED
@@ -62,6 +62,13 @@ Available assertions:
62
62
 
63
63
  `setup` and `teardown` hooks are supported.
64
64
 
65
+ ## Compile speed
66
+
67
+ The tests are compiled for build speed, not run speed: with `-O0`, and the generated C split into parallel units (Spinel's `--jobs`). Most of a Spinel build is the C compile, so this cuts it several times over. Two environment variables change it:
68
+
69
+ - `SPINEL_TEST_UNIT_OPT` -- the C optimization level (default `0`). Set `2` to test the binary the way a release build compiles it.
70
+ - `SPINEL_TEST_UNIT_JOBS` -- how many units the C is compiled as (default: the number of CPUs, up to 16). `1` compiles it as a single unit. The CPUs counted are the ones the process may use: a cgroup CPU quota (a container started with `--cpus`, for example) counts, not only the host's cores.
71
+
65
72
  ## Constraints (from Spinel)
66
73
 
67
74
  - Test code must be compilable by Spinel: no `send` with dynamic names,
@@ -218,7 +218,7 @@ module SpinelTest
218
218
  end
219
219
 
220
220
  def compile(spinel, main, bin, entries)
221
- cmd = [spinel] + include_dirs(entries).flat_map { |d| ["-I", d] } + [main, "-o", bin]
221
+ cmd = [spinel] + Toolchain.compile_flags + include_dirs(entries).flat_map { |d| ["-I", d] } + [main, "-o", bin]
222
222
  output, status = Open3.capture2e(*cmd)
223
223
  unless status.success?
224
224
  warn output unless output.empty?
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "etc"
4
+
3
5
  module SpinelTest
4
6
  module Unit
5
7
  # Finds the Spinel compiler.
@@ -15,6 +17,45 @@ module SpinelTest
15
17
  find_on_path("spinel") || mise_which("spinel")
16
18
  end
17
19
 
20
+ def self.compile_flags
21
+ opt = ENV["SPINEL_TEST_UNIT_OPT"]
22
+ opt = "0" if opt.nil? || opt.empty?
23
+ jobs = ENV["SPINEL_TEST_UNIT_JOBS"]
24
+ jobs = cpus.clamp(1, 16).to_s if jobs.nil? || jobs.empty?
25
+ ["-O", opt, "--jobs=#{jobs}"]
26
+ end
27
+
28
+ def self.cpus(cgroup_root: "/sys/fs/cgroup", proc_cgroup: "/proc/self/cgroup")
29
+ quota = cpu_quota(cgroup_root, proc_cgroup)
30
+ quota ? [Etc.nprocessors, quota.ceil].min : Etc.nprocessors
31
+ end
32
+
33
+ def self.cpu_quota(root, proc_cgroup)
34
+ quotas = cgroup_v2_dirs(root, proc_cgroup).filter_map do |dir|
35
+ max, period = read_cgroup(File.join(dir, "cpu.max"))&.split
36
+ max.to_f / period.to_f if max && max != "max" && period.to_f > 0
37
+ end
38
+ v1 = File.join(root, "cpu,cpuacct")
39
+ quota = read_cgroup(File.join(v1, "cpu.cfs_quota_us")).to_f
40
+ period = read_cgroup(File.join(v1, "cpu.cfs_period_us")).to_f
41
+ quotas << quota / period if quota > 0 && period > 0
42
+ quotas.min
43
+ end
44
+
45
+ def self.cgroup_v2_dirs(root, proc_cgroup)
46
+ path = read_cgroup(proc_cgroup)&.lines&.find { |l| l.start_with?("0::") }
47
+ path = path ? path.chomp.delete_prefix("0::") : "/"
48
+ dirs = [root]
49
+ path.split("/").reject(&:empty?).each { |part| dirs << File.join(dirs.last, part) }
50
+ dirs
51
+ end
52
+
53
+ def self.read_cgroup(path)
54
+ File.read(path)
55
+ rescue StandardError
56
+ nil
57
+ end
58
+
18
59
  def self.find_on_path(name)
19
60
  ENV["PATH"].to_s.split(File::PATH_SEPARATOR).map { |d| File.join(d, name) }
20
61
  .find { |f| File.file?(f) && File.executable?(f) }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SpinelTest
4
4
  module Unit
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinel_test-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
@@ -50,6 +50,7 @@ executables:
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - CHANGELOG.md
53
54
  - CODE_OF_CONDUCT.md
54
55
  - LICENSE.txt
55
56
  - README.md
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
- rubygems_version: 4.0.17
88
+ rubygems_version: 4.0.16
88
89
  specification_version: 4
89
90
  summary: An xUnit-style test framework for Spinel.
90
91
  test_files: []