August 7th, 2010 by Marcin Obel
Information about processor can be retrieved using Microsoft’s WMI and PowerShell scripting language. In order to check name of processor execute following command in PowerShell console:
>> (Get-WmiObject Win32_Processor)["Name"]
The command above can be used to create ByteCarrot’s check which will be able to validate for example if processor was made by Intel. Take a look at the script below:
<PowerShellCheck>
<Script>
<![CDATA[
$ProcessorName = (get-wmiobject Win32_Processor)["Name"]
if ($ProcessorName.Contains("Intel")) {
return success "The processor was made by Intel"
}
return failure "The processor was not made by Intel"
]]>
</Script>
</PowerShellCheck>
Read More
August 7th, 2010 by Marcin Obel
Information about BIOS manufacturer can be retrieved using Microsoft’s WMI and PowerShell scripting language. In order to check its name execute following command in PowerShell console:
>> (get-wmiobject win32_bios)["Manufacturer"]
The command above can be used to create ByteCarrot’s check which will be able to validate if BIOS manufacturer on your computer is for example “American Megatrends Inc.”. Take a look at the script below:
<PowerShellCheck>
<Script>
<![CDATA[
$Manufacturer = (get-wmiobject win32_bios)["Manufacturer"]
if ($Manufacturer -like "American Megatrends Inc.") {
return success "BIOS was made by $Manufacturer"
}
return failure "BIOS was made by $Manufacturer"
]]>
</Script>
</PowerShellCheck>
Read More
July 1st, 2010 by Marcin Obel
ByteCarrot contains a functionality which allows executing groups of check conditionally. Current implementation of this feature is quite limited but still is able to help in many cases. Conditions verify if specified parameter is equal (==) or not equal (!=) to other parameter or static value. They can contain parameter names surrounded by $(…) or static values surrounded by quotas (’static value’). These elements can be mixed freely. Take a look at the examples below.
1. MyParameter is equal to 2:
$(MyParameter) == ‘2′
2. MyParameter is not equal to MyOtherParameter:
$(MyParameter) != $(MyOtherParameter)
3. Two static values can be also compared (but of course it does not make sense):
‘value 1′ != ‘value 2′
Conditions in ByteCarrot can be used only with <Group /> tag but fortunately this tag can be nested multiple times, so this should not be a problem. In order to add condition to a group decorate it with “Condition” attribute like in example shown below.
<Group Condition="$(MyParameter) == '3'">
<Check1 />
<Check2 />
</Group>
Now checks from the group presented above will be executed only if MyParameter will be set to 3. Of course MyParameter can be set to 3 from the command line (-p: option), can be an input parameter or even can be declared in a section somewhere before the group where its value will be evaluated. You can even use environment variable saving its value in parameter and then using condition to evaluate parameter.
Below you can find more extended example of conditions usage. It contains three groups with conditions expecting that value of MyParameter will be specified from command line (-p: option). This example has also group with a condition based on an environment variable which value is assigned to UserName parameter at the top of the script.
<?xml version="1.0" encoding="utf-8"?>
<TestScript xmlns="http://bytecarrot.com/schemas/ByteCarrot/1.0/TestScript">
<Group>
<Parameters>
<TestHeader>Test with "My Parameter" == $(MyParameter)</TestHeader>
<UserName>$(%USERNAME%)</UserName>
</Parameters>
<Description>
<Header>Tests executed conditionally</Header>
</Description>
<Group Name="Test" Condition="$(MyParameter) == '1'">
<Description>
<Header>$(TestHeader)</Header>
</Description>
<DirectoryExists Path="C:\Windows" />
</Group>
<Group Name="Test" Condition="$(MyParameter) == '2'">
<Description>
<Header>$(TestHeader)</Header>
</Description>
<DirectoryExists Path="C:\Windows" />
<DirectoryExists Path="C:\Program Files" />
</Group>
<Group Name="Test" Condition="$(MyParameter) == '3'">
<Description>
<Header>$(TestHeader)</Header>
</Description>
<DirectoryExists Path="C:\Windows" />
<DirectoryExists Path="C:\Program Files" />
<DirectoryExists Path="C:\Users" />
</Group>
</Group>
<Group Condition="$(UserName) == 'Marcin'">
<Group Name="Test">
<DirectoryExists Path="C:\Users\$(%USERNAME%)" />
</Group>
</Group>
</TestScript>
You can execute this script saving it as conditions.xml file (for example) and using following command:
bytecarrot execute -ts:conditions.xml -hr:conditions.html -ohr -p:MyParameter=1
Remember to change MyParameter’s value in the command in order to check if conditions really work and different parts of test script are executed.
Read More
June 26th, 2010 by Marcin Obel
This post contains a different way of implementing test script presented in last post. This time instead of RubyCheck I am using PowerShellCheck but the logic remains exactly the same.
<?xml version="1.0" encoding="utf-8"?>
<TestScript xmlns="http://bytecarrot.com/schemas/ByteCarrot/1.0/TestScript">
<Group>
<Group Name="Test">
<Parameters>
<ExpectedCPUSpeed>20000</ExpectedCPUSpeed>
</Parameters>
<Description>
<Header>Tests if CPU has enough speed (at least $(ExpectedCPUSpeed) MHz)</Header>
</Description>
<PowerShellCheck>
<Script>
<![CDATA[
$Processor = Get-WmiObject Win32_Processor
$MaxClockSpeed = $Processor["MaxClockSpeed"]
$Name = $Processor["Name"]
if ($MaxClockSpeed -gt $(ExpectedCPUSpeed)) {
return success "Processor's speed is OK [CPU: $Name]"
}
return failure "Processor is to slow. Its maximum clock speed is $MaxClockSpeed MHz [CPU: $Name]"
]]>
</Script>
</PowerShellCheck>
</Group>
</Group>
</TestScript>
This example was tested with PowerShell 2.0 on Windows 7.
Read More
June 26th, 2010 by Marcin Obel
Yesterday I received an email from one of a ByteCarrot’s users. He wanted to write a script to test if hardware on which operating system works meets specified criteria. He wanted to use WMI to retrieve required information and customize messages which are a part of test script results. Of course the simplest way of creating WMI based check would be usage of WmiCheck available out of the box but not in this case because its messages can not be customized. Fortunately ByteCarrot was designed to handle also uncommon scenarios so I suggested him use RubyCheck instead of WmiCheck. In order to show him how to use this particular task in his case I have created a sample presented below.
<?xml version="1.0" encoding="utf-8"?>
<TestScript xmlns="http://bytecarrot.com/schemas/ByteCarrot/1.0/TestScript">
<Group>
<Group Name="Test">
<Parameters>
<ExpectedCPUSpeed>20000</ExpectedCPUSpeed>
</Parameters>
<Description>
<Header>Tests if CPU has enough speed (at least $(ExpectedCPUSpeed) MHz)</Header>
</Description>
<RubyCheck>
<Script>
<![CDATA[
load_assembly "System.Management";
include System::Management;
processor = ManagementObject.new("Win32_Processor.DeviceID='CPU0'");
maxClockSpeed = processor["MaxClockSpeed"].to_i;
name = processor["Name"].to_s;
if (maxClockSpeed > $(ExpectedCPUSpeed))
return success("Processor's speed is OK [CPU: #{name}]");
end
return failure("Processor is to slow. Its maximum clock speed is #{maxClockSpeed} MHz [CPU: #{name}]");
]]>
</Script>
</RubyCheck>
</Group>
</Group>
</TestScript>
Because RubyCheck is based on IronRuby (implementation of Ruby for .NET platform) there is a possibility to use .NET classes. In this case I am using ManagementObject class providing easy access to WMI objects and theirs properties.
Read More