The CLI enables a powerful automated test environment through scripting in the TCL language. A recommended updated guide to TCL is "The Tcl Programming Language: A Comprehensive Guide by Ashok P. Nadkarni (ISBN: 9781548679644)". Note that HammerDB v5.0 supports TCL 9 and an updated guide of this book for TCL 9 is expected and would be recommended for HammerDB v5.0.
The following example shows an automated test script for a Microsoft SQL Server database that has previously been created. In this example the script runs a timed tests for a duration of a minute for 1, 2 and 4 Virtual Users in a similar manner to autopilot functionality with a timer set to run for 2 minutes. Note that the previous runtimer command has been deprecated.
#!/usr/bin/tclsh puts "SETTING CONFIGURATION" dbset db mssqls diset tpcc mssqls_driver timed diset tpcc mssqls_rampup 0 diset tpcc mssqls_duration 1 vuset logtotemp 1 loadscript puts "SEQUENCE STARTED" foreach z { 1 2 4 } { puts "$z VU TEST" vuset vu $z vucreate vurun vudestroy } puts "TEST SEQUENCE COMPLETE"
Run the hammerdbcli command and at the prompt type source and the name of the script. The following output is produced without further intervention whilst also writing the output to the logfile.
C:\Program Files\HammerDB-5.0>hammerdbcli.exe HammerDB CLI v5.0 Copyright © HammerDB Ltd hosted by tpc.org 2019-2025 Type "help" for a list of commands Initialized Jobs on-disk database C:/temp/hammer.DB using existing tables (258,048 bytes) hammerdb>source cliexample.tcl SETTING CONFIGURATION Database set to MSSQLServer Value timed for tpcc:mssqls_driver is the same as existing value timed, no change made Changed tpcc:mssqls_rampup from 1 to 0 for MSSQLServer Changed tpcc:mssqls_duration from 3 to 1 for MSSQLServer Script loaded, Type "print script" to view SEQUENCE STARTED 1 VU TEST Vuser 1 created MONITOR - WAIT IDLE Vuser 2 created - WAIT IDLE Logging activated to C:/temp/hammerdb.log 2 Virtual Users Created with Monitor VU Vuser 1:RUNNING Vuser 1:DBVersion:16.0.1135.2 Vuser 1:Beginning rampup time of 0 minutes Vuser 1:Rampup complete, Taking start Transaction Count. Vuser 1:Timing test period of 1 in minutes Vuser 2:RUNNING Vuser 2:Processing 10000000 transactions with output suppressed... Vuser 1:1 ..., Vuser 1:Test complete, Taking end Transaction Count. Vuser 1:1 Active Virtual Users configured Vuser 1:TEST RESULT : System achieved 121771 NOPM from 283024 SQL Server TPM Vuser 1:FINISHED SUCCESS Vuser 2:FINISHED SUCCESS ALL VIRTUAL USERS COMPLETE vudestroy success 2 VU TEST Vuser 1 created MONITOR - WAIT IDLE Vuser 2 created - WAIT IDLE Vuser 3 created - WAIT IDLE Logging activated to C:/temp/hammerdb.log 3 Virtual Users Created with Monitor VU Vuser 1:RUNNING Vuser 1:DBVersion:16.0.1135.2 Vuser 1:Beginning rampup time of 0 minutes Vuser 1:Rampup complete, Taking start Transaction Count. Vuser 1:Timing test period of 1 in minutes Vuser 2:RUNNING Vuser 2:Processing 10000000 transactions with output suppressed... Vuser 3:RUNNING Vuser 3:Processing 10000000 transactions with output suppressed... Vuser 1:1 ..., Vuser 1:Test complete, Taking end Transaction Count. Vuser 1:2 Active Virtual Users configured Vuser 1:TEST RESULT : System achieved 177765 NOPM from 413812 SQL Server TPM Vuser 1:FINISHED SUCCESS Vuser 2:FINISHED SUCCESS Vuser 3:FINISHED SUCCESS ALL VIRTUAL USERS COMPLETE vudestroy success 4 VU TEST Vuser 1 created MONITOR - WAIT IDLE Vuser 2 created - WAIT IDLE Vuser 3 created - WAIT IDLE Vuser 4 created - WAIT IDLE Vuser 5 created - WAIT IDLE Logging activated to C:/temp/hammerdb.log 5 Virtual Users Created with Monitor VU Vuser 1:RUNNING Vuser 1:DBVersion:16.0.1135.2 Vuser 1:Beginning rampup time of 0 minutes Vuser 1:Rampup complete, Taking start Transaction Count. Vuser 1:Timing test period of 1 in minutes Vuser 2:RUNNING Vuser 2:Processing 10000000 transactions with output suppressed... Vuser 3:RUNNING Vuser 3:Processing 10000000 transactions with output suppressed... Vuser 4:RUNNING Vuser 4:Processing 10000000 transactions with output suppressed... Vuser 5:RUNNING Vuser 5:Processing 10000000 transactions with output suppressed... Vuser 1:1 ..., Vuser 1:Test complete, Taking end Transaction Count. Vuser 1:4 Active Virtual Users configured Vuser 1:TEST RESULT : System achieved 198787 NOPM from 462298 SQL Server TPM Vuser 1:FINISHED SUCCESS Vuser 3:FINISHED SUCCESS Vuser 2:FINISHED SUCCESS Vuser 5:FINISHED SUCCESS Vuser 4:FINISHED SUCCESS ALL VIRTUAL USERS COMPLETE vudestroy success TEST SEQUENCE COMPLETE hammerdb>
It is a common requirement to also want to drive HammerDB CLI scripts from an external scripting tool. The HammerDB CLI will accept the argument auto to run a specified script automatically by default expecting a filename with a .tcl extension and Tcl syntax.
hammerdbcli auto autorunbuild.tcl