Sensors and network administering


Network Test Automation with Mac OS X and Tcl

Your company has just invented the hottestenvironment
new web server to hit the market. You created
a killer test plan in Adobe Illustrator withEmacs contains most of the features you will
breathtaking diagrams of your test networkrequire for editing programs in the Darwin
environment on Macintosh G4 running Mac OS X.environment. But Emacs can be difficult to
Wouldn't it be great if you could run testsuse. The hidden keystroke commands are
from  your  Mac  too?  Well  ...  you  can!particularly annoying. For example, you must
use control (^)x^s to save a file. The
If you haven't been introduced already, theAqua-on-Emacs port does, however, provide a
Tool Command Language, Tcl, is a secretnice menu bar to assist you if you're not
weapon used by large network hardwarefamiliar  with  the  editing  environment.
corporations to test their devices. It's an
extremely flexible scripting language thatNow that you've set up your rootless
has been ported to nearly every operatingenvironment and have your editor installed,
system in existence, and that now includeswe  can  fire  up  Tcl.
Mac  OS  X.
Tcl is an installed package on Mac OS X
As wonderful as it is, Tcl isn't perfect allmachines. However, Apple didn't include
by itself. That's why I'm also going toExpect, or Tk (X11 tool kit for Tcl). Don't
discuss Expect, which is an extension of Tclask why. Not a real problem though. Michael
that allows interactive automation to yourPeters has provided an excellent port of
Tcl scripts. For instance, using Expect youExpect 5.32 which requires Tcl 8.4a2 -- a
can automate telnet sessions, databaserevision different from Apple's. You'll need
queries,  and  file  transfers.to download and install these two compressed
packages  to  start  using  Expect.
For some reason, Apple didn't include Expect
in its operating system release. Not toThe downloadable file is a StuffIt .hqx file.
worry, Expect has been ported to Mac OS X,Once downloaded, the image decompresses to a
and I'll walk you through the install of thismountable disk image. You will need to use
handy  extension.the Disk Copy utility in the Applications
Utilities  folder  to  mount  the  .img file.
Utilities  that  you  will  need
Mounting  the  Tcl  and  Expect  images
First I'll introduce you to a few utilities
that I recommend you install on your testThe mounted image is an installation package
network workstation. Nearly everything isthat you will need to double-click in order
available on the Net -- most of it from thoseto start the installation. Remember, the new
diligent code porters involved with theTcl installation is required for the Expect
open-source  sourceforge.net  project.installation.
With the current economic trends, yourThe  Tcl  8.4a2  folder  contents
manager will be pleased to know that you set
up an awesome workstation using mainlyUnfortunately, the Expect and Expect Tk (the
open-source applications. The focus here isgraphical user interface and toolkit) portion
creating an automated test environmentof the package has yet to be tackled for Mac
running on Mac OS X. However, the sameOS X. In a network test environment, we can
concepts will apply to any Unix workstationsurvive with command-line scripts. But I know
--  thanks,  again,  to  open-source efforts.how excited your manager gets when you show
them a GUI application. If you were
Rootless  X  on  Mac  OS  Xadventurous enough to port Expect Tk, or know
where a working image is hiding, please let
To begin, I recommend that you installus know in the O'Reilly TalkBack section for
Rootless  X.this article. In the meantime, we're
command-line  constrained.
Torrey Lyons has released a rootless version
of XFree86 for Mac OS X. I providedInvoking  Tcl
installation instructions for X on X in a
previous O'Reilly article, Installing XFree86Comment on this articleAfter having worked
on Mac OS X . Torrey's rootless XFree86 iswith Michael's Tcl examples, let us know what
available from sourceforge.net (X on X).you  think  or  where  you  got  stuck.
XFree86 will soon become indispensable as you
put together your test automation system. ThePost  your  comments
fact that your Mac OS X machine is running
rootless allows you to run the XFree86Tcl is a simplistic language that is
desktop and the Mac OS X desktop in the samestring-based. You can invoked Tcl by
window. Prior to this, you were required toexecuting the command tclsh from your
toggle between the two desktop environments.terminal or console window. A simple "Hello
See  Figure  1.World!"  script  looks  like  this:
The examples listed later in this articleSpongebob  #  tclsh
will also run in the Mac OS X console window
utility. But in my opinion, life is a lot%  set  myString  "Hello  World!"
easier using the X Windows environment with
multiple terminal windows opened. ThisHello  World!
feature comes in handy when you're testing
multiple network devices simultaneously, such%  puts  $myString
as  in  a  network  system  test environment.
Hello  World!
Emacs  on  Aqua
This code snippet demonstrates how Tcl uses
Many editors are now available for Unixthe set command to assign the string value
environments; the two most prevalent are vi"Hello World!" to the variable myString.
and emacs. The Emacs-on-Aqua utility is aAssigning a "$" in front of the variable,
complementary tool to run with the rootlessmyString, instructs the interpreter that the
XFree86 environment. The Emacs utilityscript is going to reference the value
executes in Mac OS X environment but allowscontained there. In this example, the string
you to easily edit files in the Darwin filevalue is "Hello World!". The puts command
system.writes the value referenced to the terminal
window.
Emacs running native under Mac OS X



1 A B C 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95