about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2014-12-10 17:28:33 +0100
committerCamille Mougey <camille.mougey@cea.fr>2014-12-10 17:28:33 +0100
commit03759804c045e68602df5ada8db12ff74d1bf784 (patch)
tree48170970b2c0fd5bfa982ecbae837723b195492b
parent40f926bf7bc78a62a63960276907b200088b91df (diff)
downloadmiasm-03759804c045e68602df5ada8db12ff74d1bf784.tar.gz
miasm-03759804c045e68602df5ada8db12ff74d1bf784.zip
Example: Add an example for ExprRandom
Diffstat (limited to '')
-rw-r--r--example/expression/expr_random.py30
-rw-r--r--test/test_all.py1
2 files changed, 31 insertions, 0 deletions
diff --git a/example/expression/expr_random.py b/example/expression/expr_random.py
new file mode 100644
index 00000000..1d399091
--- /dev/null
+++ b/example/expression/expr_random.py
@@ -0,0 +1,30 @@
+import string
+
+from miasm2.expression.expression_helper import ExprRandom
+
+print "Simple expression generator\n"
+
+depth = 8
+print "- An ID:"
+print ExprRandom.identifier()
+print "- A number:"
+print ExprRandom.number()
+
+print "- 3 expressions (without cleaning expression cache):"
+for i in xrange(3):
+    print "\t%s\n" % ExprRandom.get(depth=depth, clean=False)
+
+class ExprRandom_NoPerfect_NoReuse_UppercaseIdent(ExprRandom):
+    """ExprRandom extension with:
+     - perfect tree disabled
+     - element reuse disabled
+     - identifiers uppercased
+     """
+
+    perfect_tree = False
+    reuse_element = False
+    identifier_charset = string.uppercase
+
+print "- 3 expressions with a custom generator:"
+for i in xrange(3):
+    print "\t%s\n" % ExprRandom_NoPerfect_NoReuse_UppercaseIdent.get(depth=depth)
diff --git a/test/test_all.py b/test/test_all.py
index 0c49f264..efc5ebc6 100644
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -153,6 +153,7 @@ for script in [["symbol_exec.py"],
                ["expression/simplification_tools.py"],
                ["expression/expr_grapher.py"],
                ["expression/simplification_add.py"],
+               ["expression/expr_random.py"],
                ]:
     testset += Example(script)
 ## Jitter