super-test 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGE.txt +9 -0
  3. data/README.txt +13 -0
  4. data/bin/idb +19 -0
  5. data/bin/ii +113 -0
  6. data/bin/istart_mock +36 -0
  7. data/bin/istop_mock +16 -0
  8. data/bin/kk +181 -0
  9. data/bin/rubyatp +42 -0
  10. data/bin/start_mock +36 -0
  11. data/bin/stop_mock +16 -0
  12. data/bin/xgo +45 -0
  13. data/conf/conf.rb +11 -0
  14. data/conf/db03.yml +31 -0
  15. data/conf/db13.yml +37 -0
  16. data/conf/db19.yml +33 -0
  17. data/conf/online.yml +32 -0
  18. data/conf/super_test.yml +40 -0
  19. data/conf/system.yml +26 -0
  20. data/conf/sz00.yml +31 -0
  21. data/conf/sz06.yml +34 -0
  22. data/conf/wise00.yml +11 -0
  23. data/data/case.house +0 -0
  24. data/data/char.house +0 -0
  25. data/data/images/Bluehills.jpg +0 -0
  26. data/data/images/Sunset.jpg +0 -0
  27. data/data/images/Waterlilies.jpg +0 -0
  28. data/data/images/Winter.jpg +0 -0
  29. data/data/query.house +18595 -0
  30. data/data/user.house +8 -0
  31. data/lib/action/module/check_action.rb +58 -0
  32. data/lib/action/module/cnnt_action.rb +161 -0
  33. data/lib/action/module/datacenter_action.rb +48 -0
  34. data/lib/action/module/http_pack_helper.rb +163 -0
  35. data/lib/action/module/httpserver_action.rb +297 -0
  36. data/lib/action/module/inc.rb +21 -0
  37. data/lib/action/module/mcpack_action.rb +57 -0
  38. data/lib/action/module/sql_action.rb +84 -0
  39. data/lib/action/module/ssh_action.rb +37 -0
  40. data/lib/action/system/user_action.rb +180 -0
  41. data/lib/common/appium_helper.rb +217 -0
  42. data/lib/common/atp_helper.rb +74 -0
  43. data/lib/common/atp_report.rb +344 -0
  44. data/lib/common/data_house.rb +405 -0
  45. data/lib/common/data_model.rb +87 -0
  46. data/lib/common/http/assert_helper.rb +343 -0
  47. data/lib/common/http/fix_hpricot.rb +118 -0
  48. data/lib/common/http/html_helper.rb +362 -0
  49. data/lib/common/http/http_helper.rb +469 -0
  50. data/lib/common/http/multipart.rb +81 -0
  51. data/lib/common/isandbox_helper.rb +195 -0
  52. data/lib/common/json_helper.rb +43 -0
  53. data/lib/common/mock_helper.rb +168 -0
  54. data/lib/common/mtop_helper.rb +141 -0
  55. data/lib/common/myconf_helper.rb +49 -0
  56. data/lib/common/mylog_helper.rb +77 -0
  57. data/lib/common/pairwise.rb +121 -0
  58. data/lib/common/query_house.rb +89 -0
  59. data/lib/common/report_helper.rb +97 -0
  60. data/lib/common/robot_helper.rb +85 -0
  61. data/lib/common/socket/check.rb +325 -0
  62. data/lib/common/socket/conf_modifier.rb +149 -0
  63. data/lib/common/socket/context.rb +55 -0
  64. data/lib/common/socket/data.rb +392 -0
  65. data/lib/common/socket/data_helper.rb +41 -0
  66. data/lib/common/socket/env.rb +317 -0
  67. data/lib/common/socket/inc.rb +24 -0
  68. data/lib/common/socket/log.rb +213 -0
  69. data/lib/common/socket/log4s.rb +58 -0
  70. data/lib/common/socket/log_helper.rb +332 -0
  71. data/lib/common/socket/my_sql.rb +77 -0
  72. data/lib/common/socket/net.rb +74 -0
  73. data/lib/common/socket/network.rb +115 -0
  74. data/lib/common/socket/rlib/conf_modifier.rb +130 -0
  75. data/lib/common/socket/rlib/data_helper.rb +33 -0
  76. data/lib/common/socket/rlib/log_helper.rb +303 -0
  77. data/lib/common/socket/rlib/process_helper.rb +91 -0
  78. data/lib/common/socket/stub.rb +276 -0
  79. data/lib/common/socket/util.rb +266 -0
  80. data/lib/patterns/inc.rb +10 -0
  81. data/lib/patterns/mc_base_pattern.rb +474 -0
  82. data/lib/patterns/some_pattern.rb +145 -0
  83. data/lib/super_test.rb +114 -0
  84. data/log/super_test.log +0 -0
  85. data/log/super_test.log.wf +0 -0
  86. data/test/cover_me.rb +6 -0
  87. data/tool/jenny +0 -0
  88. data/tool/mcsend/mcsend2 +0 -0
  89. data/tool/mcsend/mcsend2_shead +0 -0
  90. data/tool/mcserver/conf/mcserver.conf +77 -0
  91. data/tool/mcserver/conf/mcserverauthip +17 -0
  92. data/tool/mcserver/mcserver +0 -0
  93. data/tool/mcserver/mcserver_trans +0 -0
  94. data/tool/mysql +0 -0
  95. data/tool/net/mcsend/mcsend +0 -0
  96. data/tool/net/mcsend/mcsend_trans +0 -0
  97. data/tool/net/mcsend/nshead.data +7 -0
  98. data/tool/net/mcsend/res_nshead.data +7 -0
  99. data/tool/net/my_client/my_client +0 -0
  100. data/tool/net/tsclient/client.tcl +205 -0
  101. data/tool/others/kk +190 -0
  102. data/tool/others/rubyatp +42 -0
  103. data/tool/others/supertest_install.sh +34 -0
  104. data/tool/trip/idb +0 -0
  105. data/tool/ts-agent/nshead.bft +12 -0
  106. data/tool/ts-agent/server.conf +10 -0
  107. data/tool/ts-agent/server.tcl +376 -0
  108. metadata +275 -0
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require 'inc'
4
+
5
+ #============================================================
6
+ # 模块测试中总结的一些测试模式
7
+ # Author:: liqiang01
8
+ # Data:: 2009-8-23 17:18:27
9
+ #============================================================
10
+
11
+ CONF_TEST_CASE=[]
12
+ MCPACK_INTERFACE_TEST_CASE=[]
13
+ module SomePatternHelper
14
+
15
+ # === 功能:
16
+ # mcpack接口异常测试模式
17
+ # 自动构造mcpack接口异常测试需要的异常数据
18
+ # 对mcpack接口的每个字段进行各种边界及特殊数据的测试
19
+ # 默认采用的用例集:
20
+ # CaseHouse.get_instance.get_all_number
21
+ # 超长字符串
22
+ # 中文,空白
23
+ # 每个子pack都增加额外的字段
24
+ # 删除每个待测试的字段
25
+ #
26
+ # === 参数解释:
27
+ # - mctxt 发送接口的命令范例
28
+ #
29
+ # === 外部变量:
30
+ # 用户也可以提供额外需要进行测试的用例集。可以使用下面的变量
31
+ # MCPACK_INTERFACE_TEST_CASE 数组类型
32
+ #
33
+ # === Example:
34
+ # txt1="..."
35
+ # MCPACK_INTERFACE_TEST_CASE=[7789, "space_provider"]
36
+ # mcpack_test_pattern(txt1).each{ |line|
37
+ # mcpack_send line
38
+ # }
39
+ # core_check
40
+ def mcpack_test_pattern(mctxt)
41
+ tmptxt="#{mctxt}"
42
+ ret=[]
43
+ while(tmptxt=~ /"([^"]+)":\(([^\)]+)\)([^ ,}{\[\]]*)/)
44
+ key=$1
45
+ type=$2
46
+ value=$3
47
+ tmptxt.sub!(/#{key}/,"")
48
+ CaseHouse.get_instance.get_all_number.each{|line|
49
+ ret.push mctxt.sub(/"#{key}":\(#{type}\)#{value}/, "\"#{key}\":\(#{type}\)#{line}")
50
+ }
51
+ if MCPACK_INTERFACE_TEST_CASE.size > 0
52
+ MCPACK_INTERFACE_TEST_CASE.each{|line|
53
+ ret.push mctxt.sub(/"#{key}":\(#{type}\)#{value}/, "\"#{key}\":\(#{type}\)#{line}")
54
+ }
55
+ end
56
+ ret.push mctxt.sub(/"#{key}":\(#{type}\)#{value}/, "")
57
+ end
58
+ while(tmptxt=~/"([^"]+)":\"([^ ",}{\[\]]*)\"/)
59
+ key=$1
60
+ value=$2
61
+ tmptxt.sub!(/#{key}/,"")
62
+ txtbig="x"*10000
63
+ txteng="xxxxxxxxxx"
64
+ txtchi="中文测试"
65
+ txtnull=""
66
+ ret.push mctxt.sub(/"#{key}":"#{value}"/, "\"#{key}\":\"#{txtbig}\"")
67
+ ret.push mctxt.sub(/"#{key}":"#{value}"/, "\"#{key}\":\"#{txteng}\"")
68
+ ret.push mctxt.sub(/"#{key}":"#{value}"/, "\"#{key}\":\"#{txtchi}\"")
69
+ ret.push mctxt.sub(/"#{key}":"#{value}"/, "\"#{key}\":\"#{txtnull}\"")
70
+ if MCPACK_INTERFACE_TEST_CASE.size > 0
71
+ MCPACK_INTERFACE_TEST_CASE.each{|line|
72
+ ret.push mctxt.sub(/"#{key}":"#{value}"/, "\"#{key}\":\"#{line}\"")
73
+ }
74
+ end
75
+ ret.push mctxt.sub(/"#{key}":\(#{type}\)#{value}/, "")
76
+ end
77
+ ret.push mctxt.gsub(/}/,",\"addbyMcpackPatternStr\":\"xxxx\",\"addbyMcpackPatternNum\":(uint32)0}")
78
+ return ret
79
+ end
80
+
81
+ # === 功能:
82
+ # 配置文件异常测试模式
83
+ # 对指定的配置项进行异常测试
84
+ # 默认的用例集:
85
+ # CaseHouse.get_instance.get_all_number 所有可能的数字边界
86
+ # CaseHouse.get_instance.rand_string(10,"aA0$") 随机字符串
87
+ # CaseHouse.get_instance.rand_string(1,"B") 空白
88
+ #
89
+ # === 参数解释:
90
+ # - host 机器
91
+ # - user 用户名
92
+ # - password 密码
93
+ # - modulename 模块的名字,重启模块需要模块名
94
+ # - conf_items 需要进行测试的配置项的名字,是个数组
95
+ #
96
+ # === 外部变量:
97
+ # 当用户需要自己定义额外的测试用例集时,可使用下面的变量
98
+ # CONF_TEST_CASE 数组类型
99
+ #
100
+ # === Example:
101
+ # items=["name1", "name2"]
102
+ # CONF_TEST_CASE=[123, "mycase"]
103
+ # conf_test_pattern("frdtransform", items)
104
+ # core_check
105
+ def conf_test_pattern(host=HOST, user=USERNAME, password=PASSWORD, modulename, conf_items)
106
+ bak_conf host, user, password, CONFPATH, "BAK_CONF_BY_CONF_TEST_PATTERN"
107
+ conf_items.each{|item|
108
+ CaseHouse.get_instance.get_all_number.each{|item_value|
109
+ puts "#{item} #{item_value}"
110
+ modify_conf_single host, user, password, CONFPATH, item, item_value.to_s
111
+ ssh_cmd host, user, password, "killall -9 #{modulename}"
112
+ sleep 3
113
+ }
114
+ [ CaseHouse.get_instance.rand_string(10,"aA0$") ].each{|item_value|
115
+ puts "#{item} #{item_value}"
116
+ modify_conf_single host, user, password, CONFPATH, item, item_value
117
+ ssh_cmd host, user, password, "killall -9 #{modulename}"
118
+ sleep 3
119
+ }
120
+ [ CaseHouse.get_instance.rand_string(1,"B") ].each{|item_value|
121
+ puts "#{item} #{item_value}"
122
+ modify_conf_single host, user, password, CONFPATH, item, item_value
123
+ ssh_cmd host, user, password, "killall -9 #{modulename}"
124
+ sleep 3
125
+ }
126
+ if (CONF_TEST_CASE.size>0)
127
+ CONF_TEST_CASE.each{|item_value|
128
+ puts "#{item} #{item_value}"
129
+ modify_conf_single host, user, password, CONFPATH, item, item_value
130
+ ssh_cmd host, user, password, "killall -9 #{modulename}"
131
+ sleep 3
132
+ }
133
+ end
134
+ }
135
+ recover_conf host, user, password, CONFPATH, "BAK_CONF_BY_CONF_TEST_PATTERN"
136
+ end
137
+ end
138
+
139
+
140
+ if __FILE__ == $0
141
+
142
+ end
143
+
144
+
145
+
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ #
4
+ # Author:: liqiang01
5
+ # Date:: 2009-8-19 21:31:34
6
+
7
+
8
+ #############################
9
+ # 初始化相关路径
10
+ $SUPER_ROOT = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}"
11
+ $SUPER_ROOT_LIB = "#{$SUPER_ROOT}/lib"
12
+ $SUPER_ROOT_DATA = "#{$SUPER_ROOT}/data"
13
+ $: << $SUPER_ROOT_LIB
14
+ $WORK_ROOT ||= ENV["WORK_ROOT"] if ENV.has_key?("WORK_ROOT")
15
+ # 如果没有定义work_root,就把super_root当成work_root
16
+ $WORK_ROOT ||= $SUPER_ROOT
17
+ $WORK_ROOT_LIB = "#{$WORK_ROOT}/lib"
18
+ # 将CASE_ROOT变为绝对路径,因为一些第三方工具需要使用绝对路径
19
+ $CASE_PATH = File.expand_path($CASE_PATH) unless $CASE_PATH.nil?
20
+ $CASE_ROOT ||= File.dirname($CASE_PATH) unless $CASE_PATH.nil?
21
+ $CASE_ROOT = File.expand_path($CASE_ROOT) unless $CASE_ROOT.nil?
22
+
23
+
24
+ #############################
25
+ # 加载需要的库,注意命名空间
26
+ require 'test/unit'
27
+ require 'common/atp_helper'
28
+ require 'common/mylog_helper'
29
+ require 'common/myconf_helper'
30
+ require 'common/http/http_helper'
31
+ require 'common/http/html_helper'
32
+ require 'common/http/assert_helper'
33
+ require 'common/data_house'
34
+ require 'common/data_model'
35
+ require 'common/robot_helper'
36
+ require 'common/json_helper'
37
+ require 'common/pairwise'
38
+ require 'common/query_house'
39
+ require 'common/mtop_helper'
40
+ require 'common/appium_helper'
41
+ require 'common/isandbox_helper'
42
+ require 'common/mock_helper'
43
+
44
+
45
+
46
+ #############################
47
+ # 加载action,包括用户产品目录下的action,包括系统和模块
48
+ Dir.glob("#{$SUPER_ROOT_LIB}/action/**/*_action.rb").each {|file| require "#{file}"}
49
+ Dir.glob("#{$WORK_ROOT_LIB}/action/**/*_action.rb").each {|file| require "#{file}"}
50
+ Dir.glob("#{$WORK_ROOT_LIB}/common/**/*_helper.rb").each {|file| require "#{file}"}
51
+
52
+
53
+ #############################
54
+ # 加载init_dir
55
+ require "#{$CASE_ROOT}/init_dir" if !$CASE_ROOT.nil? and File.exist?("#{$CASE_ROOT}/init_dir.rb")
56
+
57
+
58
+ #############################
59
+ # 将tool路径加入到 PATH 环境变量当中,只在当前shell中有效
60
+ ENV['PATH'] = "#{$WORK_ROOT}/tool:#{$SUPER_ROOT}/tool:#{ENV['PATH']}"
61
+
62
+
63
+ #############################
64
+ # 定义基类
65
+ class SuperTest < Test::Unit::TestCase
66
+ include MylogHelper
67
+ include ConfigHelper
68
+ include HtmlHelper
69
+ include HttpHelper
70
+ include AssertHelper
71
+ include RobotHelper
72
+ include JsonHelper
73
+ include MtopHelper
74
+
75
+ # 将系统的和用户自定义的以 Helper|Pattern|Action 结尾的Module,全都include进来
76
+ def initialize(*params)
77
+ Object.constants.each do |k|
78
+ if k.to_s =~ /^.+(Helper|Action)$/
79
+ m = Object.const_get(k)
80
+ self.extend(m) if m.instance_of? Module
81
+ end
82
+ end
83
+ super(*params)
84
+ end
85
+
86
+ def setup
87
+ super
88
+ # 用户仓库
89
+ @user_house = UserHouse.get_instance
90
+ # 字符仓库
91
+ @char_house = CharHouse.get_instance
92
+ # 初始化cookie池
93
+ @cookies = {}
94
+ # 初始化referer为空
95
+ @referer = ""
96
+ # 初始化用户为空
97
+ @user = nil
98
+ # 是否做压力,压力的情况下会屏蔽掉所有assert
99
+ @is_press = false
100
+ # 默认是要进行转码的
101
+ @dont_encode = false
102
+ start_appium if CONF["appium"]
103
+ end
104
+
105
+ def teardown
106
+ super
107
+ stop_appium if CONF["appium"]
108
+ end
109
+
110
+ end
111
+
112
+ if __FILE__ == $0
113
+
114
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ #
4
+
5
+
6
+ puts "Cover me !"
Binary file
Binary file
Binary file
@@ -0,0 +1,77 @@
1
+ #日志目录
2
+ log_dir : ./log
3
+ #日志文件名
4
+ log_file : mcserver.
5
+ #日志文件刷新大小(M)
6
+ log_size : 1500
7
+ #日志级别
8
+ log_level : 16
9
+
10
+
11
+ #mcserver服务
12
+
13
+ #服务名
14
+ _svr_regression_mcserver_name : mcserver
15
+ #启动服务的端口
16
+ _svr_regression_mcserver_port : 9916
17
+ #服务的读超时(单位:ms)
18
+ _svr_regression_mcserver_readtimeout : 1000
19
+ #服务的写超时(单位:ms)
20
+ _svr_regression_mcserver_writetimeout : 1000
21
+ #服务启动的线程数
22
+ _svr_regression_mcserver_threadnum : 2
23
+ #服务连接的类型(0:短连接, 1:长连接)example: 0 (use short connect)
24
+ _svr_regression_mcserver_connecttype : 0
25
+ #服务使用的pool类型(0:XPOOL, 1:CPOOL)
26
+ _svr_regression_mcserver_servertype : 0
27
+ #CPOOL的socksize当使用CPOOL时设置有效
28
+ #[默认配置(uint), _svr_regression_mcserver_quenesize : 0]
29
+ _svr_regression_mcserver_quenesize : 0
30
+ #CPOOL的socksize当使用CPOOL时设置有效
31
+ #[默认配置(uint), _svr_regression_mcserver_socksize : 0]
32
+ _svr_regression_mcserver_socksize : 0
33
+
34
+ #client服务器
35
+
36
+ #请求服务名
37
+ _reqsvr_regression_client_name : client
38
+ #请求服务的IP地址,可以设置多个IP
39
+ _reqsvr_regression_client_ip : 127.0.0.1
40
+ #请求服务的端口
41
+ _reqsvr_regression_client_port : 6000
42
+ #请求服务的读超时(单位:ms)
43
+ _reqsvr_regression_client_readtimemout : 1000
44
+ #请求服务的写超时(单位:ms)
45
+ _reqsvr_regression_client_writetimeout : 1000
46
+ #请求服务的连接超时(单位:ms)
47
+ _reqsvr_regression_client_connecttimeout : 1000
48
+ #请求服务时最大连接数
49
+ _reqsvr_regression_client_maxconnect : 10
50
+ #请求服务的重试次数
51
+ _reqsvr_regression_client_retry : 3
52
+ #服务连接的类型(0:短连接, 1:长连接)
53
+ _reqsvr_regression_client_connecttype : 0
54
+
55
+
56
+ #数据文件目录
57
+ data_dir : ./data
58
+
59
+ #认证IP文件路径
60
+ auth_file : ./conf/mcserverauthip
61
+
62
+ #作为桩时mcpack数据文件的名字
63
+ mcdata : stubdata
64
+ #是否作为桩
65
+ as_stub : 0
66
+
67
+ #含有全部字段的日志文件的名字
68
+ fulltextfile : foo.log
69
+
70
+ #每个线程usleep的时间-微秒
71
+ usleep_time_thread : 0
72
+ #线程usleep的概率 范围:[0-1] 每个线程都sleep请填 1, 不sleep请填 0
73
+ usleep_percent : 0.8
74
+ #按指定概率usleep的时间-微秒
75
+ usleep_time_percent : 10
76
+
77
+
@@ -0,0 +1,17 @@
1
+ #type 1: IP
2
+ 127.0.0.1
3
+
4
+ #type 2: IP
5
+ 127.*.*.*
6
+
7
+ #type 3: IP
8
+ 127.0.0.1/8
9
+
10
+ #type 4: IP - IP
11
+
12
+ #type 5: IP - IP
13
+
14
+ #type 6: IP - IP
15
+
16
+ *.*.*.*
17
+
Binary file
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ ID : 0
2
+ VERSION : 0
3
+ LOG_ID : 2
4
+ PROVIDER : huowaa
5
+ MAGIC_NUM : 0
6
+ RESERVED : 2
7
+
@@ -0,0 +1,7 @@
1
+ id : 0
2
+ version : 0
3
+ log_id : 2
4
+ provider : usr.imp
5
+ magic_num : 4218459028
6
+ reserved : 0
7
+ body_len : 5311
@@ -0,0 +1,205 @@
1
+ load bft.so
2
+ load cnnt.so
3
+
4
+ set ip ""
5
+ set port ""
6
+ set module_name ""
7
+ set is_gen "0"
8
+ set debug "0"
9
+
10
+ proc print_log {info} {
11
+ global debug
12
+ if {$debug == 1} {
13
+ puts $info
14
+ }
15
+ }
16
+
17
+ proc print_usage {} {
18
+ global argv0
19
+ puts "Usage:\tts-agent -f $argv0 -d -i ip -p port -m module_name"
20
+ puts " \tts-agent -f $argv0 -g -m module_name"
21
+ puts "Options:"
22
+ puts "\t-g gen template"
23
+ puts "\t-d debug mode"
24
+ puts "\t-i server ip"
25
+ puts "\t-p server port"
26
+ puts "\t-m module name, corresponding to other files, such as <module_name>_<req|res>.<bft|data>"
27
+ puts "\t-c case name"
28
+ puts "\t-r receive name"
29
+ puts "\t-h print this help"
30
+ puts "\t-v print version"
31
+ }
32
+
33
+ proc print_version {} {
34
+ puts "Version:"
35
+ puts "\t 1.0.0.0"
36
+ puts "written by wangkaihua."
37
+ }
38
+
39
+ proc gen_template {} {
40
+ global module_name
41
+ set tmp_req_bft [format "%s_req.bft" $module_name]
42
+ if {[catch {bft gen $tmp_req_bft} tmp_req]} {puts "error: failed to read file <$tmp_req_bft>";exit}
43
+ if {[catch {puts [bft export_json $tmp_req]}]} {puts "error: failed to gen template.";exit}
44
+ }
45
+
46
+ proc parse_option {} {
47
+ global argc
48
+ global argv
49
+ global ip
50
+ global port
51
+ global bft_path
52
+ global module_name
53
+ global case_name
54
+ global receive_name
55
+ global is_gen
56
+ global debug
57
+ set index 0
58
+ while {$index < $argc} {
59
+ set option [lindex $argv $index]
60
+ switch -exact $option {
61
+ -h {print_usage;exit}
62
+ -i {
63
+ incr index 1
64
+ if {$index <$argc} {set ip [lindex $argv $index]
65
+ } else {puts "error : param should be input after option -h "}
66
+ }
67
+ -p {
68
+ incr index 1
69
+ if {$index <$argc} {set port [lindex $argv $index]
70
+ } else {puts "error : param should be input after option -p "}
71
+ }
72
+ -b {
73
+ incr index 1
74
+ if {$index <$argc} {set bft_path [lindex $argv $index]
75
+ } else {puts "error : param should be input after option -b "}
76
+ }
77
+ -m {
78
+ incr index 1
79
+ if {$index <$argc} {set module_name [lindex $argv $index]
80
+ } else {puts "error : param should be input after option -m "}
81
+ }
82
+ -c {
83
+ incr index 1
84
+ if {$index <$argc} {set case_name [lindex $argv $index]
85
+ } else {puts "error : param should be input after option -c "}
86
+ }
87
+ -r {
88
+ incr index 1
89
+ if {$index <$argc} {set receive_name [lindex $argv $index]
90
+ } else {puts "error : param should be input after option -r "}
91
+ }
92
+ -v {print_version;exit}
93
+ -g {set is_gen 1}
94
+ -d {set debug 1}
95
+ default {puts "deault"}
96
+ }
97
+ incr index 1
98
+ }
99
+ }
100
+
101
+ parse_option
102
+ if {$is_gen == 1} {
103
+ gen_template
104
+ exit
105
+ }
106
+
107
+ #set serverip "10.241.14.54"
108
+ set serverip $ip
109
+ #set serverport "21040"
110
+ set serverport $port
111
+
112
+ set req_bft [format "%s/%s_req.bft" $bft_path $module_name]
113
+ puts "$req_bft."
114
+ #set req_data [format "%s_req.data" $module_name]
115
+ set req_data [format "%s" $case_name]
116
+ set res_bft [format "%s/%s_res.bft" $bft_path $module_name]
117
+ puts "$res_bft."
118
+ #set res_data [format "%s_req.recv" $module_name]
119
+ set res_data [format "%s" $receive_name]
120
+
121
+ if {![file exists $req_bft]} {
122
+ puts "ERROR: $req_bft does not exist."
123
+ exit
124
+ }
125
+
126
+ if {[catch {bft gen $req_bft} req]} {
127
+ puts "ERROR: failed to load template $req_bft"
128
+ exit
129
+ } else {
130
+ if {[catch {open $req_data "r"} send_fd]} {
131
+ puts "ERROR: failed to open $req_data"
132
+ exit
133
+ }
134
+ gets $send_fd line
135
+ if {[catch {bft import_json $req $line}]} {
136
+ puts "ERROR: failed to import req_data."
137
+ exit
138
+ }
139
+ close $send_fd
140
+ }
141
+
142
+ if {![file exists $res_bft]} {
143
+ puts "NOTICE: $res_bft does not exist. then recv data will not be parsed."
144
+ } else {
145
+ if {[catch {bft gen $res_bft} res]} {
146
+ puts "ERROR: failed to load template $res_bft"
147
+ puts $res
148
+ unset res
149
+ }
150
+ }
151
+
152
+ set clt "client"
153
+ cnnt new $clt
154
+ cnnt config $clt "client;ip-server:$serverip;port-server:$serverport;type-data:raw"
155
+ cnnt onrecv $clt CltOnRecv -id -name
156
+ cnnt start $clt
157
+
158
+ proc clear {name id} {
159
+ cnnt delete $name -id $id
160
+ }
161
+
162
+ proc CltOnRecv {data id name} {
163
+ global res
164
+ global res_data
165
+
166
+ if {[info exists res]} {
167
+ if {[catch {open $res_data "w"} recv_fd]} {
168
+ print_log "error:failed to open $req_data"
169
+ clear $name $id
170
+ return
171
+ }
172
+
173
+ print_log "NOTICE: $name ===>> recved from server:"
174
+ if {[catch {bft import $res $data}]} {
175
+ print_log "error: failed to import recv_data to res_bft"
176
+ clear $name $id
177
+ return
178
+ }
179
+ print_log [bft export_json $res]
180
+ if {[catch {puts $recv_fd [bft export_json $res]}]} {
181
+ print_log "error: failed to export res_data to json"
182
+ clear $name $id
183
+ return
184
+ }
185
+
186
+ close $recv_fd
187
+ } else {
188
+ print_log "NOTICE: $name ===>recved from server. data does not be parsed, for no res_bft file exists."
189
+ }
190
+
191
+ clear $name $id
192
+
193
+ }
194
+
195
+ print_log " ===>> sending to server: $module_name"
196
+ print_log [bft export_json $req]
197
+ set buf [bft export $req]
198
+ cnnt send $clt $buf
199
+
200
+ proc AsynWait {time} {
201
+ after $time [list set done ""]
202
+ vwait done
203
+ }
204
+ AsynWait 2000
205
+ #vwait forever