0
Tải bản đầy đủ (.pdf) (74 trang)

Hƣớng phát triển

Một phần của tài liệu NGHIÊN CỨU ỨNG DỤNG “NMODEL” TRONG VIỆC PHÁT TRIỂN HỆ THỐNG NHÚNG THỜI GIAN THỰC (Trang 68 -68 )

Trong luận văn này, tôi đã tìm hiểu và thực hiện đƣợc phân tích và kiểm thử dựa trên mô hình đối với hệ thống đóng có các trạng thái đơn giản. Demo với chƣơng trình nhỏ nhƣng đầy đủ. Tuy nhiên, do gặp khó khăn về mặt thời gian nên luận văn vẫn còn một số hạn chế là bài toán chƣa có điều kiện để cài đặt với hệ thống thực, và bài toán có khả năng chạy trên hệ thống thực nhƣng chƣa đáp ứng đƣợc về mặt thời gian thực. Do đó, trong tƣơng lai, tôi có hƣớng phát triển là: tôi sẽ tiếp tục tìm hiều và nghiên cứu về kiểm thử dựa trên mô hình với NModel trong hệ thống phản ứng có các trạng thái phức tạp, đáp ứng đƣợc về mặt thời gian thực.

TÀI LIỆU THAM KHẢO Tiếng Việt

1. TS. Lƣu Hồng Việt, “Tài liệu tóm tắt bài giảng Hệ thống điều khiển nhúng”, Đại học Bách Khoa Hà Nội.

Tiếng Anh

2. Colin Campbell, Margus Veanes, and Jonathan Jacky (2007, 2008), “NModel Reference”.

3. J. A. Cook J. S. Freudenberg (2008), “Embedded Software Architecture”, EECS 461.

4. Jonathan Jacky, Margus Veanes, Colin Campbell, Wolfram Schulte Cambridge University Press (2008, available December 2007), “Model-based Software Testing and Analysis with C#”, Cambridge University.

5. Juhan Ernits, Margus Veanes, and Johannes Helander (June 2008), “

Model-Based

Testing of Robots with NModel”.

6. Juhan Ernits, Rivo Roo, Jonathan Jacky, Margus Veanes (2009), “Model-Based Testing of Web Applications Using NModel”.

7. M. Veanes, C. Campbell, W. Grieskamp, L. Nachmanson, W. Schulte, and N. Tillmann (2005), Model-based testing of object-oriented reactive systems with Spec Explorer, Tech. Rep. MSR-TR-2005-59, Microsoft Research. Preliminary version of a book chapter in the forthcoming text book Formal Methods and Testing.

8. M. Broy, B. Jonsson, J.-P. Katoen, M. Leucker, and A. Pretschner (The volume is the outcome of a research seminar that was held in Schloss Dagstuhl in January 2004), editors, Model-Based Testing of Reactive Systems.

Website 9. http://nmodel.codeplex.com/ 10. http://blogs.msdn.com/b/specexplorer/archive/2009/10/27/what-is-model- based-testing.aspx 11. http://nmodelrs.berlios.de/ 12. http://www.kiemthuphanmem.com/blogs/3/24/model-based-testing-l-g-mbt) 13. http://voer.edu.vn/c/he-dieu-hanh-cho-cac-he-thong-nhung-hdh-thoi-gian- thuc/9f009757/07006533#.UzP9xc51mKE 14. http://www.testingvn.com/

PHỤ LỤC

HỆ THỐNG CLIENT/SERVER

Chƣơng trình mô hình contract client/server có tên là ClientServer: using NModel;

using NModel.Attributes; using NModel.Execution; namespace ClientServer {

public enum Socket { None, Created, Bound, Listening, Connecting, Connected, Disconnected, Closed }

public enum Phase { Send, ServerReceive, ClientReceive } public static class ClientServer

{

const double EmptyBuffer = double.MaxValue;

const double Temp2 = 99.9; // Temperature, 2 digits const double Temp3 = 100.0; // Temperature, 3 digits

// Biến trạng thái điều khiển

public static Socket serverSocket = Socket.None; public static Socket clientSocket = Socket.None; public static Phase phase = Phase.Send;

// Trạng thái dữ liệu

public static double clientBuffer = EmptyBuffer;

// Điều kiện trạng thái chấp nhận cho việc kiểm thử [AcceptingStateCondition]

static bool BothClosed() {

return (serverSocket == Socket.Closed && clientSocket == Socket.Closed); }

// Các điều kiện và hành động cho phép của Server public static bool ServerSocketEnabled()

{

return (serverSocket == Socket.None); }

[Action]

public static void ServerSocket() {

serverSocket = Socket.Created; }

public static bool ServerBindEnabled() {

return (serverSocket == Socket.Created); }

[Action]

public static void ServerBind() {

serverSocket = Socket.Bound; }

public static bool ServerListenEnabled() {

return (serverSocket == Socket.Bound); }

[Action]

public static void ServerListen() {

serverSocket = Socket.Listening; }

public static bool ServerAcceptEnabled() {

return (serverSocket == Socket.Listening && clientSocket ==

}

[Action]

public static void ServerAccept() {

serverSocket = Socket.Connected; clientSocket = Socket.Connected; }

public static bool ServerReceiveEnabled() {

return (serverSocket == Socket.Connected && phase == Phase.ServerReceive); }

// Các hành động Send ở trong MP này không cần tham số [Action]

public static void ServerReceive() {

phase = Phase.Send; }

public static bool ServerSendEnabled() {

return (serverSocket == Socket.Connected

&& phase == Phase.Send && clientSocket == Socket.Connected); }

// Dùng tham số ở đây, Server có thể gửi các nhiệt độ khác nhau [Action]

public static void ServerSend([Domain("Temperatures")] double datum) {

clientBuffer = datum;

phase = Phase.ClientReceive; }

// Tên miền cho tham số ServerSend là t static Set<double> Temperatures() {

return new Set<double>(Temp2, Temp3); }

public static bool ServerCloseConnectionEnabled() {

return (serverSocket == Socket.Connected); }

[Action]

public static void ServerCloseConnection() {

serverSocket = Socket.Disconnected; }

// Ngăn chặn Client bị treo

public static bool ServerCloseEnabled() {

return (serverSocket != Socket.None

// && serverSocket != Socket.Listening

&& serverSocket != Socket.Connected && serverSocket != Socket.Closed); }

[Action]

public static void ServerClose() {

serverSocket = Socket.Closed; }

// Các điều kiện và hành động được phép của Client public static bool ClientSocketEnabled()

{

return (clientSocket == Socket.None); }

[Action]

public static void ClientSocket() {

clientSocket = Socket.Created; }

public static bool ClientConnectEnabled() {

return (clientSocket == Socket.Created && serverSocket ==

Socket.Listening); }

[Action]

public static void ClientConnect() {

clientSocket = Socket.Connecting; }

public static bool ClientSendEnabled() {

return (clientSocket == Socket.Connected && phase == Phase.Send); }

// Hành động Send của client ko có tham số [Action]

public static void ClientSend() {

phase = Phase.ServerReceive; }

public static bool ClientReceiveEnabled() {

return (clientSocket == Socket.Connected && phase == Phase.ClientReceive); }

// Trả về giá trị cần thiết ở đây, server gửi các giá trị khác nhaue [Action]

public static double ClientReceive() {

double t = clientBuffer; clientBuffer = EmptyBuffer; phase = Phase.Send;

return t; }

public static bool ClientCloseEnabled() {

return (clientSocket == Socket.Connected && phase == Phase.Send);

}

[Action] public static void ClientClose() {

clientSocket = Socket.Closed; }

}

public static class Factory

{

public static ModelProgram Create() {

return new LibraryModelProgram(typeof(Factory).Assembly,"ClientServer"); }

}

Xây dựng test harness: using System;

using NModel.Conformance; using NModel.Terms;

namespace ClientServerImpl {

public class Stepper: IStepper

{

const string host = "127.0.0.1"; // localhost Server s = new Server();

Client c = new Client();

public CompoundTerm DoAction(CompoundTerm action) {

switch (action.Name) {

case("Tests"): return null; // hành động đầu tiên trong chuỗi kiểm thử. case("ServerSocket"):

s.Socket(); return null; case("ServerBind"):

s.Bind(host,port); return null; case("ServerListen"):

s.Listen(); return null; case("ServerAccept"):

s.Accept(); return null; case("ServerReceive"):

s.Receive(); return null; case("ServerSend"):

// s.Send gửi một số double, không phải string!

s.Send((double)((Literal) action.Arguments[0]).Value); return null;

case("ServerCloseConnection"): s.CloseConnection(); return null; case("ServerClose"):

s.Close(); return null; case("ClientSocket"):

c.Socket(); return null; case("ClientConnect"):

c.Connect(host,port); return null; case("ClientSend"):

c.Send("T"); return null; case("ClientReceive_Start"):

// c.Receive trả về một số double, không phải string return CompoundTerm.Create("ClientReceive_Finish", c.Receive());

case("ClientClose"): c.Close(); return null;

default: throw new Exception("Unexpected action " + action); }

}

public void Reset() {

s = new Server(); c = new Client(); }

public static IStepper Create() {

return new Stepper(); }

}

Xây dựng các tệp tin dạng .txt cho công cụ mpv, otg, và ct: Tệp tin mpv_contract.txt:

/r:ClientServer.dll /mp:ClientServer /livenessCheckIsOn+

Tệp tin mpv_scenario.txt:

/fsm:Scenario.txt Tệp tin mpv_composition.txt: #Kết hợp MP hợp đồng với MP kịch bản /r:ClientServer.dll /mp:ClientServer /fsm:Scenario.txt /combineActions+ Tệp tin otg_contract.txt: # Referenced assembly /r:ClientServer.dll /mp:ClientServer /file:ContractTest.txt Tệp tin otg_scenario.txt:

# Tạo bộ kiểm thử MP hợp đồng kết hợp với MP kịch bản /r:ClientServer.dll

/mp:ClientServer /fsm:Scenario.txt /file:ScenarioTest.txt

Tệp tin ct_contract.txt:

# Thực hiện kiểm thử với bộ kiểm thử đƣợc tạo từ MP hợp đồng /r:Stepper.dll

/iut:ClientServerImpl.Stepper.Create /testSuite:..\Model\ContractTest.txt

Tệp tin ct_scenario.txt:

# Kiểm thử với bộ kiểm thử có kết hợp MP hợp đồng với MP kịch bản /r:Stepper.dll /iut:ClientServerImpl.Stepper.Create /testSuite:..\Model\ScenarioTest.txt Tệp tin ct_contract_random.txt: /r:Stepper.dll /iut:ClientServerImpl.Stepper.Create /r:..\Model\ClientServer.dll /mp:ClientServer /runs:1 Tệp tin ct_scenario_random.txt:

# Kiểm thử ngẫu nhiên với sự kết hợp của MP hợp đồng và MP kịch bản /r:Stepper.dll

/iut:ClientServerImpl.Stepper.Create /r:..\Model\ClientServer.dll

Một phần của tài liệu NGHIÊN CỨU ỨNG DỤNG “NMODEL” TRONG VIỆC PHÁT TRIỂN HỆ THỐNG NHÚNG THỜI GIAN THỰC (Trang 68 -68 )

×