Example Program Drafts

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Custom Command Line Arguments to a TestStand Operator Interface (.NET)

Overview

The TestStand Application Manager supports processing custom command line arguments through the ProcessUserCommandLineArguments event. This can prove useful when automating test execution from a CI server.

Description

This example is similar to the .NET Basic User Interface, but has been modified to accept the following command line arguments:

Option Purpose
/SimulateFailure <failures> When used with the included example sequence file, this suppresses the simulation dialog and instead simulate failures as specified. This argument accepts the following parameters:
  • Keyboard
  • Video
  • Power
  • CPU
  • ROM
  • RAM
If no parameters are specified, then all components are simulated to pass.

 

This example demonstrates the following concepts:

  • Using _ApplicationMgrEvents_ProcessUserCommandLineArgumentsEventHandler to handle custom command line arguments
    Spoiler
    private void axApplicationMgr_ProcessUserCommandLineArguments(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ProcessUserCommandLineArgumentsEvent e)
            {
                int numParams = (e.arguments.Count) - e.currentArgument;
    
                if (e.arguments[e.currentArgument] == "/SimulateFailure")
                {
                    e.currentArgument++;
                    for (int i = 0; i < numParams; i++)
                    {
                        switch (e.arguments[e.currentArgument])
                        {
                            case "Keyboard":
                                if (e.processCommand == true)
                                    this.Fails.Keyboard = 4;
                                e.currentArgument++;
                                break;
                            case "Video":
                                if (e.processCommand == true)
                                    this.Fails.Video = 15;
                                e.currentArgument++;
                                break;
                            case "Power":
                                if (e.processCommand == true)
                                    this.Fails.Power = true;
                                e.currentArgument++;
                                break;
                            case "CPU":
                                if (e.processCommand == true)
                                    this.Fails.CPU = true;
                                e.currentArgument++;
                                break;
                            case "ROM":
                                if (e.processCommand == true)
                                    this.Fails.ROM = true;
                                e.currentArgument++;
                                break;
                            case "RAM":
                                if (e.processCommand == true)
                                    this.Fails.RAM = true;
                                e.currentArgument++;
                                break;
                            default:
                                break;
                        }
                    }
                }
                else
                {
                    e.errorProcessing = ProcessCommandLineErrors.ProcessCommandLineError_CustomError;
                    e.errorMessage = "Invalid Command Line Argument: " + e.arguments[e.currentArgument];
                }
            }
  • Modifying a TestStand user interface to print UI error messages to the console and set the return code appropriately
    Spoiler
    		private void axApplicationMgr_ReportError(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ReportErrorEvent e)
    		{
    			Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage); //this isn't working because of appdomain stuff
    			axApplicationMgr.ExitCode = e.errorCode; 		
    		}
  • Use of the ApplicationMgr.AddCommandLineArgumentsHelp function to add custom command line arguments help.
    Spoiler
    axApplicationMgr.AddCommandLineArgumentsHelp("[/SimulateFailure <failures>]", "<failures>: components to fail separated by spaces.\nvalid parameters are: Keyboard, Video, Power, CPU, ROM, & RAM", "");
  • Creating a custom UI Message handler to pass simulation data to sequence execution.
Spoiler
private void axApplicationMgr_UserMessageEvent(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_UIMessageEventEvent e)
        {
			if (e.uiMsg.Event == UIMessageCodes.UIMsg_UserMessageBase + 1)
			{
				SequenceContext SeqContext = e.uiMsg.ActiveXData as SequenceContext;
				if (SeqContext == null)
					return; //Instead of erroring when SeqContext isn't passed, we will ignore this message as to not break other client files that use the same UI message code.
				try
				{
					SeqContext.Locals.SetValBoolean("UiMsgHandled", 0, true);
					SeqContext.Locals.SetValNumber("KeyboardValue", 0, Fails.Keyboard);
					SeqContext.Locals.SetValNumber("VideoValue", 0, Fails.Video);
					SeqContext.Locals.SetValBoolean("PowerFail", 0, Fails.Power);
					SeqContext.Locals.SetValBoolean("CPUFail", 0, Fails.CPU);
					SeqContext.Locals.SetValBoolean("ROMFail", 0, Fails.ROM);
					SeqContext.Locals.SetValBoolean("RAMFail", 0, Fails.RAM);
				}
				catch (Exception theException)
				{
					Console.WriteLine("Error :" + theException.Message);
					Application.Exit();
				}

			}
        }

Note: By default, TestStand shows dialogs under certain conditions. This can cause hangs when automating sequence execution without user input, such as when ran from a CI Server. In order to prevent popups that require user input, configure the following options:

  • Disable User Management or automatically log in the System User
  • Set the 'Station Options » Execution »  On Run-Time Error' setting to something other than 'Show Dialog', such as 'Run Cleanup'.
  • Specify 'Station Options » Time Limits' for Exiting and Normal Execution such that the user will not be prompted.
  • Pass the /quit argument via the command line so TestStand automatically shuts down after all executions are complete.

Hardware and Software Requirements

TestStand 2014 SP1 or later

Visual Studio 2015 or later
LabWindows/CVI Runtime Engine 2015 or later

Steps to Implement or Execute Code

 

  1. Unzip the attached example and build the Basic User Interface solution for the bitness of TestStand you have installed.
  2. Open a command line window in the build output directory (Shift + right click » Open command window here). Alternatively, you can configure command line arguments for the Visual Studio debugger in the Project Properties under the Debug tab.
  3. In order to see the Command Line help, run:

    TestExec /?

  4. Experiment with the /SimulateFailure argument. For example:

    TestExec /runEntryPoint "Single Pass" "<ExampleDir>\TestSequence\Computer Motherboard Test Sequence.seq" /SimulateFailure Keyboard Video RAM /quit

Contributors