]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/tests/TestDhv/gentest.py
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / tests / TestDhv / gentest.py
diff --git a/apps/tests/TestDhv/gentest.py b/apps/tests/TestDhv/gentest.py
new file mode 100644 (file)
index 0000000..ff3e217
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys
+import re
+import os
+import random
+
+print "Usage: python gentest.py [numitems] [newitems]"
+
+items = sys.argv[1]
+newitems = sys.argv[2]
+
+print "Generating Configurations"
+
+fin = open("TestDhvC-Master.nc", "r")
+fout = open("TestDhvC.nc", "w")
+lines = fin.readlines()
+for line in lines:
+    if(line.find("... DISSEMINATORS") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  components new DisseminatorC(uint16_t, ")
+            fout.write(str(i))
+            fout.write(") as Dissem" + str(i) + ";\n")
+            fout.write("  TestDhvP.DisseminationUpdate" + str(i))
+            fout.write(" -> Dissem" + str(i) + ";\n")
+            fout.write("  TestDhvP.DisseminationValue" + str(i))
+            fout.write(" -> Dissem" + str(i) + ";\n\n")
+    else:
+        fout.write(line)
+
+fin.close()
+fout.close()
+
+print "Generating Modules"
+
+fin = open("TestDhvP-Master.nc", "r")
+fout = open("TestDhvP.nc", "w")
+lines = fin.readlines()
+for line in lines:
+    if(line.find("... INTERFACES") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  uses interface DisseminationUpdate<uint16_t> as DisseminationUpdate")
+            fout.write(str(i) + ";\n")
+            fout.write("  uses interface DisseminationValue<uint16_t> as DisseminationValue")
+            fout.write(str(i) + ";\n\n")
+    elif(line.find("... NEWCOUNT") != -1):
+        fout.write("  uint8_t newCount = " + str(newitems) + ";\n")
+    elif(line.find("... CHANGES") != -1):
+        for i in random.sample(range(1, int(items)+1), int(newitems)):
+            fout.write("      call DisseminationUpdate" + str(i) + ".change(&data);\n")
+    elif(line.find("... EVENTS") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  event void DisseminationValue" + str(i))
+            fout.write(".changed() {\n")
+            fout.write("    uint16_t val = *(uint16_t*) call DisseminationValue" + str(i) + ".get();\n")
+            fout.write("    if(val != 0xBEEF) { return; }\n")
+            fout.write("    bookkeep();\n")
+            fout.write("  }\n\n")
+    else:
+        fout.write(line)
+