日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

嵌入式测试大赛实例解析

發布時間:2024/3/26 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 嵌入式测试大赛实例解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

明天就是嵌入式大賽的預選賽了,今晚加班寫個博客
1、安裝環境

下載了官方的安裝包之后,官方給出了詳細的安裝說明,下載請看百度網盤地址:
鏈接:https://pan.baidu.com/s/1ngYQK3c2P1e367SFC3Q__A 密碼:dwud

1.1、首先安裝VSDP,具體的文件名為:

vspdxp_install.exe

1.2、配置虛擬串口
運行

vspdconfig.exe

在彈出來的軟件頁面中選擇

COM5 COM6

這兩個串口
1.3、安裝ETest軟件

ETest2018大賽專版-Setup.exe

1.4、運行Etest軟件-進程調度服務
1.5、運行測試設計臺
1.6、打開給定的測試項目文件
1.7、在“設備規劃”上點擊右鍵,選擇“編輯”,打開設備規劃
1.8、.選中“物理通道”下面的“232”,打開“屬性”標簽頁,選擇“端口名”為一對虛擬串口
中的一個
1.9、運行被測軟件,啟動服務,選擇端口號
1.10、打開測試項目中的測試“功能 2”
1.11、首先進行“環境設置”
1.12、點擊“運行”
1.13、使用對話框判斷測試結果
1.14、查看界面輸出結果

2、例題一
題目分享:鏈接:https://pan.baidu.com/s/1uPS_y3bo_OLRc0FFZqpvkw 密碼:rsjg

題目由一個需求文檔和測試要求給出,這是關于模擬水流監控計費器的題目
2.1、定義協議:

如仿真圖所示,這里定義了Protocol_1和Protocol_2以及CH_232_1三種自定義通信類型。具體的實現如下

//協議Protocol_1 Protocol MainSegment 包頭 StandardUInt16 Default=0X55AA ByteOrder=BigSegment 閥門控制器ID StandardUInt8 Default=0Segment 水流監控計費器ID StandardUInt8 Default=0X20Segment 瞬時流量 StandardFloat Default=0.0Segment 計費標志 StandardUInt8 Default=0Segment 管道壓力 StandardFloat Default=0.0Segment 校驗和 CRC Algorithm=CRC_SUM_8 BitCount=16 Range=(16,0) Segment 包尾 StandardUInt16 Default=0X55AA ByteOrder=Big End//協議Protocol_2 Protocol MainSegment 包頭 StandardUInt16 Default=0X55AA ByteOrder=BigSegment 水流監控計費器ID StandardUInt8 Default=0X20Segment 閥門控制器ID StandardUInt8 Default=0Segment 瞬時流量報警標志 StandardUInt8 Default=0Segment 管道壓力控制指令 StandardUInt8 Default=0Segment 校驗和 CRC Algorithm=CRC_SUM_8 BitCount=8 Range=(16,0)Segment 包尾 StandardUInt16 Default=0X55AA ByteOrder=Big End//協議CH_232_1似乎是系統定義的

遇到了一個報錯

提示我協議沒有定義,但是實際上協議是定義了的,只不過這兩個東西沒有嵌入起來
3、例題二
題目分享:鏈接:https://pan.baidu.com/s/1P16uKgLtrLjIl1o5Jo9y1Q 密碼:nmbs
模擬共享單車
這道題是去年秋季賽的分區預賽題目
按照以上的操作,打開待測元器件的服務端(也就是.exe結尾的應用程序),然后打開功能3的測試

//功能三描述 2.3 位置信息的接收處理(GN_WZ) GPS 模塊定時(1s)向外發送位置信息,鎖具控制模塊接收并處理 GPS 發送 位置信息。 序號 數據名稱 單位 范圍 1 經度 度 0-180 2 經度標志位 固定值 0X45E-東經),0X57(W-西經) 3 緯度 度 0-90 4 緯度標志位 固定值 0X4EN-北緯),0X53(S-南緯) 由于位置信息是 GPS 模塊定時發送的,為可靠性起見,需要進行如下容錯處 理: 1、當接收到的位置信息超出范圍時,該 GPS 數據幀無效,做丟包處理,鎖 具控制模塊使用上一幀的信息; 2、經緯度標志位不正確時,鎖具控制模塊使用上一幀的位置信息。 3、經度、緯度四舍五入方式保留三位小數。

測試代碼示例:

import Manu ############標準測試模板####################### ## Test:測試數據執行函數體,【測試數據】每一行數據調用一次Test ## arg:輸入參數 ## exp:預期輸出 def Test(arg,exp):print 'Hello World!'for a in arg:print afor e in exp:print eProtocol_gpstime.Hour.Value=arg[0]Protocol_gpstime.Minute.Value=arg[1]Protocol_gpstime.Second.Value=arg[2]Protocol_gpstime.JingDu.Value=arg[3]Protocol_gpstime.Flag_JD.Value=arg[4]Protocol_gpstime.WeiDu.Value=arg[5]Protocol_gpstime.Flag_WD.Value=arg[6]Protocol_gpstime.Write()show=[]str='輸入數據:時%d,分%d,秒%d,經度%f,經度標識%d,緯度%f,緯度標識%d\n' %(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6])show.append(str)show.append(exp[0])passed=Manu.Check(show)print '測試結果:%s' %passed# 斷言:根據實際需求修改一下注釋的部分 assertor=API.Platform.Assertion.Create()assertor.AddInput('時',arg[0])assertor.AddInput('分',arg[1])assertor.AddInput('秒',arg[2])assertor.AddInput('經度',arg[3])assertor.AddInput('經度標識',arg[4])assertor.AddInput('緯度',arg[5])assertor.AddInput('緯度標識',arg[6])assertor.AddOutput('界面顯示',exp[0],passed)if passed:#測試通過assertor.Pass()else:assertor.Failed()b=assertor.Commit()## Standard_Test:標準測試的方法入口,使用【測試數據】表循環調用Test方法 Standard_Test(Test) #########################################################自定義測試模板####################### ## 如果不希望使用測試數據驅動測試,則將【標準測試模板】刪除,使用【自定義模板】 ## 否則可以刪除本節 #def Main(): # print 'Hello world' #Main() #################################################

測試結果既可以通過應用程序查看

也可以通過日志文件進行查看

再來看一個接口測試的示例
接口4的需求為:

在騎行狀態下,鎖具控制模塊要在相對固定的時間(6-10S)內向服務器上 報位置信息

為了清除剛才的環境,可以點擊清除環境設置,然后點開接口4的測試,自己寫上測試代碼,點擊清理環境。
這是例題給的測試代碼:

import time,Manu ############標準測試模板####################### ## Test:測試數據執行函數體,【測試數據】每一行數據調用一次Test ## arg:輸入參數 ## exp:預期輸出 def Test(arg,exp):print 'Hello World!'print '輸入參數:%s' %arg[0]print '預期輸出:%s' %exp[0]arg=arg[0].split(',')l=[]for a in arg:l.append(int(a,16))b=RS232通道.Write(l)API.Common.Timer.Normal.Sleep(100)t1=time.time()t2=t1out=''while t2-t1<10:bool=Protocol_ServerOutput.Read()t2=time.time()if bool and Protocol_ServerOutput.Flag.Value==2: # array=Protocol_ServerOutput.ToBytes() # for a in array: # h='%02X' %a # out+=str(h) # out+=',' # # print '輸出的數據:%s' %out[:-1]breakpassed=Trueif Protocol_ServerOutput.Head.Value!=0x55AA:passed=Falseprint '包頭錯誤! %s' %Protocol_ServerOutput.Head.Valueif Protocol_ServerOutput.BikeID.Value!=0xBB:passed=Falseprint '包頭錯誤! %s' %Protocol_ServerOutput.Head.Valueif Protocol_ServerOutput.jiaoyanhe.Checked!=True:passed=Falseprint '校驗和錯誤!'if Protocol_ServerOutput.Tail.Value!=0x55AA:passed=Falseprint '包尾錯誤! %s' %Protocol_ServerOutput.Tail.Value## 斷言:根據實際需求修改一下注釋的部分 assertor=API.Platform.Assertion.Create()assertor.AddInput('輸入數據:',arg[0])assertor.AddOutput('輸出數據:',exp[0],out)if passed:#測試通過assertor.Pass()print "服務器位置與時間上報輸出接口正確。"else:assertor.Failed()print "服務器位置與時間上報輸出接口錯誤!"b=assertor.Commit()## Standard_Test:標準測試的方法入口,使用【測試數據】表循環調用Test方法 Standard_Test(Test) #############################################

運行結果為

性能測試示例:
需求:

在騎行狀態下,鎖具控制模塊定時上報位置與時間信息要控制在 6-10s 之間

示例代碼:

import time t1=time.time() def Test(arg,exp):global t1print 'Hello World!'t2=time.time()while True:bool=Protocol_ServerOutput.Read()t2=time.time()if bool:breakprint 'GPS上報時間間隔為:%.2f秒' %(t2-t1)passed=Falseif int(t2-t1)>=6 and int(t2-t1)<=10:passed=True## 斷言:根據實際需求修改一下注釋的部分 assertor=API.Platform.Assertion.Create()assertor.AddOutput('輸出參數1',exp[0],str(t2-t1))if passed:#測試通過assertor.Pass()else:assertor.Failed()t1=t2b=assertor.Commit()## Standard_Test:標準測試的方法入口,使用【測試數據】表循環調用Test方法 Standard_Test(Test) #############################################

測試結果:

4、例題三
題目分享:鏈接:https://pan.baidu.com/s/1OmASWyIFUvYCzqtJX8SFJA 密碼:n06t
模擬空調
2017年嵌入式測試分區決賽題目
注意:

1.端口設置錯誤,可能會出現“打開XXX通道失敗,可能會導致部分測試腳本失效”的問題 2.如果服務端口與協議端口重復,會導致服務端口不可用,所以最好(一定)每個協議使用不 同的端口,且端口號不能與.exe的應用程序用到的端口沖突。

4.1、溫度測試

import Manu ############標準測試模板####################### ## Test:測試數據執行函數體,【測試數據】每一行數據調用一次Test ## arg:輸入參數 ## exp:預期輸出 def Test(arg,exp):print '測試用例%d:命令設定溫度值為%d' % (arg[1],arg[0])Protocol_1.Tmp.Value=arg[0]Protocol_1.Write()API.Common.Timer.Normal.Sleep(1000)show=[]str = '遙控器設定溫度為:%d,界面預期顯示為:%d' % (arg[0],exp[0])show.append(str)show.append('界面室溫顯示是否正確?')passed=Manu.Check(show)if(passed):print '界面顯示與預期一致,界面判斷通過'else:print '界面顯示與預期不一致,界面判斷不通過'## 斷言:根據實際需求修改一下注釋的部分 assertor=API.Platform.Assertion.Create()assertor.AddInput('命令設置溫度',arg[0])assertor.AddOutput('界面顯示溫度',exp[0],passed)if (arg[0]<16 and exp[0]==16 and passed) or (arg[0]>30 and exp[0]==30 and passed) or (16<=arg[0]<=30 and exp[0]==arg[0] and passed) :#測試通過print '本次測試通過。'assertor.Pass()else:print '本次測試不通過,請輸入測試問題'assertor.Failed()b=assertor.Commit()## Standard_Test:標準測試的方法入口,使用【測試數據】表循環調用Test方法 Standard_Test(Test)

每次重新進行測試時最好清理環境,避免因上一個測試用例的結果影響到接下來的測試

總結

以上是生活随笔為你收集整理的嵌入式测试大赛实例解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。