device_input 1.0.0.1 → 1.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01a4b48883bd7c07006de058e16d3ff8ff1d9792b8905eb8abae64a82e577e5a
4
- data.tar.gz: c61bb60b4f227a3718cf90c4704df38574a7a52797cd644549a15a0076b52175
3
+ metadata.gz: ad6579dcc34efa4420edde0db593da7023730451f37b805e98b438a271bfad36
4
+ data.tar.gz: d7dea2ee2567926f779fa0aca3bcccbbe6e84bce006dd51e275d8f3c163931b0
5
5
  SHA512:
6
- metadata.gz: 6190ef1adafadaeadd24532e92ca1fa72bbdd72d00583165952b946538f55940cd211cf283171c7e467c705958038afba41c0c43224d0704e527d6ace4d8e89d
7
- data.tar.gz: 9a3dcfacafc3487358f88f3796a477410225a4ebfa3e41df06b2afc3da48717e7f053b8ab51ec607f5644ca537b68a371179bade3588b2b3df441a780c7e7e30
6
+ metadata.gz: fa18a6a3d85040cc87a25be1556cf288bbe7b42154606fe1f17bd587d53236fab9bd11faa9491194067a515addea23b5514138f6e8c1a30dcf77b92592676858
7
+ data.tar.gz: 56c653f912cbdcb3a054f56e920066245c6859e4f9e51ed83bfe7c4afd3bcefb6dad91e14a39118797a0045529028428e659bb551df90ed628d824c94f5c62f4
data/README.md CHANGED
@@ -58,7 +58,8 @@ executable code to assist in examining kernel input events.
58
58
 
59
59
  **REQUIREMENTS**
60
60
 
61
- * Ruby >= 2.0
61
+ * Ruby >= 2.3
62
+ * Earlier rubies are supported on pre-1.0 versions
62
63
 
63
64
  **DEPENDENCIES**
64
65
 
@@ -71,7 +72,7 @@ $ gem install device_input
71
72
 
72
73
  Or, if using [Bundler](http://bundler.io/), add to your `Gemfile`:
73
74
  ```ruby
74
- gem 'device_input', '~> 0.3'
75
+ gem 'device_input', '~> 1.0'
75
76
  ```
76
77
 
77
78
  # Usage
data/Rakefile ADDED
@@ -0,0 +1,120 @@
1
+ require 'rake/testtask'
2
+ desc "Run tests"
3
+ Rake::TestTask.new :test do |t|
4
+ t.pattern = 'test/*.rb'
5
+ t.warning = true
6
+ end
7
+
8
+ task default: :test
9
+
10
+
11
+ #
12
+ # METRICS
13
+ #
14
+
15
+ metrics_tasks = []
16
+
17
+ begin
18
+ require 'flog_task'
19
+
20
+ # we want: flog --all --methods-only lib
21
+ # but: FlogTask doesn't support the equivalent of --all; oh well
22
+ methods_only = true
23
+ FlogTask.new(:flog, 200, ['lib'], nil, methods_only) do |t|
24
+ t.verbose = true
25
+ end
26
+ metrics_tasks << :flog
27
+ rescue LoadError
28
+ warn 'flog_task unavailable'
29
+ end
30
+
31
+ begin
32
+ require 'flay_task'
33
+
34
+ # we want: flay --liberal lib
35
+ # but: FlayTask doesn't support the equivalent of --liberal; oh well
36
+ FlayTask.new do |t|
37
+ t.dirs = ['lib']
38
+ t.verbose = true
39
+ end
40
+ metrics_tasks << :flay
41
+ rescue LoadError
42
+ warn 'flay_task unavailable'
43
+ end
44
+
45
+ begin
46
+ require 'roodi_task'
47
+ RoodiTask.new patterns: ['lib/**/*.rb']
48
+ metrics_tasks << :roodi
49
+ rescue LoadError
50
+ warn 'roodi_task unavailable'
51
+ end
52
+
53
+ desc "Generate code metrics reports"
54
+ task :code_metrics => metrics_tasks
55
+
56
+
57
+ #
58
+ # PROFILING
59
+ #
60
+
61
+ desc "Show current system load"
62
+ task "loadavg" do
63
+ puts File.read "/proc/loadavg"
64
+ end
65
+
66
+ # make sure command is run against lib/ on the filesystem, not an installed gem
67
+ def lib_sh(cmd)
68
+ sh "RUBYLIB=lib #{cmd}"
69
+ end
70
+
71
+ # set up script, args, and rprof_args the way ruby-prof wants them
72
+ def rprof_sh(script, args, rprof_args = '')
73
+ lib_sh ['ruby-prof', rprof_args, script, '--', args].join(' ')
74
+ end
75
+
76
+ rprof_options = {
77
+ min_percent: 2,
78
+ printer: :graph,
79
+ mode: :process,
80
+ sort: :self,
81
+ }.inject('') { |memo, (flag,val)| memo + "--#{flag}=#{val} " }
82
+
83
+ evdump_options = {
84
+ count: 9999,
85
+ print: 'off',
86
+ }.inject('') { |memo, (flag,val)| memo + "--#{flag} #{val} " } + '/dev/zero'
87
+
88
+ desc "Run ruby-prof on bin/evdump (9999 events)"
89
+ task "ruby-prof" => "loadavg" do
90
+ puts
91
+ rprof_sh 'bin/evdump', evdump_options, rprof_options
92
+ end
93
+
94
+ desc "Run ruby-prof with --exclude-common-cycles"
95
+ task "ruby-prof-exclude" => "ruby-prof" do
96
+ puts
97
+ rprof_sh 'bin/evdump', evdump_options,
98
+ "#{rprof_options} --exclude-common-cycles"
99
+ end
100
+
101
+ task "no-prof" do
102
+ lib_sh "bin/evdump #{evdump_options}"
103
+ end
104
+
105
+
106
+ #
107
+ # GEM BUILD / PUBLISH
108
+ #
109
+
110
+ begin
111
+ require 'buildar'
112
+
113
+ Buildar.new do |b|
114
+ b.gemspec_file = 'device_input.gemspec'
115
+ b.version_file = 'VERSION'
116
+ b.use_git = true
117
+ end
118
+ rescue LoadError
119
+ # ok
120
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.1
1
+ 1.0.1.1
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'device_input'
3
+ s.summary = 'Read input events from e.g. /dev/input/event0'
4
+ s.description = <<EOF
5
+ Pure ruby to read input events from the Linux kernel input device subsystem.
6
+ No dependencies. Ruby 2+ required
7
+ EOF
8
+ s.authors = ["Rick Hull"]
9
+ s.homepage = 'https://github.com/rickhull/device_input'
10
+ s.license = 'GPL-3.0'
11
+
12
+ s.required_ruby_version = ">= 2.3"
13
+
14
+ s.version = File.read(File.join(__dir__, 'VERSION')).chomp
15
+
16
+ s.files = %w[device_input.gemspec VERSION README.md Rakefile]
17
+ s.files += Dir['lib/**/*.rb']
18
+ s.files += Dir['test/**/*.rb']
19
+ s.files += Dir['bin/**/*.rb']
20
+
21
+ s.executables = ['evdump']
22
+
23
+ s.add_runtime_dependency 'slop', '~> 4.0'
24
+ end
@@ -0,0 +1,98 @@
1
+ require_relative 'helper.rb'
2
+
3
+ require 'device_input'
4
+
5
+ describe DeviceInput::Event do
6
+ E = DeviceInput::Event
7
+
8
+ describe "type_labels" do
9
+ it "must return an array of strings" do
10
+ dne = E.type_labels(:does_not_exist)
11
+ expect(dne).must_be_instance_of(Array)
12
+ expect(dne.first).must_be_instance_of(String)
13
+ expect(dne.last).must_be_instance_of(String)
14
+
15
+ # 0 is EV_SYN
16
+ de = E.type_labels(0)
17
+ expect(de).must_be_instance_of(Array)
18
+ expect(de.first).must_be_instance_of(String)
19
+ expect(de.last).must_be_instance_of(String)
20
+ end
21
+ end
22
+
23
+ describe "code_labels" do
24
+ it "must return an array of strings" do
25
+ dne = E.code_labels(:does_not_exist, nil)
26
+ expect(dne).must_be_instance_of(Array)
27
+ expect(dne.first).must_be_instance_of(String)
28
+ expect(dne.last).must_be_instance_of(String)
29
+
30
+ # 0,0 = EV_SYN,SYN_REPORT
31
+ de = E.code_labels(0, 0)
32
+ expect(de).must_be_instance_of(Array)
33
+ expect(de.first).must_be_instance_of(String)
34
+ expect(de.last).must_be_instance_of(String)
35
+ end
36
+ end
37
+
38
+ describe "encode" do
39
+ it "must return a string" do
40
+ expect(E.encode(E::NULL_DATA)).must_be_instance_of(String)
41
+ end
42
+ end
43
+
44
+ describe "decode" do
45
+ it "must return a Data (struct)" do
46
+ expect(E.decode(E::NULL_MSG)).must_be_instance_of(E::Data)
47
+ end
48
+ end
49
+
50
+ describe "new instance" do
51
+ before do
52
+ @event = E.new(E::NULL_DATA)
53
+ end
54
+
55
+ it "must have data" do
56
+ expect(@event.data).must_be_instance_of(E::Data)
57
+ end
58
+
59
+ it "must have a timestamp" do
60
+ expect(@event.time).must_be_instance_of(Time)
61
+ end
62
+
63
+ it "must have a type" do
64
+ expect(@event.type).must_be_instance_of(String)
65
+ end
66
+
67
+ it "must have a code" do
68
+ expect(@event.code).must_be_instance_of(String)
69
+ end
70
+
71
+ it "must have a value" do
72
+ expect(@event.value).must_be_kind_of(Integer)
73
+ end
74
+
75
+ it "must have string representations" do
76
+ [:to_s, :pretty, :raw, :hex].each { |meth|
77
+ expect(@event.send(meth)).must_be_instance_of(String)
78
+ }
79
+ end
80
+ end
81
+ end
82
+
83
+ describe DeviceInput do
84
+ describe "read_loop" do
85
+ before do
86
+ @io = StringIO.new("\x00" * 64)
87
+ end
88
+
89
+ it "must read at least one message from an io with 64 bytes" do
90
+ events = []
91
+ DeviceInput.read_loop(@io) { |event|
92
+ events << event
93
+ }
94
+ expect(events).wont_be_empty
95
+ expect(events.first).must_be_instance_of(E)
96
+ end
97
+ end
98
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,51 @@
1
+ if ENV['CODE_COVERAGE'] and
2
+ !%w[false no].include?(ENV['CODE_COVERAGE'].downcase)
3
+
4
+ require 'simplecov'
5
+ require 'simplecov_json_formatter'
6
+
7
+ class SimpleCov::Formatter::TextFormatter
8
+ FILENAME = 'metrics/coverage'
9
+
10
+ def format(result)
11
+ tot = result.files
12
+ rpt = ["Coverage: %0.1f%%" % tot.covered_percent,
13
+ "Strength: %0.2f" % tot.covered_strength,
14
+ " Lines: %i" % tot.lines_of_code,
15
+ " Covered: %i" % tot.covered_lines,
16
+ " N/A: %i" % tot.never_lines,
17
+ ]
18
+ if tot.missed_lines > 0
19
+ rpt << "Missed: %i" % tot.missed_lines
20
+ end
21
+ if tot.skipped_lines > 0
22
+ rpt << "Skipped: %i" % tot.skipped_lines
23
+ end
24
+ rpt << result.files.map { |sfile|
25
+ "%i%% (%i/%i)\t%s" % [sfile.covered_percent,
26
+ sfile.covered_lines.length,
27
+ sfile.lines_of_code,
28
+ sfile.filename]
29
+ }.join("\n")
30
+ rpt = rpt.join("\n")
31
+
32
+ puts
33
+ puts rpt
34
+ if File.writable?(FILENAME)
35
+ File.open(FILENAME, 'w') { |f|
36
+ f.write(rpt + "\n")
37
+ }
38
+ puts "wrote #{FILENAME}"
39
+ end
40
+ end
41
+ end
42
+
43
+ SimpleCov.formatters = [
44
+ SimpleCov::Formatter::TextFormatter,
45
+ SimpleCov::Formatter::JSONFormatter,
46
+ ]
47
+
48
+ SimpleCov.start
49
+ end
50
+
51
+ require 'minitest/autorun'
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.1
4
+ version: 1.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: buildar
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '2'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: slop
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '4'
34
- type: :development
19
+ version: '4.0'
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '4'
26
+ version: '4.0'
41
27
  description: |
42
28
  Pure ruby to read input events from the Linux kernel input device subsystem.
43
29
  No dependencies. Ruby 2+ required
@@ -48,10 +34,14 @@ extensions: []
48
34
  extra_rdoc_files: []
49
35
  files:
50
36
  - README.md
37
+ - Rakefile
51
38
  - VERSION
52
39
  - bin/evdump
40
+ - device_input.gemspec
53
41
  - lib/device_input.rb
54
42
  - lib/device_input/labels.rb
43
+ - test/device_input.rb
44
+ - test/helper.rb
55
45
  homepage: https://github.com/rickhull/device_input
56
46
  licenses:
57
47
  - GPL-3.0
@@ -71,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
61
  - !ruby/object:Gem::Version
72
62
  version: '0'
73
63
  requirements: []
74
- rubygems_version: 3.2.26
64
+ rubygems_version: 3.4.4
75
65
  signing_key:
76
66
  specification_version: 4
77
67
  summary: Read input events from e.g. /dev/input/event0