This adds the first unit test to python-linux-procfs
It adds the bitmasklist_test for testing the function bitmasklist, which
is called by parse_affinity. Unlike parse_affinity, the number of cpus
is not detected, so the unit test can simulate different numbers of
cpus.
This is an expanded form of a reproducer from Jozef Bacik from
Bugzilla 1365902
If we add more unit tests in the future (we should), then we can
consider some kind of python package scheme, but for now this can live
in the base directory.
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
bitmasklist_test.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100755 bitmasklist_test.py
diff --git a/bitmasklist_test.py b/bitmasklist_test.py
new file mode 100755
index 000000000000..4fa9cc41205b
--- /dev/null
+++ b/bitmasklist_test.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+from procfs import bitmasklist
+
+class bitmasklist_test:
+ # Assume true (passed) until proven false
+ # Many tests can be run, but just one failure is recorded overall here
+ unit_test_result = 0; # Assume true (passed) until proven false
+
+ def __init__(self, line, nr_entries, expected_result):
+ self.result = 0; # Assume pass
+ self.line = line
+ self.nr_entries = nr_entries # Corresponds to the number of cpus
+ self.expected_result = expected_result
+
+ # A failure in any single test is recorded as an overall failure
+ def set_unit_test_result(self):
+ if bitmasklist_test.unit_test_result == 1:
+ return
+ if self.result == 1:
+ bitmasklist_test.unit_test_result = 1
+ return
+
+ # This is the function that actually runs the test
+ def bitmasklist_test(self):
+ print "\n##################\n"
+ cpu = bitmasklist(self.line, self.nr_entries)
+ print "Converted : ", self.line, "\nto ", cpu
+ if cpu == self.expected_result:
+ self.result = 0
+ print "PASS"
+ else:
+ self.result = 1
+ print "expected : ", self.expected_result
+ print "FAIL"
+ self.set_unit_test_result()
+
+# CPU 2
+t = \
+ bitmasklist_test("00000000,00000000,00000000,00000000,00000000,00000004", 44, [2])
+t.bitmasklist_test()
+
+# CPU 34
+t = \
+ bitmasklist_test("00000000,00000000,00000000,00000000,00000004,00000000", 44, [34])
+t.bitmasklist_test()
+
+# CPU 30
+t = \
+ bitmasklist_test("00000000,00000000,00000000,00000000,00000000,40000000", 44, [30])
+t.bitmasklist_test()
+
+# CPU 0, 32
+t = \
+ bitmasklist_test("00000000,00000000,00000000,00000000,00000001,00000001", 44, [0,32])
+t.bitmasklist_test()
+
+# cpu 0-15
+t = \
+ bitmasklist_test("ffff", 44, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
+t.bitmasklist_test()
+
+#cpu 0-71
+t = \
+ bitmasklist_test("ff,ffffffff,ffffffff", 96, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,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])
+t.bitmasklist_test()
+
+exit(bitmasklist_test.unit_test_result)
--
2.4.11