Tuesday, July 3, 2007

Quality code best practice.

The most simple test automation can be fraught with errors. To prevent these problems, you must strictly adhere to the four characteristics of high quality test code.

To review, the four characteristics are:
- Can be easily analyzed in the event of a failure.
- Takes as few environmental dependencies as possible.
- Follows good design principles.
- Is consistent with organizational and company policies.

As these characteristics are applied, it is possible to identify practical examples of these characteristics, such as:
- Do not hard-code paths and network names.
- Avoid taking network dependencies.
- Don’t assume English. Provide as much information as is reasonable when a test fails.
- Use appropriate synchronization mechanisms.
- Use Thread.Sleep sparingly. Never hard-code user credentials, especially passwords.

Tuesday, June 26, 2007

Configuring kernel debugging in Windows Vista

http://www.microsoft.com/whdc/driver/tips/debug_vista.mspx

Debugging Windows Vista
Updated: December 28, 2005

Introduction: The Boot.ini file bug
If you try to set up a kernel debugger on the latest builds of Microsoft Windows Vista, you will notice a major change. Depending on which build you have, the Boot.ini file is either missing from the build or it is present but is ignored.
This tip explains how to configure kernel debugging on a computer that is running Windows Vista. These instructions are designed for the simplest case: a computer on which Windows Vista is the only installed operating system. Instructions for computers that have both Windows Vista and versions of Windows earlier than Windows Vista are only slightly more complex and will be described in detail in the Windows Driver Kit (WDK) for Windows Vista.
Note:Early beta test builds of Windows Vista still use the Boot.ini file and, on those builds, you can edit the Boot.ini file to set up debugging. You can identify builds that still use Boot.ini by the "NOBCD" boot parameter in the Boot.ini file. The NOBCD parameter was supported only in these early builds of Windows Vista. The NOBCD parameter and the Boot.ini file are ignored in later builds, and the Boot.ini file is not created at all in builds 5253 and later.
Top of page
What has changed?
Windows Vista introduces a new boot loader architecture; a new firmware-independent boot configuration and storage system called Boot Configuration Data (BCD); and a new boot option editing tool, BCDEdit (BCDEdit.exe). These components are designed to load Windows more quickly and more securely.
The traditional Windows NT boot loader, Ntldr, is replaced by Windows Boot Manager (Bootmgr.exe) and a set of system-specific boot loaders. In the new configuration, Windows Boot Manager is generic and unaware of the specific requirements for each operating system, and each system-specific boot loader is optimized for the system that it loads.
What happened to Boot.ini?
On BIOS-based computers that are running only Windows Vista, the Boot.ini text file is gone (not hidden) and any remnants of it on interim beta test builds are ignored. On computers with both earlier versions of Windows and with Windows Vista, the Boot.ini file remains to support the older versions but it does not affect booting in Windows Vista.
On EFI-based computers that are running Windows Vista, boot options are still stored in NVRAM. However, in Windows Vista you use BCDEdit to edit boot options on an EFI-based computer just as you would on a BIOS-based computer, instead of accessing NVRAM directly by using Windows APIs or specialized tools such as NvrBoot.
Windows Vista also includes new BCD classes that are supported by the WMI provider and enable you to edit BCD programmatically. For information about BCD classes, see the end of this tip.
How do I edit the boot options?
BCDEdit (Bcdedit.exe) is a command-line tool that edits boot options in Windows Vista. It replaces Bootcfg (a boot options editing tool that is included in Windows XP and Windows Server 2003) and NvrBoot (a boot options editing tool for EFI-based computers).
Use BCDEdit to edit the boot configuration in Windows Vista. You can continue to use Bootcfg and NvrBoot and to edit the Boot.ini file in versions of Windows earlier than Windows Vista, even if they are installed on a computer that also has Windows Vista installed.
Top of page
Configuring kernel debugging in Windows Vista
You can use the following procedure to create a boot entry for debugging in Windows Vista. This procedure uses BCDEdit, which is the boot option editing tool for Windows Vista.
Briefly, the steps are:
1.
Open a Command Prompt window with elevated privileges.
2.
Edit the global debugging settings, if necessary.
3.
Display the global debugging settings.
4.
Create a new boot entry by copying an existing boot entry.
5.
Add the new boot entry to the boot menu.
6.
Enable debugging on the new boot entry.
7.
Verify that debugging is set on the new boot entry.
8.
Change the default boot entry.
9.
Reboot the computer.
The rest of this tip describes each step in more detail.
1. Open a Command Prompt window with elevated privileges.
The Command Prompt window must have elevated privileges, even if you are a member of the Administrator group on the computer.
1.
Click the Start button, point to All Programs, and then click Accessories.
2.
Right-click Command Prompt, and then click Run Elevated.
2. Edit the global debugging settings, if necessary.
In Windows Vista, the debugging connection type (serial, 1394, or USB) and the attributes of the connection type (debugport or channel) are determined by a global parameter, dbgsettings, that affects all boot entries, although you can set the debugging connection type and attributes individually for particular boot entries.
The default global debugging settings for Windows Vista are:
To change the global debugging settings, use the following command syntax.
For example:
If the command succeeds, BCDEdit displays the following message:The operation completed successfully.
3. Display the global debugging settings.
To verify that a command to change the global debugging setting was successful, use the following command to display all boot settings on the system.
In the list that appears, the global debugging settings are the last entry in the list.
The following example shows the settings after the example bcdedit /dbgsettings 1394 channel:1 command from step 2 earlier in this tip....
Kernel Debugger Settings Group
------------------------------
Identifier: {dbgsettings}
Type: 20100000
Debugger type: 1394
Debugger 1394 channel: 1
...
4. Create a new boot entry by copying an existing boot entry.
At the command prompt, type the following command. This command copies the Microsoft Windows boot entry that was last used to boot Windows, identified as {current}, and creates a new boot entry named DebugEntry. (This name is used throughout the rest of this tip. You can assign any name to the new entry.)
If the command succeeds, BCDEdit displays a message such as:The entry was successfully copied to {68602c25-5097-11da-99de-000802209f1b}.
The global universal identifier (GUID) that appears between braces in the preceding message is the identifier of the new boot entry. You use the identifier to represent the entry in all subsequent BCDEdit commands.
If the command fails, be sure that you are running in a Command Prompt window with elevated privileges and that all of the command parameters are spelled correctly, including the braces around {current}.
5. Add the new boot entry to the boot menu.
In Windows Vista, new boot loader entries are not added to the boot menu automatically. If you skip this step, the boot menu might not appear (because there is only one boot loader entry) or the menu appears, but does not list the new boot loader entry.
You can place the boot loader entries in any order. Separate each identifier (the GUID or a reserved identifier, such as {current}) with a space. To add the DebugEntry boot entry to the boot menu after the {current} entry, use the following command.
In this command, {ID} is the GUID of the DebugEntry boot loader entry, including the braces ({}), as the following example shows:
To verify that the display order is correct, use the following command:
When you type bcdedit without additional parameters, BCDEdit displays the boot manager entry and the boot loader entries in the order that they will appear in the menu.
The Windows Boot Manager entry also includes the boot menu display order, as the following example shows.
6. Enable debugging on the new boot entry.
Use the following procedure to enable debugging on the DebugEntry boot entry that you created in step 4 earlier in this tip. The first step is necessary because you need the GUID of the boot entry for the command that sets debugging.
1.
To list all of the boot loader entries on the computer, type the following command.
2.
Find the boot entry named DebugEntry and copy the GUID, including the surrounding braces ({}), from the Identifier attribute of the entry.
3.
To enable debugging on the DebugEntry boot entry, use the following command syntax.
where {ID} represents the GUID that you copied from the boot entry in step 2.
The following example demonstrates this command with the GUID from the example in step 2.
If the command succeeds, BCDEdit displays the following message at the command prompt.The operation completed successfully.
7. Verify that debugging is set on the new boot entry.
Use the following procedure to verify that debugging is set on the new DebugEntry boot entry.
1.
To list the boot loader entries on the computer, use the following command.
2.
Find the boot entry named DebugEntry. The result should include a Kernel debugger attribute on the entry with a value of Yes, as the following example shows.
8. Change the default boot entry.
The default boot entry is the boot entry that the boot manager selects when the boot menu timeout expires. Unlike earlier versions of Windows, in Windows Vista the order of boot entries in the boot menu (the display order) does not determine which boot loader entry is the default.
By default, the Microsoft Windows boot entry that the system creates is the default entry. Because the default entry is also the boot entry that is used to boot the system most recently, it is identified as {current}.
If you want the new debug-enabled boot loader entry, DebugEntry, to be the default boot entry, use the following command.
where {ID} is the GUID of the DebugEntry boot entry, as the following example shows.
If the command is successful, BCDedit displays the following message at the command prompt.The operation completed successfully.
To see this change, use the bcdedit command (without parameters) to display the entries that appear in the boot menu.
This command produces the following output. Notice that all instances of the DebugEntry GUID have been replaced by the reserved identifier {default}.
The identifiers {default} and {current} are reserved identifiers that indicate the default boot entry and the boot entry that was used most recently to boot the system. If a boot entry is both the default and the current entry, its identifier is {current}. If a boot entry is not the default or the current entry, BCDEdit restores its original GUID as its identifier.
You can identify the boot entry by its name (in the Description attribute), but you must use the identifier, not the description, in BCDEdit commands.
9. Reboot the computer.
When you reboot your computer, the Windows Boot Manager displays the boot menu. You can select the Microsoft Windows boot entry or the DebugEntry. If you do not select either choice, the Windows Boot Manager selects the default, DebugEntry.
Top of page
For more information:
Windows Driver KitTools for Debugging Drivers
Platform SDKBoot Configuration Data (BCD)BCD Classes
Windows Hardware Development CentralDevelopment Tools and Testing: OverviewDebugging Tools for Windows - Overview

Monday, May 21, 2007

Boxing - value types

I encountered this in Chapter 1 of "MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation" - MSPress Book!

Question: Structures inherit ToString from System.Object. Why would someone override that method within a structure? (Choose as many correct answers as apply.)
A. To avoid boxing.
B. To return something other than the type name.
C. The compiler requires structures to override the ToString method.
D. To avoid run-time errors caused by invalid string conversions
Correct Answers: A and B
A. Correct: Value types are boxed when an abstract method inherited from System.Object is called. Overriding the method avoids boxing.
B. Correct: By default, the ToString method simply returns the type name, which is typically not useful for a consuming application.
C. Incorrect: The compiler does not require structures to override the ToString method.
D. Incorrect: ToString never causes a run-time error; it simply returns the type name unless overridden.

O'kay I shall provide feedback to author regarding correction.


I have written two simple programs to understand the behavior correctly:
Program 1

public struct MyStruct1
{
public int i;
public override string ToString()
{
return i.ToString();
}
}
public struct MyStruct2
{
public int i;
}

class Program
{
static void Main(string[] args)
{
MyStruct1 st1;
st1.i = 55;
Console.WriteLine(st1.ToString());

MyStruct2 st2;
st2.i = 99;
Console.WriteLine(st2.ToString());
}
}

.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 58 (0x3a)
.maxstack 2
.locals init ([0] valuetype BoxUnBox.MyStruct1 st1,
[1] valuetype BoxUnBox.MyStruct2 st2)
IL_0000: nop
IL_0001: ldloca.s st1
IL_0003: ldc.i4.s 55
IL_0005: stfld int32 BoxUnBox.MyStruct1::i
IL_000a: ldloca.s st1
IL_000c: constrained. BoxUnBox.MyStruct1
IL_0012: callvirt instance string [mscorlib]System.Object::ToString()
IL_0017: call void [mscorlib]System.Console::WriteLine(string)
IL_001c: nop
IL_001d: ldloca.s st2
IL_001f: ldc.i4.s 99
IL_0021: stfld int32 BoxUnBox.MyStruct2::i
IL_0026: ldloca.s st2
IL_0028: constrained. BoxUnBox.MyStruct2
IL_002e: callvirt instance string [mscorlib]System.Object::ToString()
IL_0033: call void [mscorlib]System.Console::WriteLine(string)
IL_0038: nop
IL_0039: ret
} // end of method Program::Main


Program 2

... definition of both structs remains the same as above!
[-snip-]
static void Main(string[] args)
{
MyStruct1 st1;
st1.i = 55;
Console.WriteLine(st1);

MyStruct2 st2;
st2.i = 99;
Console.WriteLine(st2);
}

.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 44 (0x2c)
.maxstack 2
.locals init ([0] valuetype BoxUnBox.MyStruct1 st1,
[1] valuetype BoxUnBox.MyStruct2 st2)
IL_0000: nop
IL_0001: ldloca.s st1
IL_0003: ldc.i4.s 55
IL_0005: stfld int32 BoxUnBox.MyStruct1::i
IL_000a: ldloc.0
IL_000b: box BoxUnBox.MyStruct1
IL_0010: call void [mscorlib]System.Console::WriteLine(object)
IL_0015: nop
IL_0016: ldloca.s st2
IL_0018: ldc.i4.s 99
IL_001a: stfld int32 BoxUnBox.MyStruct2::i
IL_001f: ldloc.1
IL_0020: box BoxUnBox.MyStruct2
IL_0025: call void [mscorlib]System.Console::WriteLine(object)
IL_002a: nop
IL_002b: ret
} // end of method Program::Main



The above experiment shows that - in both cases MyStruct1 and MyStruct2 are boxed irrespective of ToString() was overridden in MyStruct1.

One question: Why would there be boxing at all in first case (in Program 1 above):
static void Main(string[] args)
{
MyStruct1 st1;
st1.i = 55;
Console.WriteLine(st1.ToString()); <----- this will call overridden ToString() in MyStruct1...

....
public struct MyStruct1
{
public int i;
public override string ToString()
{
return i.ToString(); <----- this, anyway, will not be boxed, right? (because compiler knows i is an int)

Lets Jump Into The Special Pool

Introduction
Many of you have heard about special pool. This is what it is and how it works.


What is Special Pool?
Special Pool is another memory pool type. Therefore, when you have Special Pool enabled, three types of memory pools exist: Paged, Non-paged and Special pool. Allocations will be made from Special Pool depending if it is enabled and configured.


How can I configure special pool?
When memory is allocated, drivers use what is called a tag to identify a memory block. Tags are used to record allocations to see how much memory is used. A tag is just a 4 byte text such as “ABCD”. Special pool can be enabled so whenever an allocation is made for a certain tag, the allocation comes from special pool. For this you need to know what tag you are looking for. Also Special Pool can be set up for a particular allocation size, such as 40.


What happens when a special pool allocation is made?
When a special pool allocation is made, one 4096 byte page is used for the allocation. The actual allocation goes at the end of a page or at the beginning depending on configuration options. Where the allocation goes depends on which option is chosen to catch underruns or overruns. If underruns are selected, the allocation goes at the top of the page. If overruns are selected, the allocation goes at the end of the page. Below is an example of overruns.


0: kd> dd 8ae24fc0-50 l 55
8ae24f70 5d5d5d5d 5d5d5d5d 5d5d5d5d 5d5d5d5d
8ae24f80 5d5d5d5d 5d5d5d5d 5d5d5d5d 5d5d5d5d
8ae24f90 5d5d5d5d 5d5d5d5d 5d5d5d5d 5d5d5d5d ß Fill pattern
8ae24fa0 5d5d5d5d 5d5d5d5d 5d5d5d5d 5d5d5d5d
8ae24fb0 5d5d5d5d 5d5d5d5d 5d5d5d5d 5d5d5d5d
8ae24fc0 00400709 00008003 0078006c e18853f8
8ae24fd0 0000003e 00000000 e1938f70 e1938f70
8ae24fe0 e1938f28 e1938eb0 e1938eb0 00000002
8ae24ff0 00000000 00000000 00000000 00000020
8ae25000 ???????? ???????? ???????? ???????? ß Next page set to an invalid address.


The idea for overruns is to catch a driver writing beyond its allocation. So the next page is set to be invalid. This will cause the system blue screen immediately when a driver attempts to write beyond its allocation. Otherwise the overwrite may not cause a problem until much later and there may be no way to find what did it. In the underrun case, the upper page is invalid.


What is the fill pattern?
The fill pattern is checked for validity after every release. If the fill pattern is written to, the system will blue screen on release.


Are there any other reasons to enable special pool besides pool corruption?
Special Pool has a feature where it saves the stack of the last thread to free the block. So if a block has been freed back to special pool, the !fpsearch command can be used to see the stack of the last free.

0: kd> !fpsearch be962c48Searching the free page list (38 entries) for VA be962c48
VA PFN Tag Size Pagable Thread Tickbe962c48 ec79 CM 3b8 Yes 81ed1020 ae2 CALL STACK AT TIME OF DEALLOCATION nt!ExFreePoolWithTag+0x22 nt!ExFreePool+0xb nt!CmpValidateAlternate+0x63 nt!CmpInitializeHiveList+0x2cd nt!CmpWorker+0x68 nt!NtInitializeRegistry+0x92 nt!_KiSystemService+0xc9 nt!NtClose+0x2d8 nt!_KiSystemService+0xc9


Beware of Red Herrings in the Pool
After enabling Special Pool, the system may blue screen on boot. This is because during boot up, the memory manager may round up some memory allocations thus giving a driver a few more bytes than it actually requested. Some of these drivers may occasionally overrun their requested allocation size, but since the memory manager allocated a few extra bytes, there’s no problem. There’s no problem until you enable Special Pool, that is… Once Special Pool is enabled, the actual allocation size will be strictly enforced and the system will bug check. This may not indicate the actual problem, however.


Conclusion
I hope this gives a better understanding of Special Pool.

Addressing Problems

Addressing Problems
Imagine you're working on a project and a large problem presents itself. The problem has far-reaching impact for you and your team. What's the best way to inform your manager of this situation? Although your first thought may be to barge into his or her office and "dump it", that may not be the best approach. An effective approach is to stop, think, and prepare for the discussion.

Use the following steps to organize your thoughts and prepare for the conversation with your manager:
- Describe the problem to your managerProvide a general overview of the problem, and show the specific impact that the problem is having on your work and on the organization's goals.
Identify your solution or approachRecommend a specific solution or approach, along with alternatives, to provide your manager with options.
- Explain the implications of the solution or approachConsider the impact that your solution or approach will have on yourself and others, including your manager and the organization as a whole.
- Discuss the benefits of your solution or approachFocus your discussion on the benefits to be gained from implementing your solution or approach.
- Accept responsibility for the outcomeLet your manager know that you are willing to take responsibility for the outcome of your solution or approach. This is an important part of your discussion and demonstrates your commitment to ensuring success.

Can u prove 2=3 ?

If you take this seriously… well you’re wrong

I like the KISS method using basic math fundamentals and a little fools’ logic. Suppose we have positive values x and y where y =
so xy=1
and x =
and x != y
and y>x,
so <
and 0 < x < 1 < y

we would all agree on those fundamentals, right? If x were and y were , then xy = 1
simple, right?
So if xy = 1
and 2 + 1 = 3,
then 2 + xy = 3

Let’s shift gears for a bit.
1/10 = .1
1/100 = .01
1/1000 = .001
So for j>=1 where we have j-1 zeroes at the end of decimal point and before the final 1
= .0001
And so on.
So if we had k = ,
1-k = .9 to j places
and .9 + k = 1
So = .1, so .9 with one place,
= .01 so .99 with two places and so on…

So for j = 1 to who knows what, we have
1-() = .9 to j places


So if we drive for infinite 9’s we have .

So where k = x = (1 -0.) and since 2 + xy = 3
On principal that 3 + 3 + 3 = 9,

. + . + . = .

but since = .
and + + = 1,

1 = .

and since x = 1 - .,
or x = 1 -1 = 0

x=0
and therefore xy = 0
and 2 + xy = 3
so 2 + 0 = 3
and 2 = 3


…of course I left out the part where now
y is probably somewhere close to ∞ (1 divided by an astronomically small number)
if it was, 0 * ∞ = 1 and/or 0
so and/or = ∞
and to reiterate 0=1 (and to think I wanted to add the astronomically small number to 2, y individual times to get 3)

And my favorite
∞ = 1 (I will now call Guinness and try to break the record for the most memorized digits of ∞)

Laugh all you want – this is my math and you reserve the right to follow my lead or be wrong. ;)

Thursday, May 17, 2007

Disable systray balloon

How to get rid of this balloon(permanently)? It is very annoying. You can set the registry bit
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\EnableBalloonTips to ZERO.

Set up JIT debugger

Steps :
1. install Debugging Tools for Window x64.
2. run command prompt with administrator authority
3. change directory to the Debugging Tools for Windows installed folder and run the command "CDB.EXE -iae". As a result, Auto and Debugger settings are added shown below.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
"Debugger"="\"C:\\Program Files\\Debugging Tools for Windows\\cdb.exe\" -p %ld -e %ld -g"
4. Using regedit, add below settings.
WOW6432Node\Microsoft\Windows NT\Current Version\AeDebug
"Auto"="1"
"Debugger"="\"C:\\Program Files\\Debugging Tools for Windows\\cdb.exe\" -p %ld -e %ld -g"

First Blog

Just try to post something for testing purpose.