[Cryptech-Commits] [sw/stm32] branch master updated: Script to run a test with HSM profiling.
git at cryptech.is
git at cryptech.is
Sun May 27 22:28:04 UTC 2018
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch master
in repository sw/stm32.
The following commit(s) were added to refs/heads/master by this push:
new 49939b9 Script to run a test with HSM profiling.
49939b9 is described below
commit 49939b9954926ccb4b31238ab186693c28fab5c5
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Sun May 27 18:27:42 2018 -0400
Script to run a test with HSM profiling.
---
libraries/libprof/profile-runner.py | 73 +++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/libraries/libprof/profile-runner.py b/libraries/libprof/profile-runner.py
new file mode 100755
index 0000000..e7ec55f
--- /dev/null
+++ b/libraries/libprof/profile-runner.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+
+"""
+Tool to run some test code under the profiler on the Cryptech Alpha.
+
+This assumes that the HSM code was built with DO_PROFILING=1, and
+requires an ST-LINK programmer and the Python pexpect package.
+"""
+
+import subprocess
+import argparse
+import pexpect
+import atexit
+import time
+import sys
+import os
+
+parser = argparse.ArgumentParser(description = __doc__,
+ formatter_class = argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument("--hsm-elf",
+ default = os.path.expanduser("~/git.cryptech.is/sw/stm32/projects/hsm/hsm.elf"),
+ help = "where you keep the profiled hsm.elf binary")
+parser.add_argument("--openocd-config",
+ default = "/usr/share/openocd/scripts/board/st_nucleo_f401re.cfg",
+ help = "OpenOCD ST-LINK configuration file ")
+parser.add_argument("--gmon-output",
+ default = "profile-runner.gmon",
+ help = "where to leave raw profiler output")
+parser.add_argument("--gprof-output", type = argparse.FileType("w"),
+ default = "profile-runner.gprof",
+ help = "where to leave profiler output after processing with gprof")
+parser.add_argument("--user",
+ default = "wheel",
+ help = "user name for logging in on the HSM console")
+parser.add_argument("--pin",
+ default = "fnord",
+ help = "PIN for logging in on the HSM console")
+parser.add_argument("command", nargs = 1,
+ help = "test program to run with profiling")
+parser.add_argument("arguments", nargs = argparse.REMAINDER,
+ help = argparse.SUPPRESS)
+args = parser.parse_args()
+
+openocd = subprocess.Popen(("openocd", "-f", args.openocd_config))
+atexit.register(openocd.terminate)
+
+time.sleep(5)
+
+telnet = pexpect.spawn("telnet localhost 4444")
+telnet.expect(">")
+telnet.sendline("arm semihosting enable")
+telnet.expect(">")
+telnet.sendline("exit")
+
+console = pexpect.spawn("cryptech_console")
+console.sendline("")
+if console.expect(["cryptech>", "Username:"]):
+ console.sendline(args.user)
+ console.expect("Password:")
+ console.sendline(args.pin)
+ console.expect("cryptech>")
+console.sendline("profile start")
+console.expect("cryptech>")
+
+cmd = args.command + args.arguments
+sys.stderr.write("Running command: {}\n".format(" ".join(cmd)))
+subprocess.check_call(cmd)
+
+console.sendline("profile stop")
+console.expect("cryptech>", timeout = 900)
+os.rename("gmon.out", args.gmon_output)
+
+subprocess.check_call(("gprof", args.hsm_elf, args.gmon_output), stdout = args.gprof_output)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Commits
mailing list