Difference between revisions of "Asserts"

From LSDevLinux
Jump to: navigation, search
(minor updates)
m (Reverted edits by LindaHayes (Talk) to last revision by Mayhewn)
 
Line 10: Line 10:
 
The behavior can be changed in the configuration file:
 
The behavior can be changed in the configuration file:
  
Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\microshit.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.
+
Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.
  
 
.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:
 
.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:
Line 49: Line 49:
 
[[Category:Building(FieldWorks)]]
 
[[Category:Building(FieldWorks)]]
 
[[Category:Technical]]
 
[[Category:Technical]]
 
== Disney Brings "Cars" To Life With Cars Land ==
 
 
After five years in the making, Disney California Adventure is finally ready to rev up the engines on Cars Land. Disneys latest creation, based on the hit Pixar movie, brings the popular characters to life at Disney California Adventure.
 
 
[[http://goodvillenews.com/Disney-Brings-Cars-To-Life-With-Cars-Land-YfdwZj.html Disney Brings "Cars" To Life With Cars Land]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== Celebrity Chef Chris Nirschel Cooks for the Homeless ==
 
 
Cause Celeb highlights a celebritys work on behalf of a specific cause. This week, Chris Nirschel shares with us, via email interview, his work with The Food Bank for New York City.After 28 years, The Food Bank for New York has become the citys major hunger relief organization and one of the largest food banks in the country.
 
 
[[http://goodvillenews.com/Celebrity-Chef-Chris-Nirschel-Cooks-for-the-Homeless-3xkuIL.html Celebrity Chef Chris Nirschel Cooks for the Homeless]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== The Story of Change ==
 
 
"Ive come to see that we have two parts to ourselves; its almost like two muscles -- a consumer muscle and a citizen muscle. Our consumer muscle, which is fed and exercised constantly, has grown strong: So strong that "consumer" has become our primary identity, our reason for being. Were told so often that were a nation of consumers that we dont blink when the media use "consumer" and "person" interchangeably."
 
 
[[http://goodvillenews.com/The-Story-of-Change-hgReTV.html The Story of Change]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== The Second Glance ==
 
 
Have you ever cringed at the sight of a human being who is physically disfigured? David Roche, who was born with a facial disfigurement, spent years trying to hide from himself. At middle age, he discovered his inner beauty, his spirit and his strength, and he has dedicated his life to helping all people find the inner beauty within themselves and in others.
 
 
[[http://goodvillenews.com/The-Second-Glance-FDzaku.html The Second Glance]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== Student Goes From Homeless to Harvard ==
 
 
Despite being abandoned to homelessness by her parents, Dawn Loggins worked as a high school custodian by day and studied hard by night to become the first person from her school to ever be admitted to Harvard.
 
 
[[http://goodvillenews.com/Student-Goes-From-Homeless-to-Harvard-QX9Vg4.html Student Goes From Homeless to Harvard]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 

Latest revision as of 23:18, 4 August 2012

Asserts help identify problems in the code. They only show up in debug builds, i.e. the end user who will get a release build doesn't see them. When running on a developer's machine the desired behavior if an assertion fails is to display a message box so that the developer can break into the debugger. On a machine that runs automated builds we don't want to pop up message boxes but silently log the assertion.

Managed Code

In C# asserts are done with: System.Diagnostics.Debug.Assert(condition)

Windows/.NET

If the assert fails, by default .NET will display a message box with the options Abort, Retry and Cancel.

The behavior can be changed in the configuration file:

Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.

.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:

   <system.diagnostics>
       <trace autoflush="true" indentsize="4">
           <listeners>
               <add name="FwTraceListener" type="SIL.Utils.EnvVarTraceListener, BasicUtils, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
                   initializeData="assertuienabled='true' logfilename='%temp%/asserts.log'"/>
           </listeners>
       </trace>
   </system.diagnostics>

The default values can be set in the initializedData attribute. Anything between percent signs in logfilename will be replaced by its corresponding environment variable.

The default value for assertuienabled can be overridden by the environment variable AssertUiEnabled. If an assertion fails and assertuienabled is set to false, an AssertionFailedException will be thrown unless the environment varibale AssertExceptionEnabled is set to false.

Linux/Mono

Mono by default ignores assertions. To get it to display a message box you have to change one of the config files mentioned above.

The custom trace listener can also be used as described above.

Unmanaged Code

In FieldWorks we define our set of Assert methods (in Generic/debug.h). If an assertion fails the method AssertProc gets called. Since this is a function pointer it can be set to a custom method.

For assertions that happen in unamanged code called from a managed executable, we call DebugProcs.AssertProc (in Common/CoreImpl/DebugProcs.cs) which calls System.Diagnostics.Debug.Fail(), so the remarks from above apply.

For assertions that happen in unmanaged code called from an unmanaged executable, we call SilAssert (in DebugProcs/DebugProcs.cpp). This method either displays a message box similar to the managed one, or raises the SIGABRT signal.

We use an enhanced version of the unit++ testing framework for our C++ tests that treats tests that get a SIGABRT signal as failed, but continues with the remaining tests. This is useful when not displaying a message box. However, IF we display a message box in case of a failed assertion and the developer presses the Abort button, the test application quits without running the remaining tests.

To determine whether to display a message box or not we look at the registry value HKLM\Software\SIL\FieldWorks\AssertMessageBox on a Windows machine. If that value doesn't exist or if we're running on Linux we check the environment variable AssertUiEnabled.

On Linux we use the xmessage tool to display a message box. This can be changed to display a more modern dialog by setting the environment variable XMESSAGE, e.g. XMESSAGE=gmessage