automate-standard-baseline 0.0.6 → 0.0.7

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.
data/bin/asb-stop ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'helpers'
6
+ require 'logger'
7
+ require 'yaml'
8
+ require 'sys/proctable'
9
+ require 'optparse'
10
+
11
+ include Sys
12
+
13
+ END {
14
+
15
+ options = opt_parse(ARGV)
16
+
17
+ pid_file = '.pid'
18
+
19
+ unless File.exists?(pid_file)
20
+ log("pid file doesn't exist!")
21
+ exit
22
+ end
23
+
24
+ pid_content = YAML.load_file(pid_file)
25
+ options.each do |k, v|
26
+ str_key = k.to_s
27
+
28
+ str_key = 'main' if str_key == 'all'
29
+ str_key = v if str_key == 'serial'
30
+
31
+ log "Stopping '#{str_key}' processes"
32
+
33
+ pids = pid_content.delete(str_key)
34
+ do_stop(pids)
35
+ end
36
+
37
+ if not pid_content.empty? and options[:all].nil?
38
+ IO.write(pid_file, pid_content.to_yaml)
39
+ else
40
+ File.delete(pid_file)
41
+ end
42
+
43
+ } # end of END
44
+
45
+ def opt_parse(args)
46
+
47
+ options = {}
48
+
49
+ opts = OptionParser.new do |opt|
50
+ opt.banner = "Usage: stop [options]"
51
+ opt.separator ""
52
+
53
+ opt.on("-a", "--all", "Stop all processes [default]") do |v|
54
+ options[:all] = v
55
+ end
56
+
57
+ opt.on("-l", "--logcat", "Stop logcat processes") do |v|
58
+ options[:logcat] = v
59
+ end
60
+
61
+ opt.on("-t", "--tcpdump", "Stop tcpdump processes") do |v|
62
+ options[:tcpdump] = v
63
+ end
64
+
65
+ opt.on("-s", "--serial [SERIAL_NUMBER]", "Stop all processes related the specified device serial number") do |v|
66
+ options[:serial] = v
67
+ end
68
+
69
+ opt.separator ""
70
+ opt.on_tail("-h", "--help", "Show this message") do
71
+ puts opt
72
+ exit
73
+ end
74
+ end
75
+
76
+ opts.parse!(args)
77
+ # stop all processes by default
78
+ options[:all] = true if options.length == 0
79
+
80
+ options
81
+ end
82
+
83
+ def do_stop(pids)
84
+ return if pids.nil?
85
+
86
+ log "Stopping #{pids.to_s}"
87
+ to_kill = pids
88
+
89
+ # find the sub-processes of these pids
90
+ ProcTable.ps do |proc|
91
+ to_kill << proc.pid if to_kill.include?(proc.ppid)
92
+ end
93
+ log "Processes will be killed (including sub-processes): #{to_kill}"
94
+
95
+ to_kill.each do |pid|
96
+ Process.kill("KILL", pid) rescue nil # in case of the process doesn't exist.
97
+ end
98
+ log "Done!"
99
+ end
@@ -109,16 +109,10 @@ end
109
109
  def trap_signals
110
110
  Signal.trap("INT") do
111
111
  logger.info "Terminating..."
112
- to_kill = [Process.pid]
113
- ProcTable.ps do |proc|
114
- to_kill << proc.pid if to_kill.include?(proc.ppid)
115
- end
116
- logger.info "Processes will be killed (including sub-processes): #{to_kill}"
117
- to_kill.each do |pid|
118
- Process.kill("KILL", pid) rescue nil # in case of the process doesn't exist.
119
- end
120
- # process logcat
121
- # process execution status (if there is)
112
+
113
+ #pull_out_tcpdump(devices)
114
+ stop_test([Process.pid])
115
+
122
116
  delete_pid_file($pid_file)
123
117
  exit 1
124
118
  end
@@ -138,11 +132,7 @@ def check_if_old_process_killed(pid_f)
138
132
  end
139
133
  end
140
134
 
141
- def delete_pid_file(pid_f)
142
- if File.exists?(pid_f)
143
- File.delete(pid_f)
144
- end
145
- end
135
+
146
136
 
147
137
  def archive_logs(devices)
148
138
  # if there is any existing tcpdump files on devices' sdcard, pull them
@@ -187,6 +177,13 @@ def load_config()
187
177
 
188
178
  end
189
179
 
180
+ def delete_pid_file(pid_f)
181
+ if File.exists?(pid_f)
182
+ File.delete(pid_f)
183
+ end
184
+ end
185
+
186
+
190
187
  ## operation steps ---start test ...
191
188
 
192
189
  trap_signals()
@@ -294,17 +291,7 @@ rescue Timeout::Error
294
291
  #main = [Process.pid]
295
292
  #logger.info "Main process #{main}"
296
293
 
297
- to_kill=[Process.pid]
298
- ProcTable.ps do |proc|
299
- to_kill << proc.pid if to_kill.include?(proc.ppid)
300
- end
301
-
302
- #delete the main process in case of kill itself
303
- to_kill.delete_at(0)
304
- logger.info "Processes will be killed : #{to_kill}"
305
- to_kill.each do |pid|
306
- Process.kill("KILL", pid) rescue nil # in case of the process doesn't exist.
307
- end
294
+ stop_test([Process.pid])
308
295
 
309
296
  delete_pid_file($pid_file)
310
297
  logger.info "Done."
@@ -27,6 +27,21 @@ def log(message)
27
27
  end
28
28
 
29
29
 
30
+ def stop_test(pid)
31
+ to_kill=pid
32
+ ProcTable.ps do |proc|
33
+ to_kill << proc.pid if to_kill.include?(proc.ppid)
34
+ end
35
+
36
+ #delete the main process in case of kill itself
37
+ to_kill.delete_at(0)
38
+ logger.info "Processes will be killed : #{to_kill}"
39
+ to_kill.each do |pid|
40
+ Process.kill("KILL", pid) rescue nil # in case of the process doesn't exist.
41
+ end
42
+ end
43
+
44
+
30
45
  def pull_out_apk(device_serial, package_name, to_path = nil)
31
46
  out_path = File.expand_path(to_path) if to_path
32
47
  out_path ||= File.expand_path("#{package_name}.apk")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automate-standard-baseline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: retriable
16
- requirement: &14437900 !ruby/object:Gem::Requirement
16
+ requirement: &19010180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *14437900
24
+ version_requirements: *19010180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sys-proctable
27
- requirement: &14436380 !ruby/object:Gem::Requirement
27
+ requirement: &19009640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,12 +32,12 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *14436380
35
+ version_requirements: *19009640
36
36
  description: auomated standard baseline test
37
37
  email: rfu@seven.com
38
38
  executables:
39
39
  - automate-standard-baseline
40
- - abs-stop
40
+ - asb-stop
41
41
  extensions: []
42
42
  extra_rdoc_files: []
43
43
  files:
@@ -45,7 +45,7 @@ files:
45
45
  - lib/automate-standard-baseline/operations.rb
46
46
  - lib/automate-standard-baseline/helpers.rb
47
47
  - bin/automate-standard-baseline
48
- - bin/abs-stop
48
+ - bin/asb-stop
49
49
  homepage: http://rubygems.org/gems/automate-standard-baseline
50
50
  licenses: []
51
51
  post_install_message:
data/bin/abs-stop DELETED
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'helpers'
6
- require 'logger'
7
- require 'yaml'
8
- require 'sys/proctable'
9
- require 'optparse'
10
-
11
- include Sys
12
-
13
- END {
14
-
15
- options = opt_parse(ARGV)
16
-
17
- pid_file = '.pid'
18
-
19
- unless File.exists?(pid_file)
20
- log("pid file doesn't exist!")
21
- exit
22
- end
23
-
24
- pid_content = YAML.load_file(pid_file)
25
- options.each do |k, v|
26
- str_key = k.to_s
27
-
28
- str_key = 'main' if str_key == 'all'
29
- str_key = v if str_key == 'serial'
30
-
31
- log "Stopping '#{str_key}' processes"
32
-
33
- pids = pid_content.delete(str_key)
34
- do_stop(pids)
35
- end
36
-
37
- if not pid_content.empty? and options[:all].nil?
38
- IO.write(pid_file, pid_content.to_yaml)
39
- else
40
- File.delete(pid_file)
41
- end
42
-
43
- } # end of END
44
-
45
- def opt_parse(args)
46
-
47
- options = {}
48
-
49
- opts = OptionParser.new do |opt|
50
- opt.banner = "Usage: stop [options]"
51
- opt.separator ""
52
-
53
- opt.on("-a", "--all", "Stop all processes [default]") do |v|
54
- options[:all] = v
55
- end
56
-
57
- opt.on("-l", "--logcat", "Stop logcat processes") do |v|
58
- options[:logcat] = v
59
- end
60
-
61
- opt.on("-t", "--tcpdump", "Stop tcpdump processes") do |v|
62
- options[:tcpdump] = v
63
- end
64
-
65
- opt.on("-s", "--serial [SERIAL_NUMBER]", "Stop all processes related the specified device serial number") do |v|
66
- options[:serial] = v
67
- end
68
-
69
- opt.separator ""
70
- opt.on_tail("-h", "--help", "Show this message") do
71
- puts opt
72
- exit
73
- end
74
- end
75
-
76
- opts.parse!(args)
77
- # stop all processes by default
78
- options[:all] = true if options.length == 0
79
-
80
- options
81
- end
82
-
83
- def do_stop(pids)
84
- return if pids.nil?
85
-
86
- log "Stopping #{pids.to_s}"
87
- to_kill = pids
88
-
89
- # find the sub-processes of these pids
90
- ProcTable.ps do |proc|
91
- to_kill << proc.pid if to_kill.include?(proc.ppid)
92
- end
93
- log "Processes will be killed (including sub-processes): #{to_kill}"
94
-
95
- to_kill.each do |pid|
96
- Process.kill("KILL", pid) rescue nil # in case of the process doesn't exist.
97
- end
98
- log "Done!"
99
- end
100
-
101
-