TestsConnection.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## ConnectTest.py
00005 ##
00006 ## コンポーネント接続テスト
00007 ##
00008 
00009 from rtc_handle import *
00010 from BasicDataType_idl import *
00011 import time
00012 import commands
00013 import SDOPackage
00014 import os
00015 import sys
00016 
00017 ##--------------------------------------------------------------------
00018 g_test_name = "<< component connection test >>"
00019 
00020 ##--------------------------------------------------------------------
00021 ## コネクタープロファイルデフォルト定義
00022 g_interface_type1 = "corba_cdr"
00023 g_dataflow_type = "push"
00024 g_subscription_type = "flush"
00025 g_push_policy = "NEW"
00026 g_push_rate = "2000"
00027 g_skip_count = "4"
00028 #g_skip_count = "0"
00029 
00030 ## ポート番号指定 ( get_ports()より )
00031 g_port1 = 0
00032 g_port2 = 1
00033 g_port3 = 2
00034 
00035 ## データポート TimedFloat
00036 g_name1 = "out"
00037 g_connector_id1 = "001"
00038 g_data_type1 = "TimedFloat"
00039 
00040 ## データポート TimedFloatSeq
00041 g_name2 = "seqout"
00042 g_connector_id2 = "002"
00043 g_data_type2 = "TimedFloatSeq"
00044 
00045 ## サービスポート 
00046 g_name3 = "MyService"
00047 g_connector_id3 = "003"
00048 g_interface_type3 = "MyService"
00049 
00050 ##--------------------------------------------------------------------
00051 ## 送受信結果判定関連
00052 g_diff_send_file = "./original-data"
00053 g_diff_recv_file = "./received-data"
00054 g_check_message = g_diff_recv_file + " file not found."
00055 g_test_result_file = "./ResultTest.log"
00056 g_test_case = ""
00057 g_test_cnt = "count"
00058 g_test_ok = "."
00059 g_test_ng = "F"
00060 g_test_ng_message = "  < received-data >"
00061 g_mess_header = "< "
00062 g_mess_footer = " > "
00063 # テスト結果内容
00064 # 例)ケース1、1回目 -> "<<< case1 count1 >>> OK."
00065 # 例)ケース1、2回目 -> "<<< case1 count2 >>> NG detected."
00066 
00067 ##--------------------------------------------------------------------
00068 ## テストケース番号の初期値設定
00069 ##  上から連番を振っている
00070 case_no = 0
00071 
00072 ## ケース毎のテスト回数
00073 loop_count = 1
00074 
00075 ## 受信側activate_componentから送信側activate_componentまでのスリープ時間(秒数)
00076 sleep_recv_act_time = 1
00077 
00078 ## activate_componentからdeactivate_componentまでのスリープ時間(秒数)
00079 sleep_act_time = 2
00080 
00081 ## forループのスリープ時間(秒数)
00082 sleep_for_time = 1
00083 
00084 ## connectからdisconnectまでのスリープ時間(秒数)
00085 sleep_connect_time =1
00086 
00087 
00088 ## ネームサーバー定義
00089 #env = RtmEnv(sys.argv, ["localhost:2809"])
00090 #list0 = env.name_space["localhost:2809"].list_obj()
00091 #env.name_space['localhost:2809'].rtc_handles.keys()
00092 #ns = env.name_space['localhost:2809']
00093 
00094 ##
00095 # @if jp
00096 # @brief ポートを接続する。
00097 # @else
00098 # @brief Connects ports. 
00099 # @endif
00100 def connect_ports():
00101 
00102     errorFlag = True
00103 
00104     # データポート1 TimedFloat
00105     ret,porf = g_out_ports[g_port1].connect(g_conprof1)
00106     if ret!=RTC.RTC_OK:
00107         errorFlag = False
00108 
00109     # データポート2 TimedFloatSeq
00110     ret,porf = g_out_ports[g_port2].connect(g_conprof2)
00111     if ret!=RTC.RTC_OK:
00112         errorFlag = False
00113 
00114     # サービスポート MyService
00115     ret,porf = g_out_ports[g_port3].connect(g_conprof3)
00116     if ret!=RTC.RTC_OK:
00117         errorFlag = False
00118     
00119 
00120     return errorFlag
00121 ##
00122 # @if jp
00123 # @brief ポートを切断する。
00124 # @else
00125 # @brief Disconnects ports. 
00126 # @endif
00127 def disconnect_ports():
00128 
00129     errorFlag = True
00130 
00131     ret = g_in_ports[g_port3].disconnect(g_conprof3.connector_id)
00132     if ret!=RTC.RTC_OK:
00133         errorFlag = False
00134     ret = g_in_ports[g_port2].disconnect(g_conprof2.connector_id)
00135     if ret!=RTC.RTC_OK:
00136         errorFlag = False
00137     ret = g_in_ports[g_port1].disconnect(g_conprof1.connector_id)
00138     if ret!=RTC.RTC_OK:
00139         errorFlag = False
00140 
00141     return errorFlag
00142 
00143 ##
00144 # @if jp
00145 # @brief ポートを活性化する。
00146 # @else
00147 # @brief Activate components. 
00148 # @endif
00149 def activate_components(sleep_recv_act_time):
00150     errorFlag = True
00151 
00152     ret = ec_recv[0].activate_component(g_compo_recv.rtc_ref)
00153     if ret!=RTC.RTC_OK:
00154         errorFlag = False
00155 
00156     time.sleep(sleep_recv_act_time)
00157 
00158     ret = ec_send[0].activate_component(g_compo_send.rtc_ref)
00159 
00160     if ret!=RTC.RTC_OK:
00161         errorFlag = False
00162 
00163     return errorFlag
00164 ##
00165 # @if jp
00166 # @brief ポートを非活性化する。
00167 # @else
00168 # @brief Deactivate components. 
00169 # @endif
00170 def deactivate_components():
00171     errorFlag = True
00172 
00173     ret = ec_send[0].deactivate_component(g_compo_send.rtc_ref)
00174     if ret!=RTC.RTC_OK:
00175         errorFlag = False
00176     ret = ec_recv[0].deactivate_component(g_compo_recv.rtc_ref)
00177     if ret!=RTC.RTC_OK:
00178         errorFlag = False
00179 
00180     return errorFlag
00181 ##
00182 # @if jp
00183 # @brief AutoTestOut と AutoTestIn を起動させる。
00184 # @else
00185 # @brief AutoTestOut and AutoTestIn are started. 
00186 # @endif
00187 def components_entry():
00188     global g_compo_send,g_compo_recv
00189     global ec_send,ec_recv
00190     global g_out_ports,g_in_ports
00191     global g_conprof1,g_conprof2,g_conprof3
00192     global env
00193 
00194     os.system('./AutoTestOutComp >/dev/null 2>&1 &') 
00195     os.system('./AutoTestInComp >/dev/null 2>&1 &') 
00196 
00197     time.sleep(2)
00198 
00199     #env = RtmEnv(sys.argv, ["localhost:2809"])
00200     list0 = env.name_space["localhost:2809"].list_obj()
00201     env.name_space['localhost:2809'].rtc_handles.keys()
00202     ns = env.name_space['localhost:2809']
00203 
00204     g_compo_send = ns.rtc_handles["AutoTestOut0.rtc"]
00205     g_compo_recv = ns.rtc_handles["AutoTestIn0.rtc"]
00206 
00207     ec_send = g_compo_send.rtc_ref.get_owned_contexts()
00208     ec_recv = g_compo_recv.rtc_ref.get_owned_contexts()
00209 
00210     g_out_ports = g_compo_send.rtc_ref.get_ports()
00211     g_in_ports = g_compo_recv.rtc_ref.get_ports()
00212 
00213     g_conprof3 = RTC.ConnectorProfile(g_name3, g_connector_id3, [g_out_ports[g_port3], g_in_ports[g_port3]], [SDOPackage.NameValue("dataport.interface_type",any.to_any(g_interface_type3))])
00214 
00215     return
00216 
00217 ##
00218 # @if jp
00219 # @brief AutoTestOut と AutoTestIn を終了させる。
00220 # @else
00221 # @brief  AutoTestOut and AutoTestIn are ended. 
00222 # @endif
00223 def components_exit():
00224     g_compo_send.rtc_ref.exit();
00225     g_compo_recv.rtc_ref.exit();
00226 
00227     time.sleep(1)
00228     return
00229     
00230 ##
00231 # @if jp
00232 # @brief グローバル変数の初期化
00233 # @else
00234 # @brief Initialization of global variable
00235 # @endif
00236 def initGlobal():
00237     global env
00238 
00239     env = RtmEnv(sys.argv, ["localhost:2809"])
00240 
00241     return
00242 
00243 ##--------------------------------------------------------------------
00244 ## 内部関数:コネクタープロファイル設定(データポート)
00245 ##
00246 ## (引数)
00247 ## subscription_type : "flush", "new", "periodic"
00248 ## push_policy       : "ALL", "FIFO", "SKIP", "NEW", ""
00249 ## connect_direction : 0:outport -> inport, 1:inport -> outport
00250 ##--------------------------------------------------------------------
00251 def make_connecter_profile(subscription_type, push_policy, connect_direction):
00252     global g_conprof1, g_conprof2, g_conprof3
00253 
00254     if connect_direction == 0:
00255         ## outport -> inport Set
00256         g_conprof1 = RTC.ConnectorProfile(g_name1, g_connector_id1, [g_out_ports[g_port1], g_in_ports[g_port1]], [SDOPackage.NameValue("dataport.data_type",any.to_any(g_data_type1)),SDOPackage.NameValue("dataport.interface_type",any.to_any(g_interface_type1)),SDOPackage.NameValue("dataport.dataflow_type",any.to_any(g_dataflow_type)),SDOPackage.NameValue("dataport.subscription_type",any.to_any(subscription_type)),SDOPackage.NameValue("dataport.publisher.push_policy",any.to_any(push_policy)),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(g_push_rate)),SDOPackage.NameValue("dataport.publisher.skip_count",any.to_any(g_skip_count))])
00257 
00258         g_conprof2 = RTC.ConnectorProfile(g_name2, g_connector_id2, [g_out_ports[g_port2], g_in_ports[g_port2]], [SDOPackage.NameValue("dataport.data_type",any.to_any(g_data_type2)),SDOPackage.NameValue("dataport.interface_type",any.to_any(g_interface_type1)),SDOPackage.NameValue("dataport.dataflow_type",any.to_any(g_dataflow_type)),SDOPackage.NameValue("dataport.subscription_type",any.to_any(subscription_type)),SDOPackage.NameValue("dataport.publisher.push_policy",any.to_any(push_policy)),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(g_push_rate)),SDOPackage.NameValue("dataport.publisher.skip_count",any.to_any(g_skip_count))])
00259 
00260         #print "outport -> inport set >>>"
00261         #print "g_conprof1=",g_conprof1
00262         #print "g_conprof2=",g_conprof2
00263     else:
00264         ## inport -> outport Set
00265         g_conprof1 = RTC.ConnectorProfile(g_name1, g_connector_id1, [g_in_ports[g_port1], g_out_ports[g_port1]], [SDOPackage.NameValue("dataport.data_type",any.to_any(g_data_type1)),SDOPackage.NameValue("dataport.interface_type",any.to_any(g_interface_type1)),SDOPackage.NameValue("dataport.dataflow_type",any.to_any(g_dataflow_type)),SDOPackage.NameValue("dataport.subscription_type",any.to_any(subscription_type)),SDOPackage.NameValue("dataport.publisher.push_policy",any.to_any(push_policy)),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(g_push_rate)),SDOPackage.NameValue("dataport.publisher.skip_count",any.to_any(g_skip_count))])
00266 
00267         g_conprof2 = RTC.ConnectorProfile(g_name2, g_connector_id2, [g_in_ports[g_port2], g_out_ports[g_port2]], [SDOPackage.NameValue("dataport.data_type",any.to_any(g_data_type2)),SDOPackage.NameValue("dataport.interface_type",any.to_any(g_interface_type1)),SDOPackage.NameValue("dataport.dataflow_type",any.to_any(g_dataflow_type)),SDOPackage.NameValue("dataport.subscription_type",any.to_any(subscription_type)),SDOPackage.NameValue("dataport.publisher.push_policy",any.to_any(push_policy)),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(g_push_rate)),SDOPackage.NameValue("dataport.publisher.skip_count",any.to_any(g_skip_count))])
00268 
00269         #print "inport -> outport set >>>"
00270         #print "g_conprof1=",g_conprof1
00271         #print "g_conprof2=",g_conprof2
00272     return
00273 
00274 
00275 ##--------------------------------------------------------------------
00276 ## 内部関数:受信ファイル削除
00277 ##
00278 ## (引数)
00279 ## なし
00280 ##--------------------------------------------------------------------
00281 def delete_recv_file():
00282     ## ファイルが存在する場合
00283     if os.path.isfile(g_diff_recv_file) == True:
00284         os.remove(g_diff_recv_file)
00285     return
00286 
00287 
00288 ##--------------------------------------------------------------------
00289 ## 内部関数:送受信ファイルのデータ比較
00290 ##
00291 ## (引数)
00292 ## なし
00293 ## (戻り値)  True : 一致、  False : 不一致
00294 ##--------------------------------------------------------------------
00295 def diff_file():
00296     bret = True
00297 
00298     ## if connect_direction == 0:
00299     ## else:
00300     ## 送信ファイル有無判定
00301     if os.path.isfile(g_diff_send_file) == False:
00302         print "send_file (%s) not found." % send_file
00303         return False
00304 
00305     ## 受信ファイル有無判定
00306     if os.path.isfile(g_diff_recv_file) == False:
00307         print "recv_file (%s) not found." % recv_file
00308         return False
00309 
00310     ## 送受信データ差分判定
00311     f_send = open(g_diff_send_file, 'r')
00312     f_recv = open(g_diff_recv_file, 'r')
00313 
00314     while(1):
00315         str_send = f_send.readline()
00316         str_recv = f_recv.readline()
00317         if len(str_send) == 0:
00318             break
00319 
00320         #print "original send date=(%s)" % str_send
00321         #print ''.join(['%x ' % ord(s) for s in str_send])
00322         #print "original recv date=(%s)" % str_recv
00323         #print ''.join(['%x ' % ord(s) for s in str_recv])
00324 
00325         ## 末尾の改行、復帰コード削除
00326         str_send2 = str_send.rstrip('\n')
00327         str_send2 = str_send2.rstrip('\r')
00328         str_recv2 = str_recv.rstrip('\n')
00329         str_recv2 = str_recv2.rstrip('\r')
00330 
00331         #print "rstrip after send date=(%s)" % str_send2
00332         #print "rstrip after recv date=(%s)" % str_recv2
00333 
00334         ## データ比較
00335         list_send = str_send2.split(" ")
00336         list_recv = str_recv2.split(" ")
00337         for ic in range(len(list_send)):
00338             try:
00339                 float_send = float(list_send[ic]);
00340                 float_recv = float(list_recv[ic]);
00341                 if float_send != float_recv:
00342                     bret = False
00343                     break;
00344             except:
00345                 if str_send2 != str_recv2:
00346                     bret = False
00347                     break;
00348          
00349 
00350     f_recv.close()
00351     f_send.close()
00352     return bret
00353 
00354 
00355 ##
00356 # @if jp
00357 # @brief 接続と切断だけを繰り返す。
00358 #
00359 #
00360 #
00361 # @else
00362 # @brief Only the connection and cutting are repeated. 
00363 #
00364 #
00365 #
00366 # @endif
00367 def test_connect_disconnect(message,arg0,arg1,arg2):
00368 
00369     errorFlag = True
00370     for i in range(loop_count):
00371 
00372         ## 1 コネクタープロファイル設定
00373         make_connecter_profile(arg0,arg1,arg2)
00374 
00375         ## 3 ポート接続
00376         bool_ret = connect_ports()
00377         if bool_ret!=True:
00378             errorFlag = False
00379 
00380         time.sleep(sleep_connect_time)
00381 
00382         ## 6 ポート切断
00383         bool_ret = disconnect_ports()
00384         if bool_ret!=True:
00385             errorFlag = False
00386 
00387         ## テスト結果出力
00388         fout = open(g_test_result_file, 'a')
00389         if errorFlag:
00390             message = g_test_ok
00391         else :
00392             message = g_test_ng
00393         print message ,
00394         sys.stdout.flush()
00395         fout.write(message)
00396         fout.close()
00397 
00398         time.sleep(sleep_for_time)
00399 
00400     return errorFlag
00401 
00402     
00403 ##
00404 # @if jp
00405 # @brief ActivateとDeactivateだけを繰り返す。
00406 #
00407 # 接続した状態で Activate と Deactivate を繰り返す。
00408 # データのチェックは行われない。
00409 #
00410 # @else
00411 # @brief Only activation and deactivation are repeated. 
00412 #
00413 # Activate and Deactivate are repeated while connected. 
00414 # Data is not checked. 
00415 #
00416 # @endif
00417 def test_activate_deactivate_2(message,arg0,arg1,arg2):
00418     
00419     errorFlag = True
00420     ## 1 コネクタープロファイル設定
00421     make_connecter_profile(arg0,arg1,arg2)
00422     
00423     ## 3 ポート接続
00424     bool_ret = connect_ports()
00425     if bool_ret!=True:
00426         errorFlag = False
00427     
00428     for i in range(loop_count):
00429     
00430         ## 2 受信データファイル削除
00431         delete_recv_file()
00432     
00433         ## 4 アクティベート
00434         bool_ret = activate_components(sleep_recv_act_time)
00435         if bool_ret!=True:
00436             errorFlag = False
00437     
00438         time.sleep(sleep_act_time)
00439     
00440         ## 5 ディアクティベート
00441         bool_ret = deactivate_components()
00442         if bool_ret!=True:
00443             errorFlag = False
00444     
00445         ## 受信ファイル有無判定
00446         if os.path.isfile(g_diff_recv_file) == False:
00447             errorFlag = False
00448             fout = open(g_test_result_file, 'a')
00449             #message = message + g_check_message
00450             message = g_test_ng
00451             fout.write(message)
00452             fout.close()
00453             print message ,
00454             sys.stdout.flush()
00455             time.sleep(sleep_for_time)
00456             continue
00457     
00458         ## ファイルサイズをチェックする
00459         time.sleep(sleep_act_time)
00460         fout = open(g_test_result_file, 'a')
00461         fsize=os.path.getsize(g_diff_recv_file)
00462         if fsize > 0:
00463             message = g_test_ok
00464             print message ,
00465             sys.stdout.flush()
00466             fout.write(message)
00467         else:
00468             errorFlag = False
00469             # テスト結果 NG
00470             message = g_test_ng
00471             print message ,
00472             sys.stdout.flush()
00473             fout.write(message)
00474 
00475         fout.close()
00476     
00477         time.sleep(sleep_for_time)
00478     
00479     ## 6 ポート切断
00480     bool_ret = disconnect_ports()
00481 
00482     return errorFlag
00483 ##
00484 # @if jp
00485 # @brief ActivateとDeactivateだけを繰り返す。
00486 #
00487 # 接続した状態で Activate と Deactivate を繰り返す。
00488 #
00489 # @else
00490 # @brief Only activation and deactivation are repeated. 
00491 #
00492 # Activate and Deactivate are repeated while connected. 
00493 #
00494 # @endif
00495 def test_activate_deactivate(message,arg0,arg1,arg2):
00496     
00497     errorFlag = True
00498     ## 1 コネクタープロファイル設定
00499     make_connecter_profile(arg0,arg1,arg2)
00500     
00501     ## 3 ポート接続
00502     bool_ret = connect_ports()
00503     if bool_ret!=True:
00504         errorFlag = False
00505     
00506     for i in range(loop_count):
00507     
00508         ## 2 受信データファイル削除
00509         delete_recv_file()
00510     
00511         ## 4 アクティベート
00512         bool_ret = activate_components(sleep_recv_act_time)
00513         if bool_ret!=True:
00514             errorFlag = False
00515     
00516         time.sleep(sleep_act_time)
00517     
00518         ## 5 ディアクティベート
00519         bool_ret = deactivate_components()
00520         if bool_ret!=True:
00521             errorFlag = False
00522     
00523         ## 受信ファイル有無判定
00524         if os.path.isfile(g_diff_recv_file) == False:
00525             errorFlag = False
00526             fout = open(g_test_result_file, 'a')
00527             #message = message + g_check_message
00528             message = g_test_ng
00529             fout.write(message)
00530             fout.close()
00531             print message ,
00532             sys.stdout.flush()
00533             time.sleep(sleep_for_time)
00534             continue
00535     
00536         ## 7 送受信データ比較
00537         time.sleep(sleep_act_time)
00538         bret = diff_file()
00539     
00540         ## 差分ファイルからテスト結果出力
00541         fout = open(g_test_result_file, 'a')
00542         # bret==True なら送受信データ一致
00543         if bret == True:
00544             # テスト結果 OK
00545             message = g_test_ok
00546             print message ,
00547             sys.stdout.flush()
00548             fout.write(message + '\n')
00549         else:
00550             errorFlag = False
00551             # テスト結果 NG
00552             message = g_test_ng
00553             print message ,
00554             sys.stdout.flush()
00555             fout.write(message + '\n')
00556             # 受信データをテスト結果ファイルへコピー
00557             fin2 = open(g_diff_recv_file, 'r')
00558             while(1):
00559                 s2 = fin2.readline()
00560                 if len(s2) == 0:
00561                     break
00562                 fout.write(s2)
00563             fin2.close()
00564         fout.close()
00565     
00566         time.sleep(sleep_for_time)
00567     
00568     ## 6 ポート切断
00569     bool_ret = disconnect_ports()
00570 
00571     return errorFlag
00572     
00573 ##
00574 # @if jp
00575 # @brief ActivateとDeactivateだけを繰り返す。
00576 #
00577 # 接続せずに Activate と Deactivate を繰り返す。
00578 #
00579 # @else
00580 # @brief Only activation and deactivation are repeated. 
00581 #
00582 # Activate and Deactivate are repeated without connecting it. 
00583 #
00584 # @endif
00585 def test_activate_deactivate_2(message,arg0,arg1,arg2):
00586     
00587     errorFlag = True
00588     
00589     for i in range(loop_count):
00590     
00591         ## 1 コネクタープロファイル設定
00592         make_connecter_profile(arg0,arg1,arg2)
00593     
00594         ## 4 アクティベート
00595         bool_ret = activate_components(sleep_recv_act_time)
00596         if bool_ret!=True:
00597             errorFlag = False
00598     
00599         time.sleep(sleep_act_time)
00600     
00601         ## 5 ディアクティベート
00602         bool_ret = deactivate_components()
00603         if bool_ret!=True:
00604             errorFlag = False
00605     
00606         ## テスト結果出力
00607         fout = open(g_test_result_file, 'a')
00608         if errorFlag:
00609             message = g_test_ok
00610         else :
00611             message = g_test_ng
00612         print message ,
00613         sys.stdout.flush()
00614         fout.write(message)
00615         fout.close()
00616     
00617         time.sleep(sleep_for_time)
00618 
00619     return errorFlag
00620     
00621 ##
00622 # @if jp
00623 # @brief 接続、activate、deactivate、切断を繰り返す。 
00624 #
00625 # データのチェックは行われない。
00626 # periodic,newの接続テストでは、ポリシーがSKIP,NEWの場合、
00627 # データの確認は行わない。
00628 #
00629 #
00630 # @else
00631 # @brief The connection, activate, deactivate, and cutting are repeated. 
00632 #
00633 # Data is not checked. 
00634 #
00635 # @endif
00636 def test_connection_5(message,arg0,arg1,arg2):
00637     
00638     errorFlag = True
00639     for i in range(loop_count):
00640     
00641         ## 2 受信データファイル削除
00642         delete_recv_file()
00643     
00644         ## 1 コネクタープロファイル設定
00645         make_connecter_profile(arg0,arg1,arg2)
00646     
00647         ## 3 ポート接続
00648         bool_ret = connect_ports()
00649         if bool_ret!=True:
00650             errorFlag = False
00651 
00652         ## 4 アクティベート
00653         bool_ret = activate_components(sleep_recv_act_time)
00654         if bool_ret!=True:
00655             errorFlag = False
00656     
00657         time.sleep(sleep_act_time)
00658     
00659         ## 5 ディアクティベート
00660         bool_ret = deactivate_components()
00661         if bool_ret!=True:
00662             errorFlag = False
00663     
00664         ## 6 ポート切断
00665         bool_ret = disconnect_ports()
00666         if bool_ret!=True:
00667             errorFlag = False
00668     
00669         ## 受信ファイル有無判定
00670         if os.path.isfile(g_diff_recv_file) == False:
00671             errorFlag = False
00672             fout = open(g_test_result_file, 'a')
00673             message = g_test_ng
00674             fout.write(message + '\n')
00675             fout.close()
00676             print message,
00677             sys.stdout.flush()
00678             time.sleep(sleep_for_time)
00679             continue
00680     
00681         ## ファイルサイズをチェックする
00682         time.sleep(sleep_act_time)
00683         fout = open(g_test_result_file, 'a')
00684         fsize=os.path.getsize(g_diff_recv_file)
00685         if fsize > 0:
00686             message = g_test_ok
00687             print message ,
00688             sys.stdout.flush()
00689             fout.write(message)
00690         else:
00691             errorFlag = False
00692             # テスト結果 NG
00693             message = g_test_ng
00694             print message ,
00695             sys.stdout.flush()
00696             fout.write(message)
00697 
00698         fout.close()
00699     
00700         time.sleep(sleep_for_time)
00701 
00702     return errorFlag
00703 ##
00704 # @if jp
00705 # @brief 接続、activate、deactivate、切断を繰り返す。 
00706 #
00707 #
00708 # @else
00709 # @brief The connection, activate, deactivate, and cutting are repeated. 
00710 #
00711 #
00712 # @endif
00713 def test_connection(message,arg0,arg1,arg2):
00714     
00715     errorFlag = True
00716     for i in range(loop_count):
00717     
00718         ## 2 受信データファイル削除
00719         delete_recv_file()
00720     
00721         ## 1 コネクタープロファイル設定
00722         make_connecter_profile(arg0,arg1,arg2)
00723     
00724         ## 3 ポート接続
00725         bool_ret = connect_ports()
00726         if bool_ret!=True:
00727             errorFlag = False
00728     
00729         ## 4 アクティベート
00730         bool_ret = activate_components(sleep_recv_act_time)
00731         if bool_ret!=True:
00732             errorFlag = False
00733     
00734         time.sleep(sleep_act_time)
00735     
00736         ## 5 ディアクティベート
00737         bool_ret = deactivate_components()
00738         if bool_ret!=True:
00739             errorFlag = False
00740     
00741         ## 6 ポート切断
00742         bool_ret = disconnect_ports()
00743         if bool_ret!=True:
00744             errorFlag = False
00745 
00746     
00747         ## 受信ファイル有無判定
00748         if os.path.isfile(g_diff_recv_file) == False:
00749             errorFlag = False
00750             fout = open(g_test_result_file, 'a')
00751             message = g_test_ng
00752             fout.write(message + '\n')
00753             fout.close()
00754             print message,
00755             sys.stdout.flush()
00756             time.sleep(sleep_for_time)
00757             continue
00758     
00759         ## 7 送受信データ比較
00760         time.sleep(sleep_act_time)
00761         bret = diff_file()
00762     
00763         ## 差分ファイルからテスト結果出力
00764         fout = open(g_test_result_file, 'a')
00765         # bret==True なら送受信データ一致
00766         if bret == True:
00767             # テスト結果 OK
00768             message = g_test_ok
00769             print message ,
00770             sys.stdout.flush()
00771             fout.write(message + '\n')
00772         else:
00773             errorFlag = False
00774             # テスト結果 NG
00775             message = g_test_ng
00776             print message ,
00777             sys.stdout.flush()
00778             fout.write(message + '\n')
00779             # 受信データをテスト結果ファイルへコピー
00780             fin2 = open(g_diff_recv_file, 'r')
00781             while(1):
00782                 s2 = fin2.readline()
00783                 if len(s2) == 0:
00784                     break
00785                 fout.write(s2)
00786             fin2.close()
00787         fout.close()
00788     
00789         time.sleep(sleep_for_time)
00790 
00791     return errorFlag
00792     
00793     
00794 ##
00795 # @if jp
00796 # @brief 接続、activate、切断、deactivateを繰り返す。 
00797 #
00798 #
00799 # @else
00800 # @brief 
00801 #
00802 #
00803 # @endif
00804 def test_connection_2(message,arg0,arg1,arg2):
00805     
00806     errorFlag = True
00807     
00808     for i in range(loop_count):
00809     
00810         ## 2 受信データファイル削除
00811         delete_recv_file()
00812     
00813         ## 1 コネクタープロファイル設定
00814         make_connecter_profile("flush", "", 0)
00815     
00816         ## 3 ポート接続
00817         bool_ret = connect_ports()
00818         if bool_ret!=True:
00819             errorFlag = False
00820     
00821         ## 4 アクティベート
00822         bool_ret = activate_components(sleep_recv_act_time)
00823         if bool_ret!=True:
00824             errorFlag = False
00825     
00826         time.sleep(sleep_act_time)
00827     
00828         ## 6 ポート切断
00829         bool_ret = disconnect_ports()
00830         if bool_ret!=True:
00831             errorFlag = False
00832     
00833         ## 5 ディアクティベート
00834         bool_ret = deactivate_components()
00835         if bool_ret!=True:
00836             errorFlag = False
00837     
00838         ## 受信ファイル有無判定
00839         if os.path.isfile(g_diff_recv_file) == False:
00840             errorFlag = False
00841             fout = open(g_test_result_file, 'a')
00842             message = g_test_ng
00843             fout.write(message + '\n')
00844             fout.close()
00845             print message,
00846             sys.stdout.flush()
00847             time.sleep(sleep_for_time)
00848             continue
00849     
00850         ## 7 送受信データ比較
00851         time.sleep(sleep_act_time)
00852         bret = diff_file()
00853     
00854         ## 差分ファイルからテスト結果出力
00855         fout = open(g_test_result_file, 'a')
00856         # bret==True なら送受信データ一致
00857         if bret == True:
00858             # テスト結果 OK
00859             message = g_test_ok
00860             print message ,
00861             sys.stdout.flush()
00862             fout.write(message + '\n')
00863         else:
00864             errorFlag = False
00865             # テスト結果 NG
00866             message = g_test_ng
00867             print message ,
00868             sys.stdout.flush()
00869             fout.write(message + '\n')
00870             # 受信データをテスト結果ファイルへコピー
00871             fin2 = open(g_diff_recv_file, 'r')
00872             while(1):
00873                 s2 = fin2.readline()
00874                 if len(s2) == 0:
00875                     break
00876                 fout.write(s2)
00877             fin2.close()
00878         fout.close()
00879         ## 差分ファイルからテスト結果出力
00880         time.sleep(sleep_for_time)
00881 
00882     return errorFlag
00883     
00884     
00885 ##
00886 # @if jp
00887 # @brief activate、接続、deactivate、切断を繰り返す。 
00888 #
00889 #  データのチェックは行われない。 
00890 #  注意:Activateを先に行っている為、受信データは途中からの内容になります。
00891 #  periodic,newの接続テストでは、ポリシーがSKIP,NEWの場合、
00892 #  データの確認は行わない。
00893 #
00894 # @else
00895 # @brief 
00896 #
00897 #
00898 # @endif
00899 def test_connection_3(message,arg0,arg1,arg2):
00900     
00901     errorFlag = True
00902 
00903     for i in range(loop_count):
00904     
00905         ## 2 受信データファイル削除
00906         delete_recv_file()
00907     
00908         ## 1 コネクタープロファイル設定
00909         make_connecter_profile(arg0,arg1,arg2)
00910     
00911         ## 4 アクティベート
00912         bool_ret = activate_components(sleep_recv_act_time)
00913         if bool_ret!=True:
00914             errorFlag = False
00915     
00916         ## 3 ポート接続
00917         bool_ret = connect_ports()
00918         if bool_ret!=True:
00919             errorFlag = False
00920     
00921         time.sleep(sleep_act_time)
00922     
00923         ## 5 ディアクティベート
00924         bool_ret = deactivate_components()
00925         if bool_ret!=True:
00926             errorFlag = False
00927     
00928         ## 6 ポート切断
00929         bool_ret = disconnect_ports()
00930         if bool_ret!=True:
00931             errorFlag = False
00932     
00933         ## 受信ファイル有無判定
00934         if os.path.isfile(g_diff_recv_file) == False:
00935             errorFlag = False
00936             fout = open(g_test_result_file, 'a')
00937             message = g_test_ng
00938             fout.write(message + '\n')
00939             fout.close()
00940             print message,
00941             sys.stdout.flush()
00942             time.sleep(sleep_for_time)
00943             continue
00944     
00945         ## 7 送受信データ比較
00946         time.sleep(sleep_act_time)
00947         fout = open(g_test_result_file, 'a')
00948         fsize=os.path.getsize(g_diff_recv_file)
00949         if fsize > 0:
00950             message = g_test_ok
00951             print message ,
00952             sys.stdout.flush()
00953             fout.write(message)
00954         else:
00955             errorFlag = False
00956             # テスト結果 NG
00957             message = g_test_ng
00958             print message ,
00959             sys.stdout.flush()
00960             fout.write(message)
00961 
00962         fout.close()
00963     
00964         time.sleep(sleep_for_time)
00965     
00966     return errorFlag
00967 
00968     
00969 ##
00970 # @if jp
00971 # @brief activate、接続、切断、deactivateを繰り返す。 
00972 #
00973 #  データのチェックは行われない。 
00974 #  注意:Activateを先に行っている為、受信データは途中からの内容になります。
00975 #  periodic,newの接続テストでは、ポリシーがSKIP,NEWの場合、
00976 #  データの確認は行わない。
00977 #
00978 # @else
00979 # @brief 
00980 #
00981 #
00982 # @endif
00983 def test_connection_4(message,arg0,arg1,arg2):
00984     
00985     errorFlag = True
00986     for i in range(loop_count):
00987     
00988         ## 2 受信データファイル削除
00989         delete_recv_file()
00990     
00991         ## 1 コネクタープロファイル設定
00992         make_connecter_profile(arg0,arg1,arg2)
00993     
00994         ## 4 アクティベート
00995         bool_ret = activate_components(sleep_recv_act_time)
00996         if bool_ret!=True:
00997             errorFlag = False
00998     
00999         ## 3 ポート接続
01000         bool_ret = connect_ports()
01001         if bool_ret!=True:
01002             errorFlag = False
01003     
01004         time.sleep(sleep_act_time)
01005     
01006         ## 6 ポート切断
01007         bool_ret = disconnect_ports()
01008         if bool_ret!=True:
01009             errorFlag = False
01010     
01011         ## 5 ディアクティベート
01012         bool_ret = deactivate_components()
01013         if bool_ret!=True:
01014             errorFlag = False
01015     
01016         ## 受信ファイル有無判定
01017         if os.path.isfile(g_diff_recv_file) == False:
01018             errorFlag = False
01019             fout = open(g_test_result_file, 'a')
01020             message = g_test_ng
01021             fout.write(message + '\n')
01022             fout.close()
01023             print message,
01024             sys.stdout.flush()
01025             time.sleep(sleep_for_time)
01026             continue
01027     
01028         ## 7 送受信データ比較
01029         time.sleep(sleep_act_time)
01030         fout = open(g_test_result_file, 'a')
01031         fsize=os.path.getsize(g_diff_recv_file)
01032         if fsize > 0:
01033             message = g_test_ok
01034             print message ,
01035             sys.stdout.flush()
01036             fout.write(message)
01037         else:
01038             errorFlag = False
01039             # テスト結果 NG
01040             message = g_test_ng
01041             print message ,
01042             sys.stdout.flush()
01043             fout.write(message)
01044 
01045         fout.close()
01046     
01047         time.sleep(sleep_for_time)
01048 
01049     return errorFlag
01050     
01051 ##
01052 # @if jp
01053 # @brief テストテーブル
01054 # @else
01055 # @brief Test table
01056 # @endif
01057 test_table = [
01058     [ test_connect_disconnect,
01059       "Connect(out->in, flush) -> Disconnect",
01060       "flush", "", 0 ],
01061     [ test_connect_disconnect,
01062       "Connect(in->out, flush) -> Disconnect",
01063       "flush", "", 1 ],
01064     [ test_activate_deactivate,
01065       "Connecting(out->in, flush), Activate -> send/recv -> Deactivate",
01066       "flush", "", 0 ],
01067     [ test_activate_deactivate,
01068       "Connecting(in->out, flush), Activate -> send/recv -> Deactivate",
01069       "flush", "", 1 ],
01070     [ test_activate_deactivate_2,
01071       "Not Connect(out->in, flush), Activate -> Deactivate",
01072       "flush", "", 0 ],
01073     [ test_connection,
01074       "Connect(out->in, flush) -> Activate -> send/recv -> Deactivate -> Disconnect",
01075       "flush", "", 0 ],
01076     [ test_connection,
01077       "Connect(in->out, flush) -> Activate -> send/recv -> Deactivate -> Disconnect",
01078       "flush", "", 1 ],
01079     [ test_connection_2,
01080       "Connect(out->in, flush) -> Activate -> send/recv -> Disconnect -> Deactivate",
01081       "flush", "", 0 ],
01082     [ test_connection_2,
01083       "Connect(in->out, flush) -> Activate -> send/recv -> Disconnect -> Deactivate",
01084       "flush", "", 1 ],
01085     [ test_connection_3,
01086       "Activate -> Connect(out->in, flush) -> send/recv -> Deactivate -> Disconnect",
01087       "flush", "", 0 ],
01088     [ test_connection_3,
01089       "Activate -> Connect(in->out, flush) -> send/recv -> Deactivate -> Disconnect",
01090       "flush", "", 1 ],
01091     [ test_connection_4,
01092       "Activate -> Connect(out->in, flush) -> send/recv -> Disconnect -> Deactivate",
01093       "flush", "", 0 ],
01094     [ test_connection_4,
01095       "Activate -> Connect(in->out, flush) -> send/recv -> Disconnect -> Deactivate",
01096       "flush", "", 1 ],
01097     [ test_connect_disconnect,
01098       "Connect(out->in, new,ALL) -> Disconnect",
01099       "new", "ALL", 0 ],
01100     [ test_connect_disconnect,
01101       "Connect(out->in, new,FIFO) -> Disconnect",
01102       "new", "FIFO", 0 ],
01103     [ test_connect_disconnect,
01104       "Connect(out->in, new,NEW) -> Disconnect",
01105       "new", "NEW", 0 ],
01106     [ test_connect_disconnect,
01107       "Connect(out->in, new,SKIP) -> Disconnect",
01108       "new", "SKIP", 0 ],
01109     [ test_connect_disconnect,
01110       "Connect(in->out, new,ALL) -> Disconnect",
01111       "new", "ALL", 1 ],
01112     [ test_connect_disconnect,
01113       "Connect(in->out, new,FIFO) -> Disconnect",
01114       "new", "FIFO", 1 ],
01115     [ test_connect_disconnect,
01116       "Connect(in->out, new,NEW) -> Disconnect",
01117       "new", "NEW", 1 ],
01118     [ test_connect_disconnect,
01119       "Connect(in->out, new,SKIP) -> Disconnect",
01120       "new", "SKIP", 1 ],
01121     [ test_activate_deactivate,
01122       "Connecting(out->in, new,ALL), Activate -> send/recv -> Deactivate",
01123       "new", "ALL", 0 ],
01124     [ test_activate_deactivate,
01125       "Connecting(out->in, new,FIFO), Activate -> send/recv -> Deactivate",
01126       "new", "FIFO", 0 ],
01127     [ test_activate_deactivate,
01128       "Connecting(out->in, new,NEW), Activate -> send/recv -> Deactivate",
01129       "new", "NEW", 0 ],
01130     [ test_activate_deactivate_2,
01131       "Connecting(out->in, new,SKIP), Activate -> send/recv -> Deactivate",
01132       "new", "SKIP", 0 ],
01133     [ test_activate_deactivate,
01134       "Connecting(in->out, new,ALL), Activate -> send/recv -> Deactivate",
01135       "new", "ALL", 1 ],
01136     [ test_activate_deactivate,
01137       "Connecting(in->out, new,FIFO), Activate -> send/recv -> Deactivate",
01138       "new", "FIFO", 1 ],
01139     [ test_activate_deactivate_2,
01140       "Connecting(in->out, new,NEW), Activate -> send/recv -> Deactivate",
01141       "new", "NEW", 1 ],
01142     [ test_activate_deactivate_2,
01143       "Connecting(in->out, new,SKIP), Activate -> send/recv -> Deactivate",
01144       "new", "SKIP", 1 ],
01145     [ test_connection,
01146       "Connect(out->in, new,ALL) -> Activate -> send/recv -> Deactivate -> Disconnect",
01147       "new", "ALL", 0 ],
01148     [ test_connection,
01149       "Connect(out->in, new,FIFO) -> Activate -> send/recv -> Deactivate -> Disconnect",
01150       "new", "FIFO", 0 ],
01151     [ test_connection_5,
01152       "Connect(out->in, new,NEW) -> Activate -> send/recv -> Deactivate -> Disconnect",
01153       "new", "NEW", 0 ],
01154     [ test_connection_5,
01155       "Connect(out->in, new,SKIP) -> Activate -> send/recv -> Deactivate -> Disconnect",
01156       "new", "SKIP", 0 ],
01157     [ test_connection,
01158       "Connect(in->out, new,ALL) -> Activate -> send/recv -> Deactivate -> Disconnect",
01159       "new", "ALL", 1 ],
01160     [ test_connection,
01161       "Connect(in->out, new,FIFO) -> Activate -> send/recv -> Deactivate -> Disconnect",
01162       "new", "FIFO", 1 ],
01163     [ test_connection_5,
01164       "Connect(in->out, new,NEW) -> Activate -> send/recv -> Deactivate -> Disconnect",
01165       "new", "NEW", 1 ],
01166     [ test_connection_5,
01167       "Connect(in->out, new,SKIP) -> Activate -> send/recv -> Deactivate -> Disconnect",
01168       "new", "SKIP", 1 ],
01169     [ test_connect_disconnect,
01170       "Connect(out->in, periodic,ALL) -> Disconnect",
01171       "periodic", "ALL", 0 ],
01172     [ test_connect_disconnect,
01173       "Connect(out->in, periodic,FIFO) -> Disconnect",
01174       "periodic", "FIFO", 0 ],
01175     [ test_connect_disconnect,
01176       "Connect(out->in, periodic,NEW) -> Disconnect",
01177       "periodic", "NEW", 0 ],
01178     [ test_connect_disconnect,
01179       "Connect(out->in, periodic,SKIP) -> Disconnect",
01180       "periodic", "SKIP", 0 ],
01181     [ test_connect_disconnect,
01182       "Connect(in->out, periodic,ALL) -> Disconnect",
01183       "periodic", "ALL", 1 ],
01184     [ test_connect_disconnect,
01185       "Connect(in->out, periodic,FIFO) -> Disconnect",
01186       "periodic", "FIFO", 1 ],
01187     [ test_connect_disconnect,
01188       "Connect(in->out, periodic,NEW) -> Disconnect",
01189       "periodic", "NEW", 1 ],
01190     [ test_connect_disconnect,
01191       "Connect(in->out, periodic,SKIP) -> Disconnect",
01192       "periodic", "SKIP", 1 ],
01193     [ test_activate_deactivate,
01194       "Connecting(out->in, periodic,ALL), Activate -> send/recv -> Deactivate",
01195       "periodic", "ALL", 0 ],
01196     [ test_activate_deactivate,
01197       "Connecting(out->in, periodic,FIFO), Activate -> send/recv -> Deactivate",
01198       "periodic", "FIFO", 0 ],
01199     [ test_activate_deactivate_2,
01200       "Connecting(out->in, periodic,NEW), Activate -> send/recv -> Deactivate",
01201       "periodic", "NEW", 0 ],
01202     [ test_activate_deactivate_2,
01203       "Connecting(out->in, periodic,SKIP), Activate -> send/recv -> Deactivate",
01204       "periodic", "SKIP", 0 ],
01205     [ test_activate_deactivate,
01206       "Connecting(in->out, periodic,ALL), Activate -> send/recv -> Deactivate",
01207       "periodic", "ALL", 1 ],
01208     [ test_activate_deactivate,
01209       "Connecting(in->out, periodic,FIFO), Activate -> send/recv -> Deactivate",
01210       "periodic", "FIFO", 1 ],
01211     [ test_activate_deactivate_2,
01212       "Connecting(in->out, periodic,NEW), Activate -> send/recv -> Deactivate",
01213       "periodic", "NEW", 1 ],
01214     [ test_activate_deactivate_2,
01215       "Connecting(in->out, periodic,SKIP), Activate -> send/recv -> Deactivate",
01216       "periodic", "SKIP", 1 ],
01217     [ test_connection,
01218       "Connect(out->in, periodic,ALL) -> Activate -> send/recv -> Deactivate -> Disconnect",
01219       "periodic", "ALL", 0 ],
01220     [ test_connection,
01221       "Connect(out->in, periodic,FIFO) -> Activate -> send/recv -> Deactivate -> Disconnect",
01222       "periodic", "FIFO", 0 ],
01223     [ test_connection_5,
01224       "Connect(out->in, periodic,NEW) -> Activate -> send/recv -> Deactivate -> Disconnect",
01225       "periodic", "NEW", 0 ],
01226     [ test_connection_5,
01227       "Connect(out->in, periodic,SKIP) -> Activate -> send/recv -> Deactivate -> Disconnect",
01228       "periodic", "SKIP", 0 ],
01229     [ test_connection,
01230       "Connect(in->out, periodic,ALL) -> Activate -> send/recv -> Deactivate -> Disconnect",
01231       "periodic", "ALL", 1 ],
01232     [ test_connection,
01233       "Connect(in->out, periodic,FIFO) -> Activate -> send/recv -> Deactivate -> Disconnect",
01234       "periodic", "FIFO", 1 ],
01235     [ test_connection_5,
01236       "Connect(in->out, periodic,NEW) -> Activate -> send/recv -> Deactivate -> Disconnect",
01237       "periodic", "NEW", 1 ],
01238     [ test_connection_5,
01239       "Connect(in->out, periodic,SKIP) -> Activate -> send/recv -> Deactivate -> Disconnect",
01240       "periodic", "SKIP", 1 ],
01241 
01242 ]
01243 ##
01244 # @if jp
01245 # @brief main
01246 # @else
01247 # @brief main
01248 # @endif
01249 def main():
01250     
01251     initGlobal()
01252     ok_counter = 0
01253     ng_counter = 0
01254 
01255     exit = 0
01256     result_message = ""
01257     for element in test_table:
01258         components_entry()
01259         
01260         message = g_mess_header + g_test_case 
01261         message = message + element[1]
01262         message = message + g_mess_footer
01263         fout = open(g_test_result_file, 'a')
01264         fout.write('\n' + message)
01265         fout.close()
01266         print "" 
01267         print message
01268         ret = element[0](message,element[2],element[3],element[4])
01269         components_exit()
01270         if ret == False:
01271             ng_counter = ng_counter + 1
01272             exit = 1
01273             result_message = "!!!FAILURES!!!"
01274             break;
01275         else :
01276             ok_counter = ok_counter + 1
01277         
01278 
01279     print ""
01280     print result_message 
01281     print "Test Results: " 
01282     print "Run:",ok_counter+ng_counter,"   Failures:", ng_counter
01283     return exit 
01284 if __name__ == "__main__":
01285   main()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17