📄 runtestssheet.cpp
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND####// RunTestsSheet.cpp : implementation file//#include "stdafx.h"#include "eCosTest.h"#include "eCosTrace.h"#include "PropertiesDialog.h"#include "ResetAttributes.h"#include "RunTestsSheet.h"#include "TestResource.h"#include "X10.h"#include <afxpriv.h>static const UINT arIds []={IDOK,IDCANCEL,ID_APPLY_NOW,IDHELP};#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CRunTestsSheetIMPLEMENT_DYNAMIC(CRunTestsSheet, CeCosPropertySheet)CRunTestsSheet::CRunTestsSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage, CBFunc pInitFunc, CRunTestsSheet **ppSheet):CeCosPropertySheet(pszCaption, pParentWnd, iSelectPage), m_pResource(NULL), m_pInitFunc(pInitFunc), m_bAllowResizing(false), m_cxMin(0), m_cyMin(0), m_Status(Stopped), m_bHideTarget(false), m_bHideRemoteControls(false), m_bModal(false), m_prop(_T("Software\\Red Hat\\eCos\\RunTests"),HKEY_CURRENT_USER), m_ppSheet(ppSheet), m_ep(CeCosTest::ExecutionParameters::RUN){ InitializeCriticalSection(&m_CS); AddPage(&executionpage); AddPage(&outputpage); AddPage(&summarypage); }CRunTestsSheet::~CRunTestsSheet(){ if(m_ppSheet){ *m_ppSheet=0; } delete m_pResource; DeleteCriticalSection(&m_CS);}BEGIN_MESSAGE_MAP(CRunTestsSheet, CeCosPropertySheet)//{{AFX_MSG_MAP(CRunTestsSheet)ON_BN_CLICKED(IDOK, OnRun)ON_BN_CLICKED(ID_APPLY_NOW, OnProperties)ON_BN_CLICKED(IDCANCEL, OnClose)ON_MESSAGE(WM_TESTOUTPUT, OnTestOutput)ON_MESSAGE(WM_RUNCOMPLETE, OnTestsComplete)ON_WM_SYSCOMMAND()ON_WM_SIZE()ON_WM_GETMINMAXINFO()ON_WM_TIMER()ON_MESSAGE(WM_KICKIDLE, OnKickIdle)ON_WM_CREATE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CRunTestsSheet message handlersBOOL CRunTestsSheet::OnInitDialog() { if(!m_bHideTarget){ m_prop.Add(_T("Platform"),(void *)&m_strTarget,GetFn,PutFn); } m_prop.Add(_T("Active timeout"),m_nTimeout,900); m_prop.Add(_T("Download timeout"),m_nDownloadTimeout,120); m_prop.Add(_T("Active timeout type"),m_nTimeoutType,TIMEOUT_AUTOMATIC); m_prop.Add(_T("Download timeout type"),m_nDownloadTimeoutType,TIMEOUT_AUTOMATIC); m_prop.Add(_T("Remote"),m_bRemote); m_prop.Add(_T("Serial"),m_bSerial,true); m_prop.Add(_T("Port"),(void *)&m_strPort,GetFn,PutFn,_T("COM1")); m_prop.Add(_T("Baud"),m_nBaud,38400); m_prop.Add(_T("Local TCPIP Host"),(void *)&m_strLocalTCPIPHost,GetFn,PutFn); m_prop.Add(_T("Local TCPIP Port"),m_nLocalTCPIPPort,1); m_prop.Add(_T("Reset Type"),m_nReset,RESET_MANUAL); m_prop.Add(_T("Reset String"),(void *)&m_strReset,GetFn,PutFn); m_prop.Add(_T("Resource Host"),(void *)&m_strResourceHost,GetFn,PutFn); m_prop.Add(_T("Resource Port"),m_nResourcePort,1); m_prop.Add(_T("Remote Host"),(void *)&m_strRemoteHost,GetFn,PutFn); m_prop.Add(_T("Remote Port"),m_nRemotePort,1); m_prop.Add(_T("Recurse"),executionpage.m_bRecurse); //m_prop.Add(_T("Loadfromdir"),executionpage.m_strLoaddir); m_prop.Add(_T("Farmed"),m_bFarmed,true); m_prop.Add(_T("Extension"),(void *)&executionpage.m_strExtension,GetFn,PutFn,_T("*.exe")); m_prop.SetDefaults(); CeCosTrace::SetOutput(TestOutputCallback,this); CeCosTrace::SetError (TestOutputCallback,this); // m_psh can only be used to set the small icon. Set the large one here. m_psh.hIcon=AfxGetApp()->LoadIcon(IDR_TT_MAINFRAME); //sheet.m_psh.dwFlags|=PSH_USEHICON/*|PSH_HASHELP*/; if(m_psh.hIcon){ SetIcon(m_psh.hIcon,FALSE); SetIcon(m_psh.hIcon,TRUE); } GetWindowRect(m_rcPrev);#ifdef _DEBUG CeCosTrace::EnableTracing(true);#endif CeCosTrace::SetInteractive(true); if(m_pInitFunc){ m_pInitFunc(&m_prop,false); } GetDlgItem(IDCANCEL)->SetWindowText(_T("&Close")); m_nTestsToComplete=0; BOOL bResult = CeCosPropertySheet::OnInitDialog(); SetDlgItemText(IDOK,_T("&Run")); SetDlgItemText(ID_APPLY_NOW,_T("&Properties")); GetDlgItem(ID_APPLY_NOW)->EnableWindow(TRUE); GetDlgItem(IDCANCEL)->EnableWindow(TRUE); // required for modeless case SetActivePage(&outputpage); SetActivePage(&summarypage); SetActivePage(&executionpage); if(m_pInitFunc){ m_pInitFunc(&m_prop,false); outputpage.UpdateData(FALSE); summarypage.UpdateData(FALSE); executionpage.UpdateData(FALSE); } /* CString strCaption = _T("Output"); TC_ITEM tcItem; tcItem.mask = TCIF_TEXT; tcItem.pszText = (LPTSTR)((LPCTSTR)strCaption); GetTabControl()->SetItem(2, &tcItem ); strCaption=_T("Summary"); GetTabControl()->SetItem(3, &tcItem ); */ // Allow resizing // WS_OVERLAPPEDWINDOW would preclude caption bar help button ModifyStyle(0,WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME ,0); CRect rect; GetWindowRect(rect); m_rcPrev=rect; m_cxMin=rect.Width(); m_cyMin=rect.Height(); m_bAllowResizing=true; WINDOWPLACEMENT wndpl; if (5==_stscanf(m_strPlacement,_T("%d %d %d %d %d"),&rect.left,&rect.top,&rect.right,&rect.bottom,&wndpl.showCmd)){ CRect rcMax; SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0); if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){ rect=CFrameWnd::rectDefault; } wndpl.length = sizeof(WINDOWPLACEMENT); wndpl.flags = 0; wndpl.ptMinPosition = CPoint(0, 0); wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER)); wndpl.rcNormalPosition = rect; // sets window's position and iconized/maximized status SetWindowPlacement(&wndpl); } // Hack: force an initial sizing (without which the tab control is badly sized) m_rcOffset.left=m_rcOffset.right=m_rcOffset.top=0; m_rcOffset.bottom=m_bModal?50:-50; MoveWindow(GetTabControl(),Stretch); for(int i=0;i<GetPageCount();i++){ MoveWindow(GetPage(i),Stretch); }#ifdef _DEBUG for(CWnd *p=GetWindow(GW_CHILD);p;p=p->GetWindow(GW_HWNDNEXT)){ TCHAR buf[256]; ::GetClassName(p->m_hWnd,buf,sizeof buf); TRACE(_T("Window %x id=%d class=%s\n"),p,p->GetDlgCtrlID(),buf); }#endif for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){ CWnd *pWnd=GetDlgItem(arIds[i]); if(pWnd){ MoveWindow(pWnd,BottomRight); pWnd->ShowWindow(SW_SHOW); // necessary in the modeless case } else { TRACE(_T("Failed to find window id=%x\n"),arIds[i]); } } // hack to lay buttons out correctly in application case if(this==AfxGetMainWnd()){ CRect rect1,rect2; GetDlgItem(IDOK)->GetWindowRect(rect1); GetDlgItem(IDCANCEL)->GetWindowRect(rect2); CRect rect(rect1); rect.left-=(rect2.left-rect1.left); rect.right-=(rect2.right-rect1.right); ScreenToClient(rect); GetDlgItem(ID_APPLY_NOW)->MoveWindow(rect); GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_SHOW); } if(!m_bModal){ SetTimer(0,100,0); } BringWindowToTop(); return bResult;}void CRunTestsSheet::OnRun(){ if(Running==m_Status){ outputpage.AddLogMsg(_T("Run canceled")); m_Status=Stopping; EnterCriticalSection(&m_CS); m_nNextToSubmit=0x7fffffff; LeaveCriticalSection(&m_CS); CeCosTest::CancelAllInstances(); } else { outputpage.UpdateData(TRUE); summarypage.UpdateData(TRUE); executionpage.UpdateData(TRUE); if(0==executionpage.SelectedTestCount()){ MessageBox(_T("No tests have selected for execution")); } else { m_ep=CeCosTest::ExecutionParameters( CeCosTest::ExecutionParameters::RUN, m_strTarget, TIMEOUT_NONE==m_nTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nTimeoutType?0:1000*m_nTimeout, TIMEOUT_NONE==m_nDownloadTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nDownloadTimeoutType?0:1000*m_nDownloadTimeout); if(m_bRemote){ CTestResource::SetResourceServer(m_strResourceHost,m_nResourcePort); if(!CTestResource::LoadSocket()){ MessageBox(_T("Could not connect to resource server")); return; } } else { if(CeCosTest::IsSim(m_ep.Target())){ //for(int i=0;i<m_nSimConcurrent;i++){ m_pResource=new CTestResource(m_ep.Target()); //} } else { const String strPort(m_bSerial?(LPCTSTR)m_strPort:CeCosTestSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort)); int nBaud=m_bSerial?m_nBaud:0; if (RESET_X10!=m_nReset) { m_pResource=new CTestResource(m_ep.Target(),strPort,nBaud); } else { m_pResource=new CTestResource(m_ep.Target(),strPort,nBaud,m_strReset); } } } m_Status=Running; SetDlgItemText(IDOK,_T("&Stop")); m_nNextToSubmit=0; outputpage.AddLogMsg(_T("Run started")); SubmitTests(); } }}struct Info { CRunTestsSheet *pSheet; CeCosTest *pTest;};DWORD CRunTestsSheet::X10ThreadFunc (void *pParam){ Info *pInfo=(Info *)pParam; String str; bool bOk=false; CResetAttributes::ResetResult n=pInfo->pSheet->m_pResource->Reset(str); if(CResetAttributes::RESET_OK==n){ str+=_TCHAR('\n'); if(CResetAttributes::IsValidReset((void *)(LPCTSTR )str)){ str+=_T(">>> Reset ok\n"); bOk=true; } else { str+=_T(">>> Could not reset target (no valid startup string seen)\n"); } } else { String str; str+=_T(">>> Could not reset target - X10 error - "); str+=CResetAttributes::Image(n); str+=_TCHAR('\n'); } LPTSTR pszCopy=new TCHAR[1+str.GetLength()]; _tcscpy(pszCopy,str); pInfo->pSheet->PostMessage(WM_TESTOUTPUT,(WPARAM)pszCopy,0); if(bOk){ // we're already in a thread, so we can call the function directly pInfo->pTest->RunLocal(); } RunCallback(pInfo); return 0;}void CALLBACK CRunTestsSheet::RunLocalFunc(void *pParam){ ((Info *)pParam)->pTest->RunLocal();}void CALLBACK CRunTestsSheet::RunRemoteFunc(void *pParam)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -