Network Test Automation with Mac OS X and Tcl

Your company has just invented the hottest newbut allows you to easily edit files in the Darwin file
web server to hit the market. You created a killersystem.
test plan in Adobe Illustrator with breathtakingEmacs running native under Mac OS X environment
diagrams of your test network environment onEmacs contains most of the features you will require
Macintosh G4 running Mac OS X. Wouldn't it be greatfor editing programs in the Darwin environment. But
if you could run tests from your Mac too? Well ... youEmacs can be difficult to use. The hidden keystroke
can!commands are particularly annoying. For example, you
If you haven't been introduced already, the Toolmust use control (^)x^s to save a file. The
Command Language, Tcl, is a secret weapon used byAqua-on-Emacs port does, however, provide a nice
large network hardware corporations to test theirmenu bar to assist you if you're not familiar with the
devices. It's an extremely flexible scripting languageediting environment.
that has been ported to nearly every operatingNow that you've set up your rootless environment
system in existence, and that now includes Mac OSand have your editor installed, we can fire up Tcl.
X.Tcl is an installed package on Mac OS X machines.
As wonderful as it is, Tcl isn't perfect all by itself.However, Apple didn't include Expect, or Tk (X11 tool
That's why I'm also going to discuss Expect, which iskit for Tcl). Don't ask why. Not a real problem though.
an extension of Tcl that allows interactive automationMichael Peters has provided an excellent port of
to your Tcl scripts. For instance, using Expect youExpect 5.32 which requires Tcl 8.4a2 -- a revision
can automate telnet sessions, database queries, anddifferent from Apple's. You'll need to download and
file transfers.install these two compressed packages to start using
For some reason, Apple didn't include Expect in itsExpect.
operating system release. Not to worry, Expect hasThe downloadable file is a StuffIt .hqx file. Once
been ported to Mac OS X, and I'll walk you throughdownloaded, the image decompresses to a
the install of this handy extension.mountable disk image. You will need to use the Disk
Utilities that you will needCopy utility in the Applications/Utilities folder to mount
First I'll introduce you to a few utilities that Ithe .img file.
recommend you install on your test networkMounting the Tcl and Expect images
workstation. Nearly everything is available on the NetThe mounted image is an installation package that
-- most of it from those diligent code portersyou will need to double-click in order to start the
involved with the open-source sourceforge.netinstallation. Remember, the new Tcl installation is
project.required for the Expect installation.
With the current economic trends, your manager willThe Tcl 8.4a2 folder contents
be pleased to know that you set up an awesomeUnfortunately, the Expect and Expect Tk (the
workstation using mainly open-source applications.graphical user interface and toolkit) portion of the
The focus here is creating an automated testpackage has yet to be tackled for Mac OS X. In a
environment running on Mac OS X. However, thenetwork test environment, we can survive with
same concepts will apply to any Unix workstation --command-line scripts. But I know how excited your
thanks, again, to open-source efforts.manager gets when you show them a GUI
Rootless X on Mac OS Xapplication. If you were adventurous enough to port
To begin, I recommend that you install Rootless X.Expect Tk, or know where a working image is hiding,
Torrey Lyons has released a rootless version ofplease let us know in the O'Reilly TalkBack section
XFree86 for Mac OS X. I provided installationfor this article. In the meantime, we're command-line
instructions for X on X in a previous O'Reilly article,constrained.
Installing XFree86 on Mac OS X . Torrey's rootlessInvoking Tcl
XFree86 is available from sourceforge.net (X on X).Comment on this articleAfter having worked with
XFree86 will soon become indispensable as you putMichael's Tcl examples, let us know what you think or
together your test automation system. The fact thatwhere you got stuck.
your Mac OS X machine is running rootless allows youPost your comments
to run the XFree86 desktop and the Mac OS XTcl is a simplistic language that is string-based. You
desktop in the same window. Prior to this, you werecan invoked Tcl by executing the command tclsh
required to toggle between the two desktopfrom your terminal or console window. A simple "Hello
environments. See Figure 1.World!" script looks like this:
The examples listed later in this article will also run inSpongebob # tclsh
the Mac OS X console window utility. But in my% set myString "Hello World!"
opinion, life is a lot easier using the X WindowsHello World!
environment with multiple terminal windows opened.% puts $myString
This feature comes in handy when you're testingHello World!
multiple network devices simultaneously, such as in aThis code snippet demonstrates how Tcl uses the
network system test environment.set command to assign the string value "Hello World!"
Emacs on Aquato the variable myString. Assigning a "$" in front of
Many editors are now available for Unixthe variable, myString, instructs the interpreter that
environments; the two most prevalent are vi andthe script is going to reference the value contained
emacs. The Emacs-on-Aqua utility is a complementarythere. In this example, the string value is "Hello
tool to run with the rootless XFree86 environment.World!". The puts command writes the value
The Emacs utility executes in Mac OS X environmentreferenced to the terminal window.